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

The following examples show how to use org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom#getFiller() . 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: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static Set<OWLObjectSomeValuesFrom> filterSVFs(final OWLClassFilter clsFilter, Set<OWLObjectSomeValuesFrom> svfs) {
	Predicate<OWLObjectSomeValuesFrom> predicate = new Predicate<OWLObjectSomeValuesFrom>() {

		@Override
		public boolean apply(OWLObjectSomeValuesFrom input) {
			OWLClassExpression filler = input.getFiller();
			Boolean result = filler.accept(new OWLClassExpressionVisitorExAdapter<Boolean>(Boolean.FALSE){
				@Override
				public Boolean visit(OWLClass cls) {
					return clsFilter.use(cls);
				}
			});
			if (result != null) {
				return result.booleanValue();
			}
			return false;
		}
	};
	svfs = Sets.filter(svfs, predicate);
	return svfs;
}
 
Example 2
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 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: 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 5
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 6
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
Set<OWLClass> getSvfClasses(OWLClass c, OWLObjectProperty p) {
	Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>();
	for(OWLOntology ont : getAllOntologies()) {
		axioms.addAll(ont.getSubClassAxiomsForSubClass(c));
	}
	Set<OWLClass> superClasses = new HashSet<OWLClass>();
	for (OWLSubClassOfAxiom axiom : axioms) {
		OWLClassExpression expr = axiom.getSuperClass();
		if (expr instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) expr;
			if (p.equals(svf.getProperty())) {
				OWLClassExpression filler = svf.getFiller();
				if (filler instanceof OWLClass) {
					superClasses.add((OWLClass) filler);
				}
			}
		}
	}
	return superClasses;
}
 
Example 7
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 8
Source File: OntologyHelper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve a map of related classes for a particular class.
 * 
 * @param owlClass
 * @return a map of relation type to a list of IRIs for nodes with that
 * relationship.
 */
public Map<String, List<String>> getRestrictions(OWLClass owlClass) {
	RestrictionVisitor visitor = new RestrictionVisitor(Collections.singleton(ontology));
	for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(owlClass)) {
		OWLClassExpression superCls = ax.getSuperClass();
		// Ask our superclass to accept a visit from the RestrictionVisitor
		// - if it is an existential restriction then our restriction visitor
		// will answer it - if not our visitor will ignore it
		superCls.accept(visitor);
	}

	Map<String, List<String>> restrictions = new HashMap<>();
	for (OWLObjectSomeValuesFrom val : visitor.getSomeValues()) {
		OWLClassExpression exp = val.getFiller();

		// Get the shortname of the property expression
		String shortForm = null;
		Set<OWLObjectProperty> signatureProps = val.getProperty().getObjectPropertiesInSignature();
		for (OWLObjectProperty sigProp : signatureProps) {
			Collection<String> labels = findLabels(sigProp.getIRI());
			if (labels.size() > 0) {
				shortForm = new ArrayList<String>(labels).get(0);
			}
		}

		if (shortForm != null && !exp.isAnonymous()) {
			IRI iri = exp.asOWLClass().getIRI();

			if (!restrictions.containsKey(shortForm)) {
				restrictions.put(shortForm, new ArrayList<String>());
			}
			restrictions.get(shortForm).add(iri.toString());
		}
	}

	return restrictions;
}
 
Example 9
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Classify the an edge and target as a human readable string for further processing.
 * 
 * @param owlGraphEdge edge under consideration
 * @param edgeDirector 
 * @param props properties set
 * @return null, "simplesubclass", "typesubclass", or "identity".
 * @see #addDirectDescendentsToShuntGraph
 * @see #addStepwiseAncestorsToShuntGraph
 */
public String classifyRelationship(OWLGraphEdge owlGraphEdge, OWLObject edgeDirector, Set<? extends OWLPropertyExpression> props){		
	String retval = null;
	
	OWLQuantifiedProperty qp = owlGraphEdge.getSingleQuantifiedProperty();
	if( qp.isSubClassOf() || props.contains(qp.getProperty()) ){
		//OWLObject target = owlGraphEdge.getTarget();
		if( edgeDirector instanceof OWLClass ){
			retval = "simplesubclass";
		}else if( edgeDirector instanceof OWLObjectSomeValuesFrom ){
			OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom)edgeDirector;
			if( props.contains(some.getProperty()) ){
				OWLClassExpression clsexp = some.getFiller();
				if( ! clsexp.isAnonymous()){
					retval = "typesubclass";
				}
			}
		}
	}else if( qp.isIdentity() ){
		retval = "identity";
	}else{
		if (LOG.isDebugEnabled()) {
			LOG.debug("Skipping complex edge: "+owlGraphEdge);
		}
	}
	
	return retval;
}
 
Example 10
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public OWLObjectSomeValuesFrom visit(OWLObjectSomeValuesFrom ce) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("Unfolding some_values_from: "+ce);
	}
	
	OWLClassExpression filler = ce.getFiller();
	if (filler != null) {
		OWLClassExpression unfold = filler.accept(this);
		if (unfold != null) {
			return factory.getOWLObjectSomeValuesFrom(ce.getProperty(), unfold);
		}
	}
	return null;
}
 
Example 11
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 12
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
	 * Add a set of edges, as ancestors to x in OWLShuntGraph g.
	 * This is reflexive.
	 *
	 * @param x
	 * @param g
	 * @param rel_ids
	 * @return the modified OWLShuntGraph
	 */
	public OWLShuntGraph addStepwiseAncestorsToShuntGraph(OWLObject x, OWLShuntGraph g, List<String> rel_ids) {

		// Add this node, our seed.
		String topicID = getIdentifier(x);
		String topicLabel = getLabel(x);
		OWLShuntNode tn = new OWLShuntNode(topicID, topicLabel);
		g.addNode(tn);

		// NEW VERSION
		Set<OWLObjectProperty> props = relationshipIDsToPropertySet(rel_ids);
		for (OWLGraphEdge e : getOutgoingEdges(x, props)) {
			OWLObject target = e.getTarget();
			String rel = classifyRelationship(e, target, props);

			if( rel != null ){

				// Placeholders.
				String objectID = null;
				String objectLabel = null;
				String elabel = null;
				
				if( rel == "simplesubclass" ){
					objectID = getIdentifier(target);
					objectLabel = getLabelOrDisplayId(target);
					elabel = getEdgeLabel(e);
				}else if( rel == "typesubclass" ){
					OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom)target;
					OWLClassExpression clsexp = some.getFiller();
					OWLClass cls = clsexp.asOWLClass();
					objectID = getIdentifier(cls);
					objectLabel = getLabelOrDisplayId(cls);
					elabel = getEdgeLabel(e);
				}
				
				// Only add when subject, object, and relation are properly defined.
				if(	elabel != null &&
					topicID != null && ! topicID.equals("") &&
					objectID != null &&	! objectID.equals("") ){
	
					// Add node.
					OWLShuntNode sn = new OWLShuntNode(objectID, objectLabel);
					boolean wuzAdded = g.addNode(sn);

					// Recur on node if it already wasn't there.
					if( wuzAdded ){
						addStepwiseAncestorsToShuntGraph(target, g, rel_ids);
					}
				
					//Add edge 
					OWLShuntEdge se = new OWLShuntEdge(topicID, objectID, elabel);
					g.addEdge(se);
				}
			}
		}

// ORIGINAL VERSION
//		// Next, get all of the named ancestors and add them to our shunt graph.
//		// We need some traversal code going up!
//		for (OWLGraphEdge e : getOutgoingEdges(x)) {
//			OWLObject t = e.getTarget();
//			if (t instanceof OWLNamedObject){				
//
//				// Figure out object.
//				String objectID = getIdentifier(t);
//				String objectLabel = getLabel(t);
//
//				// Edge.
//				String elabel = getEdgeLabel(e);
//				
//				// Only add when subject, object, and relation are properly defined.
//				if( elabel != null &&
//					topicID != null && ! topicID.equals("") &&
//					objectID != null &&	! objectID.equals("") ){
//				
//					// Add node.
//					OWLShuntNode sn = new OWLShuntNode(objectID, objectLabel);
//					boolean wuzAdded = g.addNode(sn);
//
//					// Recur on node if it already wasn't there.
//					if( wuzAdded ){
//						addStepwiseAncestorsToShuntGraph(t, g);
//					}
//				
//					//Add edge 
//					OWLShuntEdge se = new OWLShuntEdge(topicID, objectID, elabel);
//					g.addEdge(se);
//				}
//			}
//		}
		
		return g;
	}
 
Example 13
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 14
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax 
 * {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf}, 
 * into multiple {@code OWLSubClassOfAxiom}s, using a <a 
 * href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'>
 * SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose 
 * superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an 
 * {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with 
 * an {@code OWLObjectSomeValuesFrom} as superclass, with the same 
 * {@code OWLPropertyExpression}, and individual operands as filler. 
 * <p>
 * Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in
 * {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s. 
 * But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed 
 * them into {@code OWLSubClassOfAxiom}s. It must be called before this method.
 * 
 * @see #performDefaultModifications()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void splitSubClassAxioms() {
    log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf");
    
    //first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf
    SplitSubClassAxioms split = new SplitSubClassAxioms(
            this.getOwlGraphWrapper().getAllOntologies(), 
            this.getOwlGraphWrapper().getDataFactory());
    this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges());
    this.triggerWrapperUpdate();
    
    //some ontologies use an OWLObjectIntersectionOf as the filler of 
    //an OWLObjectSomeValuesFrom class expression. We go only one level down 
    //(i.e., we would not translate another OWLObjectSomeValuesFrom part of the 
    //OWLObjectIntersectionOf)
    OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory();
    List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
            OWLClassExpression superClsExpr = ax.getSuperClass();
            if (superClsExpr instanceof OWLObjectSomeValuesFrom) {
                OWLObjectSomeValuesFrom someValuesFrom = 
                        (OWLObjectSomeValuesFrom) superClsExpr;
                if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) {
                    //remove original axiom
                    changes.add(new RemoveAxiom(ont, ax));
                    
                    OWLObjectIntersectionOf filler = 
                            (OWLObjectIntersectionOf) someValuesFrom.getFiller();
                    for (OWLClassExpression op : filler.getOperands()) {
                        //we accept only OWLClasses, otherwise we would need to compose 
                        //OWLObjectPropertyExpressions
                        if (op instanceof OWLClass) {
                            OWLAxiom replAx = dataFactory.
                                    getOWLSubClassOfAxiom(ax.getSubClass(), 
                                    dataFactory.getOWLObjectSomeValuesFrom(
                                                someValuesFrom.getProperty(), op));
                            changes.add(new AddAxiom(ont, replAx));
                        }
                    }
                }
                
            }
        }
    }
    this.getOwlGraphWrapper().getManager().applyChanges(changes);
    this.triggerWrapperUpdate();
    
    log.info("OWLObjectIntersectionOf relaxation done.");
}
 
Example 15
Source File: LinkMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Search for the first class with a matching equivalent class definition. 
 * 
 * @param c
 * @param genus
 * @param relation
 * @return match or null
 */
private OWLClass hasMatchingIntersection(OWLClass c, OWLClass genus, OWLObjectProperty relation) {
	for(OWLOntology o : allOntologies) {
		Set<OWLEquivalentClassesAxiom> eqAxioms = o.getEquivalentClassesAxioms(c);
		for (OWLEquivalentClassesAxiom eqAxiom : eqAxioms) {
			Set<OWLClassExpression> expressions = eqAxiom.getClassExpressionsMinus(c);
			for (OWLClassExpression expression : expressions) {
				if (expression instanceof OWLObjectIntersectionOf) {
					OWLObjectIntersectionOf intersection = (OWLObjectIntersectionOf) expression;
					OWLClass differentiaCls = null;
					boolean matchesGenus = false;
					boolean matchesRelation = false;
					Set<OWLClassExpression> operands = intersection.getOperands();
					if (operands.size() == 2) {
						for (OWLClassExpression operand : operands) {
							if (operand.isAnonymous() == false) {
								OWLClass currentGenus = operand.asOWLClass();
								if (genus.equals(currentGenus)) {
									matchesGenus = true;
								}
							}
							else if (operand instanceof OWLObjectSomeValuesFrom) {
								OWLObjectSomeValuesFrom differentia = (OWLObjectSomeValuesFrom) operand;
								if (relation.equals(differentia.getProperty())) {
									matchesRelation = true;
									OWLClassExpression filler = differentia.getFiller();
									if (!filler.isAnonymous() && !filler.isOWLNothing() && !filler.isOWLThing()) {
										differentiaCls = filler.asOWLClass();
									}
								}
							}
						}
						if (matchesGenus && matchesRelation ) {
							 return differentiaCls;
						}
					}
				}
			}
		}
	}
	return null;
}
 
Example 16
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 17
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)));
}
 
Example 18
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 19
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);
}