On Wed, May 29, 2013 at 1:19 AM, Bai Wei <[email protected]> wrote:
> I want to find the cheapest book from some book sellers, so I write one
> rule to compare the price of the same book that is sold by different
> sellers.
>
> For example, there are three sellers. The price for the book "Intro to
> Semantic web" of each seller is 19 , 23 and 17. To find the cheapest one I
> compare them as follows:
>
> First step: min(19,23) ->19 (19 is the current minimum value)
> Second step: min(19, 17) -> 17 (Here we find the cheapest value 17)
>
> The problem I faced is how to pass the variable ?currentmin(19 in the above
> example) to the following rule:
>
> [cheapestbook: (?b rdf:type ex:cheapestbook)
> <-
> (?b rdf:type ex:book)
> (?b ex:hasPrice ?p)
> lessThan(?p, ?currentmin)]
I'd think something like :
[cheapestbook: (?b rdf:type ex:cheapestbook)
<-
(?b rdf:type ex:book)
(?b ex:hasPrice ?p)
lessThan(?p, ?currentmin)
currentMin(?currentmin) ]
would work where currentMin is a custom built-in [1] that you define.
If the value for ?currentmin isn't something that can be computed by
Jena rules, then you don't seem to have another option. You didn't
mention where the value of currentmin came from, after all. If you
can compute it using Jena rules, then you could just write a
corresponding rule
[currentmin: ( ?currentmin 'is' 'currentMin' )
<-
…]
The Jena rules allow patterns that aren't valid RDF, so you have lots
of flexibility in deciding how you want to flag a special value like
?currentMin. (?currentmin 'is' 'currentMin') probably isn't
conventional, but you can really use whatever you want, so long as you
can write a pattern to match against it in the other rules.
Of course, if the value really is fixed, e.g., 19, you can just do:
[cheapestbook: (?b rdf:type ex:cheapestbook)
<-
(?b rdf:type ex:book)
(?b ex:hasPrice ?p)
lessThan(?p, 19) ]
since Jena's rules support numbers.
[1]
http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/reasoner/rulesys/Builtin.html
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/