How to add multiple SWRL rules ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add multiple SWRL rules ?

shazz
Hi,

I noticed that calling multiple times set_as_rule on the same Imp object will override the previous rule.
So I created multiple Imp objects but then the results are pretty weird.

Is there a way to define a list of rules ?

(code here: https://github.com/shazz/Owlready2_sandbox/blob/master/country.py)

extract:
    Imp().set_as_rule("City(?c), population(?c, ?pop), greaterThan(?pop, 200000) -> BigCity(?c)")
    Imp().set_as_rule("City(?c), population(?c, ?pop), lessThan(?pop, 30000) -> SmallCity(?c)")
    Imp().set_as_rule("BigCity(?c), part_of(?c, ?country), abbrev(?country, ?ab), stringEqualIgnoreCase(?ab, 'USA') -> BigCityinUSA(?c)")  
    Imp().set_as_rule("SmallCity(?c), part_of(?c, ?country), abbrev(?country, ?ab), stringEqualIgnoreCase(?ab, 'USA') -> SmallCityinUSA(?c)")    


Results:

* Owlready * Reparenting onto_country.Montreal: {onto_country.City} => {onto_country.BigCity}
* Owlready * Reparenting onto_country.Boston: {onto_country.City} => {onto_country.BigCityinUSA}
* Owlready * Reparenting onto_country.Montpelier: {onto_country.City} => {onto_country.BigCityinUSA, onto_country.SmallCityinUSA, onto_country.SmallCity}


=> Montpelier was inferred at the same time SmallCityinUSA and BigCityinUSA but this should be disjoint

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: How to add multiple SWRL rules ?

Jiba
Administrator
Hi,

If you want to define several SWRL rules, you need several Imp() object (as you did).

I think there is a mistake here, though:

    class SmallCityinUSA(BigCity): pass

SmallCityinUSA should be a child of SmallCity.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to add multiple SWRL rules ?

shazz
Thanks Jiba. Shame on me....