Java Code Examples for org.semanticweb.owlapi.model.OWLClass#getIRI()

The following examples show how to use org.semanticweb.owlapi.model.OWLClass#getIRI() . 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: EntityCreationVisitor.java    From OWL2VOWL with MIT License 6 votes vote down vote up
@Override
public void visit(OWLClass ce) {
	AbstractClass clazz;

	if (ce.isOWLThing() || ce.isOWLNothing()) {
		// General class do not create here
		return;
	} else if (!ce.isAnonymous()) {
		clazz = new VowlClass(ce.getIRI());
	} else {
		// TODO Anonymous behaviour undefined
		logger.info("Anonymous OWLClass " + ce);
		return;
	}

	vowlData.addClass(clazz);
}
 
Example 2
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
UnfoldingVisitor(Set<OWLClass> unfoldClasses, OWLOntology ontology) throws NonDeterministicUnfoldException {
	this.unfoldClasses = new HashMap<OWLClass, OWLClassExpression>();
	factory = ontology.getOWLOntologyManager().getOWLDataFactory();
	
	for(OWLClass owlClass : unfoldClasses) {
		Set<OWLEquivalentClassesAxiom> eqAxioms = ontology.getEquivalentClassesAxioms(owlClass);
		if (eqAxioms != null && !eqAxioms.isEmpty()) {
			if(eqAxioms.size() > 1) {
				throw new NonDeterministicUnfoldException("Non deterministic unfold for class: "+owlClass.getIRI());
			}
			OWLEquivalentClassesAxiom eqAxiom = eqAxioms.iterator().next();
			Set<OWLClassExpression> expressions = eqAxiom.getClassExpressionsMinus(owlClass);
			if (expressions.size() == 1) {
				this.unfoldClasses.put(owlClass, expressions.iterator().next());
			}
			else if (expressions.size() > 1) {
				OWLClassExpression ce = factory.getOWLObjectIntersectionOf(expressions);
				this.unfoldClasses.put(owlClass, ce);
			}
		}
	}
	
	// TODO check that there are no cycles in the unfold expressions, otherwise this unfold will not terminate!
}
 
Example 3
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleIntersection(List<CheckWarning> warnings, Set<OWLOntology> allOntologies,
		OWLEquivalentClassesAxiom axiom, OWLObjectIntersectionOf intersection, OWLPrettyPrinter pp) 
{
	for(OWLClassExpression operand : intersection.getOperandsAsList()) {
		OWLClass operandCls = null;
		if (!operand.isAnonymous()) {
			operandCls = operand.asOWLClass();
		}
		else if (operand instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom ristriction = (OWLObjectSomeValuesFrom) operand;
			OWLClassExpression filler = ristriction.getFiller();
			if (!filler.isAnonymous()) {
				operandCls = filler.asOWLClass();
			}
		}
		else {
			// not translatable to OBO
			handleGeneric(warnings, allOntologies, axiom, operand, pp);
		}
		if (operandCls != null && isDangling(operandCls, allOntologies)) {
			final IRI iri = operandCls.getIRI();
			String message = "Dangling reference "+iri+" in INTERSECTION_OF axiom: "+pp.render(axiom);
			warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_INTERSECTION_OF.getTag()));
		}
	}
}
 
Example 4
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleUnionOf(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, 
		OWLEquivalentClassesAxiom axiom, OWLObjectUnionOf union, OWLPrettyPrinter pp) 
{
	List<OWLClassExpression> operands = union.getOperandsAsList();
	for(OWLClassExpression operand : operands) {
		if (!operand.isAnonymous()) {
			OWLClass operandCls = operand.asOWLClass();
			if (isDangling(operandCls, allOntologies)) {
				final IRI iri = operandCls.getIRI();
				String message = "Dangling reference "+iri+" in UNION_OF axiom: "+pp.render(axiom);
				warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_UNION_OF.getTag()));
			}
		}
		else {
			// not translatable to OBO
			handleGeneric(warnings, allOntologies, axiom, operand, pp);
		}
	}
}
 
Example 5
Source File: ABoxUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a "fake" individual for every class.
 * 
 * ABox IRI = TBox IRI + suffix
 * 
 * if suffix == null, then we are punning
 * 
 * @param srcOnt
 * @param iriSuffix
 * @throws OWLOntologyCreationException
 */
public static void makeDefaultIndividuals(OWLOntology srcOnt, String iriSuffix) throws OWLOntologyCreationException {
	OWLOntologyManager m = srcOnt.getOWLOntologyManager();
	OWLDataFactory df = m.getOWLDataFactory();
	for (OWLClass c : srcOnt.getClassesInSignature(Imports.INCLUDED)) {
		IRI iri;
		if (iriSuffix == null || iriSuffix.equals(""))
		  iri = c.getIRI();
		else
			iri = IRI.create(c.getIRI().toString()+iriSuffix);
		OWLNamedIndividual ind = df.getOWLNamedIndividual(iri);
		m.addAxiom(srcOnt, df.getOWLDeclarationAxiom(ind));
		m.addAxiom(srcOnt, df.getOWLClassAssertionAxiom(c, ind));
	}
}
 
Example 6
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Unfold the equivalence axiom of the {@link OWLClass}
 * 
 * @param owlClass
 * @return unfolded equivalence axiom or null
 * @throws NonDeterministicUnfoldException
 */
public OWLEquivalentClassesAxiom unfold(OWLClass owlClass) throws NonDeterministicUnfoldException {
	Set<OWLEquivalentClassesAxiom> axioms = ontology.getEquivalentClassesAxioms(owlClass);
	if (axioms == null || axioms.isEmpty()) {
		return null;
	}
	if (axioms.size() > 1) {
		throw new NonDeterministicUnfoldException("Non deterministic unfold for class: "+owlClass.getIRI());
	}
	final OWLEquivalentClassesAxiom axiom = axioms.iterator().next();
	OWLEquivalentClassesAxiom unfolded = visitor.unfoldAxiom(axiom, owlClass);
	return unfolded;
}
 
Example 7
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void handleEquivalentTo(List<CheckWarning> warnings, Set<OWLOntology> allOntologies,
		OWLEquivalentClassesAxiom axiom, OWLClass cls, OWLPrettyPrinter pp)
{
	if (isDangling(cls, allOntologies)) {
		final IRI iri = cls.getIRI();
		String message = "Dangling reference "+iri+" in EQUIVALENT_TO axiom: "+pp.render(axiom);
		warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_EQUIVALENT_TO.getTag()));
	}
}
 
Example 8
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void handleGeneric(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, 
		OWLEquivalentClassesAxiom axiom, OWLClassExpression ce, OWLPrettyPrinter pp) 
{
	Set<OWLClass> classes = ce.getClassesInSignature();
	for (OWLClass cls : classes) {
		if (isDangling(cls, allOntologies)) {
			final IRI iri = cls.getIRI();
			String message = "Dangling reference "+iri+" in axiom: "+pp.render(axiom);
			warnings.add(new CheckWarning(getID(), message , isFatal(), iri, null));
		}
	}
}
 
Example 9
Source File: SelfReferenceInDefinition.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) {
	OWLOntology ontology = graph.getSourceOntology();
	List<CheckWarning> violations = new ArrayList<CheckWarning>();
	for(OWLClass cls : ontology.getClassesInSignature()) {
		Set<OWLEquivalentClassesAxiom> equivalentClassesAxioms = ontology.getEquivalentClassesAxioms(cls);
		if (equivalentClassesAxioms != null && !equivalentClassesAxioms.isEmpty()) {
			for (OWLEquivalentClassesAxiom owlEquivalentClassesAxiom : equivalentClassesAxioms) {
				for (OWLClassExpression ex : owlEquivalentClassesAxiom.getClassExpressions()) {
					if (ex instanceof OWLClass)
						continue;
					Set<OWLClass> classesInSignature = ex.getClassesInSignature();
					if (classesInSignature != null && classesInSignature.contains(cls)) {
						String id = graph.getIdentifier(cls);
						String message = "Class "+id+" has a self reference in its logical definition: "+owlEquivalentClassesAxiom;
						CheckWarning warning = new CheckWarning("Self_Reference_In_Definition", message , isFatal(), cls.getIRI());
						violations.add(warning);
					}
				}
			}
		}
	}
	if (!violations.isEmpty()) {
		return violations;
	}
	return null;
}
 
Example 10
Source File: CycleCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) {
	Collection<CheckWarning> out = new ArrayList<CheckWarning>();
	
	// find strongly connected components using the Tarjan algorithm
	// use parameter to request only components with more than one node
	Tarjan<OWLClass> tarjan = new MappingTarjan<OWLClass>(true);
	List<List<OWLClass>> scc = tarjan.executeTarjan(new OWLClassAdjacency(graph, allOwlObjects));
	
	// report all strongly connected components
	for (List<OWLClass> component : scc) {
		StringBuilder sb = new StringBuilder("Cycle detected with the following classes: ");
		List<IRI> iris = new ArrayList<IRI>(component.size());
		for (OWLClass owlClass : component) {
			if (!iris.isEmpty()) {
				sb.append(", ");
			}
			final IRI iri = owlClass.getIRI();
			iris.add(iri);
			sb.append(graph.getIdentifier(iri));

			final String label = graph.getLabel(owlClass);
			if (label != null) {
				sb.append(" (");
				sb.append(label);
				sb.append(")");
			}

		}
		CheckWarning warning = new CheckWarning(getID(), sb.toString(), isFatal(), iris, null);
		out.add(warning);
	}
	return out;
}
 
Example 11
Source File: NCBIConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the NCBI Taxonomy ID of an OWL Class.
 *
 * @param taxon the class
 * @return null or the NCBI Taxonomy ID as a string
 */
public static String getTaxonID(OWLClass taxon) {
	IRI iri = taxon.getIRI();
	String iriString = iri.toString();
	if (iriString.startsWith(NCBI)) {
		return iriString.replaceFirst("^" + NCBI, "");
	} else {
		return null;
	}
}
 
Example 12
Source File: EcoToolsTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testSimpleEco() throws OWLOntologyCreationException, IOException{

	///
	/// From: http://purl.obolibrary.org/obo/ECO_0000316
	/// IGI should be: "experimental evidence used in manual assertion" in:
    ///  + evidence
       ///    + experimental evidence
       ///        + experimental phenotypic evidence
       ///            + genetic interaction evidence
       ///                - genetic interaction evidence used in manual assertion
	///

	// Create EcoTools instance.
	EcoTools eco = new EcoTools(g, g.getReasoner(), true);
	
	// Evidence type closure.
	Set<OWLClass> ecoClasses = eco.getClassesForGoCode("IGI");

	// Hopefully we're just getting one here.
	assertEquals("Right now, one code (IGI) should go to one ECO term.", 1, ecoClasses.size());
	OWLClass igi = ecoClasses.iterator().next();

	IRI igiIRI = igi.getIRI();
	assertEquals("http://purl.obolibrary.org/obo/ECO_0000316", igiIRI.toString());
	String igiId = g.getIdentifier(igi);
	assertEquals("ECO:0000316", igiId);

	String igiLabel = g.getLabel(igi);
	assertEquals("genetic interaction evidence used in manual assertion", igiLabel);
			
	// Since we're reflexive, our six ancestors should be:
	Set<String> foo = new HashSet<String>();
    foo.add("evidence"); // ECO:0000000
    foo.add("experimental evidence"); // ECO:0000006
    foo.add("experimental phenotypic evidence"); // ECO:0000059
    foo.add("genetic interaction evidence"); // ECO:0000011
    foo.add(igiLabel); // ECO:0000316
	
    // inferred by reasoner using cross products
    foo.add("experimental evidence used in manual assertion"); // ECO:0000269
    
	Set<OWLClass> ecoSuperClasses = eco.getAncestors(ecoClasses, true);

	for( OWLClass ec : ecoSuperClasses ){
		String ec_str_label = g.getLabel(ec);
		assertTrue("Actual ancestor should have been in hash, not: " + ec_str_label,
				foo.contains(ec_str_label));
	}
		
	assertEquals(6, ecoSuperClasses.size());

}
 
Example 13
Source File: LCSEnabledSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * given a CE of the form A1 and A2 and ... An,
 * get a class with an IRI formed by concatenating parts of the IRIs of Ai,
 * and create a label assertion, where the label is formed by concatenating label(A1)....
 * 
 * note that the reasoner will need to be synchronized after new classes are made
 * 
 * Note: modifies ontology but does not flush
 * 
 * see materializeClassExpression(..)
 * 
 * @param x
 * @return class
 */
public OWLClass makeClass(OWLObjectIntersectionOf x) {
	if (materializedClassExpressionMap.containsKey(x)) {
		return materializedClassExpressionMap.get(x);
	}
	//StringBuffer id = new StringBuffer();
	StringBuffer label = new StringBuffer();
	int n = 0;
	int nlabels = 0;
	
	LOG.info("LCS INTERSECTION: "+x);

	IRI intersectionIRI = null;
	// TODO - optimize following
	for (OWLClassExpression op : x.getOperands()) {
		n++;
		// throw exception if ops are not named
		OWLClass opc = (OWLClass)op;
		//String opid = opc.getIRI().toString();
		String oplabel = getAnyLabel(opc);

		if (n == 1) {
			intersectionIRI = opc.getIRI();
			// make base
			/*
			String prefix = opid.toString();
			prefix = prefix.replaceAll("#.*","#");
			if (prefix.startsWith(OBO_PREFIX))
				id.append(OBO_PREFIX);
			else 
				id.append(prefix);
				*/				
		}
		else {
			intersectionIRI = makeViewClassIRI(intersectionIRI, opc.getIRI());
		}
		
		if (n > 1) {
			label.append(" and ");
		}
		if (oplabel != null) {
			nlabels++;
			label.append("["+oplabel+"]");
		}
		else {
			label.append("?"+opc.getIRI().toString());
		}

	}
	OWLClass c = getOWLDataFactory().getOWLClass(intersectionIRI);
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	newAxioms.add( getOWLDataFactory().getOWLEquivalentClassesAxiom(c, x) );
	newAxioms.add( getOWLDataFactory().getOWLDeclarationAxiom(c));
	//LOG.info(" Generated label("+c+")="+label.toString());
	if (nlabels > 0) {
		newAxioms.add( getOWLDataFactory().getOWLAnnotationAssertionAxiom(getOWLDataFactory().getRDFSLabel(), c.getIRI(), 
				getOWLDataFactory().getOWLLiteral(label.toString())));
	}
	//TODO
	//lcsExpressionToClass.put(x, c);
	LOG.info(" new LCS: "+c+" label: "+label.toString()+" == "+x);
	this.addAxiomsToOutput(newAxioms, false);
	materializedClassExpressionMap.put(x, c);
	return c;
}
 
Example 14
Source File: OWLRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@Deprecated
public void printAttributeSim(AttributesSimScores simScores, OWLGraphWrapper graph)
{
	this.graph = graph;

	OWLClass a = simScores.a;
	OWLClass b = simScores.b;

	IRI ai = a.getIRI();
	IRI bi = b.getIRI();
	//addLabel(ai, graph.getLabel(a));
	//addLabel(bi, graph.getLabel(b));

	IRI mi = IRI.create(ai + "-" + graph.getIdentifier(b));
	String mlabel = "match to "+graph.getLabel(b)+ " from "+graph.getLabel(a);
	addType(mi, "match");

	addMatch(ai, mi);
	addMatch(bi, mi);

	OWLIndividual m = getOWLDataFactory().getOWLNamedIndividual(mi);



	//scores
	if (simScores.simJScore != null) {
		mlabel += " EquivScore=" + doubleRenderer.format(simScores.simJScore);
		addScore(m, Metric.SIMJ.toString(), simScores.simJScore);
	}
	if (simScores.AsymSimJScore != null) {
		mlabel += " SubclassScore=" + doubleRenderer.format(simScores.AsymSimJScore);
		addScore(m, "AsymmetricSimJ", simScores.AsymSimJScore);
	}

	ScoreAttributePair lcs = simScores.lcsScore;
	if (lcs != null) {
		// LCS points to a class so we use an AP
		addFact(mi, getIRI("LCS"),  ((OWLNamedObject) lcs.attributeClass).getIRI());
		addScore(m, Metric.LCSIC.toString(), lcs.score);
	}

	addLabel(mi, mlabel);

}
 
Example 15
Source File: OWLRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void printPairScores(AttributePairScores simScores) {
	OWLClass a = simScores.getA();
	OWLClass b = simScores.getB();

	IRI ai = a.getIRI();
	IRI bi = b.getIRI();
	
	// we may want to make this optional in future - turn off
	// for now as it makes file too voluminous
	//addLabel(ai, graph.getLabel(a));
	//addLabel(bi, graph.getLabel(b));

	IRI mi = IRI.create(ai + "-" + graph.getIdentifier(b));
	String mlabel = "match to "+graph.getLabel(b)+ " from "+graph.getLabel(a);
	addType(mi, "match");

	addMatch(ai, mi);
	addMatch(bi, mi);

	OWLIndividual m = getOWLDataFactory().getOWLNamedIndividual(mi);



	//scores
	if (simScores.simjScore != null) {
		mlabel += " EquivScore=" + doubleRenderer.format(simScores.simjScore);
		addScore(m, Metric.SIMJ.toString(), simScores.simjScore);
	}
	if (simScores.asymmetricSimjScore != null) {
		mlabel += " SubclassScore=" + doubleRenderer.format(simScores.asymmetricSimjScore);
		addScore(m, "AsymmetricSimJ", simScores.asymmetricSimjScore);
	}

	Set<OWLClass> lcsSet = simScores.lcsSet;
	if (lcsSet != null) {
		// LCS points to a class so we use an AP
		for (OWLClass lcs : lcsSet ) {
			addFact(mi, getIRI("LCS"),  ((OWLNamedObject) lcs).getIRI());
		}
		addScore(m, Metric.LCSIC.toString(), simScores.lcsIC);
	}

	addLabel(mi, mlabel);	
}