I'm currently trying to create a SPARQL query that can insert new axioms if it doesn't exist in the target graph. I'm using ONT-API that integrates Jena ARQ.
Here's my goal query on my blank ontology:
PREFIX t: <testOntologyIRI#>
INSERT DATA {
t:testClassA t:hasProperty t:testClassB
}
This doesn't generate the expected result: a new axiom in my blank ontology testClassA hasProperty testClassB
I've some issue with generating a new property if it doesn't exist in the target ontology.
The catch is that if I run this same query above (knowing that the property hasProperty exists in the ontology) ==> It generates implicitly the individual testClassA, testClassB and finally my goal axiom.
To counter this "issue", I wanted to create condition in my query such as:
PREFIX t: <testOntologyIRI#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
INSERT DATA {
t:testClassA ?hasProperty t:testClassB .
BIND(IF(EXISTS{t:hasProperty},t:hasProperty, t:hasProperty a owl:ObjectProperty) as ?hasProperty).
}
This query is messy to me and it doesn't work. What would you recommend editing to generate automatically a property that doesn't exist in the ontology and it is needed to insert the desired axiom?
Best regards,
You need to use a minus condition to test the absence of a particular triple.
prefix t:<testOntologyIRI#>
insert { t:testClassA t:hasProperty t:testClassB .
t:hasProperty rdf:type owl:Property
}
where { minus { t:hasProperty rdf:type owl:Property }}
If the property already exists, nothing gets inserted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.