org.semanticweb.owlapi.model.OWLAnnotation Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnmergeOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Given a list of ontologies and a target ontology, remove all the axioms from the listed
 * ontologies and their import closure from the target ontology.
 *
 * @param ontologies the list of ontologies to unmerge
 * @param targetOntology the ontology to remove axioms from
 * @param includeAnnotations true if ontology annotations should be remove
 */
public static void unmergeFrom(
    List<OWLOntology> ontologies, OWLOntology targetOntology, boolean includeAnnotations) {
  for (OWLOntology ontology : ontologies) {
    logger.info("Removing axioms from: " + ontology);
    targetOntology.getOWLOntologyManager().removeAxioms(targetOntology, ontology.getAxioms());
    if (includeAnnotations) {
      for (OWLAnnotation annotation : ontology.getAnnotations()) {
        RemoveOntologyAnnotation remove =
            new RemoveOntologyAnnotation(targetOntology, annotation);
        targetOntology.getOWLOntologyManager().applyChange(remove);
      }
    }
    for (OWLOntology imported : ontology.getImportsClosure()) {
      targetOntology.getOWLOntologyManager().removeAxioms(targetOntology, imported.getAxioms());
    }
  }
}
 
Example #2
Source File: OntologyMetadata.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public OntologyMetadata(OWLOntology ont) {
	super();
	OWLOntologyID id = ont.getOntologyID();
	if (id.getOntologyIRI().isPresent())
		ontologyIRI = id.getOntologyIRI().get().toString();
	if (id.getVersionIRI().isPresent())
		versionIRI = id.getVersionIRI().get().toString();
	importDirectives = new HashSet<String>();
	for (OWLImportsDeclaration oid : ont.getImportsDeclarations()) {
		importDirectives.add(oid.getIRI().toString());
	}
	classCount = ont.getClassesInSignature().size();
	namedIndividualCount = ont.getIndividualsInSignature().size();
	axiomCount = ont.getAxiomCount();
	annotations = new HashSet<OntologyAnnotation>();
	for (OWLAnnotation ann : ont.getAnnotations()) {
		annotations.add(new OntologyAnnotation(ann));
	}
}
 
Example #3
Source File: OWLGraphWrapper.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * It returns array of synonyms (is encoded as synonym in obo format and IAO_0000118 annotation property in OWL format) of a class
 * @param c
 * @return array of strings or null
 */
@Deprecated
public String[] getSynonymStrings(OWLObject c) {
	OWLAnnotationProperty lap = getDataFactory().getOWLAnnotationProperty(IRI.create(DEFAULT_IRI_PREFIX + "IAO_0000118")); 
	Set<OWLAnnotation>anns = null;
	if (c instanceof OWLEntity) {
		anns = OwlHelper.getAnnotations((OWLEntity) c, lap, sourceOntology);
	}
	else {
		return null;
	}

	List<String> list = new ArrayList<String>();
	for (OWLAnnotation a : anns) {
		if (a.getValue() instanceof OWLLiteral) {
			OWLLiteral val = (OWLLiteral) a.getValue();
			list.add(val.getLiteral()); // return first - todo - check zero or one
		}
	}
	return list.toArray(new String[list.size()]);
}
 
Example #4
Source File: OwlSimUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addElementLabels(OWLOntology ont, File file) throws IOException {
	OWLOntologyManager m = OWLManager.createOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	List<String> lines = FileUtils.readLines(file);
	for (String line : lines) {
		if (line.startsWith("#"))
			continue;
		String[] colVals = line.split("\t");
		if (colVals.length != 2) {
			throw new IOException("Incorrect number of value: "+line);
		}
		IRI i = getIRIById(colVals[0]);
		OWLAnnotation ann = df.getOWLAnnotation(df.getRDFSLabel(), df.getOWLLiteral(colVals[1])); 
		m.addAxiom(ont, df.getOWLAnnotationAssertionAxiom(i, ann));
	}
}
 
Example #5
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * fetches the value of a single-valued annotation property for an OWLObject
 * <p>
 * TODO: provide a flag that determines behavior in the case of >1 value
 * 
 * @param c
 * @param lap
 * @return value
 */
public String getAnnotationValue(OWLObject c, OWLAnnotationProperty lap) {
	Set<OWLAnnotation>anns = new HashSet<OWLAnnotation>();
	if (c instanceof OWLEntity) {
		for (OWLOntology ont : getAllOntologies()) {
			anns.addAll(OwlHelper.getAnnotations((OWLEntity) c, lap, ont));
		}
	}
	else {
		return null;
	}
	for (OWLAnnotation a : anns) {
		if (a.getValue() instanceof OWLLiteral) {
			OWLLiteral val = (OWLLiteral) a.getValue();
			return (String) SerializationUtils.clone(val.getLiteral()); // return first - TODO - check zero or one
		}
	}

	return null;
}
 
Example #6
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<String,String> renderAnnotations(Set<OWLAnnotation> annotations) {
	Map<String,String> result = null;
	if (annotations != null && !annotations.isEmpty()) {
		for (OWLAnnotation annotation : annotations) {
			OWLAnnotationProperty prop = annotation.getProperty();
			String literal = getLiteralValue(annotation.getValue());
			if (literal != null) {
				if (result == null) {
					result = new HashMap<String, String>();
				}
				result.put(prop.toStringID(), literal);
			}
		}
	}
	return result;
}
 
Example #7
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<OWLClass, Pair<OWLNamedIndividual, Set<OWLAnnotation>>> findLocations(OWLNamedIndividual mf) {
	Map<OWLClass, Pair<OWLNamedIndividual, Set<OWLAnnotation>>> result = new HashMap<OWLClass, Pair<OWLNamedIndividual,Set<OWLAnnotation>>>();
	Set<OWLObjectPropertyAssertionAxiom> axioms = model.getObjectPropertyAssertionAxioms(mf);
	for (OWLObjectPropertyAssertionAxiom axiom : axioms) {
		if (occursIn.equals(axiom.getProperty()) && mf.equals(axiom.getSubject())) {
			// relevant axiom
			OWLIndividual locationCandidate = axiom.getObject();
			if (locationCandidate.isNamed()) {
				OWLNamedIndividual named = locationCandidate.asOWLNamedIndividual();
				Set<OWLClass> locationTypes = getTypes(named);
				for (OWLClass locationType : locationTypes) {
					result.put(locationType, Pair.of(named, getAnnotations(axiom, named)));
				}
			}
		}
	}
	return result;
}
 
Example #8
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<OWLClass, Pair<OWLNamedIndividual, Set<OWLAnnotation>>> findProcesses(OWLNamedIndividual mf) {
	Map<OWLClass, Pair<OWLNamedIndividual, Set<OWLAnnotation>>> result = new HashMap<OWLClass, Pair<OWLNamedIndividual,Set<OWLAnnotation>>>();
	Set<OWLObjectPropertyAssertionAxiom> axioms = model.getObjectPropertyAssertionAxioms(mf);
	for (OWLObjectPropertyAssertionAxiom axiom : axioms) {
		if (partOf.equals(axiom.getProperty()) && mf.equals(axiom.getSubject())) {
			// relevant axiom
			OWLIndividual bpCandidate = axiom.getObject();
			if (bpCandidate.isNamed()) {
				final OWLNamedIndividual named = bpCandidate.asOWLNamedIndividual();
				Set<OWLClass> bpTypes = getTypes(named);
				for (OWLClass bpType : bpTypes) {
					if (bpSet.contains(bpType) == false) {
						continue;
					}
					result.put(bpType, Pair.of(named, getAnnotations(axiom, named)));
				}
			}
		}
	}
	return result;
}
 
Example #9
Source File: GetLabelsTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String getLabel(OWLEntity obj) throws MultiLabelException {
	String label = null;
	OWLAnnotationProperty labelProperty = ont.getOWLOntologyManager().getOWLDataFactory().getRDFSLabel();
	for (OWLAnnotation ann : OwlHelper.getAnnotations(obj, labelProperty, ont)) {
		if (ann.getProperty().isLabel()) {
			OWLAnnotationValue v = ann.getValue();
			if (v instanceof OWLLiteral) {
				if (label != null) {
					throw new MultiLabelException(obj);
				}
				label = ((OWLLiteral)v).getLiteral();
			}
		}
	}
	return label;
}
 
Example #10
Source File: LegoMetadata.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static String getTitle(Iterable<OWLAnnotation> annotations) {
	if (annotations != null) {
		for (OWLAnnotation annotation : annotations) {
			String propertyId = annotation.getProperty().getIRI()
					.toString();
			OWLAnnotationValue annValue = annotation.getValue();
			String value = annValue.accept(LiteralValueVisitor.INSTANCE);
			if (value != null) {
				if ("http://purl.org/dc/elements/1.1/title"
						.equals(propertyId)) {
					return value;
				}
			}
		}
	}
	return null;
}
 
Example #11
Source File: OntologyMetadataMarkdownWriter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static Set<String> getVals(String p, Set<OWLAnnotation> oAnns) {
	Set<OWLAnnotation> rmAnns = new HashSet<OWLAnnotation>();
	Set<String> vs = new HashSet<String>();
	System.err.println(" L: "+p);
	for (OWLAnnotation ann : oAnns) {
		String ps = ann.getProperty().getIRI().toString();
		ps = ps.replaceAll(".*/", "");
		if (ps.equals(p)) {
			String v = (ann.getValue() instanceof OWLLiteral) ? ((OWLLiteral)ann.getValue()).getLiteral() : ann.getValue().toString();
			//String v = ann.getValue().toString();
			vs.add(v);
			System.err.println("  P: "+ps+"="+v);
			rmAnns.add(ann);
		}
	}
	oAnns.removeAll(rmAnns);
	return vs;
}
 
Example #12
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void removeDirectives() {
	// TODO decide: move the set of directives into a constant/static collection?
	
	Set<IRI> directivesIRIs = new HashSet<IRI>();
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsEquivalent.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsGenusDifferentia.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsHasSubClass.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsIsA.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsRelationship.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsReverseGenusDifferentia.getIRI());
	
	OWLOntology o = graph.getSourceOntology();
	for(OWLAnnotation ann : o.getAnnotations()) {
		final OWLAnnotationProperty property = ann.getProperty();
		if (directivesIRIs.contains(property.getIRI())) {
			manager.applyChange(new RemoveOntologyAnnotation(o, ann));
		}
	}
}
 
Example #13
Source File: MarkdownRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);

}
 
Example #14
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String getOntologyAnnotationValue(OWLOntology o, OboFormatTag tag) {
	IRI dateTagIRI = Obo2Owl.trTagToIRI(tag.getTag());
	Set<OWLAnnotation> annotations = o.getAnnotations();
	for (OWLAnnotation annotation : annotations) {
		OWLAnnotationProperty property = annotation.getProperty();
		if(dateTagIRI.equals(property.getIRI())) {
			OWLAnnotationValue value = annotation.getValue();
			if (value != null) {
				if (value instanceof IRI) {
					return ((IRI) value).toString();
				}
				else if (value instanceof OWLLiteral) {
					return ((OWLLiteral) value).getLiteral();
				}
			}
		}
	}
	return null;
}
 
Example #15
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Retrieve the literal values for the axiom annotations with the given
 * annotation property IRI.
 * 
 * @param iri
 * @param axiom
 * @return literal values or null
 */
public static List<String> getAxiomAnnotationValues(IRI iri, OWLAxiom axiom) {
	List<String> result = null;
	for(OWLAnnotation annotation : axiom.getAnnotations()) {
		OWLAnnotationProperty property = annotation.getProperty();
		if (property.getIRI().equals(iri)) {
			OWLAnnotationValue value = annotation.getValue();
			if (value instanceof OWLLiteral) {
				String literal = ((OWLLiteral) value).getLiteral();
				if (result == null) {
					result = Collections.singletonList(literal);
				}
				else if (result.size() == 1) {
					result = new ArrayList<String>(result);
					result.add(literal);
				}
				else {
					result.add(literal);
				}
			}
		}
	}
	return result;
}
 
Example #16
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Override
public Void visit(OWLSubClassOfAxiom axiom) {
  long subclass = getOrCreateNode(getIri(axiom.getSubClass()));
  long superclass = getOrCreateNode(getIri(axiom.getSuperClass()));
  long relationship =
      getOrCreateRelationship(subclass, superclass, OwlRelationships.RDFS_SUBCLASS_OF);
  for (OWLAnnotation annotation : axiom.getAnnotations()) {
    // TODO: Is there a more elegant way to process these annotations?
    String property = annotation.getProperty().getIRI().toString();
    if (annotation.getValue() instanceof OWLLiteral) {
      Optional<Object> value =
          OwlApiUtils.getTypedLiteralValue((OWLLiteral) annotation.getValue());
      if (value.isPresent()) {
        graph.addRelationshipProperty(relationship, property, value.get());
      }
    }
  }
  return null;
}
 
Example #18
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<String> getAnnotation(OWLEntity entity, String property) {
  Set<String> annotations = new HashSet<>();
  try {
    OWLAnnotationProperty owlAnnotationProperty =
        factory.getOWLAnnotationProperty(IRI.create(property));
    for (OWLAnnotation annotation : entity.getAnnotations(ontology, owlAnnotationProperty)) {
      if (annotation.getValue() instanceof OWLLiteral) {
        OWLLiteral val = (OWLLiteral) annotation.getValue();
        annotations.add(val.getLiteral());
      }
    }
  } catch (Exception e) {
    throw new RuntimeException("Failed to get label for OWLClass " + entity);
  }
  return annotations;
}
 
Example #19
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<Mapping> getMappings() {
	Set<Mapping> ms = new HashSet<Mapping>();
	OWLAnnotationProperty vap = getVariableAnnotationProperty();
	for (OWLSubClassOfAxiom sca : ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED)) {
		Mapping m = new Mapping();
		Set<OWLAnnotation> anns = sca.getAnnotations(vap);
		for (OWLAnnotation ann : anns) {
			IRI v = (IRI) ann.getValue();
			m.vars.add(v);
		}
		if (m.vars.size() > 0) {
			m.src = sca.getSubClass();
			m.tgt = sca.getSuperClass();
			ms.add(m);
			LOG.info("MAPPING: "+m);
		}
	}
	return ms;
	
}
 
Example #20
Source File: SimpleOntologyValuesTest.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testMobiAnnotation() throws Exception {
    OWLAnnotation owlAnno = mock(OWLAnnotation.class);
    OWLAnnotation owlAnno1 = mock(OWLAnnotation.class);
      
    OWLAnnotationProperty owlProperty = mock(OWLAnnotationProperty.class);
    AnnotationProperty property = mock(AnnotationProperty.class);
    org.semanticweb.owlapi.model.IRI value = mock(org.semanticweb.owlapi.model.IRI.class);
    IRI iri = mock(IRI.class);
      
    expect(owlAnno.getProperty()).andReturn(owlProperty).anyTimes();
    expect(owlAnno.getValue()).andReturn(value).anyTimes();
      
    mockStaticPartial(SimpleOntologyValues.class, "mobiAnnotationProperty", "mobiIRI");
    expect(SimpleOntologyValues.mobiAnnotationProperty(owlProperty)).andReturn(property).anyTimes();
    expect(SimpleOntologyValues.mobiIRI(value)).andReturn(iri).anyTimes();
      
    replay(owlAnno, owlAnno1, owlProperty, property, value, iri, SimpleOntologyValues.class);
}
 
Example #21
Source File: SimpleOntologyValues.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * .
 */
public static OWLAnnotation owlapiAnnotation(Annotation anno) {
    // TODO: ??? Fix this.
    if (anno == null) {
        return null;
    }
    OWLAnnotationProperty owlAnnoProperty = owlapiAnnotationProperty(anno.getProperty());
    Value value = anno.getValue();
    if (value instanceof IRI) {
        org.semanticweb.owlapi.model.IRI iri = owlapiIRI((IRI) value);
        return new OWLAnnotationImpl(owlAnnoProperty, iri, Stream.empty());
    } else if (value instanceof Literal) {
        OWLLiteral literal = owlapiLiteral((Literal) value);
        return new OWLAnnotationImpl(owlAnnoProperty, literal, Stream.empty());
    } else if (value instanceof SimpleIndividual) {
        OWLIndividual individual = owlapiIndividual((SimpleIndividual) value);
        return new OWLAnnotationImpl(owlAnnoProperty, (OWLAnonymousIndividual) individual, Stream.empty());
    } else {
        throw new MobiOntologyException("Invalid annotation value");
    }
}
 
Example #22
Source File: SimpleOntologyValues.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * .
 */
public static Annotation mobiAnnotation(OWLAnnotation owlAnno) {
    // TODO: ??? Fix this.
    if (owlAnno == null) {
        return null;
    }

    AnnotationProperty property = mobiAnnotationProperty(owlAnno.getProperty());
    OWLAnnotationValue value = owlAnno.getValue();
    if (value instanceof OWLLiteral) {
        OWLLiteral literal = (OWLLiteral) value;
        Literal simpleLiteral = mobiLiteral(literal);
        return new SimpleAnnotation(property, simpleLiteral);
    } else if (value instanceof org.semanticweb.owlapi.model.IRI) {
        org.semanticweb.owlapi.model.IRI iri = (org.semanticweb.owlapi.model.IRI) value;
        IRI simpleIri = mobiIRI(iri);
        return new SimpleAnnotation(property, simpleIri);
    } else if (value instanceof OWLAnonymousIndividual) {
        OWLAnonymousIndividual individual = (OWLAnonymousIndividual) value;
        Individual simpleIndividual = mobiIndividual(individual);
        return new SimpleAnnotation(property, simpleIndividual);
    } else {
        throw new OWLRuntimeException("Invalid annotation value");
    }
}
 
Example #23
Source File: OWLView.java    From relex with Apache License 2.0 5 votes vote down vote up
/**
* Print out RelEx relations. All relations shown
* in a binary form.
*
* Example:
*       _subj(throw, John)
*       _obj(throw, ball)
*       tense(throw, past)
*       definite-FLAG(ball, T)
*       noun_number(ball, singular)
*/
public void printRelations(ParsedSentence parse, String sentence, int sentence_id, String ontologyname)
{
	try
	{
		sent = sentence;

		//Add the sentence to Sentence Class
		this.sentence_id = sentence_id;
		sentenceInd = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + "sentence_" + sentence_id));
		//OWLAnnotationProperty p = new OWLAnnotationPropertyImpl(IRI.create(sentence));

		//OWLAnnotation label = factory.getOWLAnnotation(sentence);
		OWLOntologyFormat ontologyFormat = manager.getOntologyFormat(ontology);
		OWLAnnotation label = (OWLAnnotation) factory.getOWLAnnotationProperty(sentence, (PrefixManager) ontologyFormat);

		OWLClassAssertionAxiom sentClass = factory.getOWLClassAssertionAxiom(this.sentence,sentenceInd);
		OWLAnnotationAssertionAxiom labelClass = factory.getOWLAnnotationAssertionAxiom((OWLAnnotationSubject) sentClass, label);
		manager.applyChange(new AddAxiom(ontology, sentClass));
		manager.applyChange(new AddAxiom(ontology, labelClass));

		printRelations(parse, null);

	}
	catch (OWLOntologyChangeException ex)
	{
		Logger.getLogger(OWLView.class.getName()).log(Level.SEVERE, null, ex);
	}
}
 
Example #24
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the definition xrefs (IAO_0000115)
 * 
 * @param c
 * @return list of definition xrefs
 */
public List<String> getDefXref(OWLObject c){
	OWLAnnotationProperty lap = getDataFactory().getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_IAO_0000115.getIRI()); 
	OWLAnnotationProperty xap = getAnnotationProperty(OboFormatTag.TAG_XREF.getTag());

	if (c instanceof OWLEntity) {
		List<String> list = new ArrayList<String>();
		for (OWLOntology ont : getAllOntologies()) {
			Set<OWLAnnotationAssertionAxiom> axioms = ont.getAnnotationAssertionAxioms(((OWLEntity) c).getIRI());
			for (OWLAnnotationAssertionAxiom axiom :axioms){
				if(lap.equals(axiom.getProperty())){
					for(OWLAnnotation annotation: axiom.getAnnotations(xap)){
						OWLAnnotationValue value = annotation.getValue();
						if(value instanceof OWLLiteral){
							list.add(((OWLLiteral)value).getLiteral());
						}
					}
				}

			}
		}
		return list;
	}
	else {
		return null;
	}
}
 
Example #25
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLAnnotation> getAnnotations(OWLEntity e, OWLOntology ont) {
	Set<OWLAnnotation> annotations;
	if (e != null && ont != null) {
		Set<OWLAnnotationAssertionAxiom> axioms = ont.getAnnotationAssertionAxioms(e.getIRI());
		annotations = new HashSet<>(axioms.size());
		for(OWLAnnotationAssertionAxiom ax : axioms) {
			annotations.add(ax.getAnnotation());
		}
	}
	else {
		annotations = Collections.emptySet();
	}
	return annotations;
}
 
Example #26
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * tests if an OWLObject has been declared obsolete in the graph.
 * 
 * @param c
 * @return boolean
 */
public boolean isObsolete(OWLObject c) {
	for (OWLOntology ont : getAllOntologies()) {
		for (OWLAnnotation ann : OwlHelper.getAnnotations((OWLEntity) c, ont)) {
			if (ann.isDeprecatedIRIAnnotation()) {
				return true;
			}
		}
	}
	return false;
}
 
Example #27
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Remove axiom annotations, which do not comply with the OBO-Basic level,
 * i.e. trailing qualifier values in OBO.<br>
 * <b>Side effect</b>: This removes the old axiom and adds the new axiom to
 * the given ontology. The method also returns the new axiom to enable
 * chaining.
 * 
 * @param axiom
 * @param ontology
 * @return axiom
 */
public static OWLAxiom reduceAxiomAnnotationsToOboBasic(OWLAxiom axiom, OWLOntology ontology) {
	Set<OWLAnnotation> annotations = axiom.getAnnotations();
	if (annotations != null && !annotations.isEmpty()) {
		boolean changed = false;
		Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>();
		for (OWLAnnotation owlAnnotation : annotations) {
			OWLAnnotationProperty p = owlAnnotation.getProperty();
			IRI iri = p.getIRI();
			/*
			 * if the property IRI is not in a predefined annotation property in 
			 * Obo2Owl assume that it's not OBO-Basic
			 */
			if (Obo2Owl.ANNOTATIONPROPERTYMAP.containsValue(iri) == false) {
				// remove axiom annotation
				changed = true;
			}
			else {
				newAnnotations.add(owlAnnotation);
			}
		}
		if (changed) {
			// only update the axiom if the annotations have been changed
			OWLAxiom newAxiom = AxiomAnnotationTools.changeAxiomAnnotations(axiom, newAnnotations, ontology);
			return newAxiom;
		}
	}
	return axiom;
}
 
Example #28
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Append xref annotations onto an existing axiom
 * 
 * @param axiom
 * @param xrefs
 * @param ontology
 * @return
 */
public static OWLAxiom appendXrefAnnotations(OWLAxiom axiom, Set<String> xrefs, OWLOntology ontology) {
    // filter existing
    Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>(axiom.getAnnotations());
       final OWLOntologyManager manager = ontology.getOWLOntologyManager();
    final OWLDataFactory factory = manager.getOWLDataFactory();

    for (String x : xrefs) {
        OWLAnnotationProperty p = factory.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#hasDbXref"));
        OWLLiteral v = factory.getOWLLiteral(x);
        newAnnotations.add(factory.getOWLAnnotation(p, v));
    }
    final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology);
    return newAxiom;
}
 
Example #29
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLAnnotation> getAnnotations(OWLEntity e, Set<OWLOntology> ontolgies) {
	Set<OWLAnnotation> annotations;
	if (e != null && ontolgies != null && !ontolgies.isEmpty()) {
		annotations = new HashSet<>();
		for(OWLOntology ont : ontolgies) {
			annotations.addAll(getAnnotations(e, ont));
		}
	}
	else {
		annotations = Collections.emptySet();
	}
	return annotations;
}
 
Example #30
Source File: ChEBIParser.java    From act with GNU General Public License v3.0 5 votes vote down vote up
private HashMap<String, EntryTypes> getData(OWLClass clazz) {
  HashMap<String, EntryTypes> data = new HashMap<String, EntryTypes>();
  for (OWLAnnotation a : clazz.getAnnotations(ontology)) {
    // err.println("\t\t Annotation Property: " + a.getProperty());
    String id = a.getProperty().toStringID();
    if (id.equals("rdfs:label")) continue;
    EntryTypes prop = entryTypes.get(id);
    String val = ((OWLLiteral)a.getValue()).getLiteral();
    // err.println("\t\t Annotation Property: " + prop);
    // err.println("\t\t Annotation Literal : " + value);
    data.put(val, prop);
  }
  return data;
}