0

I want to query those persons from RDF graphdatabse who are traveled at the same location and at the same date or ovelapped date. We have persons information with travlel location and their fromdata and todate. I am running the following query in SPARQL it gives correct result.

SPARQL query

SELECT DISTINCT ?p1 ?p2 ?o1 ?o2 ?loc ?fd1 ?td1 ?fd2 ?td2
WHERE {
    ?p1 ns:hasTravelledAt ?o1 .
    ?p2 ns:hasTravelledAt ?o2 .
    ?o1 ns:hasLocation ?loc .
    ?o2 ns:hasLocation ?loc .
    ?o1 ns:fromDate ?fd1 .
    ?o2 ns:fromDate ?fd2 .
    ?o1 ns:toDate ?td1 .
    ?o2 ns:toDate ?td2 .
  FILTER ( (?p1 != ?p2 ) && ( (?fd1 <= ?fd2 && ?fd2 <= ?td1) || (?fd2 <= ?fd1 && ?fd1 <= ?td2) ) )
}

Now I want to write the same query in Prolog but I am having issue with Filter function how can I replace Sparql Filter function in Prolog query: I am trying to run the query as follows: but not getting the result:

(select-distinct (?p1 ?p2 ?o1 ?o2 ?loc ?fd1 ?td1 ?fd2 ?td2)
 (q ?p1 !ns:hasTravelledAt ?o1)
 (q ?p2 !ns:hasTravelledAt ?o2)
 (q ?o1 !ns:hasLocation ?loc)
 (q ?o2 !ns:hasLocation ?loc)
 (q ?o1 !ns:fromDate ?fd1)
 (q ?o2 !ns:fromDate ?fd2) 
 (q ?o1 !ns:toDate ?td1)
 (q ?o2 !ns:toDate ?td2) 
?- (or (and (?fd1 <= fd2) (?fd2 <= ?td1))  (and (?fd2 <= fd1) (?fd1 <= ?td2)) )
(not (= ?p1 ?p2))
 )

Can any one help me? How can I use filter function in prolog query. Thanks

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
user3356568
  • 119
  • 2
  • 14
  • Is it safe to assume that you're using AllegroGraph? The prolog syntax you're using isn't standard prolog, and the only graph database I know of that provides both SPARQL and Prolog interfaces is AllegroGraph (Jena's backwards rule engine is similar, but clearly not what you're using here). – Joshua Taylor Feb 12 '15 at 16:43
  • Yes Joshua, you are right I am using AllegroGraph. – user3356568 Feb 12 '15 at 17:01

0 Answers0