@Override public ClientApiOntology getClientApiObject(String workspaceId) { return super.getClientApiObject(workspaceId); }
private void importObjectProperties(OWLOntology o, Authorizations authorizations) { for (OWLObjectProperty objectProperty : o.getObjectPropertiesInSignature()) { importObjectProperty(o, objectProperty, authorizations); } }
private void importOntologyAnnotationProperties(OWLOntology o, File inDir, Authorizations authorizations) { for (OWLAnnotationProperty annotation : o.getAnnotationPropertiesInSignature()) { importOntologyAnnotationProperty(o, annotation, inDir, authorizations); } }
public void loadOntologies(Configuration config, Authorizations authorizations) throws Exception { lockRepository.lock("ontology", () -> { Concept rootConcept = internalGetOrCreateConcept(null, ROOT_CONCEPT_IRI, "root", null, null, null, false, getSystemUser(), PUBLIC); Concept entityConcept = internalGetOrCreateConcept(rootConcept, ENTITY_CONCEPT_IRI, "thing", null, null, null, false, getSystemUser(), PUBLIC); getOrCreateTopObjectPropertyRelationship(authorizations); clearCache(); addEntityGlyphIcon(entityConcept, authorizations); importResourceOwl(OntologyRepositoryBase.class, "base.owl", BASE_OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "user.owl", UserRepository.OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "termMention.owl", TermMentionRepository.OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "workspace.owl", WorkspaceRepository.OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "comment.owl", COMMENT_OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "search.owl", SearchProperties.IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "longRunningProcess.owl", LongRunningProcessProperties.OWL_IRI, authorizations); importResourceOwl(OntologyRepositoryBase.class, "ping.owl", PingOntology.BASE_IRI, authorizations); File owlFile = findOwlFile(new File(dir)); if (owlFile == null) { throw new VisalloResourceNotFoundException( ); importFile(owlFile, IRI.create(iri), authorizations); } else { writePackage(new File(file), IRI.create(iri), authorizations);
Authorizations authorizations ) throws Exception { if (!hasFileChanged(documentIRI, inFileData)) { LOGGER.info("skipping %s, file has not changed", documentIRI); return; OWLOntologyManager m = createOwlOntologyManager(config, documentIRI); importOntologyAnnotationProperties(o, inDir, authorizations); clearCache(); // this is required to cause a new lookup of classes for data and object properties. long endTime = System.currentTimeMillis(); long importAnnotationPropertiesTime = endTime - startTime; importOntologyClasses(o, inDir, authorizations); clearCache(); // this is required to cause a new lookup of classes for data and object properties. endTime = System.currentTimeMillis(); long importConceptsTime = endTime - startTime; importObjectProperties(o, authorizations); clearCache(); // needed to find the relationship for inverse of endTime = System.currentTimeMillis(); long importObjectPropertiesTime = endTime - startTime; importInverseOfObjectProperties(o); endTime = System.currentTimeMillis(); long importInverseOfObjectPropertiesTime = endTime - startTime; importDataProperties(o, authorizations); endTime = System.currentTimeMillis();
public void deleteConcept(String conceptTypeIri, User user, String workspaceId) { checkDeletePrivileges(user, workspaceId); Set<Concept> concepts = getConceptAndAllChildrenByIri(conceptTypeIri, workspaceId); if (concepts.size() == 1) { for (Concept concept : concepts) { if (concept.getSandboxStatus().equals(SandboxStatus.PRIVATE)) { for (Relationship relationship : getRelationships(workspaceId)) { if (relationship.getDomainConceptIRIs().contains(conceptTypeIri) || relationship.getRangeConceptIRIs().contains(conceptTypeIri)) { Graph graph = getGraph(); Authorizations authorizations = graph.createAuthorizations(workspaceId); GraphQuery query = graph.query(authorizations); addConceptTypeFilterToQuery(query, concept.getIRI(), false, workspaceId); query.limit(0); long results = query.search().getTotalHits(); ).collect(Collectors.toList()); internalDeleteConcept(concept, workspaceId); internalDeleteProperty(property, workspaceId);
public void deleteRelationship(String relationshipIri, User user, String workspaceId) { checkDeletePrivileges(user, workspaceId); Set<Relationship> relationships = getRelationshipAndAllChildrenByIRI(relationshipIri, workspaceId); if (relationships.size() == 1) { for (Relationship relationship : relationships) { if (relationship.getSandboxStatus().equals(SandboxStatus.PRIVATE)) { Graph graph = getGraph(); Authorizations authorizations = graph.createAuthorizations(workspaceId); GraphQuery query = graph.query(authorizations); addEdgeLabelFilterToQuery(query, relationshipIri, false, workspaceId); query.limit(0); long results = query.search().getTotalHits(); ontologyProperty.getRelationshipIris().get(0).equals(relationshipIri) ).collect(Collectors.toList()); internalDeleteRelationship(relationship, workspaceId); internalDeleteProperty(property, workspaceId);
private Relationship getParentObjectProperty( OWLOntology o, OWLObjectProperty objectProperty, Authorizations authorizations ) { Collection<OWLObjectPropertyExpression> superProperties = EntitySearcher.getSuperProperties(objectProperty, o); if (superProperties.size() == 0) { return getOrCreateTopObjectPropertyRelationship(authorizations); } else if (superProperties.size() == 1) { OWLObjectPropertyExpression superPropertyExpr = superProperties.iterator().next(); OWLObjectProperty superProperty = superPropertyExpr.asOWLObjectProperty(); String superPropertyUri = superProperty.getIRI().toString(); Relationship parent = getRelationshipByIRI(superPropertyUri, PUBLIC); if (parent != null) { return parent; } parent = importObjectProperty(o, superProperty, authorizations); if (parent == null) { throw new VisalloException("Could not find or create parent: " + superProperty); } return parent; } else { throw new VisalloException("Unhandled multiple super properties. Found " + superProperties.size() + ", expected 0 or 1."); } }
protected Concept getParentConcept( OWLOntology o, OWLClass ontologyClass, File inDir, Authorizations authorizations ) throws IOException { Collection<OWLClassExpression> superClasses = EntitySearcher.getSuperClasses(ontologyClass, o); if (superClasses.size() == 0) { return getEntityConcept(OntologyRepository.PUBLIC); } else if (superClasses.size() == 1) { OWLClassExpression superClassExpr = superClasses.iterator().next(); OWLClass superClass = superClassExpr.asOWLClass(); String superClassUri = superClass.getIRI().toString(); Concept parent = getConceptByIRI(superClassUri, PUBLIC); if (parent != null) { return parent; } parent = importOntologyClass(o, superClass, inDir, authorizations); if (parent == null) { throw new VisalloException("Could not find or create parent: " + superClass); } return parent; } else { throw new VisalloException("Unhandled multiple super classes. Found " + superClasses.size() + ", expected 0 or 1."); } }
boolean updateable = OWLOntologyUtil.getUpdateable(o, dataTypeProperty); User user = getSystemUser(); OWLClass domainClass = domainClassExpr.asOWLClass(); String domainClassIri = domainClass.getIRI().toString(); Concept domainConcept = getConceptByIRI(domainClassIri, PUBLIC); if (domainConcept == null) { LOGGER.error("Could not find class with IRI \"%s\" for data type property \"%s\"", domainClassIri, dataTypeProperty.getIRI()); for (OWLAnnotation domainAnnotation : OWLOntologyUtil.getObjectPropertyDomains(o, dataTypeProperty)) { String domainClassIri = OWLOntologyUtil.getOWLAnnotationValueAsString(domainAnnotation); Relationship domainRelationship = getRelationshipByIRI(domainClassIri, PUBLIC); if (domainRelationship == null) { LOGGER.error("Could not find relationship with IRI \"%s\" for data type property \"%s\"", domainClassIri, dataTypeProperty.getIRI()); Map<String, String> possibleValues = OWLOntologyUtil.getPossibleValues(o, dataTypeProperty); Collection<TextIndexHint> textIndexHints = OWLOntologyUtil.getTextIndexHints(o, dataTypeProperty); OntologyProperty property = addPropertyTo( domainConcepts, domainRelationships,
private void importDataProperties(OWLOntology o, Authorizations authorizations) { // find all extended data tables and pre-create them boolean foundExtendedDataTable = false; for (OWLDataProperty dataTypeProperty : o.getDataPropertiesInSignature()) { for (OWLDataRange rangeClassExpr : EntitySearcher.getRanges(dataTypeProperty, o)) { String rangeIri = ((HasIRI) rangeClassExpr).getIRI().toString(); if (OWLOntologyUtil.EXTENDED_DATA_TABLE_IRI.equals(rangeIri)) { importDataProperty(o, dataTypeProperty, authorizations); foundExtendedDataTable = true; break; } } } if (foundExtendedDataTable) { clearCache(); } for (OWLDataProperty dataTypeProperty : o.getDataPropertiesInSignature()) { importDataProperty(o, dataTypeProperty, authorizations); } }
@Override public final OntologyProperty getOrCreateProperty(OntologyPropertyDefinition ontologyPropertyDefinition, User user, String workspaceId) { checkPrivileges(user, workspaceId); OntologyProperty property = getPropertyByIRI(ontologyPropertyDefinition.getPropertyIri(), workspaceId); if (property != null) { return property; return addPropertyTo( ontologyPropertyDefinition.getConcepts(), ontologyPropertyDefinition.getRelationships(),
@Override public void clearCache(String workspaceId) { checkNotNull(workspaceId, "Workspace should not be null"); LOGGER.info("clearing ontology cache for workspace %s", workspaceId); super.clearCache(workspaceId); graph.flush(); }
@Override protected Concept importOntologyClass( OWLOntology o, OWLClass ontologyClass, File inDir, Authorizations authorizations ) throws IOException { InMemoryConcept concept = (InMemoryConcept) super.importOntologyClass(o, ontologyClass, inDir, authorizations); conceptsCache.get(PUBLIC_ONTOLOGY_CACHE_KEY).put(concept.getIRI(), concept); return concept; }
@Deprecated @Override public final void addConceptTypeFilterToQuery(Query query, Collection<ElementTypeFilter> filters) { addConceptTypeFilterToQuery(query, filters, PUBLIC); }
@Deprecated @Override public final void addEdgeLabelFilterToQuery(Query query, String edgeLabel, boolean includeChildNodes) { addEdgeLabelFilterToQuery(query, edgeLabel, includeChildNodes, PUBLIC); }
private void addEntityGlyphIcon(Concept entityConcept, Authorizations authorizations) { if (entityConcept.getGlyphIcon() != null) { LOGGER.debug("entityConcept GlyphIcon already set. skipping addEntityGlyphIcon."); return; } LOGGER.debug("addEntityGlyphIcon"); InputStream entityGlyphIconInputStream = OntologyRepositoryBase.class.getResourceAsStream(RESOURCE_ENTITY_PNG); checkNotNull(entityGlyphIconInputStream, "Could not load resource " + RESOURCE_ENTITY_PNG); try { ByteArrayOutputStream imgOut = new ByteArrayOutputStream(); IOUtils.copy(entityGlyphIconInputStream, imgOut); byte[] rawImg = imgOut.toByteArray(); addEntityGlyphIconToEntityConcept(entityConcept, rawImg, authorizations); } catch (IOException e) { throw new VisalloException("invalid stream for glyph icon"); } }
@Override public void clearCache() { LOGGER.info("clearing ontology cache"); super.clearCache(); graph.flush(); }
private void importOntologyClasses(OWLOntology o, File inDir, Authorizations authorizations) throws IOException { for (OWLClass ontologyClass : o.getClassesInSignature()) { importOntologyClass(o, ontologyClass, inDir, authorizations); } }
@Deprecated @Override public final void addConceptTypeFilterToQuery(Query query, String conceptTypeIri, boolean includeChildNodes) { addConceptTypeFilterToQuery(query, conceptTypeIri, includeChildNodes, PUBLIC); }