org.semanticweb.owlapi.model.OWLAnnotationSubject Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLAnnotationSubject. 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: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Find the corresponding {@link OWLObject}s for a given set of OBO-style alternate identifiers.
 * <p>
 * WARNING: This methods scans all object annotations in all ontologies. 
 * This is an expensive method.
 * <p>
 * Consider loading all altId-mappings using {@link #getAllOWLObjectsByAltId()}.
 * 
 * @param altIds
 * @return map of altId to OWLObject (never null)
 * @see #getAllOWLObjectsByAltId()
 */
public Map<String, OWLObject> getOWLObjectsByAltId(Set<String> altIds) {
	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();
				if (altIds.contains(altId)) {
					OWLAnnotationSubject subject = aa.getSubject();
					if (subject instanceof IRI) {
						OWLObject obj = getOWLObject((IRI) subject);
						if (obj != null) {
							results.put(altId, obj);
						}
					}
				}
			}
		}
	}
	return results;
}
 
Example #3
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void mergeOntology(OWLOntology extOnt, LabelPolicy labelPolicy) throws OWLOntologyCreationException {
	OWLOntologyManager manager = getManager();
	LOG.info("Merging "+extOnt+" policy: "+labelPolicy);
	for (OWLAxiom axiom : extOnt.getAxioms()) {
		if (labelPolicy != LabelPolicy.ALLOW_DUPLICATES) {
			if (axiom instanceof OWLAnnotationAssertionAxiom) {
				OWLAnnotationAssertionAxiom aa = (OWLAnnotationAssertionAxiom)axiom;
				if (aa.getProperty().isLabel()) {
					OWLAnnotationSubject subj = aa.getSubject();
					if (subj instanceof IRI) {
						Optional<OWLLiteral> label = null;
						for (OWLAnnotationAssertionAxiom a1 : sourceOntology.getAnnotationAssertionAxioms(subj)) {
							if (a1.getProperty().isLabel()) {
								label = a1.getValue().asLiteral();
							}
						}
						if (label != null && label.isPresent()) {
							if (labelPolicy == LabelPolicy.PRESERVE_SOURCE) {
								LOG.info("Preserving existing label:" +subj+" "+label+" // ditching: "+axiom);
								continue;
							}
							if (labelPolicy == LabelPolicy.PRESERVE_EXT) {
								LOG.info("Replacing:" +subj+" "+label+" with: "+axiom);
								LOG.error("NOT IMPLEMENTED");
							}
						}
					}
				}
			}
		}
		manager.applyChange(new AddAxiom(sourceOntology, axiom));
	}
	for (OWLImportsDeclaration oid: extOnt.getImportsDeclarations()) {
		manager.applyChange(new AddImport(sourceOntology, oid));
	}
	addCommentToOntology(sourceOntology, "Includes "+summarizeOntology(extOnt));
}
 
Example #4
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 #5
Source File: OwlConverter.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("static-method")
public ElkAnnotationSubject convert(OWLAnnotationSubject subject) {
	return OWL_ANNOTATION_CONVERTER.visit(subject);
}
 
Example #6
Source File: OwlAnnotationSubjectValueVisitor.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
public ElkAnnotationSubject visit(OWLAnnotationSubject subject) {
	return subject.accept(this);
}
 
Example #7
Source File: ElkConverter.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public OWLAnnotationSubject convert(ElkAnnotationSubject input) {
	return (OWLAnnotationSubject) input.accept(this);
}
 
Example #8
Source File: GraphOwlVisitorTestBase.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
  if (builtGraph) {
    // TODO: UGH - need a better pattern for this
    return;
  }
  graph = createInstance();

  String uri = Resources.getResource("ontologies/family.owl").toURI().toString();
  manager.loadOntologyFromOntologyDocument(IRI.create(uri));

  List<MappedProperty> propertyMap = new ArrayList<>();
  MappedProperty age = mock(MappedProperty.class);
  when(age.getName()).thenReturn("isAged");
  when(age.getProperties()).thenReturn(newArrayList(ROOT + "/hasAge"));
  propertyMap.add(age);
  MappedProperty versionInfo = mock(MappedProperty.class);
  when(versionInfo.getName()).thenReturn("versionInfo");
  when(versionInfo.getProperties()).thenReturn(newArrayList(OWL + "versionInfo"));
  propertyMap.add(versionInfo);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());
  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, propertyMap);
  walker.walkStructure(visitor);
  
  for (OWLOntology ontology : manager.getOntologies()){
    String ontologyIri = OwlApiUtils.getIri(ontology);
    for (OWLAnnotation annotation : ontology.getAnnotations()) { // Get annotations on ontology iri
      OWLAnnotationSubject ontologySubject = IRI.create(ontologyIri);
      OWLAnnotationAssertionAxiom object = 
          new OWLAnnotationAssertionAxiomImpl(ontologySubject,
              annotation.getProperty(), annotation.getValue(),
              new ArrayList<OWLAnnotation>());
      visitor.visit(object);
    }
  }
  graph.shutdown();
  graphDb = new TestGraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  tx = graphDb.beginTx();
  nodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex();
  builtGraph = true;
}
 
Example #9
Source File: AbstractElkObjectConverter.java    From elk-reasoner with Apache License 2.0 votes vote down vote up
abstract OWLAnnotationSubject convert(ElkAnnotationSubject input);