Java Code Examples for org.semanticweb.owlapi.model.OWLOntologyManager#addAxiom()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntologyManager#addAxiom() . 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: GMTParser.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void parseRow(String[] row) {
	OWLDataFactory df = graph.getDataFactory();
	OWLOntologyManager mgr = graph.getManager();
	String geneSetId = row[0];
	IRI geneSetIRI = IRI.create(prefix + geneSetId);
	String desc = row[1];
	OWLClass geneSetCls = df.getOWLClass(geneSetIRI);
	OWLAxiom ax = df.getOWLAnnotationAssertionAxiom(df.getRDFSLabel(),geneSetIRI, literal(desc));
	mgr.addAxiom(graph.getSourceOntology(), ax);
			
	// assume each value is an entity, e.g. gene
	for (int i=2; i < row.length; i++) {
		OWLNamedIndividual individual = df.getOWLNamedIndividual(IRI.create(prefix + row[i]));
		mgr.addAxiom(graph.getSourceOntology(), df.getOWLClassAssertionAxiom(geneSetCls, individual));
	}
}
 
Example 2
Source File: OwlApiIncrementalReasoningTestDelegate.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Override
public void applyChanges(final Iterable<OWLAxiom> changes,
		final IncrementalChangeType type) {
	// the changes are applied indirectly by modifying the ontology
	final OWLOntologyManager manager = testOntology_
			.getOWLOntologyManager();

	for (OWLAxiom axiom : changes) {
		switch (type) {
		case ADD:
			manager.addAxiom(testOntology_, axiom);
			break;
		case DELETE:
			manager.removeAxiom(testOntology_, axiom);
			break;
		}
	}

	standardReasoner_.flush();
	incrementalReasoner_.flush();
}
 
Example 3
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void inconsistentOwlThing() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	// top subclass bottom => inconsistent
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(
			factory.getOWLThing(), factory.getOWLNothing()));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(
					factory.getOWLObjectIntersectionOf(a, b),
					factory.getOWLNothing()));
}
 
Example 4
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void inconsistentClass() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	// A subclass of bottom => A is inconsistent
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(a, factory.getOWLNothing()));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
}
 
Example 5
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Add an synonym annotation, plus an annotation on that annotation
 * that specified the type of synonym. The second annotation has the
 * property oio:hasSynonymType.
 *
 * @param ontology the current ontology
 * @param subject the subject of the annotation
 * @param type the IRI of the type of synonym
 * @param property the IRI of the annotation property.
 * @param value the literal value of the synonym
 * @return the synonym annotation axiom
 */
protected static OWLAnnotationAssertionAxiom synonym(
		OWLOntology ontology, OWLEntity subject, 
		OWLAnnotationValue type,
		OWLAnnotationProperty property, 
		OWLAnnotationValue value) {
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory dataFactory = manager.getOWLDataFactory();
	OWLAnnotationProperty hasSynonymType =
		dataFactory.getOWLAnnotationProperty(
			format.getIRI("oio:hasSynonymType"));
	OWLAnnotation annotation = 
		dataFactory.getOWLAnnotation(hasSynonymType, type);
	Set<OWLAnnotation> annotations = new HashSet<OWLAnnotation>();
	annotations.add(annotation);
	OWLAnnotationAssertionAxiom axiom =
		dataFactory.getOWLAnnotationAssertionAxiom(
			property, subject.getIRI(), value,
			annotations);
	manager.addAxiom(ontology, axiom);
	return axiom;
}
 
Example 6
Source File: AbstractOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public OWLOntology cacheInformationContentInOntology() throws OWLOntologyCreationException, UnknownOWLClassException {
	OWLOntologyManager mgr = getSourceOntology().getOWLOntologyManager();
	OWLDataFactory df = mgr.getOWLDataFactory();
	OWLOntology o = mgr.createOntology();
	OWLAnnotationProperty p = df.getOWLAnnotationProperty(IRI.create(icIRIString));
	for (OWLClass c : getSourceOntology().getClassesInSignature()) {
		Double ic = getInformationContentForAttribute(c);
		if (ic != null) {
			mgr.addAxiom(o,
					df.getOWLAnnotationAssertionAxiom(p, 
							c.getIRI(), 
							df.getOWLLiteral(ic)));
		}

	}
	return o;
}
 
Example 7
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyDisjointUnion() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	// DisjointUnion(A ) = EquivalentClasses(A owl:Nothing)
	owlManager.addAxiom(ontology, factory.getOWLDisjointUnionAxiom(a,
			Collections.<OWLClassExpression> emptySet()));
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(b, b));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
}
 
Example 8
Source File: OwlSimUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addElementLabels(OWLOntology ont, File file) throws IOException {
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	List<String> lines = FileUtils.readLines(file);
	for (String line : lines) {
		if (line.startsWith("#"))
			continue;
		String[] colVals = line.split("\t");
		if (colVals.length != 2) {
			throw new IOException("Incorrect number of value: "+line);
		}
		IRI i = getIRIById(colVals[0]);
		OWLAnnotation ann = df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral(colVals[1])); 
		m.addAxiom(ont, df.getOWLAnnotationAssertionAxiom(i, ann));
	}
}
 
Example 9
Source File: OwlSimUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addElementToAttributeAssociationsFromFile(OWLOntology ont, File file) throws IOException {
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	List<String> lines = FileUtils.readLines(file);
	for (String line : lines) {
		if (line.startsWith("#"))
			continue;
		String[] colVals = line.split("\t");
		if (colVals.length != 2) {
			throw new IOException("Incorrect number of value: "+line);
		}
		OWLNamedIndividual i = df.getOWLNamedIndividual(getIRIById(colVals[0]));
		OWLClass c = df.getOWLClass(getIRIById(colVals[1]));
		m.addAxiom(ont, df.getOWLClassAssertionAxiom(c, i));
	}
}
 
Example 10
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static OWLAxiom modifyInferredAxiom(OWLAxiom axiom, OWLOntology ontology, boolean add) {
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();
	final OWLDataFactory factory = manager.getOWLDataFactory();
	final OWLAxiom newAxiom = updateInferredAxiom(axiom, factory, add);
	
	// update ontology
	manager.removeAxiom(ontology, axiom);
	manager.addAxiom(ontology, newAxiom);
	return newAxiom;
}
 
Example 11
Source File: BridgeExtractor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addObjectProperty(OWLObjectProperty p, OWLOntology xOnt) {
	if (xOnt.getDeclarationAxioms(p).size() > 0) {
		return;
	}
	OWLOntologyManager m = ontology.getOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	m.addAxiom(xOnt, df.getOWLDeclarationAxiom(p));
	for (OWLAxiom ax : ontology.getAxioms(p, Imports.EXCLUDED)) {
		m.addAxiom(xOnt, ax);
	}
	// TODO

}
 
Example 12
Source File: DLQueryTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Execute the DL query on the given ontology graph. Uses the factory to create 
 * the {@link OWLReasoner} for an internal query ontology.
 * 
 * @param dlQuery
 * @param graph
 * @param reasonerFactory
 * @return set of {@link OWLClass} which 
 * @throws OWLParserException
 * @throws OWLOntologyCreationException
 */
public static Set<OWLClass> executeDLQuery(String dlQuery, OWLGraphWrapper graph, 
		OWLReasonerFactory reasonerFactory) throws OWLParserException, OWLOntologyCreationException 
{
	// create parser and parse DL query string
	ManchesterSyntaxTool parser = null;
	
	OWLClassExpression ce;
	try {
		parser = new ManchesterSyntaxTool(graph.getSourceOntology(), graph.getSupportOntologySet());
		ce = parser.parseManchesterExpression(dlQuery);
	} finally {
		// always dispose parser to avoid a memory leak
		if (parser != null) {
			parser.dispose();
		}
	}
	
	// create query ontology
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLOntology queryOntology = m.createOntology(IRI.generateDocumentIRI(), graph.getAllOntologies());
	OWLDataFactory f = m.getOWLDataFactory();
	OWLClass qc = f.getOWLClass(IRI.create("http://owltools.org/Q"));
	OWLEquivalentClassesAxiom ax = f.getOWLEquivalentClassesAxiom(ce, qc);
	m.addAxiom(queryOntology, ax);
	
	Set<OWLClass> subset = executeQuery(ce, queryOntology, reasonerFactory);
	if(subset.isEmpty()) {
		LOG.warn("No classes found for query subclass of:"+dlQuery);
	}
	return subset;
}
 
Example 13
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Convenience method for adding an annotation assertion to the
 * ontology.
 *
 * @param ontology the current ontology
 * @param subject the subject of the annotation
 * @param property the annotation property
 * @param value the annotation value
 * @return the annotation axiom
 */
protected static OWLAnnotationAssertionAxiom annotate(
		OWLOntology ontology, 
		OWLEntity subject,
		OWLAnnotationProperty property, 
		OWLAnnotationValue value) {
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory dataFactory = manager.getOWLDataFactory();
	OWLAnnotationAssertionAxiom axiom =
		dataFactory.getOWLAnnotationAssertionAxiom(
			property, subject.getIRI(), value);
	manager.addAxiom(ontology, axiom);
	return axiom;
}
 
Example 14
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyEnumeration() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	// ObjectOneOf() = owl:Nothing
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(a, factory.getOWLObjectOneOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLNothing()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(factory.getOWLObjectOneOf(), c));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, a));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
}
 
Example 15
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyDisjunction() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	// ObjectUnionOf() = owl:Nothing
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(a,
			factory.getOWLObjectUnionOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLNothing()));
	owlManager.addAxiom(ontology, factory
			.getOWLSubClassOfAxiom(factory.getOWLObjectUnionOf(), c));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, a));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
}
 
Example 16
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Test
public void emptyConjunction() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	OWLClass c = factory.getOWLClass(IRI.create("http://example.org/C"));
	OWLClass d = factory.getOWLClass(IRI.create("http://example.org/D"));
	// ObjectInteresectionOf() = owl:Thing
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(a,
			factory.getOWLObjectIntersectionOf()));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(b, factory.getOWLThing()));
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(
			factory.getOWLObjectIntersectionOf(), c));
	owlManager.addAxiom(ontology,
			factory.getOWLSubClassOfAxiom(factory.getOWLThing(), d));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, d));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, c));
	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(b, d));
}
 
Example 17
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Convenience method for adding a declaration axiom to the ontology.
 *
 * @param ontology the current ontology
 * @param subject the entity for which the declaration will be added
 * @return the declaration axiom
 */
protected static OWLDeclarationAxiom declare(OWLOntology ontology,
		OWLEntity subject) {
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory dataFactory = manager.getOWLDataFactory();
	OWLDeclarationAxiom axiom = 
		dataFactory.getOWLDeclarationAxiom(subject);
	manager.addAxiom(ontology, axiom);
	return axiom;
}
 
Example 18
Source File: BioChebiGenerator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create the GCIs for BioChEBI. Add the axioms into the given ontology.
 * 
 * @param ontology
 * @param ignoredClasses
 */
public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) {
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();
	final OWLDataFactory factory = manager.getOWLDataFactory();
	
	// scan axioms
	Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED);
	for (OWLSubClassOfAxiom axiom : axioms) {
		OWLClassExpression superCE = axiom.getSuperClass();
		OWLClassExpression subCE = axiom.getSubClass();
		if (subCE.isAnonymous()) {
			// sub class needs to be an named OWLClass
			continue;
		}

		if (superCE instanceof OWLObjectSomeValuesFrom == false) {
			continue;
		}
		OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE;

		OWLObjectPropertyExpression expression = some.getProperty();
		if (expression.isAnonymous()) {
			// object property expression needs to be a named OWLObjectProperty 
			continue;
		}

		OWLObjectProperty p = (OWLObjectProperty) expression;
		
		Set<OWLObjectProperty> expansions = expansionMap.get(p);
		if (expansions == null) {
			continue;
		}

		// get content for GCI
		OWLClassExpression y = some.getFiller();
		OWLClass x = subCE.asOWLClass();
		if (ignoredClasses.contains(x)) {
			continue;
		}
		for (OWLObjectProperty createProperty : expansions) {
			OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x);
			OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y);
			OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2);
			manager.addAxiom(ontology, eq);
		}
	}
	
	Set<OWLOntology> imports = ontology.getImports();
	StringBuilder sb = new StringBuilder();
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:");
	for (OWLOntology owlOntology : imports) {
		OWLOntologyID ontologyID = owlOntology.getOntologyID();
		sb.append(" ");
		appendOntologyId(ontologyID, sb);
	}
	addComment(sb.toString(), ontology);
}
 
Example 19
Source File: FoldBasedPredictor.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Map<Bioentity, Set<OWLClass>> generateAxioms(OWLOntology generatedContainer, Map<Bioentity, ? extends Collection<GeneAnnotation>> annMap, Map<Bioentity, Set<OWLClass>> allExistingAnnotations, Map<OWLClass, PredicationDataContainer> sourceData) {
	final OWLGraphWrapper g = getGraph();
	final OWLDataFactory f = g.getDataFactory();
	final OWLOntologyManager m = g.getManager();
	
	Map<Bioentity, Set<OWLClass>> allGeneratedClasses = new HashMap<Bioentity, Set<OWLClass>>();
	for(Entry<Bioentity, ? extends Collection<GeneAnnotation>> entry : annMap.entrySet()) {
		Set<OWLClass> generatedClasses = new HashSet<OWLClass>();
		Set<OWLClass> existingAnnotations = new HashSet<OWLClass>();
		Bioentity e = entry.getKey();
		for (GeneAnnotation ann : entry.getValue()) {
			// skip ND evidence annotations
			String evidenceString = ann.getShortEvidence();
			if ("ND".equals(evidenceString)) {
				continue;
			}
			// parse annotation cls
			String annotatedToClassString = ann.getCls();
			OWLClass annotatedToClass = g.getOWLClassByIdentifierNoAltIds(annotatedToClassString);
			if (annotatedToClass == null) {
				LOG.warn("Skipping annotation for prediction. Could not find cls for id: "+annotatedToClassString);
				continue;
			}
			// add annotation class (and its super classes as known annotation) 
			existingAnnotations.add(annotatedToClass);
			existingAnnotations.addAll(reasoner.getSuperClasses(annotatedToClass, false).getFlattened());
			
			// parse c16 expressions
			List<List<ExtensionExpression>> extensionExpressionGroups = ann.getExtensionExpressions();
			if (extensionExpressionGroups != null && !extensionExpressionGroups.isEmpty()) {
				for (List<ExtensionExpression> group : extensionExpressionGroups) {
					Set<OWLClassExpression> units = new HashSet<OWLClassExpression>();
					for (ExtensionExpression ext : group) {
						String extClsString = ext.getCls();
						String extRelString = ext.getRelation();
						OWLClass extCls = f.getOWLClass(g.getIRIByIdentifier(extClsString));
						OWLObjectProperty extRel = g.getOWLObjectPropertyByIdentifier(extRelString);
						if (extRel == null) {
							continue;
						}
						units.add(f.getOWLObjectSomeValuesFrom(extRel, extCls));
					}
					if (units.isEmpty()) {
						continue;
					}
					units.add(annotatedToClass);
					final OWLClassExpression groupExpression = f.getOWLObjectIntersectionOf(units);
					OWLClass generatedClass = f.getOWLClass(IRI.generateDocumentIRI());
					OWLAxiom axiom = f.getOWLEquivalentClassesAxiom(generatedClass, groupExpression);
					m.addAxiom(generatedContainer, axiom);
					generatedClasses.add(generatedClass);
					sourceData.put(generatedClass, new PredicationDataContainer(ann, annotatedToClass, evidenceString, groupExpression, group));
				}
			}
		}
		if (generatedClasses.isEmpty() == false) {
			allGeneratedClasses.put(e, generatedClasses);
			allExistingAnnotations.put(e, existingAnnotations);
		}
	}
	return allGeneratedClasses;
}
 
Example 20
Source File: ElkReasonerTest.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
/**
 * Testing correctness of the reasoner when changes are made to other, imported or not, ontologies
 * 
 */
@Test
public void testChangesToOtherOntologies() throws Exception {

	OWLOntologyManager man = TestOWLManager.createOWLOntologyManager();
	OWLDataFactory dataFactory = man.getOWLDataFactory();

	// set up resolution of prefixes
	PrefixManager pm = new DefaultPrefixManager();
	pm.setDefaultPrefix("http://www.example.com/main#");
	pm.setPrefix("A:", "http://www.example.com/A#");
	pm.setPrefix("B:", "http://www.example.com/B#");

	// define query classes
	OWLClass mainY = dataFactory.getOWLClass(":Y", pm);
	OWLClass extA = dataFactory.getOWLClass("A:A", pm);
	OWLClass extB = dataFactory.getOWLClass("B:B", pm);
	OWLClass extC = dataFactory.getOWLClass("B:C", pm);

	// loading the root ontology
	OWLOntology root = loadOntology(man, "root.owl");
	// the imported ontologies must be loaded
	OWLOntology ontoA = man.getOntology(IRI.create("http://www.example.com/A"));
	OWLOntology ontoB = man.getOntology(IRI.create("http://www.example.com/B"));

	// Create an ELK reasoner.
	OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
	OWLReasoner reasoner = reasonerFactory.createReasoner(root);

	try {
		
		assertTrue(reasoner.getSuperClasses(extA, false).containsEntity(
				extC));
		assertTrue(reasoner.getSuperClasses(mainY, false).containsEntity(
				extC));
		
		// ************************************
		// ** removing an axiom "A:A is-a B:B" from impA
		// ************************************
		OWLAxiom axiom = dataFactory.getOWLSubClassOfAxiom(extA, extB);
		man.removeAxiom(ontoA, axiom);
		reasoner.flush();
		
		assertFalse(reasoner.getSuperClasses(extA, false).containsEntity(
				extC));
		// put it back
		man.addAxiom(ontoA, axiom);
		reasoner.flush();
		
		assertTrue(reasoner.getSuperClasses(extA, false).containsEntity(
				extC));

		// ************************************
		// ** removing an axiom "B:B is-a B:C" from impB
		// ************************************
		axiom = dataFactory.getOWLSubClassOfAxiom(extB, extC);
		man.removeAxiom(ontoB, axiom);
		reasoner.flush();
		
		assertFalse(reasoner.getSuperClasses(mainY, false).containsEntity(
				extC));

	}
	finally {
		reasoner.dispose();
	}
}