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 void initializeLegacyRelationIndex() { synchronized(legacyRelationIndex) { OWLAnnotationProperty rdfsLabel = OWLManager.getOWLDataFactory().getRDFSLabel(); for (OWLOntology ont : this.getOntology().getImportsClosure()) { for (OWLObjectProperty prop : ont.getObjectPropertiesInSignature()) { for (OWLAnnotationAssertionAxiom axiom : ont.getAnnotationAssertionAxioms(prop.getIRI())) { if (axiom.getProperty().equals(rdfsLabel)) { Optional<OWLLiteral> literalOpt = axiom.getValue().asLiteral(); if (literalOpt.isPresent()) { String label = literalOpt.get().getLiteral(); legacyRelationIndex.put(prop.getIRI(), label.replaceAll(" ", "_")); } } } } } } }
/** * Returns the definitions. * * @param owlClass the owl class * @param ontology the ontology * @return the definitions * @throws Exception the exception */ private Set<Definition> getDefinitions(OWLClass owlClass, OWLOntology ontology) throws Exception { Set<Definition> defs = new HashSet<>(); for (final OWLAnnotationAssertionAxiom axiom : ontology .getAnnotationAssertionAxioms(owlClass.getIRI())) { final OWLAnnotation annotation = axiom.getAnnotation(); if (!isDefinitionAnnotation(annotation)) { continue; } final Definition def = new DefinitionJpa(); setCommonFields(def); // this is based on xml-lang attribute on the annotation def.setValue(getValue(annotation)); defs.add(def); } return defs; }
/** * Returns the attributes. * * @param owlClass the owl class * @param ontology the ontology * @return the attributes * @throws Exception the exception */ private Set<Attribute> getAttributes(OWLClass owlClass, OWLOntology ontology) throws Exception { Set<Attribute> attributes = new HashSet<>(); for (final OWLAnnotationAssertionAxiom axiom : ontology .getAnnotationAssertionAxioms(owlClass.getIRI())) { final OWLAnnotation annotation = axiom.getAnnotation(); if (isAtomAnnotation(annotation)) { continue; } final Attribute attribute = new AttributeJpa(); setCommonFields(attribute); attribute.setName(atnMap.get(getName(annotation)).getAbbreviation()); attribute.setValue(getValue(annotation)); generalEntryValues.add(attribute.getName()); attributes.add(attribute); } return attributes; }
/** * Indicates whether or not obsolete is the case. * * @param owlClass the owl class * @param ontology the ontology * @return <code>true</code> if so, <code>false</code> otherwise * @throws Exception the exception */ private boolean isObsolete(OWLClass owlClass, OWLOntology ontology) throws Exception { String obsoletePattern = getConfigurableValue(getTerminology(), "obsoletePattern"); String obsoleteAnnotation = getConfigurableValue(getTerminology(), "obsoleteAnnotation"); if (obsoletePattern == null || obsoleteAnnotation == null) { return false; } for (final OWLAnnotationAssertionAxiom axiom : ontology .getAnnotationAssertionAxioms(owlClass.getIRI())) { OWLAnnotation annotation = axiom.getAnnotation(); if (!isAtomAnnotation(annotation)) { continue; } // Look for a label matching the pattern if (getName(annotation).equals(label) && getValue(annotation).matches(obsoletePattern)) { return true; } } return false; }
private String asDirectValue(OWLAnnotationAssertionAxiom entityAnnAx){ try { //LogOutput.print(((OWLLiteral)annAx.getAnnotation().getValue()).getLiteral()); String label = ((OWLLiteral)entityAnnAx.getAnnotation().getValue()).getLiteral().toLowerCase(); //System.err.println(entityAnnAx + " " + label); if (label==null || label.equals("null") || label.equals("")){ //System.err.println("NULL LABEL: " + entityAnnAx); return ""; } return label; } catch (Exception e){ //In case of error. Accessing an object in an expected way return ""; } }
/** * 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 ""; } }
/** * In some OBO like ontologies * @param entityAnnAx * @return */ private String asNamedIndividual(OWLAnnotationAssertionAxiom entityAnnAx, OWLOntology onto, OWLDataFactory datafactory){ try { //It is an individual namedIndivIRI=(IRI)entityAnnAx.getAnnotation().getValue(); namedIndiv=datafactory.getOWLNamedIndividual(namedIndivIRI); for (OWLAnnotationAssertionAxiom annIdiv : namedIndiv.getAnnotationAssertionAxioms(onto)){ if (annIdiv.getAnnotation().getProperty().getIRI().toString().equals(rdf_label_uri)){ return ((OWLLiteral)annIdiv.getAnnotation().getValue()).getLiteral().toLowerCase(); } } return ""; } catch (Exception e){ //In case of error. Accessing an object in an expected way return ""; } }
/** * FMA originalannotations annotations appear as datatype assertions * @param entityAnnAx * @return */ private String asNamedIndividualFMA(OWLAnnotationAssertionAxiom entityAnnAx, OWLOntology onto, OWLDataFactory datafactory){ try{ //It is an individual namedIndivIRI=(IRI)entityAnnAx.getAnnotation().getValue(); namedIndiv=datafactory.getOWLNamedIndividual(namedIndivIRI); //for (OWLAnnotation indivAnn : namedIndiv.getAnnotations(onto)){ for (OWLLiteral literal_syn : namedIndiv.getDataPropertyValues(datafactory.getOWLDataProperty(IRI.create(fma_name_uri)), onto)){ return literal_syn.getLiteral().toLowerCase(); } return ""; } catch (Exception e){ //In case of error. Accessing an object in an expected way return ""; } }
private Map<String, Object> renderAnnotationAxioms(Set<OWLAnnotationAssertionAxiom> annotations) { Map<String, Object> result = null; if (annotations != null && !annotations.isEmpty()) { for (OWLAnnotationAssertionAxiom ax : annotations) { OWLAnnotationProperty prop = ax.getProperty(); String literal = getLiteralValue(ax.getValue()); if (literal != null) { if (result == null) { result = new HashMap<String, Object>(); } result.put(prop.toStringID(), literal); } } } return result; }
void addSubAnnotationProperties(Set<OWLAxiom> axioms) { // add ALL subannotprop axioms // - this is quite geared towards obo ontologies, where // we want to preserve obo headers. // TODO: make this configurable LOG.info("adding SubAnnotationProperties"); Set<OWLAxiom> sapAxioms = new HashSet<OWLAxiom>(); for (OWLOntology refOnt : this.getReferencedOntologies()) { for (OWLSubAnnotationPropertyOfAxiom a : refOnt.getAxioms(AxiomType.SUB_ANNOTATION_PROPERTY_OF)) { sapAxioms.add(a); Set<OWLAnnotationAssertionAxiom> s = refOnt.getAnnotationAssertionAxioms(a.getSubProperty().getIRI()); if (s != null && !s.isEmpty()) { for (OWLAnnotationAssertionAxiom owlAnnotationAssertionAxiom : s) { sapAxioms.add(owlAnnotationAssertionAxiom); } } } } axioms.addAll(sapAxioms); }
private OWLAxiom tr(OWLClass c, OWLAnnotationAssertionAxiom ax) { OWLAnnotationProperty p = ax.getProperty(); if (!ecmap.containsKey(c)) { // preserve as-is, exception for labels if (p.isLabel()) { OWLLiteral lit = (OWLLiteral) ax.getValue(); String newVal = lit.getLiteral() + " (" + suffix + ")"; return fac.getOWLAnnotationAssertionAxiom(ax.getProperty(), ax.getSubject(), fac.getOWLLiteral(newVal)); } return ax; } else { // the class is merged - ditch its axioms // (in future some may be preserved - syns?) // fac.getOWLAnnotationAssertionAxiom(ax.getProperty(), ecmap, // ax.getValue()); return null; } }
/** * Find all corresponding {@link OWLObject}s with an OBO-style alternate identifier. * <p> * WARNING: This methods scans all object annotations in all ontologies. * This is an expensive method. * * @return map of altId to OWLObject (never null) */ public Map<String, OWLObject> getAllOWLObjectsByAltId() { final Map<String, OWLObject> results = new HashMap<String, OWLObject>(); final OWLAnnotationProperty altIdProperty = getAnnotationProperty(OboFormatTag.TAG_ALT_ID.getTag()); if (altIdProperty == null) { return Collections.emptyMap(); } for (OWLOntology o : getAllOntologies()) { Set<OWLAnnotationAssertionAxiom> aas = o.getAxioms(AxiomType.ANNOTATION_ASSERTION); for (OWLAnnotationAssertionAxiom aa : aas) { OWLAnnotationValue v = aa.getValue(); OWLAnnotationProperty property = aa.getProperty(); if (altIdProperty.equals(property) && v instanceof OWLLiteral) { String altId = ((OWLLiteral)v).getLiteral(); OWLAnnotationSubject subject = aa.getSubject(); if (subject instanceof IRI) { OWLObject obj = getOWLObject((IRI) subject); if (obj != null) { results.put(altId, obj); } } } } } return results; }
public void buildClassMap(OWLGraphWrapper g) { IRI x = Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI(); for (OWLOntology ont : g.getAllOntologies()) { for (OWLClass c : ont.getClassesInSignature()) { for (OWLAnnotationAssertionAxiom aa : ont.getAnnotationAssertionAxioms(c.getIRI())) { if (aa.getProperty().getIRI().equals(x)) { OWLAnnotationValue v = aa.getValue(); if (v instanceof OWLLiteral) { String xid =((OWLLiteral)v).getLiteral(); OWLClass xc = (OWLClass) g.getOWLObjectByIdentifier(xid); if (xc == null) { LOG.error("Cannot get class for: "+xid); } else { config.classMap.put(xc, c); } //LOG.info(c + " ===> "+xid); } } } } } }
private void renderAnnotationAxioms(String tag, IRI piri, Set<OWLAnnotationAssertionAxiom> annotationAxioms) { List<String> vs = new ArrayList<String>(); Set<OWLAnnotationAssertionAxiom> consumed = new HashSet<OWLAnnotationAssertionAxiom>(); for (OWLAnnotationAssertionAxiom aaa : annotationAxioms) { if (aaa.getProperty().getIRI().equals(piri)) { StringBuffer v = new StringBuffer(generateText(aaa.getValue())); if (aaa.getAnnotations().size() > 0) { List<String> avs = new ArrayList<String>(); for (OWLAnnotation ann : aaa.getAnnotations()) { avs.add(generateText(ann)); } Collections.sort(avs); v.append(" [ "+StringUtils.join(avs, ", ")+" ]"); } vs.add(v.toString()); consumed.add(aaa); } } annotationAxioms.removeAll(consumed); renderTagValues(tag, vs); }
/** * Add an synonym annotation, plus an annotation on that annotation * that specified the type of synonym. The second annotation has the * property oio:hasSynonymType. * * @param ontology the current ontology * @param subject the subject of the annotation * @param type the IRI of the type of synonym * @param property the IRI of the annotation property. * @param value the literal value of the synonym * @return the synonym annotation axiom */ protected static OWLAnnotationAssertionAxiom synonym( OWLOntology ontology, OWLEntity subject, OWLAnnotationValue type, OWLAnnotationProperty property, OWLAnnotationValue value) { OWLOntologyManager manager = ontology.getOWLOntologyManager(); OWLDataFactory dataFactory = manager.getOWLDataFactory(); OWLAnnotationProperty hasSynonymType = dataFactory.getOWLAnnotationProperty( format.getIRI("oio:hasSynonymType")); OWLAnnotation annotation = dataFactory.getOWLAnnotation(hasSynonymType, type); Set<OWLAnnotation> annotations = new HashSet<OWLAnnotation>(); annotations.add(annotation); OWLAnnotationAssertionAxiom axiom = dataFactory.getOWLAnnotationAssertionAxiom( property, subject.getIRI(), value, annotations); manager.addAxiom(ontology, axiom); return axiom; }
private void testSpecies(OWLOntology ontology) { IRI iri = IRI.create("http://purl.obolibrary.org/obo/NCBITaxon_species"); OWLDataFactory df = ontology.getOWLOntologyManager(). getOWLDataFactory(); OWLClass taxon = df.getOWLClass(iri); assertTrue("Species class in signature", ontology.containsClassInSignature(iri)); // Check axioms Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED); assertEquals("Count class axioms", 1, axioms.size()); assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_species> <http://purl.obolibrary.org/obo/NCBITaxon#_taxonomic_rank>)", axioms.toArray()[0].toString()); // Check annotations List<String> values = new ArrayList<String>(); values.add("AnnotationAssertion(<http://www.geneontology.org/formats/oboInOwl#hasOBONamespace> <http://purl.obolibrary.org/obo/NCBITaxon_species> \"ncbi_taxonomy\"^^xsd:string)"); values.add("AnnotationAssertion(rdfs:label <http://purl.obolibrary.org/obo/NCBITaxon_species> \"species\"^^xsd:string)"); Set<OWLAnnotationAssertionAxiom> annotations = ontology.getAnnotationAssertionAxioms(iri); assertEquals("Count annotations for Species", 2, annotations.size()); checkAnnotations(annotations, values); }
private void testExactSynonym(OWLOntology ontology) { IRI iri = IRI.create("http://www.geneontology.org/formats/oboInOwl#hasExactSynonym"); OWLDataFactory df = ontology.getOWLOntologyManager(). getOWLDataFactory(); OWLAnnotationProperty property = df.getOWLAnnotationProperty(iri); assertTrue("Exact Synonym property in signature", ontology.containsAnnotationPropertyInSignature(iri)); // Check axioms Set<OWLAnnotationAxiom> axioms = ontology.getAxioms(property, Imports.EXCLUDED); assertEquals("Count class axioms", 0, axioms.size()); // Check annotations List<String> values = new ArrayList<String>(); values.add("AnnotationAssertion(rdfs:label <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> \"has_exact_synonym\"^^xsd:string)"); Set<OWLAnnotationAssertionAxiom> annotations = ontology.getAnnotationAssertionAxioms(iri); assertEquals("Count annotations for Exact", 1, annotations.size()); checkAnnotations(annotations, values); }
public Set<OWLAnnotationAssertionAxiom> getAnnotationValue( String turambarOntologyAnnotation) { OWLDataFactory factory = ontology.getOWLOntologyManager() .getOWLDataFactory(); final OWLAnnotationProperty dcProperty = factory .getOWLAnnotationProperty(IRI .create(turambarOntologyAnnotation)); final Set<OWLAxiom> axioms = dcProperty.getReferencingAxioms( getOntology(), true); final Set<OWLAnnotationAssertionAxiom> values = new HashSet<OWLAnnotationAssertionAxiom>(); for (OWLAxiom a : axioms) { if (a.getAxiomType().equals(AxiomType.ANNOTATION_ASSERTION)) { final OWLAnnotationAssertionAxiom annotationAssertion = (OWLAnnotationAssertionAxiom) a; values.add(annotationAssertion); } } return values; }
private Collection<String> findAnnotationNames(IRI iri, OWLAnnotationProperty annotationType) { Collection<String> classNames = new HashSet<String>(); // get all literal annotations for (OWLAnnotationAssertionAxiom axiom : ontology.getAnnotationAssertionAxioms(iri)) { if (axiom.getAnnotation().getProperty().equals(annotationType)) { OWLAnnotationValue value = axiom.getAnnotation().getValue(); Optional<String> name = getOWLAnnotationValueAsString(value); if (name.isPresent()) { classNames.add(name.get()); } } } return classNames; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } // superclass is responsible for null, identity, owlaxiom type and // annotations if (!(obj instanceof OWLAnnotationAssertionAxiom)) { return false; } OWLAnnotationAssertionAxiom other = (OWLAnnotationAssertionAxiom) obj; return subject.equals(other.getSubject()) && property.equals(other.getProperty()) && value.equals(other.getValue()); }
void processTaxon(Owlbuilder builder,OWLClass taxon){ final OWLOntologyManager manager = builder.getOntologyManager(); final OWLOntology merged = builder.getMergedSources(); final OWLOntology extracted = builder.getTarget(); if (true){ //add appropriate when figured out //log.info("Need to add taxon: " + taxon.getIRI()); //log.info("Defining Axioms"); manager.addAxioms(extracted, merged.getAxioms(taxon,org.semanticweb.owlapi.model.parameters.Imports.INCLUDED)); //log.info("Annotations"); Set<OWLAnnotationAssertionAxiom> taxonAnnotations = merged.getAnnotationAssertionAxioms(taxon.getIRI()); for (OWLAnnotationAssertionAxiom a : taxonAnnotations){ //log.info(" Annotation Axiom: " + a.toString()); if (a.getAnnotation().getProperty().isLabel()){ log.debug("Label is " + a.getAnnotation().getValue().toString()); manager.addAxiom(extracted, a); } } } }
public void processAnatomy(Owlbuilder builder, OWLClass anatomyClass) { final OWLOntologyManager manager = builder.getOntologyManager(); final OWLOntology merged = builder.getMergedSources(); final OWLOntology extracted = builder.getTarget(); if (true){ log.info("Need to add anatomy: " + anatomyClass.getIRI()); Set<OWLClassAxiom> anatAxioms = merged.getAxioms(anatomyClass,org.semanticweb.owlapi.model.parameters.Imports.INCLUDED); manager.addAxioms(extracted, anatAxioms); Set<OWLAnnotationAssertionAxiom> anatAnnotations = merged.getAnnotationAssertionAxioms(anatomyClass.getIRI()); for (OWLAnnotationAssertionAxiom a : anatAnnotations){ //log.info(" Annotation Axiom: " + a.toString()); if (a.getAnnotation().getProperty().isLabel()){ log.info("Label is " + a.getAnnotation().getValue().toString()); manager.addAxiom(extracted, a); } } } builder.initializeMiscTermAndParents(anatomyClass); }
private Metadata extractMetadata(OWLNamedIndividual individual, OWLGraphWrapper modelGraph, String modelId) { Metadata metadata = new Metadata(); metadata.modelId = modelId; metadata.individualIds = new HashSet<IRI>(); metadata.individualIds.add(individual.getIRI()); Set<OWLAnnotationAssertionAxiom> assertionAxioms = modelGraph.getSourceOntology().getAnnotationAssertionAxioms(individual.getIRI()); for (OWLAnnotationAssertionAxiom axiom : assertionAxioms) { OWLAnnotationProperty currentProperty = axiom.getProperty(); OWLAnnotationValue value = axiom.getValue(); extractMetadata(currentProperty, value, metadata); } return metadata; }
public void updateAnnotation(ModelContainer model, IRI subject, OWLAnnotation update, METADATA metadata) { Set<OWLAxiom> removeAxioms = new HashSet<OWLAxiom>(); OWLDataFactory f = model.getOWLDataFactory(); Set<OWLAnnotationAssertionAxiom> existing = model.getAboxOntology().getAnnotationAssertionAxioms(subject); OWLAnnotationProperty target = update.getProperty(); for (OWLAnnotationAssertionAxiom axiom : existing) { if (target.equals(axiom.getProperty())) { removeAxioms.add(axiom); } } removeAxioms(model, removeAxioms, metadata); addAxiom(model, f.getOWLAnnotationAssertionAxiom(subject, update), metadata); }
void removeAnnotations(ModelContainer model, IRI subject, Collection<OWLAnnotation> annotations, METADATA metadata) { OWLOntology ont = model.getAboxOntology(); Set<OWLAxiom> toRemove = new HashSet<OWLAxiom>(); Set<OWLAnnotationAssertionAxiom> candidates = ont.getAnnotationAssertionAxioms(subject); for (OWLAnnotationAssertionAxiom axiom : candidates) { OWLAnnotation annotation = axiom.getAnnotation(); if (annotations.contains(annotation)) { toRemove.add(axiom); } } removeAxioms(model, toRemove, metadata); }
/** * Returns the preferred name. * * @param iri the iri * @param ontology the ontology * @return the preferred name * @throws Exception the exception */ private String getPreferredName(IRI iri, OWLOntology ontology) throws Exception { for (final OWLAnnotationAssertionAxiom axiom : ontology .getAnnotationAssertionAxioms(iri)) { final OWLAnnotation annotation = axiom.getAnnotation(); if (!isAtomAnnotation(annotation)) { continue; } if (isPreferredType(getName(annotation))) { return getValue(annotation); } } return getTerminologyId(iri); }
/** * Helper method to extract annotation properties attached to a class. * * @param owlClass the owl class * @param ontology the ontology * @return the annotation types * @throws Exception the exception */ private Set<Atom> getAtoms(OWLClass owlClass, OWLOntology ontology) throws Exception { Set<Atom> atoms = new HashSet<>(); for (final OWLAnnotationAssertionAxiom axiom : ontology .getAnnotationAssertionAxioms(owlClass.getIRI())) { final OWLAnnotation annotation = axiom.getAnnotation(); if (!isAtomAnnotation(annotation)) { continue; } final Atom atom = new AtomJpa(); setCommonFields(atom); atom.setWorkflowStatus(WorkflowStatus.PUBLISHED); // everything after the # atom.setConceptId(getTerminologyId(owlClass.getIRI())); atom.setDescriptorId(""); atom.setCodeId(""); atom.setLexicalClassId(""); atom.setStringClassId(""); // this is based on xml-lang attribute on the annotation atom.setLanguage(getLanguage(annotation)); languages.add(atom.getLanguage()); atom.setTermType(atnMap.get(getName(annotation)).getAbbreviation()); generalEntryValues.add(atom.getTermType()); termTypes.add(atom.getTermType()); atom.setName(getValue(annotation)); atom.setWorkflowStatus(WorkflowStatus.PUBLISHED); atoms.add(atom); } return atoms; }
public String getSingleLabel(OWLAnnotationAssertionAxiom entityAnnAx, OWLOntology onto, OWLDataFactory datafactory){ String label_value=""; String uri_ann = entityAnnAx.getAnnotation().getProperty().getIRI().toString(); //Accepted URIs if (Parameters.accepted_annotation_URIs_for_classes.contains(uri_ann)){ if (!(label_value=asDirectValue(entityAnnAx)).equals("")){ return label_value; } if (!(label_value=asAnonymousIndividual(entityAnnAx, onto)).equals("")){ return label_value; } if (!(label_value=asNamedIndividual(entityAnnAx, onto, datafactory)).equals("")){ return label_value; } if (!(label_value=asNamedIndividualFMA(entityAnnAx, onto, datafactory)).equals("")){ return label_value; } } //Empty value otherwise return label_value; }
@Test public void toOwlAnnotationPropertyAxiomUsesLanguageTagSpecifiedInAssertion() { final Axiom<String> ax = new AxiomImpl<>(NamedResource.create(INDIVIDUAL), Assertion.createAnnotationPropertyAssertion(PROPERTY, "cs", false), new Value<>("cestina")); final OWLAxiom axiom = adapter.toOwlAnnotationPropertyAssertionAxiom(ax); final OWLAnnotationAssertionAxiom apAxiom = (OWLAnnotationAssertionAxiom) axiom; final Optional<OWLLiteral> literal = apAxiom.getValue().asLiteral(); assertTrue(literal.isPresent()); assertEquals(ax.getValue().getValue(), literal.get().getLiteral()); assertEquals("cs", literal.get().getLang()); }
@Test public void toOwlAnnotationPropertyAxiomUsesGloballyConfiguredLanguageWhenItIsNotSpecifiedInAssertion() { final Axiom<String> ax = new AxiomImpl<>(NamedResource.create(INDIVIDUAL), Assertion.createAnnotationPropertyAssertion(PROPERTY, false), new Value<>("english")); final OWLAxiom axiom = adapter.toOwlAnnotationPropertyAssertionAxiom(ax); final OWLAnnotationAssertionAxiom apAxiom = (OWLAnnotationAssertionAxiom) axiom; final Optional<OWLLiteral> literal = apAxiom.getValue().asLiteral(); assertTrue(literal.isPresent()); assertEquals(ax.getValue().getValue(), literal.get().getLiteral()); assertEquals(LANG, literal.get().getLang()); }
@Override public OWLAnnotationAssertionAxiom visit( ElkAnnotationAssertionAxiom axiom) { return owlFactory_.getOWLAnnotationAssertionAxiom( convert(axiom.getProperty()), convert(axiom.getSubject()), convert(axiom.getValue())); }
@Override public T visit(OWLAnnotationAssertionAxiom axiom) { throw new IllegalArgumentException( OWLAnnotationAssertionAxiom.class.getSimpleName() + " cannot be converted to " + getTargetClass().getSimpleName()); }
private Set<OWLAnnotation> getAnnotations(OWLAxiom ax, OWLNamedIndividual i) { Set<OWLAnnotation> all = new HashSet<OWLAnnotation>(); if (ax != null) { all.addAll(ax.getAnnotations()); } if (i != null) { Set<OWLAnnotationAssertionAxiom> aaas = model.getAnnotationAssertionAxioms(i.getIRI()); for(OWLAnnotationAssertionAxiom aaa : aaas) { all.add(aaa.getAnnotation()); } } return all; }
/** * any class whose label matches any of the strings returned * here will be excluded from any analysis. * * the set of excluded labels is controlled by loading an * ontology with an entity PhenoSim_0000001 where all * the literals associated with this are excluded. * (note that this method may change in future) * * @return excluded labels */ public Set<String> getExcludedLabels() { if (excludedLabels != null) return excludedLabels; excludedLabels = new HashSet<String>(); for (OWLAnnotationAssertionAxiom aa : getGraph().getSourceOntology().getAnnotationAssertionAxioms(IRI.create("http://purl.obolibrary.org/obo/PhenoSim_0000001"))) { OWLAnnotationValue v = aa.getValue(); if (v instanceof OWLLiteral) { excludedLabels.add(((OWLLiteral)v).getLiteral()); } } return excludedLabels; }
@Override public void setInformationContentFromOntology(OWLOntology o) { OWLOntologyManager mgr = getSourceOntology().getOWLOntologyManager(); OWLDataFactory df = mgr.getOWLDataFactory(); clearInformationContentCache(); for (OWLAnnotationAssertionAxiom ax : o.getAxioms(AxiomType.ANNOTATION_ASSERTION)) { if (ax.getProperty().getIRI().toString().equals(icIRIString)) { OWLLiteral lit = (OWLLiteral) ax.getValue(); OWLClass c = df.getOWLClass((IRI) ax.getSubject()); Double v = lit.parseDouble(); setInformtionContectForAttribute(c, v); } } assignDefaultInformationContentForAllClasses(); }
private void expandInheresInPartOf() { LOG.info("Expanding IPO; axioms before="+outputOntology.getAxiomCount()); IRI ipoIRI = getIRIViaOBOSuffix(INHERES_IN_PART_OF); OWLAnnotationProperty eap = getOWLDataFactory().getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/IAO_0000424")); OWLAnnotationProperty aap = getOWLDataFactory().getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/IAO_0000425")); Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLAnnotationAssertionAxiom ax : outputOntology.getAxioms(AxiomType.ANNOTATION_ASSERTION)) { if (ax.getProperty().equals(eap) || ax.getProperty().equals(aap)) { rmAxioms.add(ax); } } LOG.info("Clearing old expansions: "+rmAxioms.size()); getOWLOntologyManager().removeAxioms(outputOntology, rmAxioms); OWLAnnotationAssertionAxiom aaa = getOWLDataFactory().getOWLAnnotationAssertionAxiom(eap, ipoIRI, getOWLDataFactory().getOWLLiteral("BFO_0000052 some (BFO_0000050 some ?Y)")); addAxiomToOutput(aaa, false); MacroExpansionVisitor mev; mev = new MacroExpansionVisitor(outputOntology); mev.expandAll(); flush(); //mev.expandAll(); LOG.info("Expanded IPO; axioms after="+outputOntology.getAxiomCount()); }
private void setViewClassLabel(OWLClass c, IRI vcIRI, OWLOntology ont) { String vLabel = getViewLabel(c); if (vLabel != null) { OWLAnnotationAssertionAxiom aaa = owlDataFactory.getOWLAnnotationAssertionAxiom(owlDataFactory.getRDFSLabel(), vcIRI, owlDataFactory.getOWLLiteral(vLabel)); // anything derived -- including labels -- goes in the derived ontology owlOntologyManager.addAxiom(ont, aaa); } }
/** * finds the full closure of all external referenced entities. * TODO: include object properties * * calls {@link #getExternalReferencedEntities()} and then finds all reflexive ancestors of this set. * * to configure the traversal, see {@link OWLGraphWrapper} * * @return closure of all external referenced entities */ public Set<OWLObject> getClosureOfExternalReferencedEntities() { // the closure set, to be returned Set<OWLObject> objs = new HashSet<OWLObject>(); // set of entities in external ontologies referenced in source ontology Set<OWLEntity> refs = getExternalReferencedEntities(); LOG.info("direct external referenced entities: "+refs.size()); // build the closure for (OWLEntity ref : refs) { // todo - allow per-relation control // todo - make more efficient, allow passing of set of entities // todo - include object properties Set<OWLObject> ancs = graph.getAncestorsReflexive(ref); objs.addAll(ancs); } LOG.info("closure of direct external referenced entities: "+objs.size()); // extraObjs is the set of properties (annotation and object) // that are in the signatures of all referencing axioms Set<OWLObject> extraObjs = new HashSet<OWLObject>(); for (OWLObject obj : objs) { if (obj instanceof OWLEntity) { for (OWLOntology refOnt : this.getReferencedOntologies()) { for (OWLAnnotationAssertionAxiom aaa : refOnt.getAnnotationAssertionAxioms(((OWLEntity)obj).getIRI())) { extraObjs.add(aaa.getProperty()); extraObjs.add(aaa.getValue()); } for (OWLAxiom ax : refOnt.getReferencingAxioms((OWLEntity)obj)) { extraObjs.addAll(ax.getObjectPropertiesInSignature()); } } } } objs.addAll(extraObjs); return objs; }
/** * Check, if the named object has the annotation property IAO:0000412, * declaring the object as imported. * * @param named * @param ontology * @return true if the item has the annotation property IAO:0000412 */ public static boolean isImportMarkedEntity(OWLNamedObject named, OWLOntology ontology) { for (OWLAnnotationAssertionAxiom axiom : ontology.getAnnotationAssertionAxioms(named.getIRI())) { OWLAnnotationProperty property = axiom.getProperty(); if (importedMarkerIRI.equals(property.getIRI())) { return true; } } return false; }