Skip to content

Commit bbfb2e8

Browse files
Merge pull request #35 from OwnYourData/bugfix_deletion_orginal_attributes
Removal of original data works for object and normal attributes
2 parents c86a141 + a896233 commit bbfb2e8

1 file changed

Lines changed: 17 additions & 34 deletions

File tree

src/main/java/com/example/anonymization/data/QueryBuildingService.java

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,6 @@ static ParameterizedSparqlString createDataModelQuery(
4646
}
4747

4848
static ParameterizedSparqlString createAttributeOrderQuery(Resource attribute) {
49-
/*
50-
SELECT ?pos ?value
51-
WHERE {
52-
# You know this subject (replace _:b0 with your actual subject IRI/variable)
53-
_:b0 soya:attributeOrder ?head .
54-
55-
# Each cell of the RDF list and its value
56-
?head rdf:rest* ?cell .
57-
?cell rdf:first ?value .
58-
59-
# Compute the position of each cell in the list
60-
{
61-
SELECT ?cell (COUNT(?mid) AS ?pos)
62-
WHERE {
63-
# ?head is taken from the outer query (correlated subquery)
64-
?head rdf:rest* ?mid .
65-
?mid rdf:rest* ?cell .
66-
}
67-
GROUP BY ?cell
68-
}
69-
}
70-
ORDER BY ?pos
71-
*/
7249
String queryString = """
7350
PREFIX soya: <https://w3id.org/soya/ns#>
7451
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@@ -120,22 +97,28 @@ static ParameterizedSparqlString createPropertyQuery(Set<Property> configs, Reso
12097

12198
static ParameterizedSparqlString deleteOriginalPropertyQuery(Set<Property> properties, Resource objectType) {
12299
ParameterizedSparqlString queryString = new ParameterizedSparqlString();
100+
123101
queryString.append("DELETE {\n");
124-
for (int i = 0; i < properties.size(); i++) {
125-
queryString.append(" ?object ?p" + i + " ?v" + i + " .\n");
126-
queryString.append(" ?v" + i + " ?p ?o . \n");
127-
}
128-
queryString.append("}\nWHERE {\n");
102+
queryString.append(" ?object ?prop ?value .\n");
103+
queryString.append(" ?value ?p ?o .\n");
104+
queryString.append("}\n");
105+
queryString.append("WHERE {\n");
129106
queryString.append(" ?object a ?type .\n");
130-
int i = 0;
107+
queryString.append(" ?object ?prop ?value .\n");
108+
109+
// Restrict ?prop to the given properties
110+
queryString.append(" VALUES ?prop {\n");
131111
for (Property property : properties) {
132-
queryString.append(" OPTIONAL { ?object ?p" + i + " ?v" + i + " .\n");
133-
queryString.append(" ?v" + i + " ?p ?o . } \n");
134-
queryString.setParam("p" + i, property);
135-
i++;
112+
queryString.append(" <"+property.getURI()+">\n");
136113
}
137-
queryString.append("}");
114+
queryString.append(" }\n");
115+
116+
// Optionally delete triples where the value is a subject
117+
queryString.append(" OPTIONAL { ?value ?p ?o . }\n");
118+
queryString.append("}\n");
119+
138120
queryString.setParam("type", objectType);
121+
139122
return queryString;
140123
}
141124

0 commit comments

Comments
 (0)