use of org.semanticweb.owlapi.model.OWLIndividual in project webprotege by protegeproject.
the class GetIndividualsActionHandler method execute.
@Nonnull
@Override
public GetIndividualsResult execute(@Nonnull GetIndividualsAction action, @Nonnull ExecutionContext executionContext) {
Stream<OWLNamedIndividual> stream;
if (action.getType().isOWLThing()) {
stream = rootOntology.getIndividualsInSignature(Imports.INCLUDED).stream();
} else {
stream = rootOntology.getImportsClosure().stream().flatMap(o -> o.getClassAssertionAxioms(action.getType()).stream()).map(OWLClassAssertionAxiom::getIndividual).filter(OWLIndividual::isNamed).map(OWLIndividual::asOWLNamedIndividual);
}
Counter counter = new Counter();
List<OWLNamedIndividualData> individualsData = stream.peek(i -> counter.increment()).map(renderingManager::getRendering).filter(i -> {
String searchString = action.getFilterString();
return searchString.isEmpty() || StringUtils.containsIgnoreCase(i.getBrowserText(), searchString);
}).distinct().sorted().collect(toList());
PageRequest pageRequest = action.getPageRequest();
Pager<OWLNamedIndividualData> pager = Pager.getPagerForPageSize(individualsData, pageRequest.getPageSize());
Page<OWLNamedIndividualData> page = pager.getPage(pageRequest.getPageNumber());
OWLClassData type = renderingManager.getRendering(action.getType());
logger.info(BROWSING, "{} {} retrieved instances of {} ({})", projectId, executionContext.getUserId(), action.getType(), renderingManager.getRendering(action.getType()).getBrowserText());
return new GetIndividualsResult(type, page, counter.getCount(), individualsData.size());
}
use of org.semanticweb.owlapi.model.OWLIndividual in project stanbol by apache.
the class RegistryManagerImpl method populateRegistry.
protected Registry populateRegistry(OWLOntology registry) throws RegistryContentException {
log.debug("Populating registry content from ontology {}", registry);
Registry reg = riFactory.createRegistry(registry);
Set<OWLOntology> closure = registry.getOWLOntologyManager().getImportsClosure(registry);
// Just scan all individuals. Recurse in case the registry imports more registries.
for (OWLIndividual ind : registry.getIndividualsInSignature(true)) {
// We do not allow anonymous registry items.
if (ind.isAnonymous())
continue;
RegistryItem item = null;
// IRI id = ind.asOWLNamedIndividual().getIRI();
Type t = RegistryUtils.getType(ind, closure);
if (t == null) {
log.warn("Undetermined type for registry ontology individual {}", ind);
continue;
}
switch(t) {
case LIBRARY:
log.debug("Found library for individual {}", ind);
// Create the library and attach to parent and children
item = populateLibrary(ind.asOWLNamedIndividual(), closure);
reg.addChild(item);
item.addRegistryContentListener(this);
break;
case ONTOLOGY:
log.debug("Found ontology for individual {}", ind);
// Create the ontology and attach to parent
item = populateOntology(ind.asOWLNamedIndividual(), closure);
item.addRegistryContentListener(this);
// We don't know where to attach it within this method.
break;
default:
break;
}
}
try {
reg.addRegistryContentListener(this);
log.info("Registry {} added.", reg.getIRI());
population.put(reg.getIRI(), reg);
} catch (Exception e) {
log.error("Invalid identifier for library item " + reg, e);
return null;
}
return reg;
}
use of org.semanticweb.owlapi.model.OWLIndividual in project stanbol by apache.
the class RegistryManagerImpl method populateLibrary.
protected Library populateLibrary(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI libId = ind.getIRI();
RegistryItem lib = null;
if (population.containsKey(libId)) {
// We are not allowing multityping either.
lib = population.get(libId);
if (!(lib instanceof Library))
throw new RegistryContentException("Inconsistent multityping: for item " + libId + " : {" + Library.class + ", " + lib.getClass() + "}");
} else {
lib = riFactory.createLibrary(ind);
try {
population.put(lib.getIRI(), lib);
} catch (Exception e) {
log.error("Invalid identifier for library item " + lib, e);
return null;
}
}
// EXIT nodes.
Set<OWLNamedObject> ironts = new HashSet<OWLNamedObject>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (OWLOntology o : registries) {
if (ind instanceof OWLIndividual) {
// Get usages of hasOntology as an object property
for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(hasOntology, o)) if (value.isNamed())
ironts.add(value.asOWLNamedIndividual());
// Get usages of hasOntology as an annotation property
for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (hasOntologyAnn.equals(ann.getProperty())) {
OWLAnnotationValue value = ann.getValue();
if (value instanceof OWLNamedObject)
ironts.add((OWLNamedObject) value);
else if (value instanceof IRI)
ironts.add(df.getOWLNamedIndividual((IRI) value));
}
}
}
for (OWLNamedObject iront : ironts) {
IRI childId = iront.getIRI();
// If some populate*() method has created it, it will be there.
RegistryItem ront = population.get(childId);
// Otherwise populating it will also put it in population.
if (ront == null)
ront = populateOntology(iront, registries);
lib.addChild(ront);
if (ontologyIndex.get(childId) == null)
ontologyIndex.put(childId, new HashSet<IRI>());
ontologyIndex.get(childId).add(libId);
}
return (Library) lib;
}
use of org.semanticweb.owlapi.model.OWLIndividual in project stanbol by apache.
the class TestOntologySpaces method setup.
@BeforeClass
public static void setup() throws Exception {
factory = onManager.getOntologySpaceFactory();
if (factory == null)
fail("Could not instantiate ontology space factory");
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
OWLDataFactory df = mgr.getOWLDataFactory();
ont = mgr.createOntology(baseIri);
inMemorySrc = new RootOntologySource(ont);
// Let's state that Linus is a human being
OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
mgr.applyChange(new AddAxiom(ont, linusIsHuman));
ont2 = mgr.createOntology(baseIri2);
minorSrc = new RootOntologySource(ont2);
dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
minorSrc = new RootOntologySource(ont2);
}
use of org.semanticweb.owlapi.model.OWLIndividual in project stanbol by apache.
the class OntologyNetworkConfigurationUtils method getScopesToActivate.
/**
* Get the list of scopes to activate on startup
*
* @param config
* @return
*/
public static String[] getScopesToActivate(OWLOntology config) {
Set<OWLIndividual> scopes = cScope.getIndividuals(config);
List<String> result = new ArrayList<String>();
boolean doActivate = false;
for (OWLIndividual iScope : scopes) {
Set<OWLLiteral> activate = iScope.getDataPropertyValues(activateOnStart, config);
Iterator<OWLLiteral> it = activate.iterator();
while (it.hasNext() && !doActivate) {
OWLLiteral l = it.next();
doActivate |= Boolean.parseBoolean(l.getLiteral());
}
if (iScope.isNamed() && doActivate)
result.add(((OWLNamedIndividual) iScope).getIRI().toString());
}
return result.toArray(EMPTY_IRI_ARRAY);
}
Aggregations