我使用TopBraid免费版创建了具有SPIN规则的OWL本体。我将本体和SPIN规则加载到Sesame OpenRDF Workbench中:
Application Name OpenRDF Workbench
Version 4.1.2
Runtime Information
Operating System Windows 8.1 6.3 (amd64)
Java Runtime Oracle Corporation Java HotSpot(TM) 64-Bit Server VM (1.8.0_91)
Process User Greg
Memory
Used 646 MB
Maximum 3463 MB
我创建了一个简单的测试本体。它有一个具有一个SPIN规则和一个数据类型属性的类。
CONSTRUCT {
?this BugReproduction:hasTimeStamp ?timeStamp .
}
WHERE {
BIND (now() AS ?timeStamp) .
}
SPIN规则将xsd:dateTime
时间戳添加到我的测试类的测试实例中。这是整个测试本体的RDF,包括我的类,数据类型属性和规则(短):
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:sp="http://spinrdf.org/sp#"
xmlns:BugReproduction="http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproduction#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:spin="http://spinrdf.org/spin#"
xmlns:spl="http://spinrdf.org/spl#"
xmlns:arg="http://spinrdf.org/arg#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xml:base="http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproduction">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://spinrdf.org/spl"/>
<owl:versionInfo rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Created with TopBraid Composer</owl:versionInfo>
</owl:Ontology>
<owl:Class rdf:ID="TimeStampBug">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<spin:rule>
<sp:Construct>
<sp:templates rdf:parseType="Collection">
<rdf:Description>
<sp:object rdf:parseType="Resource">
<sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>timeStamp</sp:varName>
</sp:object>
<sp:predicate>
<owl:DatatypeProperty rdf:ID="hasTimeStamp"/>
</sp:predicate>
<sp:subject rdf:resource="http://spinrdf.org/spin#_this"/>
</rdf:Description>
</sp:templates>
<sp:where rdf:parseType="Collection">
<sp:Bind>
<sp:expression>
<sp:now/>
</sp:expression>
<sp:variable rdf:parseType="Resource">
<sp:varName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>timeStamp</sp:varName>
</sp:variable>
</sp:Bind>
</sp:where>
</sp:Construct>
</spin:rule>
</owl:Class>
<owl:DatatypeProperty rdf:about="#hasTimeStamp">
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
</owl:DatatypeProperty>
</rdf:RDF>
<!-- Created with TopBraid -->
因此,在Sesame中清除我的SPIN存储库并使用工作台的修改/添加命令(使用&#34;使用基URI作为上下文标识符&#34;未选中框,这对于避免错误很重要)。然后我使用SPARQL Update查询来创建我的类的测试实例:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX sxxicc: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/SXXIComplianceCheck#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX sp: <http://spinrdf.org/sp#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX smf: <http://topbraid.org/sparqlmotionfunctions#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX spl: <http://spinrdf.org/spl#>
PREFIX spin: <http://spinrdf.org/spin#>
PREFIX arg: <http://spinrdf.org/arg#>
PREFIX SXXIComplianceCheckIndividuals: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/SXXIComplianceCheckIndividuals#>
PREFIX sxxicci: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/SXXIComplianceCheckIndividuals#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX bugs: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproduction#>
PREFIX bugsi: <http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#>
INSERT DATA {
bugsi:aTimeStampBug_test1 a bugs:TimeStampBug .
}
然后我探索生成的bugsi:aTimeStampBug_test1个体,找到SPIN:规则已经运行了几次并产生了几个时间戳。时间戳的数量因测试而异。以下是一个示例结果:
Subject
Predicate
Object
Context
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.571-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.592-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.594-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.595-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.596-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.597-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.598-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.599-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.600-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.601-05:00
<http://www.disa.mil/dso/a2i/ontologies/PBSM/Interface/BugReproductionInstantiations#aTimeStampBug_test1>
BugReproduction:hasTimeStamp
2016-07-11T20:56:58.602-05:00
因此,我的SPIN:规则已经运行了几次以进行类的一次实例化。 SPIN:规则应该为一个类的实例化运行多少次?我以为它只运行一次,但看起来我错了。
答案 0 :(得分:0)
只要类的实例发生更改,SPIN:rule
就会在类的实例上运行。我发布的示例设置了由我的规则生成的无限循环更改,生成另一个规则运行生成另一个更改(新时间戳)等,直到达到某个不明确的限制。该限制可能与芝麻的整体状态有关(例如资源或超时驱动),因此我获得了可变数量的时间戳。一个简单的解决方案是使用SPIN:constructor
而不是只在实例化时运行(当类被声明时),而不是在实例化发生变化时。