Advertisement
Guest User

ontology

a guest
Mar 29th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. ontology = '/full/path/ontology.owl'
  2. world = default_world
  3. fileno, filename = tempfile.mkstemp()
  4. world.set_backend(filename = filename)
  5. onto = world.get_ontology(ontology).load()
  6.  
  7. with onto:
  8.     patient = onto.search_one(label='Patient')
  9.     fev = onto.search_one(label='FEV')
  10.    
  11.     has_value = onto.search_one(label='hasValue')
  12.     has_assessment = onto.search_one(label='hasAssessment')
  13.     has_gold_stage = onto.search_one(label='hasGOLDStage')
  14.  
  15.     gold_rules = [
  16.         f"""{patient.iri}(?p), {fev.iri}(?f), {has_assessment.iri}(?p, ?f), {has_value.iri}(?f, ?v),
  17.            greaterThanOrEqual(?v, 80) -> {has_gold_stage.iri}(?p, 1)""",
  18.         f"""{patient.iri}(?p), {fev.iri}(?f), {has_assessment.iri}(?p, ?f), {has_value.iri}(?f, ?v),
  19.            greaterThanOrEqual(?v, 50), lessThan(?v, 80) -> {has_gold_stage.iri}(?p, 2)""",
  20.         f"""{patient.iri}(?p), {fev.iri}(?f), {has_assessment.iri}(?p, ?f), {has_value.iri}(?f, ?v),
  21.            greaterThanOrEqual(?v, 30), lessThan(?v, 50) -> {has_gold_stage.iri}(?p, 3)""",
  22.         f"""{patient.iri}(?p), {fev.iri}(?f), {has_assessment.iri}(?p, ?f), {has_value.iri}(?f, ?v),
  23.            lessThan(?v, 30) -> {has_gold_stage.iri}(?p, 4)"""
  24.     ]
  25.    
  26.     for rule in rules:
  27.         Imp().set_as_rule(rule)
  28.        
  29.     patient_one = patient()
  30.     high_fev = fev()
  31.     high_fev.hasValue = 85
  32.     patient_one.hasAssessment = high_fev
  33.    
  34.     patient_two = patient()
  35.     low_fev = fev()
  36.     low_fev.hasValue = 43
  37.     patient_two.hasAssessment = low_fev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement