比较两(2)类个体的SWRL规则

2024-10-01 22:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含不同类的简单本体,其中courseslessons是类。我正在尝试运行一个SWRL规则,该规则将属性belongsTo关联到lessons的个人。我正在使用OWLReady2和Python

with onto:
    #courses
    class course_id (onto.courses >> int): pass
    class course_title (onto.courses >> str): pass
    #lessons
    class lesson_id (onto.lessons >> int): pass
    class lesson_title (onto.lessons >> str): pass
    class course_id (onto.lessons >> int): pass
    

    class belongTo(onto.lessons >> onto.courses): pass

    rule = Imp()
    rule.set_as_rule("""lessons(?l), courses(?c), course_id(?c, ?cid), course_id(?l, ?cid) -> belongTo(?l, ?c) """)



sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)

这个想法是,如果course_id是相似的,那么课程应该属于课程。但我的代码似乎不起作用。我得到了这些推论:

* Owlready * Adding relation lmsontology.Introduction belongTo lmsontology.Introduction
* Owlready * Adding relation lmsontology.Databases belongTo lmsontology.Databases

Tags: idtitle规则passruleclassintcourse
1条回答
网友
1楼 · 发布于 2024-10-01 22:32:11

在您的示例中,我检测到以下问题:

  • 缺少courseslessons的类
  • course_id定义了两次,使第一个过时
  • 这个例子并没有遵循通常的命名惯例:对于概念来说是单数名词,对于角色来说是动词表达式,比如hasId
  • 没有定义任何个人,所以在运行reasoner时,swrl规则基本上没有什么可应用的

一般来说,为了调试规则,我建议从一个琐碎的规则或工作示例逐步构建它,并在每个步骤中检查结果是否符合预期

相关问题 更多 >

    热门问题