org.semanticweb.owlapi.vocab.OWLRDFVocabulary Java Examples

The following examples show how to use org.semanticweb.owlapi.vocab.OWLRDFVocabulary. 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: DescriptionTreeSimilarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * adds additional axioms specific to this method.
 * Creates a named LCS class equivalent to the generated expression
 * 
 * @param id
 * @param result
 * @param axioms
 */
@Override
protected void translateResultsToOWLAxioms(String id, OWLNamedIndividual result, Set<OWLAxiom> axioms) {
	OWLDataFactory df = graph.getDataFactory();
	
	// declare a named class for the LCS and make this equivalent to the anonymous expression
	OWLClass namedLCS = df.getOWLClass(IRI.create(id+"_LCS"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
			namedLCS.getIRI(), 
			df.getOWLLiteral("LCS of "+simEngine.label(a)+" and "+simEngine.label(b))));
	axioms.add(df.getOWLEquivalentClassesAxiom(namedLCS, lcs));

	// link the similarity object to the named LCS
	OWLAnnotationProperty lcsp = df.getOWLAnnotationProperty(annotationIRI("has_least_common_subsumer"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(lcsp, result.getIRI(), namedLCS.getIRI()));
}
 
Example #2
Source File: OWLGraphWrapperBasic.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCommentToOntology(OWLOntology ont, String cmt) {
	OWLDataFactory df = getDataFactory();
	OWLAnnotationProperty p = 
			df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI());
	OWLLiteral v = df.getOWLLiteral(cmt);
	OWLAnnotation ann = df.getOWLAnnotation(p, v);
	AddOntologyAnnotation addAnn = 
			new AddOntologyAnnotation(ont, ann);
	getManager().applyChange(addAnn);
}
 
Example #3
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getOntologyLabel() {
  OWLAnnotationProperty labelProperty =
      factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
  String ontologyLabel = StringUtils.EMPTY;
  for (OWLAnnotation annotation : ontology.getAnnotations()) {
    if (annotation.getProperty().equals(labelProperty)
        && annotation.getValue() instanceof OWLLiteral) {
      OWLLiteral val = (OWLLiteral) annotation.getValue();
      ontologyLabel = val.getLiteral();
    }
  }
  return ontologyLabel;
}
 
Example #4
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getLabel(OWLEntity entity) {
  Set<String> annotation = getAnnotation(entity, OWLRDFVocabulary.RDFS_LABEL.toString());
  if (!annotation.isEmpty()) {
    return annotation.iterator().next();
  } else {
    return extractOWLClassId(entity);
  }
}
 
Example #5
Source File: NodeTransformer.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
static boolean isDeprecated(Node n) {
  if (!n.hasProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString())) {
    return false;
  }
  if (n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString()) instanceof Boolean) {
    return (Boolean) n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString());
  } else {
    return Boolean.valueOf((String)n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString(), "false"));
  }
}
 
Example #6
Source File: MarkdownRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void renderControlledAnnotations(OWLNamedObject c) {
	Set<OWLAnnotationAssertionAxiom> annotationAxioms = 
			ontology.getAnnotationAssertionAxioms(c.getIRI());
	renderAnnotationAxiom("Label", OWLRDFVocabulary.RDFS_LABEL.getIRI(), annotationAxioms);
	renderAnnotationAxiom("Definition", Obo2OWLVocabulary.IRI_IAO_0000115.getIRI(), annotationAxioms);
	renderAnnotationAxiom("Comment", OWLRDFVocabulary.RDFS_COMMENT.getIRI(), annotationAxioms);

	renderSection("Synonyms");

	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_hasExactSynonym.getIRI(), 
			annotationAxioms);
	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_hasBroadSynonym.getIRI(), 
			annotationAxioms);
	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_hasNarrowSynonym.getIRI(), 
			annotationAxioms);
	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_hasRelatedSynonym.getIRI(), 
			annotationAxioms);

	renderSection("Cross-references");

	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI(), 
			annotationAxioms);

	renderSection("Subsets");

	renderAnnotationAxioms("", 
			Obo2OWLVocabulary.IRI_OIO_inSubset.getIRI(), 
			annotationAxioms);		
}
 
Example #7
Source File: EquivalenceSetMergeUtilTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMerge() throws OWLOntologyCreationException, IOException, IncoherentOntologyException, OWLOntologyStorageException {
    ParserWrapper pw = new ParserWrapper();
    OWLGraphWrapper g =
            pw.parseToOWLGraph(getResourceIRIString("equivalence-set-merge-util-test.obo"));
    OWLOntology ont1 = g.getSourceOntology();
    ElkReasonerFactory rf = new ElkReasonerFactory();
    OWLReasoner reasoner = rf.createReasoner(ont1);
    EquivalenceSetMergeUtil esmu = new EquivalenceSetMergeUtil(g, reasoner);
    esmu.setPrefixScore("A", 8.0);
    esmu.setPrefixScore("B", 6.0);
    esmu.setPrefixScore("C", 4.0);
    OWLAnnotationProperty lp = g.getDataFactory().getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI() );
    esmu.setPropertyPrefixScore( lp, "C", 5.0);
    esmu.setPropertyPrefixScore( lp, "B", 4.0);
    esmu.setPropertyPrefixScore( lp, "A", 3.0);
    
    OWLAnnotationProperty dp = g.getDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_IAO_0000115.getIRI() );
    esmu.setPropertyPrefixScore( dp, "B", 5.0);
    esmu.setPropertyPrefixScore( dp, "A", 4.0);
    esmu.setPropertyPrefixScore( dp, "C", 3.0);
    
    esmu.setRemoveAxiomatizedXRefs(true);

    esmu.merge();
    OWLDocumentFormat fmt = new OBODocumentFormat();
    pw.saveOWL(g.getSourceOntology(), "target/esmu.owl");
    //pw.setCheckOboDoc(false);
    pw.saveOWL(g.getSourceOntology(), fmt, "target/esmu.obo");
    
    OWLOntology ont2 = pw.parseOWL(getResourceIRIString("equivalence-set-merge-util-expected.obo"));
    assertEquals(0, compare(ont1, ont2));
}
 
Example #8
Source File: TransformationUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addLabel(OWLNamedIndividual i, OWLGraphWrapper g, OWLReasoner reasoner) {
	OWLOntology ontology = g.getSourceOntology();
	Set<OWLClass> types = new HashSet<>();
	if (reasoner == null) {
		for (OWLClassExpression x : OwlHelper.getTypes(i, ontology)) {
			if (!x.isAnonymous()) {
				types.add((OWLClass) x);
			}
		}
	}
	else {
		 types = reasoner.getTypes(i, true).getFlattened();
	}
	StringBuffer iLabel = null;
	for (OWLClass type : types) {
		String label = g.getLabel(type);
		if (iLabel == null)
			iLabel = new StringBuffer("a");
		else
			iLabel.append(" & ");
		iLabel.append(" "+label);
	}
	OWLDataFactory df = g.getDataFactory();
	OWLAxiom ax =
			df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
			i.getIRI(), 
			df.getOWLLiteral(iLabel.toString()));
	g.getManager().addAxiom(ontology,
			ax);
}
 
Example #9
Source File: ConjunctiveSetInformationContentRatioSimilarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void translateResultsToOWLAxioms(String id, OWLNamedIndividual result, Set<OWLAxiom> axioms) {
	OWLDataFactory df = simEngine.getGraph().getDataFactory();
	
	// declare a named class for the LCS and make this equivalent to the anonymous expression
	OWLClass namedLCS = df.getOWLClass(IRI.create(id+"_LCS"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
			namedLCS.getIRI(), 
			df.getOWLLiteral("LCS of "+simEngine.label(a)+" and "+simEngine.label(b))));
	axioms.add(df.getOWLEquivalentClassesAxiom(namedLCS, getLCS()));

	// link the similarity object to the named LCS
	OWLAnnotationProperty lcsp = df.getOWLAnnotationProperty(annotationIRI("has_least_common_subsumer"));
	axioms.add(df.getOWLAnnotationAssertionAxiom(lcsp, result.getIRI(), namedLCS.getIRI()));
}
 
Example #10
Source File: GoMySQLDatabaseDumper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @return
 */
private OWLProperty getSubClassAsObjectProperty() {
	if (is_a != null)
		return is_a;
	OWLDataFactory df = graph.getDataFactory();
	is_a = df.getOWLObjectProperty(IRI.create("http://foo.org#is_a"));
	OWLAnnotationAssertionAxiom ax = df.getOWLAnnotationAssertionAxiom(
			df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()), 
			is_a.getIRI(),
			df.getOWLLiteral("is_a"));
	graph.getManager().addAxiom(graph.getSourceOntology(), ax);
	return is_a;
}
 
Example #11
Source File: OWLInAboxTranslator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Cognate of "is_a" relation as defined in RO-2005
 * @return
 */
private OWLObjectProperty getSubClassOfAsTLR() {
	//return  getOWLDataFactory().getOWLObjectProperty(IRI.create("http:x.org/is_a"));
	return (OWLObjectProperty) trTypeLevel(OWLRDFVocabulary.RDFS_SUBCLASS_OF.getIRI());
}
 
Example #12
Source File: SimCommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@CLIMethod("--lcsx-all")
public void lcsxAll(Opts opts) throws Exception {
	opts.info("LABEL", "ont 1");
	String ont1 = opts.nextOpt();

	opts.info("LABEL", "ont 2");
	String ont2 = opts.nextOpt();

	if (simOnt == null) {
		simOnt = g.getManager().createOntology();
	}

	SimEngine se = new SimEngine(g);

	Set <OWLObject> objs1 = new HashSet<OWLObject>();
	Set <OWLObject> objs2 = new HashSet<OWLObject>();

	System.out.println(ont1+" -vs- "+ont2);
	for (OWLObject x : g.getAllOWLObjects()) {
		if (! (x instanceof OWLClass))
			continue;
		String id = g.getIdentifier(x);
		if (id.startsWith(ont1)) {
			objs1.add(x);
		}
		if (id.startsWith(ont2)) {
			objs2.add(x);
		}
	}
	Set<OWLClassExpression> lcsh = new HashSet<OWLClassExpression>();
	OWLObjectRenderer r = new ManchesterOWLSyntaxOWLObjectRendererImpl();
	OWLPrettyPrinter owlpp = new OWLPrettyPrinter(g, r);
	owlpp.hideIds();
	for (OWLObject a : objs1) {
		for (OWLObject b : objs2) {
			OWLClassExpression lcs = se.getLeastCommonSubsumerSimpleClassExpression(a, b);
			if (lcs instanceof OWLAnonymousClassExpression) {
				if (lcsh.contains(lcs)) {
					// already seen
					continue;
				}
				lcsh.add(lcs);
				String label = owlpp.render(lcs);
				IRI iri = IRI.create(Obo2OWLConstants.DEFAULT_IRI_PREFIX+"U_"+
						g.getIdentifier(a).replaceAll(":", "_")+"_" 
						+"_"+g.getIdentifier(b).replaceAll(":", "_"));
				OWLClass namedClass = g.getDataFactory().getOWLClass(iri);
				// TODO - use java obol to generate meaningful names
				OWLEquivalentClassesAxiom ax = g.getDataFactory().getOWLEquivalentClassesAxiom(namedClass , lcs);
				g.getManager().addAxiom(simOnt, ax);
				g.getManager().addAxiom(simOnt,
						g.getDataFactory().getOWLAnnotationAssertionAxiom(
								g.getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
								iri,
								g.getDataFactory().getOWLLiteral(label)));
				System.out.println("LCSX:"+owlpp.render(a)+" -vs- "+owlpp.render(b)+" = \n "+label);
				//LOG.info("  Adding:"+owlpp.render(ax));
				LOG.info("  Adding:"+ax);

			}
		}					
	}
}
 
Example #13
Source File: TableToAxiomConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setPropertyToLabel() {
	property = OWLRDFVocabulary.RDFS_LABEL.getIRI();
}
 
Example #14
Source File: TableToAxiomConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void setPropertyToComment() {
	property = OWLRDFVocabulary.RDFS_COMMENT.getIRI();
}
 
Example #15
Source File: OWLRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addLabel(IRI subj, String value) {
	if (value == null) return;
	addFact(subj, OWLRDFVocabulary.RDFS_LABEL.getIRI(), value);
}
 
Example #16
Source File: Similarity.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Set<OWLAxiom> translateResultsToOWLAxioms() {

		System.out.println("TRANSLATING TO OWL AXIOM:"+this);
		OWLGraphWrapper graph = simEngine.getGraph();
		Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();

		OWLDataFactory df = graph.getDataFactory();
		if (!(a instanceof OWLNamedObject)) {
			System.err.println(a+ "not named - cant write OWL results");
			return axioms;
		}
		if (!(b instanceof OWLNamedObject)) {
			System.err.println(b+ "not named - cant write OWL results");
			return axioms;
		}
		IRI ia = ((OWLNamedObject) a).getIRI();
		IRI ib = ((OWLNamedObject) b).getIRI();
		String[] toksA = splitIRI(ia);
		String[] toksB = splitIRI(ib);
		String id = toksA[0]+toksA[1]+"-vs-"+toksB[1];

		persistentIRI = IRI.create(id);

		// each similarity is stored as an individual of class similarity_relationship
		OWLNamedIndividual result = df.getOWLNamedIndividual(persistentIRI);
		OWLClass ac = df.getOWLClass(annotationIRI("similarity_relationship"));
		axioms.add(df.getOWLClassAssertionAxiom(ac, result));
		axioms.add(df.getOWLAnnotationAssertionAxiom(df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()),
				result.getIRI(), 
				df.getOWLLiteral("Similarity relationship between "+simEngine.label(a)+" and "+simEngine.label(b))));

		// each object in the pair is connected to the similarity
		OWLAnnotationProperty p = df.getOWLAnnotationProperty(annotationIRI("has_similarity_relationship"));
		axioms.add(df.getOWLAnnotationAssertionAxiom(p, ((OWLNamedObject) a).getIRI(), result.getIRI()));
		axioms.add(df.getOWLAnnotationAssertionAxiom(p, ((OWLNamedObject) b).getIRI(), result.getIRI()));

		// every similarity has a score
		OWLAnnotationProperty sp = df.getOWLAnnotationProperty(annotationIRI("has_score"));
		axioms.add(df.getOWLAnnotationAssertionAxiom(sp, result.getIRI(), df.getOWLLiteral(score)));

		translateResultsToOWLAxioms(id, result, axioms);

		return axioms;
	}
 
Example #17
Source File: OwlApiUtils.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
static String getNeo4jName(OWLRDFVocabulary vocab) {
  return XMLUtils.getNCNameSuffix(vocab.getIRI());
}
 
Example #18
Source File: VocabularyNeo4jImplTest.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Before
public void setupGraph() throws IOException {
  try (Transaction tx = graphDb.beginTx()) {
    hippocampalFormation = buildConcept("http://example.org/#birnlex5", "Hippocampal formation");
    hippocampus = buildConcept("http://example.org/#hippocampus", "Hippocampus", "foo", "fizz");
    GraphUtil.addProperty(graphDb.getNodeById(hippocampus.getId()), Concept.SYNONYM,
        "cornu ammonis");
    GraphUtil.addProperty(graphDb.getNodeById(hippocampus.getId()), Concept.SYNONYM
        + LuceneUtils.EXACT_SUFFIX, "cornu ammonis");
    GraphUtil.addProperty(graphDb.getNodeById(hippocampus.getId()), Concept.ABREVIATION, "hpcs");
    GraphUtil.addProperty(graphDb.getNodeById(hippocampus.getId()), Concept.ABREVIATION
        + LuceneUtils.EXACT_SUFFIX, "hpcs");
    hippocampusStructure =
        buildConcept("http://example.org/#hippocampusStructure", "Hippocampus structure", "baz");
    structureOfHippocampus =
        buildConcept("http://example.org/#structureOfHippocampus", "Structure of hippocampus",
            "baz");
    cerebellum = buildConcept("http://example.org/#cerebellum", "Cerebellum", "baz", "foo");
    specialChars =
        buildConcept("http://example.org/#specialChars", "(-)-protein alpha", "baz", "foo bar");
    parkinsons = buildConcept("http://example.org/#parkinsons", "Parkinson's Disease", "baz");
    GraphUtil.addProperty(graphDb.getNodeById(parkinsons.getId()), Concept.SYNONYM, "the");
    GraphUtil.addProperty(graphDb.getNodeById(parkinsons.getId()), Concept.ACRONYM, "PD");
    GraphUtil.addProperty(graphDb.getNodeById(parkinsons.getId()), Concept.ACRONYM
        + LuceneUtils.EXACT_SUFFIX, "PD");
    als = buildConcept("http://example.org/#als", "amyotrophic lateral sclerosis");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.SYNONYM, "Lou Gehrig's");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.SYNONYM
        + LuceneUtils.EXACT_SUFFIX, "Lou Gehrig's");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.SYNONYM,
        "motor neuron disease, bulbar");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.SYNONYM
        + LuceneUtils.EXACT_SUFFIX, "motor neuron disease, bulbar");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.ACRONYM, "ALS");
    GraphUtil.addProperty(graphDb.getNodeById(als.getId()), Concept.ACRONYM
        + LuceneUtils.EXACT_SUFFIX, "ALS");
    deprecated = buildConcept("http://example.org/#cerebellum2", "Cerebellum", "baz", "foo");
    GraphUtil.addProperty(graphDb.getNodeById(deprecated.getId()),
        OWLRDFVocabulary.OWL_DEPRECATED.toString(), "true");
    tx.success();
  }

  CurieUtil curieUtil = mock(CurieUtil.class);
  when(curieUtil.getPrefixes()).thenReturn(newHashSet("H", "S"));
  when(curieUtil.getExpansion("H")).thenReturn("http://example.org/#h");
  when(curieUtil.getExpansion("S")).thenReturn("http://example.org/#s");
  when(curieUtil.getIri(anyString())).thenReturn(Optional.<String>empty());
  when(curieUtil.getIri("HP:0008")).thenReturn(Optional.of("http://example.org/#hippocampus"));
  vocabulary = new VocabularyNeo4jImpl(graphDb, null, curieUtil, new NodeTransformer());
}
 
Example #19
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * gets the value of rdfs:comment for an OWLObject
 * 
 * @param c
 * @return comment of null
 */
public String getComment(OWLObject c) {
	OWLAnnotationProperty lap = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI()); 

	return getAnnotationValue(c, lap);
}
 
Example #20
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * gets the value of rdfs:comment for an OWLObject
 * <p>
 * This is a curried FlexLoader s-expression version of {@link #getComment(OWLObject)}.
 * 
 * @param c
 * @param sargs
 * @return comment of null
 * @see #getComment(OWLObject)
 */
public String getComment(OWLObject c, List<String> sargs) {
	OWLAnnotationProperty lap = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI()); 

	return getAnnotationValue(c, lap);
}