It's much easier to work with SELECT to getthe right variables, then add
the CONSTRUCT.
prefix code: <http://example.org/code/>
prefix ce: <http://example.org/codedentity/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
FROM NAMED <g1.n3>
FROM NAMED <g2.n3>
{
GRAPH <g2.n3> { ?code code:classifies ?ref1 }
FILTER NOT EXISTS { GRAPH <g1.n3> { ?code code:classifies ?ref2 } }
}
I still not sure what you mean by "code" but if we're ignoring the ce:
classifier then the query above returns:
-------------------------
| code | ref1 |
=========================
| code:cca | ce:5541-32 |
| code:nff | ce:1221-32 |
-------------------------
so that gets the ?code
Add a CONSTRUCT:
prefix code: <http://example.org/code/>
prefix ce: <http://example.org/codedentity/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?code ?p ?x . ?ce2 ?r ?y .
}
FROM NAMED <g1.n3>
FROM NAMED <g2.n3>
{
GRAPH <g2.n3> { ?code2 code:classifies ?ref }
FILTER NOT EXISTS { GRAPH <g1.n3> { ?code1 code:classifies ?ref } }
# Look again to get the data needed for the construct template.
GRAPH <g2.n3>
{ ?code code:classifies ?ce2 .
?ce2 ?r ?y. ?code ?p ?x }
}
---------------------------------------------
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix code: <http://example.org/code/> .
@prefix ce: <http://example.org/codedentity/> .
code:cca code:classifies ce:5541-32 .
ce:1221-32 rdfs:label "1221-32" .
code:nff code:classifies ce:1221-32 .
ce:5541-32 rdfs:label "5541-32" .
---------------------------------------------
I don't see why "nff" should be in the results.
We have:
ce:nff rdfs:label "nff" .
but ce:nff isn't connected to a triple with code:classifies -- are the
code:nff and ce:nff mixed up?
Andy
On 14/05/14 15:52, Leo Papa wrote:
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> <http://example.org/g1%3E>
|
|{ ?codeG1 <http://example.org/code/classifies>
<http://example.org/code/classifies%3E> ?ce1}
|
|GRAPH <http://example.org/g2> <http://example.org/g2%3E>
|
|{ ?codeG2 <http://example.org/code/classifies>
<http://example.org/code/classifies%3E> ?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/> <http://example.org/code/%3E> .
|
|@prefix ce: <http://example.org/codedentity/>
<http://example.org/codedentity/%3E> .
|
|@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
<http://www.w3.org/2000/01/rdf-schema#%3E> .|
|
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 lot
|
|