Skip to content
Permalink
Browse files

feat(gravsearch): Allow comparing variables representing resource IRIs (

  • Loading branch information
benjamingeer committed Sep 22, 2020
1 parent 9069056 commit f359c8e4f3899d6e49dab395055b3bf1297c5766
@@ -649,6 +649,48 @@ except that the first argument is a variable representing a resource:
FILTER knora-api:matchLabel(?book, "Zeitglöcklein")
```

### Filtering on Resource IRIs

A `FILTER` can compare a variable with another variable or IRI
representing a resource. For example, to find a letter whose
author and recipient are different persons:

```
PREFIX beol: <http://0.0.0.0:3333/ontology/0801/beol/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
CONSTRUCT {
?letter knora-api:isMainResource true .
?letter beol:hasAuthor ?person1 .
?letter beol:hasRecipient ?person2 .
} WHERE {
?letter a beol:letter .
?letter beol:hasAuthor ?person1 .
?letter beol:hasRecipient ?person2 .
FILTER(?person1 != ?person2) .
}
OFFSET 0
```

To find a letter whose author is not a person with a specified IRI:

```
PREFIX beol: <http://0.0.0.0:3333/ontology/0801/beol/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
CONSTRUCT {
?letter knora-api:isMainResource true .
?letter beol:hasAuthor ?person1 .
?letter beol:hasRecipient ?person2 .
} WHERE {
?letter a beol:letter .
?letter beol:hasAuthor ?person1 .
?letter beol:hasRecipient ?person2 .
FILTER(?person1 != <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA>) .
}
OFFSET 0
```

### CONSTRUCT Clause

In the `CONSTRUCT` clause of a Gravsearch query, the variable representing the
@@ -153,8 +153,8 @@ The classes involved in generating prequeries can be found in `org.knora.webapi.
If the client submits a count query, the prequery returns the overall number of hits, but not the results themselves.

In a first step, before transforming the WHERE clause, query patterns must be further optimised by removing
the `rdfs:type` statement for entities whose type could be inferred from a property since there would be no need
for explicit `rdfs:type` statements for them (unless the property from which the type of an entity must be inferred from
the `rdfs:type` statement for entities whose type could be inferred from their use with a property IRI, since there would be no need
for explicit `rdfs:type` statements for them (unless the property IRI from which the type of an entity must be inferred from
is wrapped in an `OPTIONAL` block). This optimisation takes the Gravsearch query as input (rather than the generated SPARQL),
because it uses type information that refers to entities in the Gravsearch query, and the generated SPARQL might
have different entities.
@@ -65,6 +65,34 @@
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA> a beol:person;
rdfs:label "Testperson3";
knora-base:isDeleted false;
knora-base:attachedToProject <http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF>;
knora-base:creationDate "2020-09-21T07:14:09.621165Z"^^xsd:dateTime;
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF>;
beol:hasGivenName <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA/values/R0yqYbumTD-R7wA3U57ndQ>;
beol:hasFamilyName <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA/values/Eaj-gUutRpONYPetDp-SyQ> .

<http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA/values/Eaj-gUutRpONYPetDp-SyQ> a knora-base:TextValue;
knora-base:valueHasUUID "Eaj-gUutRpONYPetDp-SyQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2020-09-21T07:14:09.621165Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "Hummel";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA/values/R0yqYbumTD-R7wA3U57ndQ> a knora-base:TextValue;
knora-base:valueHasUUID "R0yqYbumTD-R7wA3U57ndQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2020-09-21T07:14:09.621165Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "Johann Nepomuk";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA> a beol:letter;
rdfs:label "Testbrief1";
knora-base:isDeleted false;
@@ -168,6 +196,80 @@
knora-base:hasPermissions "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g> a beol:letter;
rdfs:label "letter to self";
knora-base:isDeleted false;
knora-base:attachedToProject <http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF>;
knora-base:creationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF>;
beol:title <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/jGtT_87FS2qTkUEigdXMPg>;
beol:creationDate <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/5_JuhLykRBmhJs_b9X0qhg>;
beol:hasAuthor <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA>;
beol:hasAuthorValue <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/b5JkQWJEQz6V-Spue9TqGA>;
beol:hasRecipient <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA>;
beol:hasRecipientValue <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/HqYA8dx1QzGzb9hqZNLDzA>;
beol:hasText <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/xFaiZnw4RH-ES-eovy_FgQ> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/xFaiZnw4RH-ES-eovy_FgQ> a knora-base:TextValue;
knora-base:valueHasUUID "xFaiZnw4RH-ES-eovy_FgQ"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueHasMaxStandoffStartIndex "1"^^xsd:nonNegativeInteger;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "I am writing this to myself.";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/b5JkQWJEQz6V-Spue9TqGA> a knora-base:LinkValue;
knora-base:valueHasUUID "Cvp07eTqQQSnYdcvqlWW_g"^^xsd:string;
knora-base:isDeleted false;
rdf:subject <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g>;
rdf:predicate beol:hasAuthor;
rdf:object <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA>;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasRefCount 1;
knora-base:valueHasString "http://rdfh.ch/0801/VvYVIy-FSbOJBsh2d9ZFJw";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/HqYA8dx1QzGzb9hqZNLDzA> a knora-base:LinkValue;
knora-base:valueHasUUID "HqYA8dx1QzGzb9hqZNLDzA"^^xsd:string;
knora-base:isDeleted false;
rdf:subject <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g>;
rdf:predicate beol:hasRecipient;
rdf:object <http://rdfh.ch/0801/F4n1xKa3TCiR4llJeElAGA>;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasRefCount 1;
knora-base:valueHasString "http://rdfh.ch/0801/VvYVIy-FSbOJBsh2d9ZFJw";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/5_JuhLykRBmhJs_b9X0qhg> a knora-base:DateValue;
knora-base:valueHasUUID "5_JuhLykRBmhJs_b9X0qhg"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasCalendar "GREGORIAN";
knora-base:valueHasEndJDN 2458274;
knora-base:valueHasEndPrecision "DAY";
knora-base:valueHasOrder 0;
knora-base:valueHasStartJDN 2458274;
knora-base:valueHasStartPrecision "DAY";
knora-base:valueHasString "2018-06-04 CE";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/jGtT_87FS2qTkUEigdXMPg> a knora-base:TextValue;
knora-base:valueHasUUID "jGtT_87FS2qTkUEigdXMPg"^^xsd:string;
knora-base:isDeleted false;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasOrder 0;
knora-base:valueHasString "letter to self";
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF> .

<http://rdfh.ch/0801/letter_resource> a beol:letter;
rdfs:label "Test letter";
knora-base:isDeleted false;
@@ -0,0 +1,126 @@
{
"@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA",
"@type" : "beol:letter",
"beol:hasAuthorValue" : {
"@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA/values/Cvp07eTqQQSnYdcvqlWW_g",
"@type" : "knora-api:LinkValue",
"knora-api:arkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD/Cvp07eTqQQSnYdcvqlWW_gI"
},
"knora-api:attachedToUser" : {
"@id" : "http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF"
},
"knora-api:hasPermissions" : "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser",
"knora-api:linkValueHasTarget" : {
"@id" : "http://rdfh.ch/0801/VvYVIy-FSbOJBsh2d9ZFJw",
"@type" : "beol:person",
"knora-api:arkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/VvYVIy=FSbOJBsh2d9ZFJwi"
},
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF"
},
"knora-api:attachedToUser" : {
"@id" : "http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF"
},
"knora-api:creationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-06-04T08:56:22.513Z"
},
"knora-api:hasPermissions" : "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser",
"knora-api:userHasPermission" : "RV",
"knora-api:versionArkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/VvYVIy=FSbOJBsh2d9ZFJwi.20180604T085622513Z"
},
"rdfs:label" : "Testperson2"
},
"knora-api:userHasPermission" : "RV",
"knora-api:valueCreationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-06-04T08:56:33.879Z"
},
"knora-api:valueHasUUID" : "Cvp07eTqQQSnYdcvqlWW_g",
"knora-api:versionArkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD/Cvp07eTqQQSnYdcvqlWW_gI.20180604T085633879Z"
}
},
"beol:hasRecipientValue" : {
"@id" : "http://rdfh.ch/0801/_B3lQa6tSymIq7_7SowBsA/values/DVqPKuBBSIauVqjUC7bNvA",
"@type" : "knora-api:LinkValue",
"knora-api:arkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD/DVqPKuBBSIauVqjUC7bNvAe"
},
"knora-api:attachedToUser" : {
"@id" : "http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF"
},
"knora-api:hasPermissions" : "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser",
"knora-api:linkValueHasTarget" : {
"@id" : "http://rdfh.ch/0801/H7s3FmuWTkaCXa54eFANOA",
"@type" : "beol:person",
"knora-api:arkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/H7s3FmuWTkaCXa54eFANOAd"
},
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF"
},
"knora-api:attachedToUser" : {
"@id" : "http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF"
},
"knora-api:creationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-06-04T08:55:34.086Z"
},
"knora-api:hasPermissions" : "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser",
"knora-api:userHasPermission" : "RV",
"knora-api:versionArkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/H7s3FmuWTkaCXa54eFANOAd.20180604T085534086Z"
},
"rdfs:label" : "Testperson1"
},
"knora-api:userHasPermission" : "RV",
"knora-api:valueCreationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-06-04T08:56:33.879Z"
},
"knora-api:valueHasUUID" : "DVqPKuBBSIauVqjUC7bNvA",
"knora-api:versionArkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD/DVqPKuBBSIauVqjUC7bNvAe.20180604T085633879Z"
}
},
"knora-api:arkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD"
},
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/yTerZGyxjZVqFMNNKXCDPF"
},
"knora-api:attachedToUser" : {
"@id" : "http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF"
},
"knora-api:creationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2018-06-04T08:56:33.879Z"
},
"knora-api:hasPermissions" : "CR knora-admin:Creator|M knora-admin:ProjectMember|V knora-admin:KnownUser|RV knora-admin:UnknownUser",
"knora-api:userHasPermission" : "RV",
"knora-api:versionArkUrl" : {
"@type" : "xsd:anyURI",
"@value" : "http://0.0.0.0:3336/ark:/72163/1/0801/_B3lQa6tSymIq7_7SowBsAD.20180604T085633879Z"
},
"rdfs:label" : "Testbrief1",
"@context" : {
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"beol" : "http://0.0.0.0:3333/ontology/0801/beol/v2#",
"xsd" : "http://www.w3.org/2001/XMLSchema#"
}
}

0 comments on commit f359c8e

Please sign in to comment.