tags:

views:

52

answers:

2

I have the following RDF:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:ppl="http://www.blah.com/people#"&gt;

    <rdfs:Class rdf:ID="Person">
        <ppl:Name/>
        <ppl:LastName/>
    </rdfs:Class>

    <rdfs:Class rdf:ID="John">
        <rdfs:subClassOf rdf:resource="#Person"/>
        <ppl:name>John</ppl:name>
        <ppl:LastName>Smith</ppl:LastName>
    </rdfs:Class>
</rdf:RDF>

This looks fine but I would like to avoid the possibility of doing a subClassOf John. For instance, this should not work:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:ppl="http://www.blah.com/people2#"&gt;

    <rdfs:Class rdf:ID="Person">
        <ppl:Name/>
        <ppl:LastName/>
    </rdfs:Class>

    <rdfs:Class rdf:ID="John">
        <rdfs:subClassOf rdf:resource="#Person"/>
        <ppl:name>John</ppl:name>
        <ppl:LastName>Smith</ppl:LastName>
    </rdfs:Class>


    <rdfs:Class rdf:ID="Peter">
        <rdfs:subClassOf rdf:resource="#John"/>
        <ppl:name>Peter</ppl:name>
        <ppl:LastName>Smith</ppl:LastName>
    </rdfs:Class>
</rdf:RDF>

How may I add that restriction?

EDIT:

After cygri answer I tried a different approach:

<rdf:Description ID="John">
    <rdf:type rdf:resource="#Person"/>
    <ppl:name>John</ppl:name>
    <ppl:LastName>Smith</ppl:LastName>
</rdf:Description>

<rdf:Description ID="Peter">
    <rdf:type rdf:resource="#John"/>
    <ppl:name>Peter</ppl:name>
    <ppl:LastName>Smith</ppl:LastName>
</rdf:Description>

But this still works :(

+2  A: 

Not sure what you're trying to do. Your modelling looks weird to me, why is John a class? John should be an individual of type Person. (And you can't have subclasses of individuals, so changing John into an individual answers your question about preventing subclassing too.)

Updated: RDF as such doesn't prevent you from saying nonsensical things. So you can still parse, serialize, and query your data even if it is nonsense. But you can use an OWL consistency checker to validate your ontology. In this particular case, you have to check wether the ontology is in OWL DL. (OWL DL is the variant of OWL that introduces the restriction that individuals can't have subclasses, amongst other things. In OWL Full, this would be allowed, unless you add a constraint that the Class class is disjoint with the Person class.

cygri
Can you provide the xml snippet to make John an individual?
Macarse
I just edited my question with another approach, but it still doesn't work as expected.
Macarse
+2  A: 

You're still treating John as a class. You want something like this:

<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:ppl="http://www.blah.com/people#"&gt;

    <rdfs:Class rdf:ID="Person" />

    <rdf:Description rdf:ID="John">
        <rdf:type rdf:resource="#Person"/>
        <ppl:name>John</ppl:name>
        <ppl:LastName>Smith</ppl:LastName>
    </rdf:Description>

</rdf:RDF>

rdfs:subClassOf and rdf:type are different sorts of relationships.

rdfs:subClassOf is useful for stating that, say, all People are Mammals, and all Mammals are Animals.

rdf:type is used for stating that, say, John is a Person (and John is a Mammal and an Animal for that matter).

For what it's worth, semanticoverflow.com is also a good place for asking RDF-related questions.

Toby Inkster