我在我的本体下定义了一些类。但是我遇到了一个问题,我无法关闭我的本体库的世界。令我惊讶的是,如果我重写Teacher class
为
class Teacher(Employee):
equivalent_to = [Person & empolied.min(1, University)]
或者
class Teacher(Employee):
equivalent_to = [Person & empolied.min(1, College)]
甚至
class Teacher(Employee):
equivalent_to = [Person]
它将成功关闭。看来问题是从表达式中提出来的University | College
。
此外,我可以关闭本体中的任何类,包括Thing
.
是什么原因?
# -*- coding: utf-8 -*-
from owlready2 import *
import datetime
society = get_ontology("http://test.org/society.owl")
with society:
class Person(Thing):
def __ini__(self, wholename='', birthday=None, gender='male', *args, **kwargs):
super(Person, self).__ini__(*args, **kwargs)
self.wholename = wholename
self.birthday = birthday
self.gender = gender
self.info = ''
def __str__(self):
return '%s (%s, %s)'%(self.wholename, self.birthday, self.gender)
class Orgonization(Thing):
def __ini__(self, wholename='', birthday=0, members=[], taxno='', *args, **kwargs):
super(Person, self).__ini__(*args, **kwargs)
self.wholename = wholename
self.birthday = birthday
self.members = members
self.taxno = taxno
self.info = ''
class Institution(Orgonization):
pass
class University(Institution):
pass
class College(Institution):
pass
class Employee(Person):
def __ini__(self, no=0, level=0, salary=0, *args, **kwargs):
super(Person, self).__ini__(*args, **kwargs)
self.no = no
self.level = level
self.salary = salary
def show_info(self):
print(self)
print('no: %s\nlevel: %d\nsalary: %.2f'%(self.no, self.level, self.salary))
class empolied(Employee >> Orgonization):
pass
class empoly(Orgonization >> Employee):
inverse_property = empolied
class friend(Person >> Person, SymmetricProperty):
pass
class Teacher(Employee):
equivalent_to = [Person & empolied.min(1, University | College)]
zjc = College('zjc', wholename='***', taxno='***')
song = Teacher('songcw', wholename='***', birthday=datetime.date(1986, 7, 5), gender='male', no='800052', level=7, salary=8000)
jiangy = Teacher('jiangy', wholename='***', birthday=datetime.date(1986, 10, 5), gender='female', no='800026', level=10, salary=3000)
chenjy = Teacher('chenjy', wholename='***', birthday=datetime.date(1986, 7, 5), gender='female', no='80005*', level=10, salary=3000)
AllDifferent([zjc, song, jiangy, chenjy])
# society.save()
close_world(society)
以下是错误。
Traceback (most recent call last):
File "/Users/william/Folders/ontology/owlsociety.py", line 88, in <module>
close_world(society)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/close.py", line 90, in close_world
close_world(individual, Properties, close_instance_list, recursive)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/close.py", line 45, in close_world
elif len(range_classes) == 1: self.is_a.append(Prop.only(range_classes[0]))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/util.py", line 58, in append
def append(self, x): old = list(self); super().append(x) ; self._callback(self._obj, old)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/individual.py", line 177, in _instance_is_a_changed
if isinstance(base, ClassConstruct): base._set_ontology(self.namespace.ontology)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/class_construct.py", line 247, in _set_ontology
if isinstance(self.value, ClassConstruct): self.value ._set_ontology(ontology)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/class_construct.py", line 150, in _set_ontology
super()._set_ontology(ontology)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/owlready2/class_construct.py", line 44, in _set_ontology
raise OwlReadySharedBlankNodeError("A ClassConstruct cannot be shared by two ontologies, because it correspond to a RDF blank node. Please create a dupplicate.")
owlready2.base.OwlReadySharedBlankNodeError: A ClassConstruct cannot be shared by two ontologies, because it correspond to a RDF blank node. Please create a dupplicate.