2

I have a simple ontology with different classes, which courses and lessons are classes. I'm trying to run a SWRL rule that associates a property belongsTo to individuals of the lessons. I'm using OWLReady2 and 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)

The idea is that if the course_id are similar, the lesson should belong to the course. But my code does not seem to be working. I'm getting these inferences:

* Owlready * Adding relation lmsontology.Introduction belongTo lmsontology.Introduction
* Owlready * Adding relation lmsontology.Databases belongTo lmsontology.Databases
TheSoldier
  • 484
  • 1
  • 5
  • 25
  • 1
    what means "not working"? what do you do after you added the rule? Is there any data matching the rule body? – UninformedUser Aug 28 '20 at 04:08
  • @UninformedUser I've added more details to the code and the error message. By data matching the rule and body, do you mean instances of both classes? – TheSoldier Aug 28 '20 at 07:48
  • @UninformedUser I resolved the error, but the inferences are not what I'm expecting – TheSoldier Aug 28 '20 at 08:05
  • 1
    I don't see why the rule should not work with Pellet. As I asked before, your instance data does match the body of the rule? Such that it will be triggered? – UninformedUser Aug 28 '20 at 17:18

1 Answers1

0

In your example I detect the following issues:

  • The classes for courses and lessons are missing.
  • course_id is defined twice making the first one obsolete
  • The example does not stick to the usual naming convention: singular nouns for concepts and verb-expressions like hasId for roles.
  • No individuals are defined, so afaik the swrl rules have essentially nothing to apply to, when you run the reasoner.

In general to debug rules I would suggest to incrementally build it up from a trivial rule or working example and in each step checking whether the result is as expected.

cknoll
  • 2,130
  • 4
  • 18
  • 34