Trace Log
Trace Log

Reputation: 47

graphdb owl-max cardinality restriction not working

Can I restrict insert of data in graphdb based on cardinality rules defined in my ontology.

I loaded the following ontology in a graphdb repository with "owl-max" Ruleset. Based on discussion here. I am trying to restrict that a person can have only one "age" property.

@prefix :      <http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

:Person  a               owl:Class ;
        rdfs:subClassOf  [ a                owl:Restriction ;
                           owl:cardinality  "1"^^xsd:nonNegativeInteger ;
                           owl:onProperty   :hasAge
                         ] .

<http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age>
        a       owl:Ontology .

:hasAge  a      owl:DatatypeProperty .

I now insert a person record as below

prefix :      <http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age#>
prefix data: <http://data.example.com/>

Insert DATA {
    data:dow a :Person ;
               :hasAge 26 .
}

The next time i insert an updated age for that person,

Insert DATA {
    data:dow :hasAge 27 .
}

I expected an that age 27 triple overrides age 26 triple or I get an insert error. However both ages are stored for the person.

data:dow a <http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age#Person> ;
    <http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age#hasAge> "26"^^xsd:integer , "27"^^xsd:integer .

Upvotes: 1

Views: 429

Answers (2)

Vladimir Alexiev
Vladimir Alexiev

Reputation: 2601

Thanks to @aksw for the excellent answers. According to http://graphdb.ontotext.com/documentation/standard/reasoning.html#predefined-rulesets, owl-max and owl-rl should do what was asked.

I want to add a clarification: @trace-log, there is no implicit "overwrite " operation in SPARQL, and it doesn't matter what rule set you use. You must use the DELETE...INSERT... statement to update triples in the way you describe.

Upvotes: 0

UninformedUser
UninformedUser

Reputation: 8465

disclaimer: This is not meant to be a proper nor correct answer, I just used it because formatting in comment is weird.

Not sure whether owl-max profile supports the inconsistency rule you'd need here. As a workaround, you could at least try to add a custom rule:

PREFIX sys: <http://www.ontotext.com/owlim/system#>
INSERT DATA {
    <_:custom> sys:addRuleset
        '''Prefices { 
                    x : http://stackoverflow.com/q/24188632/1281433/people-have-exactly-one-age#
           }
           Axioms {}
           Rules
           {
           Consistency: max_one_age_value
              a <x:hasAge> b
              a <x:hasAge> c [Constraint b != c]
              -----------------------
           }'''
}

Upvotes: 3

Related Questions