Java 类org.semanticweb.owlapi.model.OWLClassAxiom 实例源码

项目:owltools    文件:CommandRunner.java   
/**
 * Check that there is an axiom, which use a class (in its signature) that
 * has a ancestor in the root term set.
 * 
 * @param axioms set to check
 * @param rootTerms set root of terms
 * @return boolean
 */
private boolean hasFilterClass(Set<OWLClassAxiom> axioms, Set<OWLClass> rootTerms) {
    if (axioms != null && !axioms.isEmpty()) {
        for (OWLClassAxiom ax : axioms) {
            if (ax instanceof OWLEquivalentClassesAxiom) {
                Set<OWLClass> signature = ax.getClassesInSignature();
                for (OWLClass sigCls : signature) {
                    NodeSet<OWLClass> superClasses = reasoner.getSuperClasses(sigCls, false);
                    for(OWLClass root : rootTerms) {
                        if (superClasses.containsEntity(root)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
项目:owltools    文件:NCBI2OWLTest.java   
private void testSpecies(OWLOntology ontology) {
    IRI iri = IRI.create("http://purl.obolibrary.org/obo/NCBITaxon_species");
    OWLDataFactory df = ontology.getOWLOntologyManager().
        getOWLDataFactory();
    OWLClass taxon = df.getOWLClass(iri);
    assertTrue("Species class in signature",
        ontology.containsClassInSignature(iri));

    // Check axioms
    Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED);
    assertEquals("Count class axioms", 1, axioms.size());
    assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_species> <http://purl.obolibrary.org/obo/NCBITaxon#_taxonomic_rank>)", axioms.toArray()[0].toString());

    // Check annotations
    List<String> values = new ArrayList<String>();
    values.add("AnnotationAssertion(<http://www.geneontology.org/formats/oboInOwl#hasOBONamespace> <http://purl.obolibrary.org/obo/NCBITaxon_species> \"ncbi_taxonomy\"^^xsd:string)");
    values.add("AnnotationAssertion(rdfs:label <http://purl.obolibrary.org/obo/NCBITaxon_species> \"species\"^^xsd:string)");

    Set<OWLAnnotationAssertionAxiom> annotations = 
        ontology.getAnnotationAssertionAxioms(iri);
    assertEquals("Count annotations for Species", 2, annotations.size());

    checkAnnotations(annotations, values);
}
项目:owlbuilder    文件:Participant.java   
public void processAnatomy(Owlbuilder builder, OWLClass anatomyClass) {
    final OWLOntologyManager manager = builder.getOntologyManager();
    final OWLOntology merged = builder.getMergedSources();
    final OWLOntology extracted = builder.getTarget();
    if (true){
        log.info("Need to add anatomy: " + anatomyClass.getIRI());
        Set<OWLClassAxiom> anatAxioms = merged.getAxioms(anatomyClass,org.semanticweb.owlapi.model.parameters.Imports.INCLUDED);
        manager.addAxioms(extracted, anatAxioms);
        Set<OWLAnnotationAssertionAxiom> anatAnnotations =
                merged.getAnnotationAssertionAxioms(anatomyClass.getIRI());
        for (OWLAnnotationAssertionAxiom a : anatAnnotations){
            //log.info("   Annotation Axiom: " + a.toString());
            if (a.getAnnotation().getProperty().isLabel()){
                log.info("Label is " + a.getAnnotation().getValue().toString());
                manager.addAxiom(extracted, a);
            }
        }
    }
    builder.initializeMiscTermAndParents(anatomyClass);

}
项目:owltools    文件:ObsoleteClassInSignature.java   
protected void check(OWLClass owlClass, OWLGraphWrapper graph, List<CheckWarning> warnings, OWLPrettyPrinter pp) {
    final Set<OWLOntology> allOntologies = graph.getAllOntologies();
    for(OWLOntology ontology : allOntologies){
        Set<OWLClassAxiom> axioms = ontology.getAxioms(owlClass, Imports.EXCLUDED);
        if (axioms != null && !axioms.isEmpty()) {
            // check axioms 
            for (OWLClassAxiom axiom : axioms) {
                Set<OWLClass> signature = axiom.getClassesInSignature();
                for (OWLClass signatureClass : signature) {
                    if (graph.isObsolete(signatureClass)) {
                        StringBuilder sb = new StringBuilder();
                        sb.append("Obsolete class ");
                        String id = graph.getIdentifier(signatureClass);
                        if (id != null) {
                            sb.append(id);
                            String sigLabel = graph.getLabel(signatureClass);
                            if (sigLabel != null) {
                                sb.append(" '").append(sigLabel).append('\'');
                            }
                        }
                        else {
                            sb.append(signatureClass.getIRI());
                        }
                        sb.append(" in axiom: ");
                        sb.append(pp.render(axiom));
                        warnings.add(new CheckWarning(getID(), sb.toString() , isFatal(), owlClass.getIRI()));
                    }
                }
            }
        }
    }
}
项目:owltools    文件:AltIdInSignature.java   
protected void check(OWLClass owlClass, OWLGraphWrapper graph, Map<String, OWLObject> altIds, List<CheckWarning> warnings, OWLPrettyPrinter pp) {
    final Set<OWLOntology> allOntologies = graph.getAllOntologies();
    for(OWLOntology ontology : allOntologies){
        Set<OWLClassAxiom> axioms = ontology.getAxioms(owlClass, Imports.EXCLUDED);
        if (axioms != null && !axioms.isEmpty()) {
            // check axioms 
            for (OWLClassAxiom axiom : axioms) {
                Set<OWLClass> signature = axiom.getClassesInSignature();
                for (OWLClass signatureClass : signature) {
                    String identifier = graph.getIdentifier(signatureClass);
                    if (identifier != null) {
                        OWLObject replacement = altIds.get(identifier);
                        if (replacement != null) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("Alternate Identifier ");
                            sb.append(identifier);
                            sb.append(" for main class ");
                            String replacementId = graph.getIdentifier(replacement);
                            if (replacementId != null) {
                                sb.append(replacementId);
                                String replacementLabel = graph.getLabel(replacement);
                                if (replacementLabel != null) {
                                    sb.append(" '").append(replacementLabel).append('\'');
                                }
                            }
                            else {
                                sb.append(replacement);
                            }
                            sb.append(" in axiom: ");
                            sb.append(pp.render(axiom));
                            warnings.add(new CheckWarning(getID(), sb.toString() , isFatal(), owlClass.getIRI()));
                        }
                    }
                }
            }
        }
    }
}
项目:owltools    文件:NCBI2OWLTest.java   
private void testBacteria(OWLOntology ontology) {
    String curie = "ncbi:2";
    IRI iri = OWLConverter.format.getIRI(curie);
    OWLDataFactory df = ontology.getOWLOntologyManager().
        getOWLDataFactory();
    OWLClass taxon = df.getOWLClass(iri);
    assertTrue("Bacteria class in signature",
        ontology.containsClassInSignature(iri));

    // Check axioms
    Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED);
    assertEquals("Count class axioms for Bacteria", 1, axioms.size());
    assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_2> <http://purl.obolibrary.org/obo/NCBITaxon_131567>)", axioms.toArray()[0].toString());

    // Check annotations
    List<String> values = new ArrayList<String>();
    values.add(expandAnnotation(curie, "ncbitaxon:has_rank", OWLConverter.format.getIRI("ncbi:superkingdom")));
    values.add(expandAnnotation(curie, "oio:hasOBONamespace", "ncbi_taxonomy"));
    values.add(expandAnnotation(curie, "oio:hasDbXref", "GC_ID:11"));
    values.add(expandLabel(curie, "rdfs:label", "Bacteria"));
    values.add(expandSynonym(curie, "ncbitaxon:genbank_common_name", "oio:hasExactSynonym", "eubacteria"));
    values.add(expandSynonym(curie, "ncbitaxon:synonym", "oio:hasRelatedSynonym", "not Bacteria Haeckel 1894"));
    values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Prokaryota"));
    values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Monera"));
    values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Procaryotae"));
    values.add(expandSynonym(curie, "ncbitaxon:in_part", "oio:hasRelatedSynonym", "Prokaryotae"));
    values.add(expandSynonym(curie, "ncbitaxon:blast_name", "oio:hasRelatedSynonym", "eubacteria"));

    Set<OWLAnnotationAssertionAxiom> annotations = 
        ontology.getAnnotationAssertionAxioms(iri);
    assertEquals("Count annotations for Bacteria", values.size(), annotations.size());

    checkAnnotations(annotations, values);
}
项目:owltools    文件:NCBI2OWLTest.java   
private void testActinobacteria(OWLOntology ontology) {
    String curie = "ncbi:201174";
    IRI iri = OWLConverter.format.getIRI(curie);
    OWLDataFactory df = ontology.getOWLOntologyManager().
        getOWLDataFactory();
    OWLClass taxon = df.getOWLClass(iri);
    assertTrue("Actinobacteria class in signature",
        ontology.containsClassInSignature(iri));

    // Check axioms
    Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED);
    assertEquals("Count class axioms for Actinobacteria", 1, axioms.size());
    assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_201174> <http://purl.obolibrary.org/obo/NCBITaxon_2>)", axioms.toArray()[0].toString());

    // Check annotations
    List<String> values = new ArrayList<String>();
    values.add(expandAnnotation(curie, "ncbitaxon:has_rank", OWLConverter.format.getIRI("ncbi:phylum")));
    values.add(expandAnnotation(curie, "oio:hasOBONamespace", "ncbi_taxonomy"));
    values.add(expandAnnotation(curie, "oio:hasDbXref", "GC_ID:11"));
    values.add(expandLabel(curie, "rdfs:label", "Actinobacteria [NCBITaxon:201174]"));
    values.add(expandSynonym(curie, "ncbitaxon:scientific_name", "oio:hasExactSynonym", "Actinobacteria"));
    values.add(expandSynonym(curie, "ncbitaxon:synonym", "oio:hasRelatedSynonym", "'Actinobacteria'"));
    values.add(expandSynonym(curie, "ncbitaxon:synonym", "oio:hasRelatedSynonym", "not Actinobacteria Cavalier-Smith 2002"));
    values.add(expandSynonym(curie, "ncbitaxon:blast_name", "oio:hasRelatedSynonym", "actinobacteria"));

    Set<OWLAnnotationAssertionAxiom> annotations = 
        ontology.getAnnotationAssertionAxioms(iri);
    assertEquals("Count annotations for Actinobacteria",
            values.size(), annotations.size());

    checkAnnotations(annotations, values);
}
项目:SciGraph    文件:ReasonerUtilTest.java   
@Test
public void fullEquivalenceClassesAreAdded() throws Exception {
  OWLClass e0 = dataFactory.getOWLClass(IRI.create("http://example.org/e0"));
  OWLClass e1 = dataFactory.getOWLClass(IRI.create("http://example.org/e1"));
  OWLClass e2 = dataFactory.getOWLClass(IRI.create("http://example.org/e2"));
  OWLClassAxiom fullEquivalence = dataFactory.getOWLEquivalentClassesAxiom(e0, e1, e2);
  assertThat(ont.containsAxiom(fullEquivalence), is(false));
  util.removeUnsatisfiableClasses();
  util.reason();
  assertThat(ont.containsAxiom(fullEquivalence), is(true));
}
项目:SciGraph    文件:ReasonerUtilTest.java   
@Test
public void subclassHierarchyIsRepaired() throws Exception {
  OWLClass dx = dataFactory.getOWLClass(IRI.create("http://example.org/dx"));
  OWLClass cx = dataFactory.getOWLClass(IRI.create("http://example.org/cx"));
  OWLClass root = dataFactory.getOWLClass(IRI.create("http://example.org/root"));
  OWLClassAxiom inferrredSubclass = dataFactory.getOWLSubClassOfAxiom(dx, cx);
  OWLClassAxiom originalSubclass = dataFactory.getOWLSubClassOfAxiom(dx, root);
  assertThat(ont.containsAxiom(inferrredSubclass), is(false));
  assertThat(ont.containsAxiom(originalSubclass), is(true));
  util.removeUnsatisfiableClasses();
  util.reason();
  assertThat(ont.containsAxiom(inferrredSubclass), is(true));
  assertThat(ont.containsAxiom(originalSubclass), is(false));
}
项目:SciGraph    文件:ReasonerUtilTest.java   
@Test
public void redundantAxioms_areRemoved() throws Exception {
  OWLClass e = dataFactory.getOWLClass(IRI.create("http://example.org/e"));
  OWLClass c = dataFactory.getOWLClass(IRI.create("http://example.org/c"));
  OWLClassAxiom originalSubclass = dataFactory.getOWLSubClassOfAxiom(e, c);
  assertThat(ont.containsAxiom(originalSubclass), is(true));
  util.removeRedundantAxioms();
  assertThat(ont.containsAxiom(originalSubclass), is(false)); 
}
项目:elk-reasoner    文件:OwlConverter.java   
@SuppressWarnings("static-method")
public ElkClassAxiom convert(OWLClassAxiom owlClassAxiom) {
    return owlClassAxiom.accept(OWL_CLASS_AXIOM_CONVERTER);
}
项目:owltools    文件:AssertInferenceTool.java   
public static void assertAllInferences(OWLGraphWrapper graph, String idsInputFile) {
        final OWLOntology ontology = graph.getSourceOntology();
        final OWLOntologyManager manager = ontology.getOWLOntologyManager();
        final OWLDataFactory factory = manager.getOWLDataFactory();

        Set<String> ids = loadIdsInputFile(idsInputFile);

        final OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
        final OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
        try {
            logger.info("Start check all");
            // check all classes from the main ontology
            AllInferenceReport report = new AllInferenceReport();
            Set<OWLClass> classes = ontology.getClassesInSignature(Imports.EXCLUDED);
            int count = 0;
            int total = ids != null ? ids.size() : classes.size();
            int step = 100;
            for (final OWLClass owlClass : classes) {
                if (ids != null) {
                    String id = graph.getIdentifier(owlClass);
                    if (ids.contains(id) == false) {
                        continue;
                    }
                }
                count += 1;
                // get axioms for the current class
                Set<OWLClassAxiom> axioms = ontology.getAxioms(owlClass, Imports.EXCLUDED);

                handleAxioms(owlClass, axioms, ontology, manager, factory, reasoner, report);
//              handleAxioms2(owlClass, axioms, ontology, manager, factory, reasoner, report);
                if (count % step == 0) {
                    logger.info("Current count "+count+" of "+total);
                }
            }
            PrintWriter writer = new PrintWriter(System.out);
            report.printReport(writer);
            writer.close();
        }
        finally {
            reasoner.dispose();
        }
    }