Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/03-apis/api-v2/query-language.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/05-internals/design/api-v2/gravsearch.md
Expand Up @@ -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.
Expand Down
113 changes: 113 additions & 0 deletions test_data/all_data/beol-data.ttl
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +196,91 @@
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:hasSubject <http://rdfh.ch/0801/XNn6wanrTHWShGTjoULm5g/values/YdnovfaXRnW4c5qO7h02Ag>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the statement with a 'hasSubject' because if not this test letter will appear in the visualizations of the BEOL subject index and their respective letters.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is test data. Why would it be used on the BEOL live server?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beol-data.ttl is not a pure test data. It contains subject index definition as list nodes, etc. The imported BEOL data and the data in this file are combined and made available on production server. for example, you can see that test letter defined in this file has ended up on Beol production server.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but that doesn't seem right to me, because there are already fake letters in beol-data.ttl. Wouldn't it be better to make two files, to separate the real data from the test data?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the hasSubject in 99d13d1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but that doesn't seem right to me, because there are already fake letters in beol-data.ttl. Wouldn't it be better to make two files, to separate the real data from the test data?

It would have been, but never happened!

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/YdnovfaXRnW4c5qO7h02Ag> a knora-base:ListValue;
knora-base:valueHasUUID "YdnovfaXRnW4c5qO7h02Ag"^^xsd:string;
knora-base:attachedToUser <http://rdfh.ch/users/PSGbemdjZi4kQ6GHJVkLGF>;
knora-base:hasPermissions "CR knora-admin:Creator|V knora-admin:UnknownUser";
knora-base:isDeleted false;
knora-base:valueCreationDate "2020-09-18T10:46:06.442289Z"^^xsd:dateTime;
knora-base:valueHasListNode <http://rdfh.ch/lists/0801/dragging_motion_pursuit_curves_tractrix_construction>;
knora-base:valueHasOrder 0;
knora-base:valueHasString "http://rdfh.ch/lists/0801/logarithmic_curves" .

<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;
Expand Down
126 changes: 126 additions & 0 deletions test_data/searchR2RV2/LetterNotToSelf.jsonld
@@ -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#"
}
}