我应该亚级RDF:重新化语句吗?

发布于 2025-01-28 13:07:22 字数 816 浏览 3 评论 0原文

我想做一个“关于语句的语句”,例如我有userx members of groupy,并想对此进行声明(例如,他们于5月11日加入)。

因此,我有类似的东西:

statementX a rdf:statement
statementX subject userX
statementX predicate memberOf
statementX object groupY
statementX since "2022-05-11T11:32:52"^^xsd:dateTime

我的问题是,是否值得子分类rdf:语句? Say 用户groupstatement RDF:subclassof rdf:语句,然后statementx a userGroupStatement

这是有道理的吗,这是人们做的事情吗?还是人们只是使用rdf:语句,还是创建自己的加入类?利弊是什么?

在我的想法中,至少可以让我建模某种类型的语句具有某些属性,例如,userGroupStatement具有'afa farter'属性(domain usergroupStatement,范围XSD:DateTime)。但是,我可以看到它无济于事,因为userGroupStatement的主题/谓词/对象仍然可以是任何Resource> Resource。还是出于建模目的,我应该只制作一个新的语句链接对象,而忘记了RDF:完全说明?

I want to make a reified 'statement about a statement', say I have userX memberOf groupY and want to make a statement about that (say, that they joined on May 11).

So, I have something like:

statementX a rdf:statement
statementX subject userX
statementX predicate memberOf
statementX object groupY
statementX since "2022-05-11T11:32:52"^^xsd:dateTime

My question is, is it worthwhile subclassing rdf:statement? Say UserGroupStatement rdf:subClassOf rdf:statement, then statementX a UserGroupStatement.

Does that make sense, is it something people do? Or do people just use rdf:statement, or create their own joining classes? What would be the pros and cons?

In my thinking, it would at least allow me to model that a certain type of statement has certain properties, e.g. that a UserGroupStatement has a 'since' property (domain UserGroupStatement, range xsd:datetime). But then I can see that it doesn't help me specify anything else, because the subject/predicate/object of the UserGroupStatement could still be any Resource. Or for modelling purposes should I just make a new statement-like linking object, and forget about rdf:statement altogether?

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

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

发布评论

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

评论(1

别闹i 2025-02-04 13:07:22

如果适合您的用例,则可以子类rdf:语句,但要小心资本s,因为uris对案例敏感。

然后,您可以使用OWL进一步限制该子类上的属性,但这只会帮助您进行推理。我假设您想验证数据,因为用例 shacl 更适合。

shacl示例

@prefix : <http://example.org/>.
@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#>.
@prefix sh: <http://www.w3.org/ns/shacl#>.
    
# Ontology
:UserStatement rdfs:subClassOf rdf:Statement.

## Knowledge Base
:GroupY a :Group.
:UserX a :User; :memberOf :GroupY.
:AdminX a :Admin; :memberOf :GroupY.    

:CorrectStatement a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :memberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:IncorrectStatement1 a :UserStatement;
    rdf:subject :AdminX;
    rdf:predicate :memberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:IncorrectStatement2 a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :schmemberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:InorrectStatement3 a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :memberOf;
    rdf:object :GroupY.

# SHACL Shape
:UserStatementShape a sh:NodeShape;
    sh:targetClass :UserStatement;  
    sh:property                                       
        [sh:path rdf:type; sh:hasValue :UserStatement; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:subject; sh:class :User; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:predicate; sh:hasValue :memberOf; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:object; sh:class :Group; sh:minCount 1; sh:maxCount 1],
        [sh:path :since; sh:nodeKind sh:Literal; sh:datatype xsd:dateTime; sh:minCount 1; sh:maxCount 1];
    sh:closed true.

输出

将示例保存为test.ttl,install pyshacl pyshacl test.ttl,您将获得以下内容:

$ pyshacl test.ttl
Validation Report
Conforms: False
Results (3):
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:datatype xsd:dateTime ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:nodeKind sh:Literal ; sh:path :since ]
    Focus Node: :InorrectStatement3
    Result Path: :since
    Message: Less than 1 values on :InorrectStatement3->:since
Constraint Violation in HasValueConstraintComponent (http://www.w3.org/ns/shacl#HasValueConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:hasValue :memberOf ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:predicate ]
    Focus Node: :IncorrectStatement2
    Result Path: rdf:predicate
    Message: Node :IncorrectStatement2->rdf:predicate does not contain a value in the set: [':memberOf']
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:class :User ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:subject ]
    Focus Node: :IncorrectStatement1
    Value Node: :AdminX
    Result Path: rdf:subject
    Message: Value does not have class :User

If it suits your use case, you can subclass rdf:Statement but be careful about the capital S, as URIs are case sensitive.

You could then use OWL to restrict the properties on that subclass further but that would help you only with inference. I assume you want to validate your data, for that use case SHACL or ShEx are better suited.

SHACL Example

@prefix : <http://example.org/>.
@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#>.
@prefix sh: <http://www.w3.org/ns/shacl#>.
    
# Ontology
:UserStatement rdfs:subClassOf rdf:Statement.

## Knowledge Base
:GroupY a :Group.
:UserX a :User; :memberOf :GroupY.
:AdminX a :Admin; :memberOf :GroupY.    

:CorrectStatement a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :memberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:IncorrectStatement1 a :UserStatement;
    rdf:subject :AdminX;
    rdf:predicate :memberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:IncorrectStatement2 a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :schmemberOf;
    rdf:object :GroupY;
    :since "2022-05-11T11:32:52"^^xsd:dateTime.

:InorrectStatement3 a :UserStatement;
    rdf:subject :UserX;
    rdf:predicate :memberOf;
    rdf:object :GroupY.

# SHACL Shape
:UserStatementShape a sh:NodeShape;
    sh:targetClass :UserStatement;  
    sh:property                                       
        [sh:path rdf:type; sh:hasValue :UserStatement; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:subject; sh:class :User; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:predicate; sh:hasValue :memberOf; sh:minCount 1; sh:maxCount 1],
        [sh:path rdf:object; sh:class :Group; sh:minCount 1; sh:maxCount 1],
        [sh:path :since; sh:nodeKind sh:Literal; sh:datatype xsd:dateTime; sh:minCount 1; sh:maxCount 1];
    sh:closed true.

Output

Save the example as test.ttl, install pySHACL and run pyshacl test.ttl and you will get the following:

$ pyshacl test.ttl
Validation Report
Conforms: False
Results (3):
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:datatype xsd:dateTime ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:nodeKind sh:Literal ; sh:path :since ]
    Focus Node: :InorrectStatement3
    Result Path: :since
    Message: Less than 1 values on :InorrectStatement3->:since
Constraint Violation in HasValueConstraintComponent (http://www.w3.org/ns/shacl#HasValueConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:hasValue :memberOf ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:predicate ]
    Focus Node: :IncorrectStatement2
    Result Path: rdf:predicate
    Message: Node :IncorrectStatement2->rdf:predicate does not contain a value in the set: [':memberOf']
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
    Severity: sh:Violation
    Source Shape: [ sh:class :User ; sh:maxCount Literal("1", datatype=xsd:integer) ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:path rdf:subject ]
    Focus Node: :IncorrectStatement1
    Value Node: :AdminX
    Result Path: rdf:subject
    Message: Value does not have class :User
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文