public String getValueAsString() { if (value instanceof IRI) { return value.toString(); } else if (value instanceof OWLLiteral) { return ((OWLLiteral) value).getLiteral(); } else if (value instanceof OWLAnonymousIndividual) { return ((OWLAnonymousIndividual) value).getID().toString(); } else if (value instanceof Var) { return ((Var) value).getName(); } else { return value.toString(); } }
private String getStringValue(OWLAnnotationAssertionAxiom ax) { OWLAnnotationValue value = ax.getValue(); String stringValue = value.accept(new OWLAnnotationValueVisitorEx<String>() { @Override public String visit(IRI iri) { return iri.toString(); } @Override public String visit(OWLAnonymousIndividual individual) { return null; } @Override public String visit(OWLLiteral literal) { return literal.getLiteral(); } }); return stringValue; }
private static JsonAnnotation create(final String key, OWLAnnotationValue value, final CurieHandler curieHandler) { return value.accept(new OWLAnnotationValueVisitorEx<JsonAnnotation>() { @Override public JsonAnnotation visit(IRI iri) { String iriString = curieHandler.getCuri(iri); return JsonAnnotation.create(key, iriString, VALUE_TYPE_IRI); } @Override public JsonAnnotation visit(OWLAnonymousIndividual individual) { return null; // do nothing } @Override public JsonAnnotation visit(OWLLiteral literal) { return JsonAnnotation.create(key, literal.getLiteral(), getType(literal)); } }); }
private static void extractEvidenceIRIValues(OWLAnnotation annotation, final Set<IRI> iriSet) { if (annotation != null) { OWLAnnotationProperty property = annotation.getProperty(); if (HAS_EVIDENCE_IRI.equals(property.getIRI()) || HAS_EVIDENCE_IRI_OLD.equals(property.getIRI())){ annotation.getValue().accept(new OWLAnnotationValueVisitor() { @Override public void visit(OWLLiteral literal) { // ignore } @Override public void visit(OWLAnonymousIndividual individual) { // ignore } @Override public void visit(IRI iri) { iriSet.add(iri); } }); } } }
/** * As in Mouse and NCI anatomy. Annotations al rdf:labels in anonymous individuals * It seems also GO ontology (to be checked) * @param entityAnnAx * @return */ private String asAnonymousIndividual(OWLAnnotationAssertionAxiom entityAnnAx, OWLOntology onto){ try { geneid_value=((OWLAnonymousIndividual)entityAnnAx.getAnnotation().getValue()).asOWLAnonymousIndividual();//.getID() for (OWLAnnotationAssertionAxiom annGeneidAx : onto.getAnnotationAssertionAxioms(geneid_value)){ if (annGeneidAx.getAnnotation().getProperty().getIRI().toString().equals(rdf_label_uri)){ return ((OWLLiteral)annGeneidAx.getAnnotation().getValue()).getLiteral().toLowerCase(); } } return ""; } catch (Exception e){ //In case of error. Accessing an object in an expected way return ""; } }
public void visit(OWLDataPropertyAssertionAxiom axiom) { if (!axiom.getSubject().isAnonymous()) { return; // not interesting for the anonymous individual forest } OWLAnonymousIndividual sub=axiom.getSubject().asOWLAnonymousIndividual(); nodes.add(sub); OWLClassExpression c=factory.getOWLDataHasValue(axiom.getProperty(),axiom.getObject()); if (nodelLabels.containsKey(sub)) { nodelLabels.get(sub).add(c); } else { Set<OWLClassExpression> labels=new HashSet<OWLClassExpression>(); labels.add(c); nodelLabels.put(sub,labels); } }
private OWLNamedIndividual findEvidenceIndividual(OWLAnnotationValue value) { return value.accept(new OWLAnnotationValueVisitorEx<OWLNamedIndividual>() { @Override public OWLNamedIndividual visit(final IRI iri) { OWLNamedIndividual i = null; for(OWLNamedIndividual current : model.getIndividualsInSignature()) { if (current.getIRI().equals(iri)) { i = current; break; } } return i; } @Override public OWLNamedIndividual visit(OWLAnonymousIndividual individual) { return null; } @Override public OWLNamedIndividual visit(OWLLiteral literal) { return null; } }); }
public static String getLabel(OWLEntity e, OWLOntology ont) { final Iterator<OWLAnnotation> iterator = EntitySearcher.getAnnotations(e, ont).iterator(); while (iterator.hasNext()) { final OWLAnnotation an = iterator.next(); if (an.getProperty().isLabel()) { OWLAnnotationValue val = an.getValue(); if (val instanceof IRI) { return ((IRI) val).toString(); } else if (val instanceof OWLLiteral) { OWLLiteral lit = (OWLLiteral) val; return lit.getLiteral(); } else if (val instanceof OWLAnonymousIndividual) { OWLAnonymousIndividual ind = (OWLAnonymousIndividual) val; return ind.toStringID(); } else { throw new RuntimeException("Unexpected class " + val.getClass()); } } } return e.toStringID(); }
public static String getLabel(OWLEntity e, OWLOntology ont) { return EntitySearcher.getAnnotations(e, ont) .filter(an -> an.getProperty().isLabel()) .findFirst() .map(an -> { final OWLAnnotationValue val = an.getValue(); if (val instanceof IRI) { return ((IRI) val).toString(); } else if (val instanceof OWLLiteral) { OWLLiteral lit = (OWLLiteral) val; return lit.getLiteral(); } else if (val instanceof OWLAnonymousIndividual) { OWLAnonymousIndividual ind = (OWLAnonymousIndividual) val; return ind.toStringID(); } else { throw new RuntimeException("Unexpected class " + val.getClass()); } }) .orElse(e.toStringID()); }
@Override public void addToOntology() { OWLClass clazz = featurePool.getReusableClass(); OWLAnonymousIndividual individual = factory.getOWLAnonymousIndividual(); addAxiomToOntology(factory.getOWLClassAssertionAxiom(clazz, individual)); }
@Test public void testIsBnode() { QueryArgument arg = new QueryArgument(mock(OWLAnonymousIndividual.class)); assertTrue(arg.isBnode()); QueryArgument arg2 = new QueryArgument(new Var("x")); assertFalse(arg2.isBnode()); }
public static String getModelState(OWLOntology model, String defaultValue) { String modelState = defaultValue; Set<OWLAnnotation> modelAnnotations = model.getAnnotations(); for (OWLAnnotation modelAnnotation : modelAnnotations) { IRI propIRI = modelAnnotation.getProperty().getIRI(); if (AnnotationShorthand.modelstate.getAnnotationProperty().equals(propIRI)) { String value = modelAnnotation.getValue().accept(new OWLAnnotationValueVisitorEx<String>() { @Override public String visit(IRI iri) { return null; } @Override public String visit(OWLAnonymousIndividual individual) { return null; } @Override public String visit(OWLLiteral literal) { return literal.getLiteral(); } }); if (value != null) { modelState = value; } } } return modelState; }
static boolean isTagged(Set<OWLAnnotation> annotations, OWLAnnotationProperty p) { if (annotations != null && !annotations.isEmpty()) { for (OWLAnnotation annotation : annotations) { if (p.equals(annotation.getProperty())) { String value = annotation.getValue().accept(new OWLAnnotationValueVisitorEx<String>() { @Override public String visit(IRI iri) { return null; } @Override public String visit(OWLAnonymousIndividual individual) { return null; } @Override public String visit(OWLLiteral literal) { return literal.getLiteral(); } }); if (value != null && ModelWriterHelper.DERIVED_VALUE.equalsIgnoreCase(value)) { return true; } } } } return false; }
protected OWLClassExpression getClassExpressionFor(OWLDataFactory factory,OWLAnonymousIndividual node,OWLAnonymousIndividual predecessor) { Set<OWLAnonymousIndividual> successors=edges.get(node); if (successors==null||(successors.size()==1&&successors.iterator().next()==predecessor)) { // the tree consists of a single node if (!nodelLabels.containsKey(node)) { return factory.getOWLThing(); } else if (nodelLabels.get(node).size()==1) { return nodelLabels.get(node).iterator().next(); } else { return factory.getOWLObjectIntersectionOf(nodelLabels.get(node)); } } Set<OWLClassExpression> concepts=new HashSet<OWLClassExpression>(); for (OWLAnonymousIndividual successor : successors) { OWLObjectProperty op; Edge pair=new Edge(node,successor); if (edgeOPLabels.containsKey(pair)) { op=edgeOPLabels.get(pair); } else { pair=new Edge(successor,node); if (!edgeOPLabels.containsKey(pair)) { throw new RuntimeException("Internal error: some edge in the forest of anonymous individuals has no edge label although it should. "); } else { op=edgeOPLabels.get(pair); } } concepts.add(factory.getOWLObjectSomeValuesFrom(op,getClassExpressionFor(factory,successor,node))); } return concepts.size()==1 ? concepts.iterator().next() : factory.getOWLObjectIntersectionOf(concepts); }
protected Map<Set<OWLAnonymousIndividual>,OWLAnonymousIndividual> findSuitableRoots(Set<Set<OWLAnonymousIndividual>> components) { Map<Set<OWLAnonymousIndividual>,OWLAnonymousIndividual> componentsToRoots=new HashMap<Set<OWLAnonymousIndividual>,OWLAnonymousIndividual>(); for (Set<OWLAnonymousIndividual> component : components) { // We have to find a node with at most one relation to the named individuals // if there is one with exactly one relation that is a bit nicer for the rolling-up // so we try to find that OWLAnonymousIndividual root=null; OWLAnonymousIndividual rootWithOneNamedRelation=null; for (OWLAnonymousIndividual ind : component) { if (specialOPEdges.containsKey(ind)) { if (specialOPEdges.get(ind).size()<2) { rootWithOneNamedRelation=ind; } } else { root=ind; } } if (root==null&&rootWithOneNamedRelation==null) { throw new IllegalArgumentException("Invalid input ontology: One of the trees in the forst of anomnymous individuals has no root that satisfies the criteria on roots (cf. OWL 2 Structural Specification and Functional-Style Syntax, Sec. 11.2)."); } else if (rootWithOneNamedRelation!=null) { componentsToRoots.put(component,rootWithOneNamedRelation); } else { componentsToRoots.put(component,root); } } return componentsToRoots; }
protected Set<Set<OWLAnonymousIndividual>> getComponents() { Set<Set<OWLAnonymousIndividual>> components=new HashSet<Set<OWLAnonymousIndividual>>(); if (nodes.isEmpty()) return components; Set<OWLAnonymousIndividual> toProcess=nodes; Set<OWLAnonymousIndividual> currentComponent; List<Edge> workQueue=new ArrayList<Edge>(); Edge nodePlusPredecessor; while (!toProcess.isEmpty()) { currentComponent=new HashSet<OWLAnonymousIndividual>(); nodePlusPredecessor=new Edge(toProcess.iterator().next(),null); workQueue.add(nodePlusPredecessor); while (!workQueue.isEmpty()) { nodePlusPredecessor=workQueue.remove(0); currentComponent.add(nodePlusPredecessor.first); // see whether there are any successors that we have to check if (edges.containsKey(nodePlusPredecessor.first)) { // add successors to the workQueue for (OWLAnonymousIndividual ind : edges.get(nodePlusPredecessor.first)) { if (nodePlusPredecessor.second==null||!(ind.getID().equals(nodePlusPredecessor.second.getID()))) { // check for cycle for (Edge pair : workQueue) { if (pair.first==ind) { throw new IllegalArgumentException("Invalid input ontology: The anonymous individuals cannot be arranged into a forest as required (cf. OWL 2 Structural Specification and Functional-Style Syntax, Sec. 11.2) because there is a cycle. "); } } workQueue.add(new Edge(ind,nodePlusPredecessor.first)); } } } } components.add(currentComponent); toProcess.removeAll(currentComponent); } return components; }
public static Set<OWLObject> findTaggedEntities(OWLAnnotationProperty p, Set<OWLAnnotationValue> values, final OWLGraphWrapper graph) { if (p == null || values == null || values.isEmpty()) { return Collections.emptySet(); } final Set<OWLObject> entities = new HashSet<OWLObject>(); Set<OWLOntology> allOntologies = graph.getAllOntologies(); for (OWLOntology ontology : allOntologies) { Set<OWLAnnotationAssertionAxiom> axioms = ontology.getAxioms(AxiomType.ANNOTATION_ASSERTION); for (OWLAnnotationAssertionAxiom axiom : axioms) { if (p.equals(axiom.getProperty()) && values.contains(axiom.getValue())) { axiom.getSubject().accept(new OWLAnnotationSubjectVisitor(){ @Override public void visit(IRI iri) { OWLObject owlObject = graph.getOWLObject(iri); if (owlObject != null) { entities.add(owlObject); } } @Override public void visit(OWLAnonymousIndividual individual) { // do nothing } }); } } } return entities; }
public static String getIri(OWLIndividual individual) { if (individual.isAnonymous()) { return ((OWLAnonymousIndividual)individual).getID().getID(); } else { return individual.asOWLNamedIndividual().getIRI().toString(); } }
@Override public void addAnonymousIndividualsToSet(Set<OWLAnonymousIndividual> anons) { addAnonymousIndividualsToSetForValue(anons, getFiller()); addAnonymousIndividualsToSetForValue(anons, property); if (property instanceof HasIncrementalSignatureGenerationSupport) { HasIncrementalSignatureGenerationSupport property1 = (HasIncrementalSignatureGenerationSupport) property; property1.addAnonymousIndividualsToSet(anons); } }
@Override public void addAnonymousIndividualsToSet(Set<OWLAnonymousIndividual> anons) { if (getSubject().isAnonymous()) { anons.add(getSubject().asOWLAnonymousIndividual()); } addAnonymousIndividualsToSetForValue(anons, getProperty()); addAnonymousIndividualsToSetForValue(anons, getObject()); }
@Override public void visit(OWLAnonymousIndividual individual) { // Anon individuals aren't entities // But store them in a set anyway for utility if (anonymousIndividuals != null) { verifyNotNull(anonymousIndividuals).add(individual); } }
@Override public void addAnonymousIndividualsToSet(Set<OWLAnonymousIndividual> anons) { for (OWLIndividual individual : values) { if (individual.isAnonymous()) { anons.add(individual.asOWLAnonymousIndividual()); } } }
@Override public void addAnonymousIndividualsToSet(Set<OWLAnonymousIndividual> anons) { for (OWLIndividual individual : individuals) { if (individual.isAnonymous()) { anons.add(individual.asOWLAnonymousIndividual()); } } }
public int getIndex(OWLAnonymousIndividual ind) { Integer i = indexMap.get(ind); if(i == null) { i = indexMap.size(); indexMap.put(ind, i); } return i; }
public QueryArgument(OWLAnonymousIndividual value) { this.type = QueryArgumentType.BNODE; this.value = value; }
public OWLAnonymousIndividual getValueAsBNode() { return (OWLAnonymousIndividual) value; }
static void fillAspects(OWLOntology model, OWLReasoner reasoner, CurieHandler curieHandler, Set<OWLClass> bpSet, Set<OWLClass> mfSet, Set<OWLClass> ccSet, OWLClass bp, OWLClass mf, OWLClass cc) { final IRI namespaceIRI = Obo2Owl.trTagToIRI(OboFormatTag.TAG_NAMESPACE.getTag()); final OWLDataFactory df = model.getOWLOntologyManager().getOWLDataFactory(); final OWLAnnotationProperty namespaceProperty = df.getOWLAnnotationProperty(namespaceIRI); final Set<OWLOntology> ontologies = model.getImportsClosure(); for(OWLClass cls : model.getClassesInSignature(Imports.INCLUDED)) { if (cls.isBuiltIn()) { continue; } String id = curieHandler.getCuri(cls); if (id.startsWith("GO:") == false) { continue; } // if a reasoner object is passed, use inference to populate // the 3 subset if (reasoner != null) { if (reasoner.getSuperClasses(cls, false).containsEntity(mf) || reasoner.getEquivalentClasses(cls).contains(mf)) { mfSet.add(cls); } if (reasoner.getSuperClasses(cls, false).containsEntity(bp) || reasoner.getEquivalentClasses(cls).contains(bp)) { bpSet.add(cls); } if (reasoner.getSuperClasses(cls, false).containsEntity(cc) || reasoner.getEquivalentClasses(cls).contains(cc)) { ccSet.add(cls); } } for (OWLAnnotation annotation : OwlHelper.getAnnotations(cls, ontologies)) { if (annotation.getProperty().equals(namespaceProperty)) { String value = annotation.getValue().accept(new OWLAnnotationValueVisitorEx<String>() { @Override public String visit(IRI iri) { return null; } @Override public String visit(OWLAnonymousIndividual individual) { return null; } @Override public String visit(OWLLiteral literal) { return literal.getLiteral(); } }); if (value != null) { if ("molecular_function".equals(value)) { mfSet.add(cls); } else if ("biological_process".equals(value)) { bpSet.add(cls); } else if ("cellular_component".equals(value)) { ccSet.add(cls); } } } } } }
public void visit(OWLAnonymousIndividual individual){ //Do nothing }
protected static Individual H(OWLAnonymousIndividual anonymousIndividual) { return Individual.createAnonymous(anonymousIndividual.getID() .toString()); }
protected static Individual H(OWLIndividual individual) { if (individual.isAnonymous()) return H((OWLAnonymousIndividual) individual); else return H((OWLNamedIndividual) individual); }
public Edge(OWLAnonymousIndividual first,OWLAnonymousIndividual second) { this.first=first; this.second=second; }
@Override public OWLAnonymousIndividual visit(ElkAnonymousIndividual expression) { return owlFactory_.getOWLAnonymousIndividual(expression.getNodeId()); }
@SuppressWarnings("static-method") public ElkAnonymousIndividual convert( OWLAnonymousIndividual owlAnonymousIndividual) { return new ElkAnonymousIndividualWrap<OWLAnonymousIndividual>( owlAnonymousIndividual); }
@Override public ElkAnonymousIndividual visit( OWLAnonymousIndividual owlAnonymousIndividual) { return CONVERTER.convert(owlAnonymousIndividual); }
@Override public ElkAnonymousIndividual visit(OWLAnonymousIndividual anon) { return CONVERTER.convert(anon); }