Hello fellas,
I am trying to make my mind around this issue and I still cannot figure it out.
I have Graph g1 (g1.n3 attached) and Graph g2 (g2.n3 attached), where g2 has
the same structure of g1
and share a subset of entities (CODE)
- (code1, code2) in g1
-
(code1, code2, code3, code4) in g2
I create Jena DatasetGraph with g1 and g2 and a query (query.txt attached)
DatasetGraph dsg = DatasetGraphFactory.createMem();
dsg.addGraph("http://example.org/g1", g1);
dsg.addGraph("http://example.org/g2" g2);
QueryExecutionFactory.create(query,DatasetFactory.create(dsg)).execConstruct().getGraph();
I want to achieve a query result that CONSTRUCT the graph/model constraining on
the CODEs in g2 that are not in g1,
hence:
CONSTRUCT { ?codeG2 ?p ?x . ?ce2 ?r ?y . }
WHERE
{ GRAPH <http://example.org/g1>
{ ?codeG1 <http://example.org/code/classifies> ?ce1}
GRAPH <http://example.org/g2>
{ ?codeG2 <http://example.org/code/classifies> ?ce2 .
?ce2 ?r ?y. ?codeG2 ?p ?x }
FILTER(?codeG2 != ?codeG1)
}
The result I expect should be (g_result.n3 attached):
Graph: http://example.org/result
@prefix code: <http://example.org/code/> .
@prefix ce: <http://example.org/codedentity/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .code:nff code:classifies
ce:1221-32.
ce:nff rdfs:label "nff" .
ce:1221-32 rdfs:label "1221-32" .
code:nff a code:Code.
code:cca code:classifies ce:5541-32.
ce:cca rdfs:label "cca" .
ce:5541-32 rdfs:label "5541-32" .code:cca a code:Code.
Instead of the expected/wanted result I have a graph that contains the correct
CONSTRUCT pattern, but does not FILTER according the condition. What's more
weird is that the filter
will work for (?codeG2 = ?codeG1) but not the !=.
Where am I doing it wrong? Someone can try to test this?
Thanks a lotCONSTRUCT { ?codeG2 ?p ?x . ?ce2 ?r ?y . }
WHERE {
GRAPH <http://example.org/g1>
{ ?codeG1 <http://example.org/code/classifies> ?ce1}
GRAPH <http://example.org/g2>
{ ?codeG2 <http://example.org/code/classifies> ?ce2 .
?ce2 ?r ?y. ?codeG2 ?p ?x
}
FILTER(?codeG2 != ?codeG1)
} @prefix code: <http://example.org/code/> .
@prefix ce: <http://example.org/codedentity/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
code:afr code:classifies ce:3455-32.
ce:afr rdfs:label "afr" .
ce:3455-32 rdfs:label "3455-32" .
code:afr a code:Code.
code:tfs code:classifies ce:9983-32.
ce:tfs rdfs:label "tfs" .
ce:9983-32 rdfs:label "9983-32" .
code:tfs a code:Code.
@prefix code: <http://example.org/code/> .
@prefix ce: <http://example.org/codedentity/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
code:afr code:classifies ce:4411-32.
#(notice same CODE BUT DIFFERENT CE from g1)
ce:afr rdfs:label "afr" .
ce:4411-32 rdfs:label "4411-32" .
ce:afr a ce:Code.
code:tfs code:classifies ce:7601-32.
#(notice same CODE BUT DIFFERENT CE from g1)
ce:tfs rdfs:label "tfs" .
ce:7601-32 rdfs:label "7601-32" .
ce:tfs a ce:Code.
code:nff code:classifies ce:1221-32.
ce:nff rdfs:label "nff" .
ce:1221-32 rdfs:label "1221-32" .
ce:nff a ce:Code.
code:cca code:classifies ce:5541-32.
ce:cca rdfs:label "cca" .
ce:5541-32 rdfs:label "5541-32" .
ce:cca a ce:Code
@prefix code: <http://example.org/code/> .
@prefix ce: <http://example.org/codedentity/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
code:nff code:classifies ce:1221-32.
ce:nff rdfs:label "nff" .
ce:1221-32 rdfs:label "1221-32" .
code:nff a code:Code.
code:cca code:classifies ce:5541-32.
ce:cca rdfs:label "cca" .
ce:5541-32 rdfs:label "5541-32" .
code:cca a code:Code.