运行 SWRL 规则时,我进入 swrlapi Invalid SWRL atom predicate 'Person'
。
大多数帮助建议将“人”添加到本体中。我想我已经做到了,但我想确定一下。
我的本体是经过一些修改的海龟底漆:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix owl2: <http://www.w3.org/2006/12/owl2#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@base <http://example.com/owl/families#> .
###########################################
# Object properties
###########################################
<hasAncestor> rdf:type owl:ObjectProperty ,
owl:TransitiveProperty ,
owl2:IrreflexiveProperty .
<hasChild> rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf <hasAncestor> ;
rdfs:domain <Person> ;
rdfs:range <Person> ;
owl:equivalentProperty <child> .
_:x0 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:hasValue <female> .
_:x1 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x0) .
<hasDaughter> rdf:type owl:ObjectProperty ;
rdfs:range _:x1 ,
<Person> ;
rdfs:domain <Person> ;
rdfs:subPropertyOf <hasChild> ;
rdfs:domain <Parent> ;
owl2:disjointObjectProperties <hasSon> .
<hasGender> rdf:type owl:ObjectProperty .
<hasHusband> rdf:type owl:ObjectProperty ;
owl:inverseOf <hasWife> .
<hasSon> rdf:type owl:ObjectProperty .
_:x3 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:hasValue <male> .
_:x4 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x3) .
<hasSon> rdfs:range _:x4 ;
rdfs:subPropertyOf <hasChild> ;
rdfs:range <Person> ;
rdfs:domain <Person> ,
<Parent> .
<hasSpouse> rdf:type owl:ObjectProperty ,
owl:SymmetricProperty ,
owl2:IrreflexiveProperty .
<hasWife> rdf:type owl:ObjectProperty ,
owl:InverseFunctionalProperty ,
owl:FunctionalProperty ,
owl2:AsymmetricProperty ,
owl2:IrreflexiveProperty ;
rdfs:domain <Person> ;
rdfs:range <Person> ;
rdfs:subPropertyOf <loves> ;
rdfs:range <Woman> ;
rdfs:subPropertyOf <hasSpouse> ;
rdfs:domain <Man> .
<loves> rdf:type owl:ObjectProperty ;
rdfs:domain <Person> .
###########################################
# Data properties
###########################################
<hasAge> rdf:type owl:DatatypeProperty ,
owl:FunctionalProperty ;
rdfs:domain <Person> ;
rdfs:range xsd:integer ;
owl:equivalentProperty <age> .
###########################################
# Classes
###########################################
<Adult> rdf:type owl:Class .
_:x5 rdf:type owl2:DataRange ;
owl2:onDataRange xsd:integer ;
owl2:minInclusive "21"^^xsd:int .
_:x6 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:someValuesFrom _:x5 .
_:x7 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x6) .
<Adult> owl:equivalentClass _:x7 ,
<Grownup> .
<Child> rdf:type owl:Class .
_:x8 rdf:type owl2:DataRange ;
owl2:onDataRange xsd:integer ;
owl2:minInclusive "21"^^xsd:int .
_:x9 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:someValuesFrom _:x8 .
_:x10 rdf:type owl:Class ;
owl:complementOf _:x9 .
_:x11 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x10) .
<Child> owl:equivalentClass _:x11 .
<CivilMarriage> rdf:type owl:Class .
<Man> rdf:type owl:Class ;
rdfs:subClassOf <Parent> .
_:x12 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:hasValue <male> .
_:x13 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x12) .
<Man> owl:equivalentClass _:x13 .
<Marriage> rdf:type owl:Class .
_:x14 rdf:type owl:Class ;
owl:unionOf (<CivilMarriage> <ReligiousMarriage>) .
<Marriage> owl:equivalentClass _:x14 .
<Narcissist> rdf:type owl:Class .
_:x15 rdf:type owl2:SelfRestriction ;
owl:onProperty <loves> .
_:x16 rdf:type owl:Class ;
owl:intersectionOf (_:x15 <Person>) .
<Narcissist> owl:equivalentClass _:x16 .
<Parent> rdf:type owl:Class ;
rdfs:subClassOf <Parent> .
_:x17 rdf:type owl:Restriction ;
owl:onProperty <hasChild> ;
owl2:onClass <Person> ;
owl:minCardinalityQ "1"^^xsd:nonNegativeInteger .
_:x18 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x17) .
<Parent> owl:equivalentClass _:x18 .
<Person> rdf:type owl:Class ;
rdf:about "Person"^^xsd:string ;
rdf:ID "Person"^^xsd:string ;
rdfs:label "Person"^^xsd:string .
_:x19 rdf:type owl:Class ;
owl:oneOf (<female> <male>) .
_:x20 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:allValuesFrom _:x19 .
_:x21 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:cardinality "1"^^xsd:nonNegativeInteger .
_:x22 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:cardinality "1"^^xsd:nonNegativeInteger .
_:x23 rdf:type owl:Class ;
owl:intersectionOf (_:x20 _:x21 _:x22) .
<Person> rdfs:subClassOf _:x23 .
<ReligiousMarriage> rdf:type owl:Class ;
owl:disjointWith <CivilMarriage> .
<Teenager> rdf:type owl:Class .
_:x24 rdf:type owl2:DataRange ;
owl2:minInclusive "13"^^xsd:int ;
owl2:maxExclusive "20"^^xsd:int ;
owl2:onDataRange xsd:integer .
_:x25 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:someValuesFrom _:x24 .
_:x26 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x25) .
<Teenager> owl:equivalentClass _:x26 .
<Woman> rdf:type owl:Class ;
rdfs:subClassOf <Parent> .
_:x27 rdf:type owl:Restriction ;
owl:onProperty <hasGender> ;
owl:hasValue <female> .
_:x28 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x27) .
<Woman> owl:equivalentClass _:x28 .
<YoungChild> rdf:type owl:Class .
_:x29 rdf:type owl:Class ;
owl:unionOf (<Adult> <Teenager>) .
_:x30 rdf:type owl:Class ;
owl:complementOf _:x29 .
_:x31 rdf:type owl:Class ;
owl:intersectionOf (<Person> _:x30) .
<YoungChild> owl:equivalentClass _:x31 .
###########################################
# Individuals
###########################################
# Bill
_:x32 rdf:type owl:Class ;
owl:complementOf <Narcissist> .
<Bill> rdf:type _:x32 ;
<hasAge> "13"^^xsd:integer ;
<hasGender> <male> .
# Ellen
_:x33 rdf:type owl2:DataRange ;
owl2:minInclusive "15"^^xsd:int ;
owl2:onDataRange xsd:integer ;
owl2:maxInclusive "21"^^xsd:int .
_:x34 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:someValuesFrom _:x33 .
<Ellen> rdf:type _:x34 .
# Emily
_:x35 rdf:type owl2:DataRange ;
owl:oneOf ("39"^^xsd:integer "49"^^xsd:integer) .
_:x36 rdf:type owl:Restriction ;
owl:onProperty <hasAge> ;
owl:someValuesFrom _:x35 .
<Emily> rdf:type _:x36 .
# Jack
_:x37 rdf:type owl2:NegativeDataPropertyAssertion ;
rdf:subject <Jack> ;
rdf:predicate <hasAge> ;
rdf:object "53"^^xsd:integer .
# Jeff
_:x38 rdf:type owl:Restriction ;
owl:onProperty <hasChild> ;
owl:cardinality "2"^^xsd:nonNegativeInteger .
<Jeff> rdf:type _:x38 ;
<hasAge> "77"^^xsd:integer ;
<hasChild> <Ellen> ;
<hasWife> <Emily> ;
<loves> <Jeff> ;
<hasChild> <Jack> .
# John
<John> rdf:type <Person> ;
<hasDaughter> <Susan> ;
<hasGender> <male> ;
<hasWife> <Mary> ;
<hasSon> <Bill> ;
<hasAge> "33"^^xsd:integer ;
owl:sameAs <Jack> .
# Mary
<Mary> <hasAge> "31"^^xsd:integer ;
<hasGender> <female> ;
<hasSon> <Bill> ;
<hasDaughter> <Susan> .
# Susan
<Susan> <hasAge> "8"^^xsd:integer ;
<hasGender> <female> .
<female> owl:sameAs <feminine> .
<male> owl:sameAs <masculine> .
###########################################
# General axioms
###########################################
_:x39 rdf:type owl:AllDifferent;
owl:distinctMembers (<John> <Mary> <Bill> <Susan>).
_:x40 rdf:type owl:AllDifferent;
owl:distinctMembers (<Jeff> <Emily> <Jack> <Ellen> <Susan>) .
_:x41 rdf:type owl:AllDifferent;
owl:distinctMembers (<male> <female>) .
# The following representation passes validation, but does not conform to the Turtle specification.
#(<hasSpouse> <hasSon>) rdfs:subPropertyOf <hasSon> .
_:x42 rdf:first <hasSon> ;
rdf:rest rdf:nil .
_:x43 rdf:type rdf:List ;
rdf:first <hasSpouse> ;
rdf:rest _:x42 ;
rdfs:subPropertyOf <hasSon> .
# The following representation passes validation, but does not conform to the Turtle specification.
#(<hasSpouse> <hasDaughter>) rdfs:subPropertyOf <hasDaughter> .
_:x44 rdf:first <hasDaughter> ;
rdf:rest rdf:nil .
_:x45 rdf:type rdf:List ;
rdf:first <hasSpouse> ;
rdf:rest _:x44 ;
rdfs:subPropertyOf <hasDaughter> .
我已经做了以下尝试修复它:
- 我将
f
前缀修改为基本前缀,因为我认为我的 Turtle 规则可能只会识别本体中的基本前缀。 - 根据对此处答案的评论,我
manager.getOntologyFormat(ontology).asPrefixOWLOntologyFormat().setDefaultPrefix(base + "#")
在定义本体之后和添加规则引擎之前添加。 - 阅读此内容后,我添加了“人”的
rdf:about
rdf:ID
声明rdfs:label
然而,Invalid SWRL atom predicate 'Person'
当我运行以下命令并推断时,我仍然得到:
SWRLRule rule = ruleEngine.createSWRLRule("IsSenior-Rule",
"Person(?p) ^ hasAge(?p, ?age) ^ swrlb:greaterThan(?age, 60) -> Senior(?p)");