Tricky reasnong problem for SPARQL and OWL: Lists of property chains containing numerical value constraints

EDIT (19/2): The problem with doing this with a SPARQL query, is now solved! See this blog post.


Thought I should write up on my NMRSpectrum similarity search problem, which I've got quite stuck with ... even after trying to get some advice from Semantic Overflow. So ... here we go.


I have a problem that I can't seem to express successfully in either pure SPARQL nor using OWL class descriptions, seemingly because the problem combines lists, property chains, and numerical value constraints, in a troublesome mix.

The concrete example problem

You have a database of (nmr) spectra which each holds a (varying) number of peaks (= the list), where each peak has one shift, which is of numerical (decimal) type.

Say now that you have an unknown spectra, for which you have just a list of shift values, and you want to do a similarity search against the database, in order to identify the unknown spectra from known examples.

In practice, using the list of shift values for the unknown spectrum, you want to find all spectra which - for each shift value in the list - contains at least one peak with a shift value close enough to that value (within a specified limit).

How to do it in Prolog

In Prolog I could implement it as a "procedure" which goes through the list of values, and for each value does a comparison to all the spectras' peaks' values.
'

Whenever it finds that one of the values of the list has no counterpart in the current spectrum, it skips that spectrum and continues by testing another spectrum.

Whenever it finds a matching (within a range) shift value of a peak of a spectrum, it continues to check the other peaks in the spectrum. If all the values in the list has counterparts in the peaks' shifts' of the spectrum, the spectrum will be added to the results.

Problem with SPARQL

The above I can't seem to express in SPARQL though, since both value comparison and operating on lists, seem problem-prone:

Value comparison

AFAIK, the only way to do value comparison is in the FILTER construct, which happens too late, since I need to do the value comparison for each of the peaks separately, so that I can make sure that only those spectra for which ALL the given values found corresponding peaks, are returned.

Operating on lists

...and the need to treat each peak separately makes me need to receive the peaks of each spectrum as a list or set. (I can't just go on and pick up a peak over and over, (using something like ?spectrum nmr:hasPeak ?peak), since it will take the same peak over and over!). I don't know of any way to receive and store a list of properties, in SPARQL, but maybe I have missed something?

What about OWL?

In OWL, there is the ability to value restrictions, by using a combination of owl:Restriction, owl:SomeValuesFrom, xsd:minExclusive and xsd:maxExclusive, as pointed out by Kendall Clark on the pellet-users mailing list, in a message from 1/11/2010 (Title: "SPARQL sugar in Pellet 2.1").

But then representing a spectrum class with a list of property chains (peaks having shift values), with each shift value belonging to some of a number of numerical ranges (the unknown spectrum's shift values + proximity limit), becomes quite a daunting task ... and I can't really get clear about whether it is not possible at all, or if it is just me who don't see how to do it.

Any hints are welcome