gpt4 book ai didi

python - 为什么我无法关闭本体世界

转载 作者:行者123 更新时间:2023-12-01 02:04:00 24 4
gpt4 key购买 nike

我在本体下定义了一些类。但我遇到了一个问题,我无法关闭本体库的世界。令我惊讶的是,如果我将 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 | 引发的。学院

此外,我可以关闭本体中的任何类,包括 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.

最佳答案

当 Owlready 尝试关闭匿名 Unversity|College 类时,会引发错误。

显式声明类:

class TertiaryEducationalInstitution(Institution):
equivalent_to = [University|College]

然后使用它:

class Teacher(Employee):
equivalent_to = [Person & empolied.min(1, TertiaryEducationalInstitution)]

close_world(society)

关于python - 为什么我无法关闭本体世界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49247557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com