RDF 避免 rdfs:subClassOf

发布于 2024-09-08 01:11:01 字数 2166 浏览 2 评论 0原文

我有以下 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#">

    <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>

这看起来不错,但我想避免执行 subClassOf John 的可能性。 例如,这不应该起作用:

<?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#">

    <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>

我如何添加该限制?

编辑:

cygri 的回答之后,我尝试了一种不同的方法:

<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>

但这仍然有效:(

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#">

    <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#">

    <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's 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 :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-09-15 01:11:01

不确定你想做什么。你的造型对我来说看起来很奇怪,为什么约翰是一个班级?约翰应该是一个人类型的个体。 (并且您不能拥有个体的子类,因此将 John 更改为个体也可以回答您有关防止子类化的问题。)

更新: RDF 本身并不能阻止您说出无意义的话。所以你仍然可以解析、序列化和查询你的数据,即使它是无意义的。但是您可以使用 OWL 一致性检查器来验证您的本体。在这种特殊情况下,您必须检查本体是否在 OWL DL 中。 (OWL DL 是 OWL 的变体,它引入了个人不能拥有子类等限制。在 OWL Full 中,这是允许的,除非您添加一个约束,即 Class 类是与 Person 类不相交。

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.

行雁书 2024-09-15 01:11:01

你仍然把约翰当作一个阶级。您想要这样的东西:

<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#">

    <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 和 rdf:type 是不同类型的关系。

rdfs:subClassOf 对于声明所有人类都是哺乳动物,所有哺乳动物都是动物很有用。

rdf:type 用于声明,比如说,John 是一个人(John 是一个哺乳动物和一个动物)。

就其价值而言,semanticoverflow.com 也是询问 RDF 相关问题的好地方。

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#">

    <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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文