Skip to content

Instantly share code, notes, and snippets.

@pebbie
Last active July 22, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pebbie/b9185abf294d03968d98224acb7358d0 to your computer and use it in GitHub Desktop.
Save pebbie/b9185abf294d03968d98224acb7358d0 to your computer and use it in GitHub Desktop.
first attempt on trying to import/export existing vocabulary into/from wikibase. this query is for exporting annotated wikibase into RDF/OWL using OWL equivalentXX property
CONSTRUCT {
?ss ?pe ?oo .
?ss rdfs:label ?l
}
WHERE {
# original statement
?s ?p ?o.
?s rdfs:label ?l.
# we know there's an equivalent property for p
# equivalent property (P3)
[] wikibase:directClaim ?p; wdt:P3 ?pe .
FILTER(?pe != owl:equivalentProperty && ?pe != owl:equivalentClass && ?pe != owl:sameAs)
# in addition, change ?o if there's an equivalent class of it
OPTIONAL{
# equivalent class (P2)
?o wdt:P2 ?o_.
}
# replace if(bound(?o_), ?o_, ?o) with coalesce
BIND(COALESCE(?o_, ?o) as ?oo)
# in addition, change ?s if there's an equivalent class of it
OPTIONAL{
# equivalent class (P2)
?s wdt:P2 ?s_.
}
OPTIONAL{
# equivalent property (P3)
?s wdt:P3 ?s__ .
}
OPTIONAL{
# same as (P8)
?s wdt:P8 ?s___ .
}
# replace if(bound(?s_), ?s_, ?s) with coalesce
BIND(COALESCE(?s_, ?s__, ?s___, ?s) as ?ss)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment