Skip to content

Commit 1ca2f9f

Browse files
committed
Add support for fallback label properties
Some RDFS/OWL vocabulary standards have loose conventions of lexicalization, i.e. there is not a recommendation or adherence to use one label property over another and, sometimes, interchange of properties is common in practice. For e.g., some OWL ontologies may use `skos:prefLabel` alone, or in conjunction with `rdfs:label`. Some other standards like ShACL may see users migrate from `rdfs:label` to `sh:name` during the lifecycle of their projects. We can support such community practice by lifting any (implied) requirement of the _preview property_, and writing queries that use a fallback sequence of label properties in the order `shacl:name`, `skos:prefLabel` and `rdfs:label` -- the main lexicalization we have now. Performance impact of the additional OPTIONALs appear to be neglible on first glance, but a deeper investigation may need to be pursued in case performance issues do crop up at any time after this change. Multilingual use cases also need to be (manually) tested. P.S: The _object preview property_ is out of scope for this change, assuming that such usage is currently isolated to only a select few cases, like SKOS-XL (and SKOS itself has a tighter convention).
1 parent c3d0d5d commit 1ca2f9f

12 files changed

+406
-28
lines changed

dqgen/resources/query_templates/instance_additions.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,25 @@ WHERE {
7070
GRAPH ?insertionsGraph {
7171
?instance a ?class .
7272
{% for lang in languages %}
73-
{% if preview_object_property == "" %}
73+
{% if preview_object_property == "" and preview_property == "" %}
74+
# fall back to known labels if no preview property
75+
optional {
76+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
77+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
78+
}
79+
80+
optional {
81+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
82+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
83+
}
84+
85+
optional {
86+
?instance shacl:name ?shaclName{{lang|title}} .
87+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
88+
}
89+
90+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
91+
{% elif preview_object_property == "" %}
7492
optional {
7593
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
7694
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -84,7 +102,16 @@ WHERE {
84102
{% endif %}
85103
{% endfor %}
86104
{% if languages|length > 1 %}
87-
{% if preview_object_property == "" %}
105+
{% if preview_object_property == "" and preview_property == "" %}
106+
# fall back to alternative labels if no preview property
107+
{
108+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
109+
{
110+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
111+
}
112+
GROUP BY ?instance order by ?prefLabel
113+
}
114+
{% elif preview_object_property == "" %}
88115
{
89116
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
90117
{

dqgen/resources/query_templates/instance_deletions.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,25 @@ WHERE {
8787
?instance a ?class .
8888

8989
{% for lang in languages %}
90-
{% if preview_object_property == "" %}
90+
{% if preview_object_property == "" and preview_property == "" %}
91+
# fall back to known labels if no preview property
92+
optional {
93+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
94+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
95+
}
96+
97+
optional {
98+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
99+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
100+
}
101+
102+
optional {
103+
?instance shacl:name ?shaclName{{lang|title}} .
104+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
105+
}
106+
107+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
108+
{% elif preview_object_property == "" %}
91109
optional {
92110
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
93111
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -101,7 +119,16 @@ WHERE {
101119
{% endif %}
102120
{% endfor %}
103121
{% if languages|length > 1 %}
104-
{% if preview_object_property == "" %}
122+
{% if preview_object_property == "" and preview_property == "" %}
123+
# fall back to alternative labels if no preview property
124+
{
125+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
126+
{
127+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
128+
}
129+
GROUP BY ?instance order by ?prefLabel
130+
}
131+
{% elif preview_object_property == "" %}
105132
{
106133
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
107134
{

dqgen/resources/query_templates/movement_cross_instance.rq

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,25 @@ WHERE {
6666
?newInstance a ?class .
6767
?newInstance ?property ?value .
6868
{% for lang in languages %}
69-
{% if preview_object_property == "" %}
69+
{% if preview_object_property == "" and preview_property == "" %}
70+
# fall back to known labels if no preview property
71+
optional {
72+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
73+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
74+
}
75+
76+
optional {
77+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
78+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
79+
}
80+
81+
optional {
82+
?instance shacl:name ?shaclName{{lang|title}} .
83+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
84+
}
85+
86+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
87+
{% elif preview_object_property == "" %}
7088
optional {
7189
?newInstance {{ preview_property }} ?prefLabel{{lang|title}} .
7290
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -80,7 +98,16 @@ WHERE {
8098
{% endif %}
8199
{% endfor %}
82100
{% if languages|length > 1 %}
83-
{% if preview_object_property == "" %}
101+
{% if preview_object_property == "" and preview_property == "" %}
102+
# fall back to alternative labels if no preview property
103+
{
104+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
105+
{
106+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
107+
}
108+
GROUP BY ?instance order by ?prefLabel
109+
}
110+
{% elif preview_object_property == "" %}
84111
{
85112
SELECT ?newInstance (SAMPLE (?prefLabel) as ?prefLabelRandom)
86113
{
@@ -112,7 +139,25 @@ WHERE {
112139
?oldInstance a ?class .
113140
?oldInstance ?property ?value .
114141
{% for lang in languages %}
115-
{% if preview_object_property == "" %}
142+
{% if preview_object_property == "" and preview_property == "" %}
143+
# fall back to known labels if no preview property
144+
optional {
145+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
146+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
147+
}
148+
149+
optional {
150+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
151+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
152+
}
153+
154+
optional {
155+
?instance shacl:name ?shaclName{{lang|title}} .
156+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
157+
}
158+
159+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?oldPrefLabel{{lang|title}})
160+
{% elif preview_object_property == "" %}
116161
optional {
117162
?oldInstance {{ preview_property }} ?oldPrefLabel{{lang|title}} .
118163
FILTER (lang(?oldPrefLabel{{lang|title}}) = "{{ lang }}")
@@ -126,7 +171,16 @@ WHERE {
126171
{% endif %}
127172
{% endfor %}
128173
{% if languages|length > 1 %}
129-
{% if preview_object_property == "" %}
174+
{% if preview_object_property == "" and preview_property == "" %}
175+
# fall back to alternative labels if no preview property
176+
{
177+
SELECT ?oldInstance (SAMPLE (?prefLabelRd) as ?oldInstancePrefLabelRandom)
178+
{
179+
?oldInstance shacl:name|skos:prefLabel|rdfs:label ?prefLabelRd .
180+
}
181+
GROUP BY ?oldInstance order by ?prefLabelRd
182+
}
183+
{% elif preview_object_property == "" %}
130184
{
131185
SELECT ?oldInstance (SAMPLE (?prefLabelRd) as ?oldInstancePrefLabelRandom)
132186
{

dqgen/resources/query_templates/movement_cross_property.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,25 @@ WHERE {
6565
?instance a ?class .
6666
?instance ?newProperty ?value .
6767
{% for lang in languages %}
68-
{% if preview_object_property == "" %}
68+
{% if preview_object_property == "" and preview_property == "" %}
69+
# fall back to known labels if no preview property
70+
optional {
71+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
72+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
73+
}
74+
75+
optional {
76+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
77+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
78+
}
79+
80+
optional {
81+
?instance shacl:name ?shaclName{{lang|title}} .
82+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
83+
}
84+
85+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
86+
{% elif preview_object_property == "" %}
6987
optional {
7088
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
7189
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -79,7 +97,16 @@ WHERE {
7997
{% endif %}
8098
{% endfor %}
8199
{% if languages|length > 1 %}
82-
{% if preview_object_property == "" %}
100+
{% if preview_object_property == "" and preview_property == "" %}
101+
# fall back to alternative labels if no preview property
102+
{
103+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
104+
{
105+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
106+
}
107+
GROUP BY ?instance order by ?prefLabel
108+
}
109+
{% elif preview_object_property == "" %}
83110
{
84111
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
85112
{

dqgen/resources/query_templates/property_additions.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,25 @@ WHERE {
8888
?instance a ?class .
8989
?instance ?property ?value .
9090
{% for lang in languages %}
91-
{% if preview_object_property == "" %}
91+
{% if preview_object_property == "" and preview_property == "" %}
92+
# fall back to known labels if no preview property
93+
optional {
94+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
95+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
96+
}
97+
98+
optional {
99+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
100+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
101+
}
102+
103+
optional {
104+
?instance shacl:name ?shaclName{{lang|title}} .
105+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
106+
}
107+
108+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
109+
{% elif preview_object_property == "" %}
92110
optional {
93111
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
94112
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -102,7 +120,16 @@ WHERE {
102120
{% endif %}
103121
{% endfor %}
104122
{% if languages|length > 1 %}
105-
{% if preview_object_property == "" %}
123+
{% if preview_object_property == "" and preview_property == "" %}
124+
# fall back to alternative labels if no preview property
125+
{
126+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
127+
{
128+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
129+
}
130+
GROUP BY ?instance order by ?prefLabel
131+
}
132+
{% elif preview_object_property == "" %}
106133
{
107134
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
108135
{

dqgen/resources/query_templates/property_deletions.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,25 @@ WHERE {
8282
?instance a ?class .
8383
?instance ?property ?value .
8484
{% for lang in languages %}
85-
{% if preview_object_property == "" %}
85+
{% if preview_object_property == "" and preview_property == "" %}
86+
# fall back to known labels if no preview property
87+
optional {
88+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
89+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
90+
}
91+
92+
optional {
93+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
94+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
95+
}
96+
97+
optional {
98+
?instance shacl:name ?shaclName{{lang|title}} .
99+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
100+
}
101+
102+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
103+
{% elif preview_object_property == "" %}
86104
optional {
87105
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
88106
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -96,7 +114,16 @@ WHERE {
96114
{% endif %}
97115
{% endfor %}
98116
{% if languages|length > 1 %}
99-
{% if preview_object_property == "" %}
117+
{% if preview_object_property == "" and preview_property == "" %}
118+
# fall back to alternative labels if no preview property
119+
{
120+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
121+
{
122+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
123+
}
124+
GROUP BY ?instance order by ?prefLabel
125+
}
126+
{% elif preview_object_property == "" %}
100127
{
101128
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
102129
{

dqgen/resources/query_templates/property_value_updates.rq

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,25 @@ WHERE {
7474
?instance a ?class .
7575
?instance ?property ?newValue .
7676
{% for lang in languages %}
77-
{% if preview_object_property == "" %}
77+
{% if preview_object_property == "" and preview_property == "" %}
78+
# fall back to known labels if no preview property
79+
optional {
80+
?instance rdfs:label ?rdfsLabel{{lang|title}} .
81+
FILTER(LANG(?rdfsLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?rdfsLabel{{lang|title}}), "{{ lang }}"))
82+
}
83+
84+
optional {
85+
?instance skos:prefLabel ?skosLabel{{lang|title}} .
86+
FILTER(LANG(?skosLabel{{lang|title}}) = "" || LANGMATCHES(LANG(?skosLabel{{lang|title}}), "{{ lang }}"))
87+
}
88+
89+
optional {
90+
?instance shacl:name ?shaclName{{lang|title}} .
91+
FILTER(LANG(?shaclName{{lang|title}}) = "" || LANGMATCHES(LANG(?shaclName{{lang|title}}), "{{ lang }}"))
92+
}
93+
94+
BIND (COALESCE(?shaclName{{lang|title}}, ?skosLabel{{lang|title}}, ?rdfsLabel{{lang|title}}) AS ?prefLabel{{lang|title}})
95+
{% elif preview_object_property == "" %}
7896
optional {
7997
?instance {{ preview_property }} ?prefLabel{{lang|title}} .
8098
FILTER (lang(?prefLabel{{lang|title}}) = "{{ lang }}")
@@ -88,7 +106,16 @@ WHERE {
88106
{% endif %}
89107
{% endfor %}
90108
{% if languages|length > 1 %}
91-
{% if preview_object_property == "" %}
109+
{% if preview_object_property == "" and preview_property == "" %}
110+
# fall back to alternative labels if no preview property
111+
{
112+
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
113+
{
114+
?instance shacl:name|skos:prefLabel|rdfs:label ?prefLabel .
115+
}
116+
GROUP BY ?instance order by ?prefLabel
117+
}
118+
{% elif preview_object_property == "" %}
92119
{
93120
SELECT ?instance (SAMPLE (?prefLabel) as ?prefLabelRandom)
94121
{

0 commit comments

Comments
 (0)