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