public OWLOntology getMergedOntology() {
   final IRI mergedOntologyIRI =
       IRI.create(queryOntology.getOntologyID().getDefaultDocumentIRI() + "-merged");
   final OWLOntologyManager mm = controller.getOWLOntologyManager();
   if (mm.contains(mergedOntologyIRI)) {
     return mm.getOntology(mergedOntologyIRI);
   } else {
     try {
       final OWLOntology mergedOntology = mm.createOntology(mergedOntologyIRI);
       mm.setOntologyFormat(mergedOntology, new RDFXMLOntologyFormat());
       final String mergedOntologyFileName =
           mergedOntologyIRI
                   .toURI()
                   .toString()
                   .substring(mergedOntologyIRI.toURI().toString().lastIndexOf("/") + 1)
               + ".owl";
       mm.setOntologyDocumentIRI(
           mergedOntology,
           IRI.create(
               controller.getRuleSpec().getOutputDir().toURI() + "/" + mergedOntologyFileName));
       mm.applyChange(
           new AddImport(
               mergedOntology,
               mm.getOWLDataFactory()
                   .getOWLImportsDeclaration(
                       queryOntology.getOntologyID().getDefaultDocumentIRI())));
       return mergedOntology;
     } catch (OWLOntologyCreationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       return null;
     }
   }
 }
Esempio n. 2
0
  public KuabaRepository createNewRepository(String url, File destination) {
    IRI iri;
    if (url == null) iri = IRI.generateDocumentIRI();
    else iri = IRI.create(url);

    try {
      OWLOntology inst = manager.createOntology(iri);
      OWLImportsDeclaration imp =
          manager.getOWLDataFactory().getOWLImportsDeclaration(IRI.create(ONTOLOGY_URL));
      AddImport addi = new AddImport(inst, imp);
      manager.applyChange(addi);
      KuabaRepository repo = new OwlApiKuabaRepository(inst, manager.getOWLDataFactory());
      repoMap.put(inst.getOntologyID().getOntologyIRI(), repo);
      fileMap.put(repo, destination);

      TemplateGenerator.generateRootQuestion(repo);

      if (destination != null) this.save(repo);
      return repo;
    } catch (OWLOntologyCreationException ex) {
      Logger.getLogger(OwlApiFileGateway.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
  }
 @Override
 public void removeSubDataProperty(String subDataPropertyName, String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLDataProperty subDataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + subDataPropertyName));
   OWLAxiom axiom = factory.getOWLSubDataPropertyOfAxiom(subDataProperty, dataProperty);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   RemoveAxiom removeAxiom = new RemoveAxiom(localContext, axiom);
   try {
     synchronized (this) {
       changeManager.validateRemovalChange(axiom);
       manager.applyChange(removeAxiom);
     }
   } catch (RemovalException ex) {
     logger.severe(
         ex.getMessage()
             + " Change ( removeSubDataProperty "
             + subDataPropertyName
             + " of "
             + dataPropertyName
             + ") will not be applied.");
   }
 }
 @Override
 public void addDataPropertyFloatRange(String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLDatatype floatDatatype = factory.getFloatOWLDatatype();
   OWLAxiom axiom = factory.getOWLDataPropertyRangeAxiom(dataProperty, floatDatatype);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   AddAxiom addAxiom = new AddAxiom(localContext, axiom);
   manager.applyChange(addAxiom);
 }
 @Override
 public void addDataPropertyDomain(String dataPropertyName, String domainName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLClass domain = factory.getOWLClass(IRI.create(prefix + domainName));
   OWLAxiom axiom = factory.getOWLDataPropertyDomainAxiom(dataProperty, domain);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   AddAxiom addAxiom = new AddAxiom(localContext, axiom);
   manager.applyChange(addAxiom);
 }
Esempio n. 6
0
  public HeD2OwlHelper(
      OWLOntology ontology,
      OWLOntologyManager manager,
      OWLDataFactory factory,
      PrefixManager prefixManager) {
    super(ontology, manager, factory, prefixManager);

    OWLImportsDeclaration imprt =
        manager
            .getOWLDataFactory()
            .getOWLImportsDeclaration(IRI.create("http://asu.edu/sharpc2b/sharp"));
    manager.applyChange(new AddImport(ontology, imprt));
  }
 @Override
 public void addSubDataProperty(String subDataPropertyName, String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLDataProperty subDataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + subDataPropertyName));
   OWLAxiom axiom = factory.getOWLSubDataPropertyOfAxiom(subDataProperty, dataProperty);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   AddAxiom addAxiom = new AddAxiom(localContext, axiom);
   try {
     synchronized (this) {
       changeManager.validateAddSubDataPropertyChange(axiom, subDataProperty, dataProperty);
       manager.applyChange(addAxiom);
     }
   } catch (DeclarationException ex) {
     logger.info(
         ex.getMessage()
             + " Change ( addSubDataProperty "
             + subDataPropertyName
             + " of "
             + dataPropertyName
             + " ) will not be applied.");
   } catch (RedundancyException ex) {
     synchronized (this) {
       removeSubDataProperty(ex.getSubCls(), ex.getCls());
       manager.applyChange(addAxiom);
     }
   } catch (CycleException ex) {
     logger.severe(
         ex.getMessage()
             + " Change ( addSubDataProperty "
             + subDataPropertyName
             + " of "
             + dataPropertyName
             + ") will not be applied.");
   }
 }
 @Override
 public void addDataProperty(String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLAxiom axiom = factory.getOWLDeclarationAxiom(dataProperty);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   AddAxiom addAxiom = new AddAxiom(localContext, axiom);
   try {
     synchronized (this) {
       changeManager.validateAddChange(axiom);
       manager.applyChange(addAxiom);
     }
   } catch (DeclarationException ex) {
     logger.info(
         ex.getMessage()
             + "Change ( addDataProperty "
             + dataPropertyName
             + " ) will not be applied.");
   }
 }
 @Override
 public void removeDataPropertyBooleanRange(String dataPropertyName) {
   OWLDataFactory factory = manager.getOWLDataFactory();
   OWLDataProperty dataProperty =
       factory.getOWLDataProperty(IRI.create(prefix + dataPropertyName));
   OWLDatatype booleanDatatype = factory.getBooleanOWLDatatype();
   OWLAxiom axiom = factory.getOWLDataPropertyRangeAxiom(dataProperty, booleanDatatype);
   axiom = changeManager.getAnnotatedAxiom(axiom);
   RemoveAxiom removeAxiom = new RemoveAxiom(localContext, axiom);
   try {
     synchronized (this) {
       changeManager.validateRemovalChange(axiom);
       manager.applyChange(removeAxiom);
     }
   } catch (RemovalException ex) {
     logger.severe(
         ex.getMessage()
             + " Change ( removeDataPropertyBooleanRange"
             + dataPropertyName
             + ") will not be applied.");
   }
 }
Esempio n. 10
0
  public static void main(String[] args)
      throws OWLOntologyCreationException, IOException, OWLOntologyStorageException {
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = manager.createOntology(ontologyIRI);
    OWLDataFactory factory = manager.getOWLDataFactory();

    // create basic concepts with their IRIs
    currentPhase = factory.getOWLClass(IRI.create(ontologyIRI + "#CurrentPhase"));
    previousPhase = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#previousPhase"));
    detectedPhase = factory.getOWLClass(IRI.create(ontologyIRI + "#DetectedPhase"));

    // init the currentPhase-class with the "start"-individual
    OWLNamedIndividual start1 = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "start"));
    manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(currentPhase, start1));

    // create rule1
    SWRLRule rulePP = buildRule("port_placement", "port", "unknown", "place");
    manager.applyChange(new AddAxiom(ontology, rulePP));

    // create rule2
    SWRLRule ruleMob1 =
        buildRule("mobilisation", "atraumatic_grasper", "gallbladder_fundus", "grasp");
    manager.applyChange(new AddAxiom(ontology, ruleMob1));

    SWRLRule ruleMob2 =
        buildRule("mobilisation", "atraumatic_grasper", "gastrocolic_ligament", "grasp");
    manager.applyChange(new AddAxiom(ontology, ruleMob2));

    SWRLRule ruleDis1 =
        buildRule("dissection", "atraumatic_grasper", "hepatoduodenal_ligament", "grasp");
    manager.applyChange(new AddAxiom(ontology, ruleDis1));

    SWRLRule ruleDis2 =
        buildRule("dissection", "atraumatic_grasper", "hepatoduodenal_ligament", "lift");
    manager.applyChange(new AddAxiom(ontology, ruleDis2));

    SWRLRule ruleDis3 =
        buildRule("dissection", "instrument", "calot_triangle", "instrumental_property");
    manager.applyChange(new AddAxiom(ontology, ruleDis3));

    SWRLRule ruleDis4 =
        buildRule("dissection", "sharp_instrument", "hepatoduodenal_ligament", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleDis4));

    SWRLRule ruleResCA1 =
        buildRule("resection_cystic_artery", "sharp_instrument", "cystic_artery", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleResCA1));

    SWRLRule ruleResCA2 = buildRule("resection_cystic_artery", "clip", "cystic_artery", "clipping");
    manager.applyChange(new AddAxiom(ontology, ruleResCA2));

    SWRLRule ruleResCD1 =
        buildRule("resection_cystic_duct", "sharp_instrument", "cystic_duct", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleResCD1));

    SWRLRule ruleResCD2 = buildRule("resection_cystic_duct", "clip", "cystic_duct", "clipping");
    manager.applyChange(new AddAxiom(ontology, ruleResCD2));

    SWRLRule ruleResG1 =
        buildRule(
            "resection_gallbladder", "sharp_instrument", "gallbladder_serosa", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleResG1));

    SWRLRule ruleResG2 =
        buildRule("resection_gallbladder", "sharp_instrument", "gallbladder_serosa", "dissect");
    manager.applyChange(new AddAxiom(ontology, ruleResG2));

    SWRLRule ruleResG3 =
        buildRule("resection_gallbladder", "sharp_instrument", "gallbladder", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleResG3));

    SWRLRule ruleResG4 =
        buildRule(
            "resection_gallbladder", "sharp_instrument", "gallbladder_liverbed", "cutting_action");
    manager.applyChange(new AddAxiom(ontology, ruleResG4));

    SWRLRule ruleClose1 = buildRule("closure", "specimen_bag", "unknown", "instrumental_property");
    manager.applyChange(new AddAxiom(ontology, ruleClose1));

    SWRLRule ruleClose2 = buildRule("closure", "specimen_bag", "organ", "instrumental_property");
    manager.applyChange(new AddAxiom(ontology, ruleClose2));

    // Strange rules with the instrument "drain". It should be called "drainage" as by the next two
    // rules.

    // SWRLRule ruleDrain1 = buildRule("drain", "drain", "unknown", "putting_action");
    // manager.applyChange(new AddAxiom(ontology, ruleDrain1));

    // SWRLRule ruleDrain2 = buildRule("drain", "drain", "unknown", "instrumental_property");
    // manager.applyChange(new AddAxiom(ontology, ruleDrain2));

    SWRLRule ruleDrainage1 = buildRule("drain", "drainage", "unknown", "instrumental_property");
    manager.applyChange(new AddAxiom(ontology, ruleDrainage1));

    SWRLRule ruleDrainage2 = buildRule("drain", "drainage", "organ", "instrumental_property");
    manager.applyChange(new AddAxiom(ontology, ruleDrainage2));

    // save in RDF/XML format
    File output = new File("D:/DiplArbeit/OurWork/USECASE/RULES/CCE_rules.owl");
    output.createNewFile();
    manager.saveOntology(ontology, IRI.create(output.toURI()));
  }
Esempio n. 11
0
  private OWLOntology parseWithReasoner(OWLOntologyManager manager, OWLOntology ontology) {
    try {
      PelletOptions.load(new URL("http://" + cssLocation + "pellet.properties"));
      PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner(ontology);
      reasoner.getKB().prepare();
      List<InferredAxiomGenerator<? extends OWLAxiom>> generators =
          new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
      generators.add(new InferredSubClassAxiomGenerator());
      generators.add(new InferredClassAssertionAxiomGenerator());
      generators.add(new InferredDisjointClassesAxiomGenerator());
      generators.add(new InferredEquivalentClassAxiomGenerator());
      generators.add(new InferredEquivalentDataPropertiesAxiomGenerator());
      generators.add(new InferredEquivalentObjectPropertyAxiomGenerator());
      generators.add(new InferredInverseObjectPropertiesAxiomGenerator());
      generators.add(new InferredPropertyAssertionGenerator());
      generators.add(new InferredSubDataPropertyAxiomGenerator());
      generators.add(new InferredSubObjectPropertyAxiomGenerator());

      InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, generators);

      OWLOntologyID id = ontology.getOntologyID();
      Set<OWLImportsDeclaration> declarations = ontology.getImportsDeclarations();
      Set<OWLAnnotation> annotations = ontology.getAnnotations();

      Map<OWLEntity, Set<OWLAnnotationAssertionAxiom>> entityAnnotations =
          new HashMap<OWLEntity, Set<OWLAnnotationAssertionAxiom>>();
      for (OWLClass aEntity : ontology.getClassesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLObjectProperty aEntity : ontology.getObjectPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDataProperty aEntity : ontology.getDataPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLNamedIndividual aEntity : ontology.getIndividualsInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLAnnotationProperty aEntity : ontology.getAnnotationPropertiesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }
      for (OWLDatatype aEntity : ontology.getDatatypesInSignature()) {
        entityAnnotations.put(aEntity, aEntity.getAnnotationAssertionAxioms(ontology));
      }

      manager.removeOntology(ontology);
      OWLOntology inferred = manager.createOntology(id);
      iog.fillOntology(manager, inferred);

      for (OWLImportsDeclaration decl : declarations) {
        manager.applyChange(new AddImport(inferred, decl));
      }
      for (OWLAnnotation ann : annotations) {
        manager.applyChange(new AddOntologyAnnotation(inferred, ann));
      }
      for (OWLClass aEntity : inferred.getClassesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLObjectProperty aEntity : inferred.getObjectPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDataProperty aEntity : inferred.getDataPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLNamedIndividual aEntity : inferred.getIndividualsInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLAnnotationProperty aEntity : inferred.getAnnotationPropertiesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }
      for (OWLDatatype aEntity : inferred.getDatatypesInSignature()) {
        applyAnnotations(aEntity, entityAnnotations, manager, inferred);
      }

      return inferred;
    } catch (FileNotFoundException e1) {
      return ontology;
    } catch (MalformedURLException e1) {
      return ontology;
    } catch (IOException e1) {
      return ontology;
    } catch (OWLOntologyCreationException e) {
      return ontology;
    }
  }
Esempio n. 12
0
  /** @param args */
  public static void main(String[] args) {
    String external = "http://purl.obolibrary.org/obo/iao/dev/external.owl";
    String externalDerived = "http://purl.obolibrary.org/obo/iao/dev/externalDerived.owl";
    String externalByHand = "http://purl.obolibrary.org/obo/iao/dev/externalByHand.owl";
    String metaData = "http://purl.obolibrary.org/obo/iao/dev/ontology-metadata.owl";

    String reasonerName = "hermit";

    String path = "C:/Documents and Settings/Jie/My Documents/Ontology/iao/releases/2012-01-05/";
    String saveIaoFilename = path + "merged/iao-main-infer.owl";
    String inferOntURIStr = "http://purl.obolibrary.org/obo/iao/dev/iao_inferredSuperClasses.owl";
    String saveInferFilename = path + "merged/iao-inferredSuperClasses.owl";

    // Get hold of an ontology manager
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    AutoIRIMapper mapper = new AutoIRIMapper(new File(path + "ontology/"), false);
    manager.addIRIMapper(mapper);

    OWLOntology iaoOnt = OntologyManipulator.load(path + "ontology/iao-main.owl", manager);
    // OntologyManipulator.printPrefixNSs(manager, iaoOnt);

    OWLDataFactory df = manager.getOWLDataFactory();

    // get all imported ontologies
    Set<OWLOntology> importOnts = iaoOnt.getImports();

    // remove imports statements from the loaded ontology
    for (OWLOntology importOnt : importOnts) {
      IRI importOntIRI = importOnt.getOntologyID().getOntologyIRI();
      if (importOntIRI.equals(IRI.create(metaData))
          || importOntIRI.equals(IRI.create(external))
          || importOntIRI.equals(IRI.create(externalByHand))
          || importOntIRI.equals(IRI.create(externalDerived))) {
        RemoveImport ri = new RemoveImport(iaoOnt, df.getOWLImportsDeclaration(importOntIRI));
        manager.applyChange(ri);
      }
    }

    // merge the removed imported ontologies to the loaded one
    for (OWLOntology importOnt : importOnts) {
      IRI importOntIRI = importOnt.getOntologyID().getOntologyIRI();
      if (importOntIRI.equals(IRI.create(metaData))
          || importOntIRI.equals(IRI.create(external))
          || importOntIRI.equals(IRI.create(externalByHand))
          || importOntIRI.equals(IRI.create(externalDerived))) {
        // OntologyManipulator.printPrefixNSs(manager, importOnt);
        iaoOnt = OntologyManipulator.mergeToTargetOnt(manager, iaoOnt, importOnt);
      }
    }

    // generate the inferred hierarchy and clean the super classes
    OWLReasoner reasoner = OWLReasonerRunner.runReasoner(manager, iaoOnt, reasonerName);

    iaoOnt =
        OWLReasonerRunner.getCleanedOntologyWithInferredSuperClasses(
            manager, iaoOnt, inferOntURIStr, reasoner);
    OntologyManipulator.saveToFile(manager, iaoOnt, saveIaoFilename);

    if (manager.contains(IRI.create(inferOntURIStr))) {
      OWLOntology inferOnt = manager.getOntology(IRI.create(inferOntURIStr));
      OntologyManipulator.saveToFile(manager, inferOnt, saveInferFilename);
    }
  }