Re: adding a swrl rule through owlready2
Posted by
d.onto on
URL: http://owlready.306.s1.nabble.com/adding-a-swrl-rule-through-owlready2-tp3346p3361.html
I finally added the namespaces in the rule and everything is working accordingly :
def main():
"""add a swrl rule."""
parser = argparse.ArgumentParser()
parser.add_argument("--ontology", help="ontology file", required=True)
parser.add_argument(
"--destination", help="destination ontology file", required=True
)
args = parser.parse_args()
input_file = args.ontology
output_file = args.destination
onto = owl.get_ontology(input_file).load()
with onto:
swrl_rule = """ http://maccve/onto#Machine(?m) ^ http://maccve/onto#Package(?p) ^ http://maccve/onto#CVE(?c) ^ http://maccve/onto#mcontains(?m, ?p) ^ http://maccve/onto#has_CVE(?p, ?c) -> http://maccve/onto#contains_CVE(?m, ?c) """
rule = owl.Imp()
rule.set_as_rule(swrl_rule)
onto.save(file=output_file, format="rdfxml")
if __name__ == "__main__":
main()