Java Code Examples for org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom#getProperty()

The following examples show how to use org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom#getProperty() . 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: LinkMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check that the given subClass does not already has a matching subClass axiom.
 * 
 * @param subCls
 * @param p
 * @param superCls
 * @return existing axiom or null
 */
private OWLAxiom hasLinks(OWLClass subCls, OWLObjectProperty p, OWLClass superCls) {
	for(OWLOntology o : allOntologies) {
		Set<OWLSubClassOfAxiom> subClsAxioms = o.getSubClassAxiomsForSubClass(subCls);
		for (OWLSubClassOfAxiom subClsAxiom : subClsAxioms) {
			OWLClassExpression ce = subClsAxiom.getSuperClass();
			if (ce instanceof OWLObjectSomeValuesFrom) {
				OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) ce;
				OWLObjectPropertyExpression property = someValuesFrom.getProperty();
				if (p.equals(property)) {
					OWLClassExpression filler = someValuesFrom.getFiller();
					if (superCls.equals(filler)) {
						return subClsAxiom;
					}
				}
			}
		}
	}
	return null;
}
 
Example 2
Source File: LegoShuntGraphTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderAdditionalNodeExpression(StringBuilder line, OWLClassExpression expression, OWLPrettyPrinter owlpp, OWLGraphWrapper graph) {
	if (expression instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom object = (OWLObjectSomeValuesFrom) expression;
		OWLObjectPropertyExpression property = object.getProperty();
		OWLClassExpression filler = object.getFiller();
		line.append("<TR><TD>");
		line.append(getLabel(property, owlpp, graph));
		line.append("</TD><TD>");
		line.append(getLabel(filler, owlpp, graph));
		line.append("</TD></TR>");
	}
	else {
		line.append("<TR><TD COLSPAN=\"2\">");
		line.append(getLabel(expression, owlpp, graph));
		line.append("</TD></TR>");
	}
}
 
Example 3
Source File: LegoDotWriter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderAdditionalNodeExpression(StringBuilder line, OWLClassExpression expression, OWLPrettyPrinter owlpp) {
	if (expression instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom object = (OWLObjectSomeValuesFrom) expression;
		OWLObjectPropertyExpression property = object.getProperty();
		OWLClassExpression filler = object.getFiller();
		line.append("<TR><TD>");
		line.append(getLabel(property, owlpp));
		line.append("</TD><TD>");
		line.append(getLabel(filler, owlpp));
		line.append("</TD></TR>");
	}
	else {
		line.append("<TR><TD COLSPAN=\"2\">");
		line.append(getLabel(expression, owlpp));
		line.append("</TD></TR>");
	}
}
 
Example 4
Source File: AbstractSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public String generateLabel(OWLClassExpression x) {
	StringBuffer sb = new StringBuffer();
	if (x instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) x;	
		OWLObjectPropertyExpression p = svf.getProperty();
		if (propertyToFormatMap.containsKey(p)) {
			return String.format(propertyToFormatMap.get(p), generateLabel(svf.getFiller()));
		}
		else {
			String pStr = p.toString();
			if (p instanceof OWLEntity) {
				pStr = getAnyLabel((OWLEntity)p);
			}
			return pStr + " some "+generateLabel(svf.getFiller());
		}
	}
	else if (x instanceof OWLObjectIntersectionOf) {
		OWLObjectIntersectionOf oio = (OWLObjectIntersectionOf) x;
		for (OWLClassExpression op : oio.getOperands()) {
			if (sb.length() > 0) {
				sb.append(" and ");
			}
			sb.append(generateLabel(op));
		}
		return sb.toString();
	}
	else if (x instanceof OWLClass) {
		return this.getAnyLabel((OWLClass) x);
	}
	return x.toString();
}
 
Example 5
Source File: TransformationUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Names all inner ObjectSomeValuesFrom expressions
 * 
 * @param srcOntology
 * @param tgtOntology
 * @param qmap
 * @param isAddLabels
 * @return
 */
public static Map<OWLClass, OWLClassExpression> nameObjectSomeValuesFrom(OWLOntology srcOntology,
		OWLOntology tgtOntology,
		Map<OWLClass,OWLClassExpression> qmap,
		boolean isAddLabels) {

	if (qmap == null) 
		qmap = new HashMap<OWLClass, OWLClassExpression>();
	OWLOntologyManager mgr = srcOntology.getOWLOntologyManager();
	OWLDataFactory df = mgr.getOWLDataFactory();
	for (OWLOntology ont : srcOntology.getImportsClosure()) {
		for (OWLAxiom ax : srcOntology.getAxioms()) {
			for (OWLClassExpression x : ax.getNestedClassExpressions()) {
				if (x instanceof OWLObjectSomeValuesFrom) {
					OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)x;
					OWLClass filler = (OWLClass) svf.getFiller();
					OWLObjectProperty p = (OWLObjectProperty) svf.getProperty();
					IRI iri = getSkolemIRI(filler, p);
					OWLClass c = df.getOWLClass(iri);
					mgr.addAxiom(tgtOntology, df.getOWLEquivalentClassesAxiom(c, svf));
					qmap.put(c, svf);
					if (isAddLabels) {
						Set<OWLAnnotation> anns = OwlHelper.getAnnotations(filler, df.getRDFSLabel(), ont);
						for (OWLAnnotation ann : anns) {
							mgr.addAxiom(tgtOntology, df.getOWLAnnotationAssertionAxiom(c.getIRI(), ann));
						}
					}
				}
			}
		}
	}
	return qmap;

}
 
Example 6
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check all classes for potential redundant subClass axioms of type:
 * <pre>
 *   A SubClassOf R some B
 *    and
 *   A SubClassOf B
 * </pre>
 * 
 * @return list of axiom pairs
 */
public List<PotentialRedundant> checkPotentialRedundantSubClassAxioms() {
	List<PotentialRedundant> result = new ArrayList<PotentialRedundant>();
	for(OWLClass cls : graph.getAllOWLClasses()) {
		Set<OWLSubClassOfAxiom> axioms = graph.getAllOWLSubClassOfAxiomsForSubClass(cls);
		if (axioms.size() > 1) {
			// only check sets with more than one axiom
			for (OWLSubClassOfAxiom main : axioms) {
				OWLClassExpression mainSuperClassCE = main.getSuperClass();
				if (mainSuperClassCE.isAnonymous()) {
					continue;
				}
				OWLClass mainSuperClass = mainSuperClassCE.asOWLClass();
				for (OWLSubClassOfAxiom current : axioms) {
					if (main == current) {
						continue;
					}
					OWLClassExpression currentSuperClass = current.getSuperClass();
					if (currentSuperClass.isAnonymous() && currentSuperClass instanceof OWLObjectSomeValuesFrom) {
						OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) currentSuperClass;
						final OWLClassExpression filler = someValuesFrom.getFiller();
						if (mainSuperClass.equals(someValuesFrom.getFiller())) {
							final OWLObjectPropertyExpression property = someValuesFrom.getProperty();
							final OWLClassExpression subClass = current.getSubClass();
							final PotentialRedundant redundant = new PotentialRedundant(main, current, subClass.asOWLClass(), property.asOWLObjectProperty(), filler.asOWLClass());
							result.add(redundant);
						}
					}
				}
			}
		}
	}
	
	if (!result.isEmpty()) {
		return result;
	}
	return null;
}
 
Example 7
Source File: BioChebiGenerator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create the GCIs for BioChEBI. Add the axioms into the given ontology.
 * 
 * @param ontology
 * @param ignoredClasses
 */
public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) {
	final OWLOntologyManager manager = ontology.getOWLOntologyManager();
	final OWLDataFactory factory = manager.getOWLDataFactory();
	
	// scan axioms
	Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED);
	for (OWLSubClassOfAxiom axiom : axioms) {
		OWLClassExpression superCE = axiom.getSuperClass();
		OWLClassExpression subCE = axiom.getSubClass();
		if (subCE.isAnonymous()) {
			// sub class needs to be an named OWLClass
			continue;
		}

		if (superCE instanceof OWLObjectSomeValuesFrom == false) {
			continue;
		}
		OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE;

		OWLObjectPropertyExpression expression = some.getProperty();
		if (expression.isAnonymous()) {
			// object property expression needs to be a named OWLObjectProperty 
			continue;
		}

		OWLObjectProperty p = (OWLObjectProperty) expression;
		
		Set<OWLObjectProperty> expansions = expansionMap.get(p);
		if (expansions == null) {
			continue;
		}

		// get content for GCI
		OWLClassExpression y = some.getFiller();
		OWLClass x = subCE.asOWLClass();
		if (ignoredClasses.contains(x)) {
			continue;
		}
		for (OWLObjectProperty createProperty : expansions) {
			OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x);
			OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y);
			OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2);
			manager.addAxiom(ontology, eq);
		}
	}
	
	Set<OWLOntology> imports = ontology.getImports();
	StringBuilder sb = new StringBuilder();
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:");
	for (OWLOntology owlOntology : imports) {
		OWLOntologyID ontologyID = owlOntology.getOntologyID();
		sb.append(" ");
		appendOntologyId(ontologyID, sb);
	}
	addComment(sb.toString(), ontology);
}
 
Example 8
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * given an ontology *ont* and a set of object properties *filterProps*, remove all axioms from ontology that
 * have an object property P in their signature where P is not in *filterProps*
 * 
 * use basic reasoning to map up more specific relationships
 * 
 * @param ont
 * @param filterProps
 * @param reasoner
 */
public static void retainAxiomsInPropertySubset(OWLOntology ont, Set<OWLObjectProperty> filterProps, OWLReasoner reasoner) {
	LOG.info("Removing axioms that use properties not in set: "+filterProps);
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	OWLDataFactory df = ont.getOWLOntologyManager().getOWLDataFactory();
	for (OWLAxiom ax : ont.getAxioms()) {
		Set<OWLObjectProperty> ps = ax.getObjectPropertiesInSignature();
		ps.removeAll(filterProps);
		if (ps.size() > 0) {
			rmAxioms.add(ax);

			// if p not-in SubSet, and
			//  A = X SubClassOf p Some Y,
			// then rewrite as
			//  A = X SubClassOf p' some Y, where p' SubPropertyOf p
			// rewrite as weaker axioms.
			// TOOD - Elk does not support superobjectprops - do in wrapper for now?
			if (ax instanceof OWLSubClassOfAxiom) {
			    OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom)ax;
			    if (!sca.getSubClass().isAnonymous()) {
			        if (sca.getSuperClass() instanceof OWLObjectSomeValuesFrom) {
			            OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) sca.getSuperClass();
			            OWLObjectPropertyExpression p = svf.getProperty();
			            Set<OWLObjectPropertyExpression> sps = 
			                    getSuperObjectProperties(p, reasoner, ont);
			            sps.retainAll(filterProps);
			            for (OWLObjectPropertyExpression sp : sps) {
			                OWLObjectSomeValuesFrom newSvf = df.getOWLObjectSomeValuesFrom(sp, svf.getFiller());
			                OWLSubClassOfAxiom newSca = df.getOWLSubClassOfAxiom(sca.getSubClass(), newSvf);
			                LOG.info("REWRITE: "+sca+" --> "+newSca);
			                newAxioms.add(newSca);
			            }
			        }
			    }
			}
			//else if (ax instanceof OWLEquivalentClassesAxiom) {
			//	((OWLEquivalentClassesAxiom)ax).getClassExpressions();
			//}
			
		}
	}
	LOG.info("Removing "+rmAxioms.size()+" axioms");
	ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms);
	LOG.info("Adding "+newAxioms.size()+" axioms");
	ont.getOWLOntologyManager().addAxioms(ont, newAxioms);
}
 
Example 9
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Check the list of axioms for potential redundant subClass axioms of type:
 * <pre>
 *   A SubClassOf R some B
 *    and
 *   A SubClassOf B
 * </pre>
 * 
 * @param inferredAxioms
 * @return list of axiom pairs
 */
public List<PotentialRedundant> checkPotentialRedundantSubClassAxioms(Collection<? extends OWLAxiom> inferredAxioms) {
	List<PotentialRedundant> result = new ArrayList<PotentialRedundant>();
	for(OWLAxiom axiom : inferredAxioms) {
		if (axiom instanceof OWLSubClassOfAxiom) {
			OWLSubClassOfAxiom main = (OWLSubClassOfAxiom) axiom;
			OWLClassExpression mainSuperClassCE = main.getSuperClass();
			if (mainSuperClassCE.isAnonymous()) {
				continue;
			}
			OWLClassExpression mainSubClassCE = main.getSubClass();
			if (mainSubClassCE.isAnonymous()) {
				continue;
			}
			OWLClass mainSuperClass = mainSuperClassCE.asOWLClass();
			OWLClass mainSubClass = mainSubClassCE.asOWLClass();
			Set<OWLSubClassOfAxiom> subClassAxioms = graph.getAllOWLSubClassOfAxiomsForSubClass(mainSubClass);
			if (subClassAxioms != null && subClassAxioms.size() > 1) {
				for (OWLSubClassOfAxiom current : subClassAxioms) {
					if (main == current) {
						continue;
					}
					OWLClassExpression currentSuperClass = current.getSuperClass();
					if (currentSuperClass.isAnonymous() && currentSuperClass instanceof OWLObjectSomeValuesFrom) {
						OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) currentSuperClass;
						final OWLClassExpression filler = someValuesFrom.getFiller();
						if (mainSuperClass.equals(filler)) {
							final OWLObjectPropertyExpression property = someValuesFrom.getProperty();
							final OWLClassExpression subClass = current.getSubClass();
							result.add(new PotentialRedundant(main, current, subClass.asOWLClass(), property.asOWLObjectProperty(), filler.asOWLClass()));
						}
					}
				}
			}
		}
	}
	if (!result.isEmpty()) {
		return result;
	}
	return null;
}
 
Example 10
Source File: GCIUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Generates trivial SVF axioms from existing GCIs
 * 
 * <pre>
 * For each GCI of the form CX SubClassOf R some DX
 *  for each C that is an inferred direct subclass of or equivalent to CX
 *     for each D that is an inferred direct superclass of or equivalent to DX
 *       add an axiom C SubClassOf R some D
 * </pre>
 * @param ontology
 * @param reasoner
 * @return axioms
 */
public static Set<OWLSubClassOfAxiom> getSubClassOfSomeValuesFromAxioms(OWLOntology ontology,
		OWLReasoner reasoner) {

	Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>();
	OWLDataFactory df = ontology.getOWLOntologyManager().getOWLDataFactory();
	for (OWLSubClassOfAxiom ax : ontology.getAxioms(AxiomType.SUBCLASS_OF)) {
		OWLClassExpression c = ax.getSubClass();
		if (ax.getSuperClass() instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ax.getSuperClass();
			OWLObjectPropertyExpression p = svf.getProperty();
			OWLClassExpression filler = svf.getFiller();
			if (filler.isAnonymous() || c.isAnonymous()) {
				if (c.isBottomEntity())
					continue;
				if (filler.isTopEntity())
					continue;
				
				Set<OWLClass> childSet = reasoner.getEquivalentClasses(c).getEntities();
				if (childSet.size() == 0) {
					childSet = reasoner.getSubClasses(c, true).getFlattened();
				}
				for (OWLClass childClass : childSet) {
					if (childClass.isBottomEntity())
						continue;
					Set<OWLClass> childClassSuperClasses = 
							reasoner.getSuperClasses(childClass, false).getFlattened();
					childClassSuperClasses.addAll(reasoner.getEquivalentClasses(childClass).getEntities());
					Set<OWLClass> parentSet = reasoner.getEquivalentClasses(filler).getEntities();
					if (parentSet.size() == 0) {
						parentSet = reasoner.getSuperClasses(filler, true).getFlattened();
					}
					// TODO: remove additional redundancy (R some X) SubClassOf (R some Y)
					// Elk cannot test arbitrary entailments
						for (OWLClass parentClass : parentSet) {
						if (parentClass.isTopEntity())
							continue;
						
						// do not assert C SubClassOf part-of some D, if C SubClassOf D is entailed
						if (childClassSuperClasses.contains(parentClass))
							continue;
						axioms.add(df.getOWLSubClassOfAxiom(childClass, 
								df.getOWLObjectSomeValuesFrom(p, parentClass)));
					}
				}
			}

		}
	}
	LOG.info("Inferred SVFs: "+axioms.size());
	return axioms;
}
 
Example 11
Source File: LegoShuntGraphTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private String getLabel(OWLClassExpression expression, OWLPrettyPrinter owlpp, OWLGraphWrapper graph) {
	if (expression instanceof OWLClass) {
		return graph.getLabelOrDisplayId(expression);
	}
	else if (expression instanceof OWLObjectIntersectionOf) {
		StringBuilder sb = new StringBuilder();
		OWLObjectIntersectionOf intersectionOf = (OWLObjectIntersectionOf) expression;
		sb.append("<TABLE>");
		for (OWLClassExpression ce : intersectionOf.getOperands()) {
			sb.append("<TR><TD>");
			if (ce instanceof OWLClass) {
				sb.append(graph.getLabelOrDisplayId((OWLClass)ce));
			}
			else if (ce instanceof OWLObjectSomeValuesFrom){
				OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) ce;
				OWLObjectPropertyExpression property = some.getProperty();
				if (property.isAnonymous()) {
					sb.append(owlpp.render(property));
				}
				else {
					sb.append(graph.getLabelOrDisplayId(property.asOWLObjectProperty()));
				}
				sb.append(" <B>some</B> ");
				OWLClassExpression filler = some.getFiller();
				if (filler instanceof OWLClass) {
					sb.append(graph.getLabelOrDisplayId((OWLClass)filler));
				}
				else {
					sb.append(owlpp.render(filler));
				}
			}
			else {
				sb.append(ce.toString());
			}
			sb.append("</TD></TR>");
		}
		sb.append("</TABLE>");
		return sb.toString();
	}
	return owlpp.render(expression);
}
 
Example 12
Source File: LegoDotWriter.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private CharSequence getLabel(OWLClassExpression expression, OWLPrettyPrinter owlpp) {
	if (expression instanceof OWLClass) {
		return insertLineBrakes(graph.getLabelOrDisplayId(expression));
	}
	else if (expression instanceof OWLObjectIntersectionOf) {
		StringBuilder sb = new StringBuilder();
		OWLObjectIntersectionOf intersectionOf = (OWLObjectIntersectionOf) expression;
		sb.append("<TABLE>");
		for (OWLClassExpression ce : intersectionOf.getOperands()) {
			sb.append("<TR><TD>");
			if (ce instanceof OWLClass) {
				sb.append(insertLineBrakes(graph.getLabelOrDisplayId((OWLClass)ce)));
			}
			else if (ce instanceof OWLObjectSomeValuesFrom){
				OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) ce;
				OWLObjectPropertyExpression property = some.getProperty();
				if (property.isAnonymous()) {
					sb.append(owlpp.render(property));
				}
				else {
					sb.append(insertLineBrakes(graph.getLabelOrDisplayId(property.asOWLObjectProperty())));
				}
				sb.append(" <B>some</B> ");
				OWLClassExpression filler = some.getFiller();
				if (filler instanceof OWLClass) {
					sb.append(insertLineBrakes(graph.getLabelOrDisplayId((OWLClass)filler)));
				}
				else {
					sb.append(insertLineBrakes(escape(owlpp.render(filler))));
				}
			}
			else {
				sb.append(insertLineBrakes(escape(ce.toString())));
			}
			sb.append("</TD></TR>");
		}
		sb.append("</TABLE>");
		return sb.toString();
	}
	return insertLineBrakes(escape(owlpp.render(expression)));
}