use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class SessionResource method asOntologyOWL.
@GET
@Produces(value = { MANCHESTER_OWL, FUNCTIONAL_OWL, OWL_XML, TEXT_PLAIN })
public Response asOntologyOWL(@PathParam(value = "id") String sessionId, @PathParam("scopeid") String scopeid, @DefaultValue("false") @QueryParam("merge") boolean merge, @Context HttpHeaders headers) {
session = sesMgr.getSession(sessionId);
if (session == null)
return Response.status(NOT_FOUND).build();
IRI prefix = IRI.create(getPublicBaseUri() + "ontonet/session/");
// Export to OWLOntology, the only to support OWL formats.
ResponseBuilder rb = Response.ok(session.export(OWLOntology.class, merge, prefix));
// addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class AbstractOWLApiReasoningService method isConsistent.
/**
* Only check consistency.
*
* Subclasses may want to change how.
*
* @param ontology
* @param rules
* @return
* @throws ReasoningServiceException
*/
@Override
public boolean isConsistent(OWLOntology ontology, List<SWRLRule> rules) throws ReasoningServiceException {
log.debug("Create a input ontology to merge rules in.");
OWLOntology input;
try {
OWLOntologyManager manager = createOWLOntologyManager();
input = manager.createOntology();
Set<SWRLRule> ruleSet = new HashSet<SWRLRule>();
ruleSet.addAll(rules);
manager.addAxioms(input, ruleSet);
input = manager.getOntology(input.getOntologyID());
log.debug("Created ontology: {}", input);
return getReasoner(ontology).isConsistent();
} catch (OWLOntologyCreationException e) {
log.error("An error have been thrown while attempting to create ontology. Message was: {}", e.getLocalizedMessage());
// TODO Add explanation of this exception
throw new ReasoningServiceException();
}
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class TestOWLAPIInputSources method testOfflineImport.
/**
* Uses a {@link ParentPathInputSource} to load an ontology importing a modified FOAF, both located in the
* same resource directory.
*
* @throws Exception
*/
@Test
public void testOfflineImport() throws Exception {
URL url = getClass().getResource("/ontologies/maincharacters.owl");
assertNotNull(url);
File f = new File(url.toURI());
assertNotNull(f);
OntologyInputSource<OWLOntology> coreSource = new ParentPathInputSource(f);
// // Check that all the imports closure is made of local files
// Set<OWLOntology> closure = coreSource.getImports(true);
// for (OWLOntology o : closure)
// assertEquals("file", o.getOWLOntologyManager().getOntologyDocumentIRI(o).getScheme());
assertEquals(coreSource.getRootOntology().getOntologyID().getOntologyIRI(), IRI.create(Constants.PEANUTS_MAIN_BASE));
// Linus is stated to be a foaf:Person
OWLNamedIndividual iLinus = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Linus"));
// Lucy is stated to be a foaf:Perzon
OWLNamedIndividual iLucy = df.getOWLNamedIndividual(IRI.create(Constants.PEANUTS_MAIN_BASE + "#Lucy"));
OWLClass cPerzon = df.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Perzon"));
Set<OWLIndividual> instances = cPerzon.getIndividuals(coreSource.getRootOntology());
assertTrue(!instances.contains(iLinus) && instances.contains(iLucy));
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class TestOWLAPIInputSources method testOfflineSingleton.
/**
* Loads a modified FOAF by resolving a URI from a resource directory.
*
* @throws Exception
*/
@Test
public void testOfflineSingleton() throws Exception {
URL url = getClass().getResource("/ontologies/mockfoaf.rdf");
assertNotNull(url);
OntologyInputSource<OWLOntology> coreSource = new RootOntologySource(IRI.create(url));
assertNotNull(df);
/*
* To check it fetched the correct ontology, we look for a declaration of the bogus class foaf:Perzon
* (added in the local FOAF)
*/
OWLClass cPerzon = df.getOWLClass(IRI.create("http://xmlns.com/foaf/0.1/Perzon"));
assertTrue(coreSource.getRootOntology().getClassesInSignature().contains(cPerzon));
}
use of org.semanticweb.owlapi.model.OWLOntology in project stanbol by apache.
the class AbstractOntologyCollectorImpl method getOntologyAsOWLOntology.
protected OWLOntology getOntologyAsOWLOntology(OWLOntologyID ontologyId, boolean merge, org.semanticweb.owlapi.model.IRI universalPrefix) {
// if (merge) throw new UnsupportedOperationException("Merge not implemented yet for OWLOntology.");
// Remove the check below. It might be an unmanaged dependency (TODO remove from collector and
// reintroduce check?).
// if (!hasOntology(ontologyIri)) return null;
OWLOntology o;
o = ontologyProvider.getStoredOntology(ontologyId, OWLOntology.class, merge);
if (merge) {
final Set<OWLOntology> set = new HashSet<OWLOntology>();
log.debug("Merging {} with its imports, if any.", o);
set.add(o);
// Actually, if the provider already performed the merge, this won't happen
for (OWLOntology impo : o.getImportsClosure()) {
log.debug("Imported ontology {} will be merged with {}.", impo, o);
set.add(impo);
}
OWLOntologySetProvider provider = new OWLOntologySetProvider() {
@Override
public Set<OWLOntology> getOntologies() {
return set;
}
};
OWLOntologyMerger merger = new OWLOntologyMerger(provider);
try {
o = merger.createMergedOntology(OWLManager.createOWLOntologyManager(), ontologyId.getOntologyIRI());
} catch (OWLOntologyCreationException e) {
log.error("Failed to merge imports for ontology " + ontologyId, e);
// do not reassign the root ontology
}
} else {
// Rewrite import statements
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
/*
* TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of
* going upOne() add "session" or "ontology" if needed). But only do this if we keep considering
* imported ontologies as *not* managed.
*/
for (OWLImportsDeclaration oldImp : o.getImportsDeclarations()) {
changes.add(new RemoveImport(o, oldImp));
String s = oldImp.getIRI().toString();
// FIXME Ugly way to check, but we'll get through with it
if (s.contains("::"))
s = s.substring(s.indexOf("::") + 2, s.length());
boolean managed = managedOntologies.contains(oldImp.getIRI());
// For space, always go up at least one
String tid = getID();
if (backwardPathLength > 0)
tid = tid.split("/")[0];
org.semanticweb.owlapi.model.IRI target = org.semanticweb.owlapi.model.IRI.create((managed ? universalPrefix + "/" + tid + "/" : URIUtils.upOne(universalPrefix) + "/") + s);
changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
}
o.getOWLOntologyManager().applyChanges(changes);
}
return o;
}
Aggregations