Создание новых классов и отдельных лиц с помощью SWRL в Protege

Я пытался написать правила SWRL, которые автоматизируют создание новых сущностей и их назначение классам и предикатам в онтологии Protege. Код здесь не привел ни к созданию ни одного человека, ни пример в readme.

Для ясности, вот правило, которое я пытаюсь заставить работать:

Person(?person) ^ hasSSN(?person, ?ssn) ^ swrlx:makeOWLThing(?patient, ?person) -> Patient(?patient) ^ hasPID(?patient, ?ssn)

В этой онтологии:

@prefix : <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48> .

<http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48> rdf:type owl:Ontology .

#################################################################
#    Annotation properties
#################################################################

###  http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled
<http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> rdf:type owl:AnnotationProperty .


#################################################################
#    Data properties
#################################################################

###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#hasPID
:hasPID rdf:type owl:DatatypeProperty .


###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#hasSSN
:hasSSN rdf:type owl:DatatypeProperty .


#################################################################
#    Classes
#################################################################

###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#Patient
:Patient rdf:type owl:Class .


###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#Person
:Person rdf:type owl:Class .


#################################################################
#    Individuals
#################################################################

###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person1
:person1 rdf:type owl:NamedIndividual ,
                  :Person ;
         :hasSSN 1001 .


###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person2
:person2 rdf:type owl:NamedIndividual ,
                  :Person ;
         :hasSSN 1002 .


###  http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#person3
:person3 rdf:type owl:NamedIndividual ,
                  :Person ;
         :hasSSN 1003 .


#################################################################
#    Rules
#################################################################

:person rdf:type <http://www.w3.org/2003/11/swrl#Variable> .

:ssn rdf:type <http://www.w3.org/2003/11/swrl#Variable> .

:patient rdf:type <http://www.w3.org/2003/11/swrl#Variable> .

[ <http://swrl.stanford.edu/ontologies/3.3/swrla.owl#isRuleEnabled> "true"^^xsd:boolean ;
   rdfs:comment "Patient For Every Person With PID Equal To SSN"^^xsd:string ;
   rdfs:label "PatientForEveryPersonWithPIDEqualToSSN"^^xsd:string ;
   rdf:type <http://www.w3.org/2003/11/swrl#Imp> ;
   <http://www.w3.org/2003/11/swrl#body> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
                                           rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#ClassAtom> ;
                                                       <http://www.w3.org/2003/11/swrl#classPredicate> :Person ;
                                                       <http://www.w3.org/2003/11/swrl#argument1> :person
                                                     ] ;
                                           rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
                                                      rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#DatavaluedPropertyAtom> ;
                                                                  <http://www.w3.org/2003/11/swrl#propertyPredicate> :hasSSN ;
                                                                  <http://www.w3.org/2003/11/swrl#argument1> :person ;
                                                                  <http://www.w3.org/2003/11/swrl#argument2> :ssn
                                                                ] ;
                                                      rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
                                                                 rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#BuiltinAtom> ;
                                                                             <http://www.w3.org/2003/11/swrl#builtin> <http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing> ;
                                                                             <http://www.w3.org/2003/11/swrl#arguments> ( :patient
                                                                                                                          :person
                                                                                                                        )
                                                                           ] ;
                                                                 rdf:rest rdf:nil
                                                               ]
                                                    ]
                                         ] ;
   <http://www.w3.org/2003/11/swrl#head> [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
                                           rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#ClassAtom> ;
                                                       <http://www.w3.org/2003/11/swrl#classPredicate> :Patient ;
                                                       <http://www.w3.org/2003/11/swrl#argument1> :patient
                                                     ] ;
                                           rdf:rest [ rdf:type <http://www.w3.org/2003/11/swrl#AtomList> ;
                                                      rdf:first [ rdf:type <http://www.w3.org/2003/11/swrl#DatavaluedPropertyAtom> ;
                                                                  <http://www.w3.org/2003/11/swrl#propertyPredicate> :hasPID ;
                                                                  <http://www.w3.org/2003/11/swrl#argument1> :patient ;
                                                                  <http://www.w3.org/2003/11/swrl#argument2> :ssn
                                                                ] ;
                                                      rdf:rest rdf:nil
                                                    ]
                                         ]
 ] .

###  Generated by the OWL API (version 4.2.8.20170104-2310) https://github.com/owlcs/owlapi

person Wassadamo    schedule 12.08.2018    source источник


Ответы (1)


Пеллет не поддерживает SWRLX:

 WARNING: Ignoring rule Rule([Person(?person), hasSSN(?person,?ssn), makeOWLThing([?patient, ?person])] => [Patient(?patient), hasPID(?patient,?ssn)]):
 No builtin for http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#makeOWLThing

Однако вы можете использовать перевод Drools. На вкладке SWRLT нажмите:

  1. OWL+SWRL -> Слюни
  2. Запустить слюни
  3. Слюни -> Сова

Вот что было сгенерировано (в синтаксисе Turtle):

@prefix p1: <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48#> .
@prefix p2: <http://www.semanticweb.org/richard/ontologies/2018/7/untitled-ontology-48##> .

# ...

p2:d5d68a85_03f9_4a69_8c07_9f1a57ffe7aa rdf:type owl:NamedIndividual, p1:Patient ;
                                        p1:hasPID 1003 .

p2:c8c3_3ad6_4c49_b9f6_940f711e8d5f rdf:type owl:NamedIndividual, p1:Patient ;
                                    p1:hasPID 1002 .

p2:c2038_2adb_4d12_b3ee_326cc45ffa2b rdf:type owl:NamedIndividual, p1:Patient ;
                                     p1:hasPID 1001 .

Обратите внимание на двойные ## в сгенерированных URI.

person Stanislav Kralin    schedule 13.08.2018
comment
Спасибо! Это сработало для меня. Есть ли способ изменить имя этого URI "c2038_2adb_4d12_b3ee_326cc45ffa2b" на "patient1" в SWRL? Что-то вроде: Name(?patient, "patient" + charAt(?ssn, length(?ssn) - 1)) - person Wassadamo; 14.08.2018
comment
@Wassadamo, к сожалению, не знаю. - person Stanislav Kralin; 15.08.2018
comment
Я где-то читал, что в любом случае менять эти IRI - плохая практика. Потому что это нарушает какое-то желательное свойство... что-то вроде непрозрачности в именовании. Не могу найти ссылку. Я полагаю, что если кто-то хочет также отображать имена пациентов, это следует сделать с помощью автоматически сгенерированного поля аннотаций/имен или чего-то еще. - person Wassadamo; 21.08.2018
comment
@Wassadamo, FYI: Protege позволяет отображать объекты по свойству аннотации, например. грамм. rdfs:label (см. меню Вид). - person Stanislav Kralin; 05.10.2018