/
isPropertyUsed.scala.txt
51 lines (45 loc) · 1.77 KB
/
isPropertyUsed.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
@*
* Copyright © 2021 Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*@
@import org.knora.webapi.IRI
@*
* Checks whether a property is used (i.e., is the property of any statements).
*
* @param triplestore the name of the triplestore being used.
* @param propertyIri the IRI of the property.
* @param ignoreKnoraConstraints if true, knora-base:subjectClassConstraint and knora-base:objectClassConstraint will be ignored.
* This is necessary when modifying the cardinalities of a class.
* @param ignoreRdfSubjectAndObject if true, rdf:subject and rdf:object will be ignored. This is necessary when checking
* for references to a resource that is to be erased.
*@
@(triplestore: String,
internalPropertyIri: IRI,
internalClassIri: IRI,
ignoreKnoraConstraints: Boolean = false,
ignoreRdfSubjectAndObject: 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 owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
ASK
@* Ensure that inference is not used in this query. *@
@if(triplestore.startsWith("graphdb")) {
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@internalPropertyIri") AS ?property)
BIND(IRI("@internalClassIri") AS ?classIri)
{
# select all items of type classIri with property ?property.
?s ?property ?o .
?s rdf:type ?classIri .
}
UNION {
# select all items belonging to a subclass of classIri and with property ?property.
?s ?property ?o .
?s rdf:type ?class .
?class rdfs:subClassOf* ?classIri .
}
}