org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom. 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: DLLikeQueryTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
@Ignore("Disabling test due to lack of resources to debug")
public void testRestrictionQuery2() throws Exception {
	OWLGraphWrapper g = getOntologyWrapper();
	OWLClass c = g.getOWLClass("http://example.org#axon_terminals_degenerated");
	OWLObjectProperty p = g.getOWLObjectProperty("http://example.org#has_part");
	boolean ok = false;
	OWLObjectSomeValuesFrom obj = g.getDataFactory().getOWLObjectSomeValuesFrom(p, c);

	for (OWLObject x : g.queryDescendants(obj)) {
		System.out.println("R2:"+x);
		ok = true;
	}
	assertTrue(ok);
	assertEquals(10, g.queryDescendants(obj).size());
}
 
Example #2
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 #3
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 6 votes vote down vote up
private void getAnnotations() throws MobiOntologyException {
    if (owlOntology == null) {
        throw new MobiOntologyException("ontology is null");
    }
    ontoAnnotations = new HashSet<>();
    annotations = new HashSet<>();

    ontoAnnotations = owlOntology.annotations()
            .map(SimpleOntologyValues::mobiAnnotation)
            .collect(Collectors.toSet());
    annotations.addAll(ontoAnnotations);

    OWLOntologyWalker walker = new OWLOntologyWalker(Collections.singleton(owlOntology));
    OWLOntologyWalkerVisitor visitor = new OWLOntologyWalkerVisitor(walker) {
        @Override
        public void visit(OWLObjectSomeValuesFrom desc) {
            annotations.add(SimpleOntologyValues.mobiAnnotation(getCurrentAnnotation()));
        }
    };

    walker.walkStructure(visitor);
}
 
Example #4
Source File: FrameMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Expression makeExpression(OWLClassExpression x) {
	if (x.isAnonymous()) {
		if (x instanceof OWLObjectIntersectionOf) {
			return makeIntersectionOf((OWLObjectIntersectionOf)x);
		}
		else if (x instanceof OWLObjectSomeValuesFrom) {
			return makeSomeValuesFrom((OWLObjectSomeValuesFrom)x);
		}
		else {
			return null;
		}
	}
	else {
		return makeClassStub(x);
	}
}
 
Example #5
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 #6
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public HandlerResult visit(OWLObjectMinCardinality ce) {
	final OWLClassExpression filler = ce.getFiller();
	final HandlerResult recursive = filler.accept(this);
	OWLObjectSomeValuesFrom newCE;
	if (recursive == null) {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), filler);
	}
	else if (recursive.remove) {
		return HandlerResult.remove();
	}
	else {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), recursive.modified);
	}
	return HandlerResult.modified(newCE);
}
 
Example #7
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public HandlerResult visit(OWLObjectExactCardinality ce) {
	if (ce.getCardinality() == 0) {
		// remove the ce if the max cardinality is zero
		return HandlerResult.remove();
	}
	final OWLClassExpression filler = ce.getFiller();
	final HandlerResult recursive = filler.accept(this);
	OWLObjectSomeValuesFrom newCE;
	if (recursive == null) {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), filler);
	}
	else if (recursive.remove) {
		return HandlerResult.remove();
	}
	else {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), recursive.modified);
	}
	return HandlerResult.modified(newCE);
}
 
Example #8
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public HandlerResult visit(OWLObjectMaxCardinality ce) {
	if (ce.getCardinality() == 0) {
		// remove the ce if the max cardinality is zero
		return HandlerResult.remove();
	}
	final OWLClassExpression filler = ce.getFiller();
	final HandlerResult recursive = filler.accept(this);
	OWLObjectSomeValuesFrom newCE;
	if (recursive == null) {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), filler);
	}
	else if (recursive.remove) {
		return HandlerResult.remove();
	}
	else {
		newCE = factory.getOWLObjectSomeValuesFrom(ce.getProperty(), recursive.modified);
	}
	return HandlerResult.modified(newCE);
}
 
Example #9
Source File: OWLInAboxTranslator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param i - source
 * @param supc - target expression (e.g. R some B)
 * @return OWLObjectPropertyAssertionAxiom or null
 */
private OWLObjectPropertyAssertionAxiom trEdge(OWLIndividual i, OWLClassExpression supc) {
	if (supc instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)supc;
		OWLObjectPropertyExpression p = trTypeLevel(svf.getProperty());
		OWLIndividual j;
		if (svf.getFiller().isAnonymous()) {
			j = anonClassToIndividual(svf.getFiller());
			add(trEdge(j, svf.getFiller()));
		}
		else {
			j = classToIndividual((OWLClass)svf.getFiller());
		}

		OWLObjectPropertyAssertionAxiom e = getOWLDataFactory().getOWLObjectPropertyAssertionAxiom(p, i, j); 
		return e;
	}
	return null;

}
 
Example #10
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void makeHasPhenotypeInstancesDirect() {
	// x Type has_phenotype some C ==> x Type C
	LOG.info("x Type has_phenotype some C ==> x Type C");
	OWLObjectProperty hasPhenotype = getOWLObjectPropertyViaOBOSuffix(HAS_PHENOTYPE);
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	for (OWLClassAssertionAxiom caa : outputOntology.getAxioms(AxiomType.CLASS_ASSERTION)) {
		OWLClassExpression ex = caa.getClassExpression();
		OWLIndividual i = caa.getIndividual();
		if (ex instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ex;
			if (svf.getProperty().equals(hasPhenotype)) {
				rmAxioms.add(caa);
				newAxioms.add(getOWLDataFactory().getOWLClassAssertionAxiom(svf.getFiller(), i));
			}

		}
	}
	LOG.info("making instances direct: +"+newAxioms.size()+ " -"+rmAxioms.size());
	addAxiomsToOutput(newAxioms, false);
	removeAxiomsFromOutput(rmAxioms, false);
}
 
Example #11
Source File: AutomaticSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void gatherProperties(OWLClassExpression x) {
	if (x instanceof OWLClass) {
		return;
	}
	else if (x instanceof OWLObjectIntersectionOf) {
		for (OWLClassExpression y : ((OWLObjectIntersectionOf)x).getOperands()) {
			gatherProperties(y);
		}		
	}
	else if (x instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)x;
		gatherProperties(svf.getProperty());
		gatherProperties(svf.getFiller());
	}
	else {
		//
	}
}
 
Example #12
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 #13
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 #14
Source File: OldSimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private OWLClass expressionToClass(OWLClassExpression x) {
	if (x instanceof OWLClass)
		return (OWLClass)x;
	if (this.expressionToClassMap.containsKey(x))
		return this.expressionToClassMap.get(x);
	OWLClass c = owlDataFactory.getOWLClass(IRI.create("http://owlsim.org#"+idNum));
	idNum++;

	OWLEquivalentClassesAxiom eca =
		owlDataFactory.getOWLEquivalentClassesAxiom(c, x);
	owlOntologyManager.addAxiom(sourceOntology, eca);
	expressionToClassMap.put(x, c);

	// fully fold tbox (AND and SOME only)
	if (x instanceof OWLObjectIntersectionOf) {
		for (OWLClassExpression y : ((OWLObjectIntersectionOf)x).getOperands()) {
			expressionToClass(y);
		}
	}
	else if (x instanceof OWLObjectSomeValuesFrom) {
		expressionToClass(((OWLObjectSomeValuesFrom)x).getFiller());
	}
	return c;
}
 
Example #15
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 #16
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 #17
Source File: EliminateEJVar.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * return named properties p such that c \subseteq \some inv(p) T
 * @param c
 * @return
 */
protected Set<URI> getNamedInverseSuperPropertiesOrSelf(OWLClassExpression c) {
	Set<OWLClassExpression> subs = taxo.getAllSubsumers(c);
	Set<URI> ret = new HashSet<URI>();
	for (OWLClassExpression ex: subs) {
		if (ex.getClassExpressionType().equals(ClassExpressionType.OBJECT_SOME_VALUES_FROM)) {
			OWLObjectSomeValuesFrom rest = (OWLObjectSomeValuesFrom) ex;
			OWLObjectPropertyExpression prop = rest.getProperty().getSimplified();
			if (prop.isAnonymous()) {
				OWLObjectProperty namedProp = prop.getNamedProperty();
				ret.add(namedProp.getIRI().toURI());
			}
			
		}
	}
	return ret;
	
}
 
Example #18
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private OWLClassExpression replaceVariables(OWLClassExpression inx,
		BindingSet bset) {
	if (inx instanceof OWLNamedObject) {
		IRI y = replaceIRI(((OWLNamedObject)inx).getIRI(), bset);
		if (inx instanceof OWLClass) {
			return getOWLDataFactory().getOWLClass(y);
		}
	}
	else if (inx instanceof OWLObjectSomeValuesFrom) {
		OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)inx;
		return getOWLDataFactory().getOWLObjectSomeValuesFrom(
				replaceVariables(svf.getProperty(),bset),
				replaceVariables(svf.getFiller(),bset));

	}
	else if (inx instanceof OWLObjectIntersectionOf) {
		Set<OWLClassExpression> es = new HashSet<OWLClassExpression>();
		for (OWLClassExpression e : ((OWLObjectIntersectionOf)inx).getOperands()) {
			es.add(replaceVariables(e, bset));
		}
		return getOWLDataFactory().getOWLObjectIntersectionOf(es);
	}
	else {
		
	}
	return null;
}
 
Example #19
Source File: DLLikeQueryTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
@Ignore("Disabling test due to lack of resources to debug")
public void testRestrictionQuery() throws Exception {
	OWLGraphWrapper g = getOntologyWrapper();
	OWLClass c = g.getOWLClass("http://example.org#degenerated");
	OWLObjectProperty p = g.getOWLObjectProperty("http://example.org#has_quality");
	boolean ok = false;
	OWLObjectSomeValuesFrom obj = g.getDataFactory().getOWLObjectSomeValuesFrom(p, c);
	for (OWLObject x : g.queryDescendants(obj)) {
		System.out.println("R:"+x);
		ok = true;
	}
	assertEquals(5, g.queryDescendants(obj).size());
	assertTrue(ok);
}
 
Example #20
Source File: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Map<OWLClass, Set<OWLObjectSomeValuesFrom>> getExpressions(OWLOntology ontology, Set<OWLObjectProperty> properties, OWLClassFilter filter) {
	final ExpressionMaterializingReasonerFactory rf = new ExpressionMaterializingReasonerFactory(new ElkReasonerFactory());
	final ExpressionMaterializingReasoner reasoner = rf.createReasoner(ontology);
	try {
		reasoner.materializeExpressions(properties);
		final Map<OWLClass, Set<OWLObjectSomeValuesFrom>> newAxioms = new HashMap<OWLClass, Set<OWLObjectSomeValuesFrom>>();
		for (OWLClass cls : ontology.getClassesInSignature()) {
			if (filter != null && filter.use(cls) == false) {
				continue;
			}
			// find existing some value froms
			Set<OWLObjectSomeValuesFrom> existingSVFs = getSuperSVFs(ontology.getSubClassAxiomsForSubClass(cls));
			// get all direct super classes
			Set<OWLClassExpression> directSuperCE = reasoner.getSuperClassExpressions(cls, true);
			// filter for SVFs
			Set<OWLObjectSomeValuesFrom> directSuperSVFs = getSVFs(directSuperCE);
			
			// missing direct SVFs, calculate using a set difference
			Set<OWLObjectSomeValuesFrom> missingSVFs = Sets.difference(directSuperSVFs, existingSVFs);
			
			// add to result set
			if (missingSVFs.isEmpty() == false) {
				missingSVFs = new HashSet<OWLObjectSomeValuesFrom>(missingSVFs);
				if (filter != null) {
					missingSVFs = filterSVFs(filter, missingSVFs);
				}
				if (missingSVFs.isEmpty() == false) {
					newAxioms.put(cls, missingSVFs);
				}
			}
		}
		return newAxioms;
	}
	finally {
		reasoner.dispose();
	}
}
 
Example #21
Source File: GCIUtilTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testOrganismPair() throws Exception{
	g =  getOntologyWrapper("limb_gci.owl");
	ElkReasonerFactory rf = new ElkReasonerFactory();
	OWLReasoner r = rf.createReasoner(g.getSourceOntology());
	try {
		Set<OWLSubClassOfAxiom> axioms = GCIUtil.getSubClassOfSomeValuesFromAxioms(r);
		int n = 0;
		for (OWLSubClassOfAxiom axiom : axioms) {
			String c = ((OWLClass) axiom.getSubClass()).getIRI().toString();
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) axiom.getSuperClass();
			String rel = ((OWLObjectProperty) svf.getProperty()).getIRI().toString();
			String p = ((OWLClass) svf.getFiller()).getIRI().toString();
			String axstr = c + " " + rel + " " + p;
			System.out.println(axstr);
			if ("http://x.org/phalanx-development http://x.org/part-of http://x.org/digit-development".equals(axstr)) {
				n |= 1;
			}
			if ("http://x.org/digit-development http://x.org/part-of http://x.org/autopod-development".equals(axstr)) {
				n |= 2;
			}
			if ("http://x.org/limb-development http://x.org/part-of http://x.org/organism-development".equals(axstr)) {
				n |= 4;
			}
			if ("http://x.org/autopod-development http://x.org/part-of http://x.org/limb-development".equals(axstr)) {
				n |= 8;
			}
		}
		assertEquals(4, axioms.size());
		assertEquals(15, n);
	}
	finally {
		r.dispose();
	}

}
 
Example #22
Source File: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Set<OWLObjectSomeValuesFrom> getSuperSVFs(Set<OWLSubClassOfAxiom> axioms) {
	final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>();
	for (OWLSubClassOfAxiom existing : axioms) {
		OWLClassExpression superCE = existing.getSuperClass();
		superCE.accept(new OWLClassExpressionVisitorAdapter() {
			@Override
			public void visit(OWLObjectSomeValuesFrom svf) {
				svfs.add(svf);
			}

		});
	}
	return svfs;
}
 
Example #23
Source File: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Set<OWLObjectSomeValuesFrom> getSVFs(Set<OWLClassExpression> expressions) {
	final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>();
	for(OWLClassExpression ce : expressions) {
		ce.accept(new OWLClassExpressionVisitorAdapter(){
			@Override
			public void visit(OWLObjectSomeValuesFrom svf) {
				svfs.add(svf);
			}
			
		});
	}
	return svfs;
}
 
Example #24
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Void visit(OWLObjectSomeValuesFrom desc) {
  long restriction =
      getOrCreateNode(getIri(desc), OwlLabels.OWL_SOME_VALUES_FROM, OwlLabels.OWL_ANONYMOUS);
  if (!desc.getProperty().isAnonymous()) {
    long property = getOrCreateNode(getIri(desc.getProperty()));
    getOrCreateRelationship(restriction, property, OwlRelationships.PROPERTY);
    long cls = getOrCreateNode(getIri(desc.getFiller()));
    getOrCreateRelationship(restriction, cls, OwlRelationships.FILLER);
  }
  return null;
}
 
Example #25
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 #26
Source File: RestrictionVisitor.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(@NotNull OWLObjectSomeValuesFrom ce) {
	// This method gets called when a class expression is an existential
	// (someValuesFrom) restriction and it asks us to visit it
	someValues.add(ce);
	restrictedProperties.add(ce.getProperty());
}
 
Example #27
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 #28
Source File: AbstractSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<OWLAxiom> createPropertyView(OWLObjectProperty viewProperty, Set<OWLClass> classes, String labelFormat) {
	OWLAnnotationProperty rdfsLabel = getOWLDataFactory().getRDFSLabel();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	propertyToFormatMap.put(viewProperty, labelFormat);
	for (OWLClass c : classes) {
		if (c.equals(getOWLDataFactory().getOWLNothing())) {
			continue;
		}
		OWLClass vc = getOWLDataFactory().getOWLClass(makeViewClassIRI(c.getIRI(), viewProperty.getIRI(), "-", false, false));
		OWLObjectSomeValuesFrom vx = getOWLDataFactory().getOWLObjectSomeValuesFrom(viewProperty, c);
		newAxioms.add(
				getOWLDataFactory().getOWLEquivalentClassesAxiom(vc, vx)
		);
		newAxioms.add(
				getOWLDataFactory().getOWLDeclarationAxiom(vc)
		);
		String label = getAnyLabel(c);
		String viewLabel = String.format(labelFormat, label);
		newAxioms.add(
				getOWLDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, vc.getIRI(), 
						getOWLDataFactory().getOWLLiteral(viewLabel))
		);
		LOG.info("VIEW_CLASS:"+vc+" "+viewLabel+" = P some "+c);
		addViewMapping(c, viewProperty, vc);
		newClasses.add(vc);
	}	
	LOG.info("Num new classes:"+newClasses.size());
	addAxiomsToOutput(newAxioms, true);
	return newAxioms;
}
 
Example #29
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 #30
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;

}