Java Code Examples for org.semanticweb.owlapi.model.OWLDataFactory#getOWLImportsDeclaration()

The following examples show how to use org.semanticweb.owlapi.model.OWLDataFactory#getOWLImportsDeclaration() . 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: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void addImportsFromSupportOntologies() {
	OWLOntology sourceOntology = getSourceOntology();
	OWLDataFactory factory = getDataFactory();
	for (OWLOntology  o : getSupportOntologySet()) {
		Optional<IRI> ontologyIRI = o.getOntologyID().getOntologyIRI();
		if (ontologyIRI.isPresent()) {
			OWLImportsDeclaration importsDeclaration = factory.getOWLImportsDeclaration(ontologyIRI.get());
			AddImport ai = new AddImport(sourceOntology, importsDeclaration);
			LOG.info("Applying: "+ai);
			getManager().applyChange(ai);
		}
		else {
			String msg = "Could not add import due to missing ontology id: "+o;
			LOG.error(msg);
			throw new RuntimeException(msg);
		}
	}
	this.setSupportOntologySet(new HashSet<OWLOntology>());
}
 
Example 2
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static List<OWLOntologyChange> handleSupportOntologies(OWLGraphWrapper graph)
{
	OWLOntology ontology = graph.getSourceOntology();
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory factory = manager.getOWLDataFactory();
	
	List<OWLOntologyChange> removeImportChanges = new ArrayList<OWLOntologyChange>();
	Set<OWLOntology> supportOntologySet = graph.getSupportOntologySet();
	for (OWLOntology support : supportOntologySet) {
		Optional<IRI> supportIRI = support.getOntologyID().getOntologyIRI();
		if(supportIRI.isPresent()) {
			IRI ontologyIRI = supportIRI.get();
			OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(ontologyIRI);
			ChangeApplied status = manager.applyChange(new AddImport(ontology, importDeclaration));
			if (ChangeApplied.SUCCESSFULLY == status) {
				// the change was successful, create remove import for later
				removeImportChanges.add(new RemoveImport(ontology, importDeclaration));
			}
		}
	}
	return removeImportChanges;
}
 
Example 3
Source File: ImportedXrefTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test() throws Exception {
	// load the base ontology
	ParserWrapper pw = new ParserWrapper();
	OWLOntology direct = pw.parseOBO(getResourceIRIString("graph/xref_test.obo"));
	
	OWLGraphWrapper directGraph = new OWLGraphWrapper(direct);
	
	// check that the test class has the expected number of xrefs
	OWLClass c = directGraph.getOWLClassByIdentifier("FOO:0001");
	
	List<String> directDefXrefs = directGraph.getDefXref(c);
	assertEquals(2, directDefXrefs.size());

	List<String> directXrefs = directGraph.getXref(c);
	assertEquals(2, directXrefs.size());
	
	// create an ontology using an import
	OWLOntologyManager manager = pw.getManager();
	OWLDataFactory factory = manager.getOWLDataFactory();
	OWLOntology importer = manager.createOntology();
	OWLImportsDeclaration importDeclaration = factory.getOWLImportsDeclaration(direct.getOntologyID().getOntologyIRI().orNull());
	manager.applyChange(new AddImport(importer, importDeclaration));
	
	OWLGraphWrapper importerGraph = new OWLGraphWrapper(importer);
	
	// check that the wrapper uses also imports for lookups of xrefs
	List<String> importedDefXrefs = importerGraph.getDefXref(c);
	assertEquals(2, importedDefXrefs.size());

	List<String> importedXrefs = importerGraph.getXref(c);
	assertEquals(2, importedXrefs.size());
}