org.semanticweb.owlapi.model.OWLClassAxiom Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLClassAxiom. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractConverter.java    From OWL2VOWL with MIT License 6 votes vote down vote up
private void processClasses(OWLOntology ontology, VowlData vowlData) {
	// use classExpressions;

	for (OWLClass owlClass : ontology.classesInSignature(Imports.INCLUDED).collect(Collectors.toSet())) {
		for (OWLClassAxiom owlClassAxiom : ontology.axioms(owlClass, Imports.INCLUDED)
				.collect(Collectors.toSet())) {
			OwlClassAxiomVisitor temp = new OwlClassAxiomVisitor(vowlData, owlClass);
			try {
				owlClassAxiom.accept(temp);
				temp.Destrucotre();
				temp = null;
			} catch (Exception e) {
				logger.info("ProcessClasses : Failed to accept owlClassAxiom -> Skipping");
			}
		}
		HasKeyAxiomParser.parse(ontology, owlClass, vowlData);
		owlClass = null;
	}
}
 
Example #2
Source File: NCBI2OWLTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
}
 
Example #3
Source File: ObsoleteClassInSignature.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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()));
					}
				}
			}
		}
	}
}
 
Example #4
Source File: AltIdInSignature.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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()));
						}
					}
				}
			}
		}
	}
}
 
Example #5
Source File: NCBI2OWLTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example #6
Source File: NCBI2OWLTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example #7
Source File: ReasonerUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #8
Source File: ReasonerUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #9
Source File: ReasonerUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@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)); 
}
 
Example #10
Source File: OwlConverter.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("static-method")
public ElkClassAxiom convert(OWLClassAxiom owlClassAxiom) {
	return owlClassAxiom.accept(OWL_CLASS_AXIOM_CONVERTER);
}
 
Example #11
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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();
		}
	}