# For PersonProfession instances with a professionLabel,
# create a schema:Occupation from the label and add a direct
# schema:hasOccupation link from the person to it.
# Affects 730 PersonProfession instances.

PREFIX tm:     <https://daniel.degu.cl/ontologies/theatre-migrants/>
PREFIX schema: <https://schema.org/>
PREFIX skos:   <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>

INSERT {
  ?person schema:hasOccupation ?occupation .
  ?occupation a schema:Occupation .
  ?occupation a skos:Concept .
  ?occupation schema:name ?labelEN .
  ?occupation rdfs:label ?labelEN .
  ?occupation skos:prefLabel ?labelEN .
}
WHERE {
  ?pp a tm:PersonProfession .
  ?pp tm:personProfessionPerson ?person .
  ?pp tm:professionLabel ?label .
  BIND(STRLANG(REPLACE(STR(?label), "\\s+$", ""), "en") AS ?labelEN)
  BIND(IRI(CONCAT(
    "http://example.org/migrants/Profession-",
    ENCODE_FOR_URI(REPLACE(STR(?label), "\\s+", ""))
  )) AS ?occupation)
}
