public static String getIri(OWLClassExpression expression) { if (expression.isAnonymous()) { return "_:" + hash(expression.toString()); } else { return expression.asOWLClass().getIRI().toString(); } }
/** * Determines if a class description contains any unreferenced entities with respect to the ontology that contains the entailments which are being * explained. * * @param desc The description to be searched * @return <code>true</code> if the description references entities that the ontology that contains entailments which are being explained, otherwise * <code>false</code> */ public static boolean containsUnreferencedEntity(final OWLOntology ontology, final OWLClassExpression desc) { for (final OWLEntity entity : desc.signature().collect(Collectors.toList())) if (!ontology.containsEntityInSignature(entity)) { if (entity instanceof OWLClass && (((OWLClass) entity).isOWLThing() || ((OWLClass) entity).isOWLNothing())) continue; return true; } return false; }
@Override public void visit(OWLClass desc) { if (!done && !processedClasses.contains(desc)) { processedClasses.add(desc); Set<OWLClassExpression> set = desc.getSuperClasses(onts); for (OWLClassExpression s : set) { if (s.equals(desc)) { break; } else if (!done && !(s.isAnonymous() || s.asOWLClass().isBuiltIn())) s.asOWLClass().accept(this); } } }
@Override public Boolean visit(OWLClass object) { if (object.isOWLThing()) return Boolean.FALSE; else if (object.isOWLNothing()) return Boolean.FALSE; else return Boolean.TRUE; } @Override
public void visit(OWLClass cls) { if (onts != null){ for (OWLClassExpression superCls : cls.getSuperClasses(onts)){ superCls.accept(this); } for (OWLClassExpression equiv : cls.getEquivalentClasses(onts)){ equiv.accept(this); } } }
public OWLClassExpression visit(OWLClass d) { if (d.isOWLThing()) return m_factory.getOWLNothing(); if (d.isOWLNothing()) return m_factory.getOWLThing(); return m_factory.getOWLObjectComplementOf(d); } public OWLClassExpression visit(OWLObjectIntersectionOf d) {
/** * Tr term frame. * * @param termFrame the term frame * @return the oWL class expression */ public OWLClassExpression trTermFrame(Frame termFrame) { OWLClass cls = trClass(checkNotNull(termFrame.getId())); add(fac.getOWLDeclarationAxiom(cls)); termFrame.getTags().stream().filter(OboFormatTag.TAG_ALT_ID.getTag()::equals).forEach(t -> // Generate deprecated and replaced_by details for alternate // identifier add(translateAltIds(termFrame.getClauses(t), cls.getIRI(), true))); termFrame.getTags().forEach(t -> add(trTermFrameClauses(cls, termFrame.getClauses(t), t))); return cls; }
private void indexEquivalentRelations(OWLClass owlClass) throws OWLOntologyCreationException { OWLReasoner reasoner = getOWLReasoner(ontology); // get direct children addEquivalentTerms(owlClass.getIRI(), reasoner.getEquivalentClasses(owlClass).getEntities().stream() .map(OWLNamedObject::getIRI) .collect(Collectors.toSet())); Set<String> relatedDescriptions = new HashSet<>(); for (OWLClassExpression expression : owlClass.getEquivalentClasses(getManager().getOntologies())) { if (expression.isAnonymous()) { relatedDescriptions.add(manSyntaxRenderer.render(expression)); } } if (!relatedDescriptions.isEmpty()) { addEquivalentClassDescriptions(owlClass.getIRI(), relatedDescriptions); } }
@Override public void visit(OWLObjectIntersectionOf ce) { Set<OWLClassExpression> operands = ce.operands().collect(Collectors.toSet()); AbstractNode node = vowlData.getClassForIri(owlClass.getIRI()); for (OWLClassExpression operand : operands) { if (!operand.isAnonymous()) { node.addElementToIntersection(operand.asOWLClass().getIRI()); node.addAttribute(VowlAttribute.INTERSECTION); } else { // TODO Anonymous undefined behavior logger.info("Anonymous exists in intersections. " + operand); } } }
/** * Imports closure changed. */ protected final void importsClosureChanged() { // NOTE: This method only gets called when the ontology being parsed // adds a direct import. This is enough // for resolving the imports closure. // We cache IRIs of various entities here. // We also mop up any triples that weren't parsed and consumed in the // imports closure. ontology.annotationPropertiesInSignature(INCLUDED) .forEach(e -> annPropertyIRIs.add(e.getIRI())); ontology.dataPropertiesInSignature(INCLUDED).forEach(e -> dataPropertyIRIs.add(e.getIRI())); ontology.objectPropertiesInSignature(INCLUDED) .forEach(e -> objectPropertyIRIs.add(e.getIRI())); ontology.classesInSignature(INCLUDED).forEach(e -> classIRIs.add(e.getIRI())); ontology.datatypesInSignature(INCLUDED).forEach(e -> dataRangeIRIs.add(e.getIRI())); ontology.individualsInSignature(INCLUDED).forEach(e -> individualIRIs.add(e.getIRI())); }
@Override public Set<OWLObject> getOWLObjects(OWLOntology ontology, ErrorListener errorListener) { Set<OWLObject> toReturn = new HashSet<>(); ontology.classesInSignature().forEach(owlClass -> EntitySearcher .getAnnotationAssertionAxioms(owlClass.getIRI(), ontology).forEach(annotationAxiom -> { PatternExtractor patternExtractor = patternModel.getPatternModelFactory().getPatternExtractor(errorListener); OWLAnnotation annotation = annotationAxiom.getAnnotation(); PatternOPPLScript script = annotation.accept(patternExtractor); if (script != null && getName().equals(script.getName())) { toReturn.add(annotationAxiom); } })); return toReturn; }
@Override public void visit(OWLObjectComplementOf object) { OWLClassExpression description=object.getOperand(); if (description instanceof OWLObjectHasSelf) { OWLObjectPropertyExpression objectProperty=((OWLObjectHasSelf)description).getProperty(); Atom roleAtom=getRoleAtom(objectProperty,X,X); m_bodyAtoms.add(roleAtom); } else if (description instanceof OWLObjectOneOf && ((OWLObjectOneOf)description).individuals().count()==1) { OWLIndividual individual=((OWLObjectOneOf)description).individuals().iterator().next(); m_bodyAtoms.add(Atom.create(getConceptForNominal(individual),X)); } else if (!(description instanceof OWLClass)) throw new IllegalStateException(INVALID_NORMAL_FORM); else m_bodyAtoms.add(Atom.create(AtomicConcept.create(((OWLClass)description).getIRI().toString()),X)); } @Override
public Collection<DeviceClassMetadata> getAllDeviceClasses() { IRI controllableURI = IRI.create(this.ontologyWithDOGONT.getOntologyID().getOntologyIRI().toString() + "#Controllable"); OWLClass controllableClass = this.ontManager.getOWLDataFactory().getOWLClass(controllableURI); SubClassesVisitor descendantsVisitor = new SubClassesVisitor(ontology, controllableClass); controllableClass.accept(descendantsVisitor); Set<OWLClass> descendants = descendantsVisitor.getClasses(); ArrayList<DeviceClassMetadata> devices = new ArrayList<>(); for (OWLClass d : descendants) { String name = d.getIRI().toString(); if (!name.equalsIgnoreCase(NOTHING)) { if (d.getSubClasses(ontology).isEmpty()) { devices.add(this.getDeviceClassById(d.getIRI().toString())); } } } return devices; }
Set<OWLSubClassOfAxiom> subClassOfAxioms = ((OWLEquivalentClassesAxiom)pattern).asOWLSubClassOfAxioms(); for (OWLSubClassOfAxiom axiom : subClassOfAxioms) { if(!axiom.getSubClass().isAnonymous()){ patternSubClass = axiom.getSubClass(); patternSuperClass = axiom.getSuperClass(); Set<OWLEntity> signature = patternSuperClass.getSignature(); signature.remove(patternSubClass.asOWLClass()); Query query = converter.asQuery("?x", dataFactory.getOWLObjectIntersectionOf(cls, patternSuperClass), signature); logger.info("Running query\n" + query); Map<OWLEntity, String> variablesMapping = converter.getVariablesMapping(); entity2IRIMap.put(patternSubClass.asOWLClass(), cls.getIRI()); boolean skip = false; for (OWLEntity entity : signature) { String var = variablesMapping.get(entity); if(qs.get(var) == null){ logger.warn("Variable " + var + " is not bound."); skip = true; break; if(qs.get(var).isLiteral()){ skip = true; break; break; entity2IRIMap.put(entity, IRI.create(resource.getURI()));
private OWLClass generateComplementRepresentation(Taxonomy<OWLClass> taxonomy, OWLClassExpression originalClass) { OWLClass complementClass = null; if( !originalClass.isAnonymous() && ( originalClass instanceof OWLClass ) ) { return OWL.factory.getOWLClass( IRI.create( ( (OWLClass) originalClass ).getIRI() + COMPLEMENT_POSTFIX ) ); } do { complementClass = OWL.factory.getOWLClass( IRI.create( ANONYMOUS_COMPLEMENT_REPRESENTATION_BASE + RND.nextLong()) ); } while ( taxonomy.contains( complementClass ) ); return complementClass; }
public ControlCommandMetadata getControlCommandMetadataById(String id) { IRI funcURI = IRI.create(id); OWLClass cmdClass = this.ontManager.getOWLDataFactory().getOWLClass(funcURI); String cmdId = id; int numParams = 0; NParamsDescriptionReader npdr = new NParamsDescriptionReader(this.ontology); for (OWLSubClassOfAxiom a : this.ontology.getSubClassAxiomsForSubClass(cmdClass)) { a.getSuperClass().accept(npdr); } if (npdr.isNParamsDescription()) { cmdId = cmdClass.getIRI().toString(); numParams = npdr.getNParams(); } return new ControlCommandMetadata(cmdId, numParams); }
public boolean isValidConceptName(String cName) { boolean isValid = false; OWLDataFactory df = ont.getOWLOntologyManager().getOWLDataFactory(); OWLClass c = df.getOWLClass(IRI.create(cName)); if(ont.containsClassInSignature(c.getIRI())) isValid = true; else System.err.println("\tInvalid concept name. '" + cName + "' is not contained in the ontology signature"); return isValid; }
public void addSynonym(OWLClass cls, String synonym) { OWLAnnotationProperty property = factory.getOWLAnnotationProperty(IRI .create("http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#FULL_SYN")); OWLAnnotation commentAnno = factory.getOWLAnnotation(property, factory.getOWLLiteral(synonym, "en")); OWLAxiom ax = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), commentAnno); manager.applyChange(new AddAxiom(ontology, ax)); }
public Collection<DeviceClassMetadata> getDeviceClassDescendants(DeviceClassMetadata dc) { IRI deviceURI = IRI.create(dc.getClassId()); OWLClass deviceClass = this.ontManager.getOWLDataFactory().getOWLClass(deviceURI); SubClassesVisitor descendantsVisitor = new SubClassesVisitor(ontology, deviceClass); deviceClass.accept(descendantsVisitor); Set<OWLClass> subclases = descendantsVisitor.getClasses(); ArrayList<DeviceClassMetadata> devices = new ArrayList<>(); for (OWLClass d : subclases) { String name = d.getIRI().toString(); if (!name.equalsIgnoreCase(NOTHING)) { devices.add(this.getDeviceClassById(d.getIRI().toString())); } } return devices; }