SPARQL query for merge operation

3 views
Skip to first unread message

Anne Massenkeil

unread,
Dec 4, 2025, 7:01:31 PM (7 days ago) Dec 4
to vocbench-user
Hi, 

I'm trying to merge two child concepts into one within a SKOS taxonomy but having trouble constructing the correct SPARQL query. Basic requirements for the merge are:

Source concept (to be retired)
Target concept (to be kept)
Transfer the skos:prefLabel and skos:altLabel (in all language codes) from the source to the target concept

Has anyone here advice on how to execute a query for this or a similar scenario? 

Many thanks in advance!

BR,
Anne

Andrea Turbati

unread,
Dec 5, 2025, 4:30:52 AM (7 days ago) Dec 5
to vocben...@googlegroups.com
Dear Anne,
this is a possible SPARQL UPDATE to move the skos labels (skos:prefLabel and skos:altLabel) from a SOURCE_CONCEPT to a TARGET_CONCEPT concept created in VocBench (you need to replace the SOURCE_CONCEPT and TARGET_CONCEPT) with their IRI:


PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

DELETE {
    GRAPH ?graph {
        ?sourceConcept skos:prefLabel ?prefLabel .
        ?sourceConcept skos:altLabel ?altLabel .
    }
}
INSERT {
    GRAPH ?graph {
        ?targetConcept skos:prefLabel ?prefLabel .
        ?targetConcept skos:altLabel ?altLabel .
    }
}
WHERE {
    GRAPH ?graph {
        BIND ( <SOURCE_CONCEPT> AS ?sourceConcept)
        BIND ( <TARGET_CONCEPT> AS ?targetConcept)
        ?sourceConcept skos:prefLabel ?prefLabel .
        OPTIONAL {
            ?sourceConcept skos:altLabel ?altLabel .
        }
    }
}



Just a couple of warnings:
1) if you are executing this query on a VocBench project having Validation active, be sure that ALL the labels of the SOURCE_CONCEPT have been already validated (otherwise there could be problems since using SPARQL UPDATE you are de facto bypassing the validation mechanism provided by VocBench)
2) if the TARGET_CONCEPT already has any prefLabel, then after this SPARQL UPDATE such concept will have multiple prefLabel, so you'll need to manually fix this
3) I placed the skos:altLabel of the WHERE in an OPTIONAL part, to avoid problems if the SOURCE_CONCEPT does not have any altLabel
4) this SPARQL UPDATE only remove/create the skos:prefLabel and skos:altLabel, if you need to deal with other porperties you need to change the query accordingly

Let me know if this is what you were looking for.

Andrea
This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
--
You received this message because you are subscribed to the Google Groups "vocbench-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vocbench-use...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vocbench-user/383cf91c-bab4-4034-b8bd-f96bfd7e9d25n%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages