Ensure that multiple subjects point to same list of blank nodes
Asked Answered
M

2

5

Consider the following instance of SomeClass:

 instances:some_thing1
                a semapi:SomeClass ;
                semapi:hasChainTo (
                      [ ... ] [ ... ] [ ... ]
                ) .

I need every instance (some_thing2, some_thing3, etc.) to have its hasChainTo property point at the same list of blank nodes (as in there is only one copy of it). I need to maintain the list of blank nodes syntax because the chains get very deep and this syntax is very fluid for writing out each chain (for SomeClass2, SomeClass3, etc.).

If I simply make a base class and subClassOf from it, the hasChainTo property inherits but not the object it's pointing to. This intuitively makes sense but I need the other behavior.

How can this be accomplished?

Murrain answered 27/6, 2013 at 7:38 Comment(0)
E
5

If you want to refer to the same thing from multiple nodes in the graph, you should give it a URI. It doesn't have to be a full http: URI - you could use a UUID:

instances:some_thing_1
  semapi:hasChainTo <urn:uuid:12345>.
instances:some_thing_2
  semapi:hasChainTo <urn:uuid:12345>.
instances:some_thing_3
  semapi:hasChainTo <urn:uuid:12345>.

<urn:uuid:12345>
  semapi:chain (
    [ .. ] [ .. ] [ .. ]
  ).

Don't confuse RDFS/OWL sub-classes with inheritance of state and behaviour in object-oriented languages. The class hierarchy in RDFS is for classifying nodes - i.e. assigning them to a class, where a class is some set of resources. There is no direct equivalent of the code-reuse you get from inheritance in languages like Java.

Edenedens answered 27/6, 2013 at 8:30 Comment(2)
If OWL is in the picture (which it probably isn't, since RDF lists are being used), once there's a way to refer to the list though, you could specify that SomeClass SubClassOf semapi:hasChainTo value <urn:uuid:12345>, which means that each instance of SomeClass does in fact semapi:hasChainTo <urn:uuid:12345> (and "each instance" includes instances of subclasses).Nebuchadnezzar
Yes, it's true that you could do that. You'd be trading off needing the complexity of an OWL reasoner vs. the need to assert one extra triple each time an instance is created. Since parliament already flagged update performance as a concern, I'm not sure I'd make the trade-off in favour of the reasoner. But that decision depends entirely on the full details of the context of the project.Edenedens
N
2

You're probably working in RDF(S), and not in OWL, but if you do have the ability to use OWL based tools, and for the sake of anyone who finds this question and can use OWL based tools, here's an OWL-based answer.

If you want every instance of a class (including instances of its subclasses) to have some property value in common, you can use an Individual Value Restriction. In the Manchester syntax, you can say that instances of SomeClass all have the value sharedIndividual for the propery hasValue by the axiom:

SomeClass SubClassOf hasValue value sharedIndividual

Then every instance of SomeClass has the type hasValue value sharedIndividual, which means that the instance has sharedIndividual as a value for the hasValue property.

Here's the N3 serialization of an ontology with a class SomeClass and two subclasses SomeSubClass and AnotherSubClass. Each of the three classes has a declared individual. The type hasValue value sharedIndividual is a superclass of SomeClass.

@prefix :        <http://www.example.com/valueClassExample#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://www.example.com/valueClassExample>
      a       owl:Ontology .

:hasValue
      a       owl:ObjectProperty .

:sharedValue
      a       owl:Thing , owl:NamedIndividual .

:SomeClass
      a       owl:Class ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:hasValue :sharedValue ;
                owl:onProperty :hasValue
              ] .

:SomeSubClass
      a       owl:Class ;
      rdfs:subClassOf :SomeClass .

:AnotherSubClass
      a       owl:Class ;
      rdfs:subClassOf :SomeClass .

:SomeClassInstance
      a       :SomeClass , owl:NamedIndividual .

:SomeSubClassInstance
      a       owl:NamedIndividual , :SomeSubClass .

:AnotherSubClassInstance
      a       owl:NamedIndividual , :AnotherSubClass .

With this ontology loaded in Protégé and with Pellet attached for reasoning, asking which individuals have sharedValue as a value of the hasValue property shows all the individuals.

result of <code>hasValue value sharedProperty</code> DL query

Nebuchadnezzar answered 27/6, 2013 at 11:41 Comment(2)
Thank you for the response. It's worth noting here for others that this is supported in OWL 2 profiles EL and RL but not QL via the ObjectHasValue restriction. w3.org/TR/owl2-profilesMurrain
@Murrain Very good observation! I'm almost always working in OWL DL, so I haven't learned all the ins and outs of the various profiles, but this could be very important for someone needing to stay within one of them!Nebuchadnezzar

© 2022 - 2024 — McMap. All rights reserved.