/
findLinkValueByObject.scala.txt
83 lines (72 loc) · 2.83 KB
/
findLinkValueByObject.scala.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@*
* Copyright © 2015-2021 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*@
@import org.knora.webapi.IRI
@**
* Looks for a `knora-base:LinkValue` describing a direct link between two resources, returns all information
* about it, and checks whether the direct link also exists.
*
* @param triplestore the name of the triplestore being used.
* @param subjectIri the IRI of the resource that is the source of the link.
* @param predicateIri the IRI of the property that links the two resources.
* @param maybeObjectIri if provided, the IRI of the resource that is the target of the link.
* @param linkValueIri if provided, the IRI of the `LinkValue`.
* @param includeDeleted if true, a `LinkValue` will be returned even if it is deleted. Currently this is
* only for testing purposes.
*@
@(triplestore: String,
subjectIri: IRI,
predicateIri: IRI,
objectIri: IRI,
includeDeleted: Boolean = false)
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix knora-base: <http://www.knora.org/ontology/knora-base#>
SELECT ?linkValue ?directLinkExists ?targetResourceClass ?objPred ?objObj
@* Ensure that inference is not used in this query. *@
@if(triplestore.startsWith("graphdb")) {
FROM <http://www.ontotext.com/explicit>
}
WHERE {
<@subjectIri> <@{predicateIri}Value> ?linkValue .
?linkValue rdf:type knora-base:LinkValue ;
rdf:subject <@subjectIri> ;
rdf:predicate <@predicateIri> ;
rdf:object <@objectIri> .
@if(!includeDeleted) {
FILTER NOT EXISTS {
?linkValue knora-base:isDeleted true ;
}
}
OPTIONAL {
<@subjectIri> <@predicateIri> <@objectIri> .
<@objectIri> rdf:type ?targetResourceClass .
BIND(true AS ?directLinkExists)
}
{
?linkValue ?objPred ?objObj .
FILTER(?objPred != knora-base:attachedToProject)
}
UNION
{
@* Return the project of the resource that contains the value. *@
<@subjectIri> knora-base:attachedToProject ?resourceProject .
BIND(knora-base:attachedToProject AS ?objPred)
BIND(?resourceProject AS ?objObj)
}
}