org.semanticweb.owlapi.model.OWLClassExpression Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLClassExpression. 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: SimpleABoxToGAF.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<GeneAnnotation> generateAssociations(OWLNamedIndividual ind, OWLOntology ont) {
	Set<GeneAnnotation> assocs = new HashSet<GeneAnnotation>();
	String eid = graph.getIdentifier(ind);
	for (OWLClassExpression x : OwlHelper.getTypes(ind, ont)) {
		GeneAnnotation ga = new GeneAnnotation();
		if (x.isAnonymous()) {
			// TODO
		}
		else {
			ga.setCls(graph.getIdentifier(x));
		}
		ga.setBioentity(eid);
		assocs.add(ga);
	}
	return assocs;
}
 
Example #2
Source File: NCBIConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check to make sure that this taxon has the required properties.
 *
 * <ul>
 * <li>label exists</li>
 * <li>exactly one superClass</li>
 * </ul>
 *
 * @param ontology the current ontology
 * @param taxon the subject
 * @return true if the check succeeds, otherwise false.
 */
public static Boolean checkTaxon(OWLOntology ontology, 
		OWLClass taxon) {
	String id = getTaxonID(taxon);

	String label = getFirstLiteral(ontology, taxon,
		"rdfs:label");
	if (label == null || label.trim().length() == 0) {
		logger.error("No SCIENTIFIC NAME provided for " + id);
		return false;
	}
	Set<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(taxon);
	Set<OWLClassExpression> superClasses = new HashSet<>();
	for(OWLSubClassOfAxiom ax : axioms) {
		superClasses.add(ax.getSuperClass());
	}
	if (superClasses.size() < 1 && !id.equals("1")) {
		logger.error("No PARENT ID for " + id);
		return false;
	} else if (superClasses.size() > 1) {
		logger.error("Multiple PARENT IDs for " + id);
		return false;
	}

	return true;
}
 
Example #3
Source File: OwlApiClassExpressionSubClassesQueryTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
public OwlApiClassExpressionSubClassesQueryTest(
		final QueryTestManifest<OWLClassExpression, RelatedEntitiesTestOutput<OWLClass>> manifest) {
	super(manifest,
			new OwlApiReasoningTestDelegate<RelatedEntitiesTestOutput<OWLClass>>(
					manifest) {

				@Override
				public RelatedEntitiesTestOutput<OWLClass> getActualOutput()
						throws Exception {
					final NodeSet<OWLClass> subNodes = getReasoner()
							.getSubClasses(manifest.getInput().getQuery(),
									true);
					return new OwlApiRelatedEntitiesTestOutput<OWLClass>(
							subNodes);
				}

				@Override
				public Class<? extends Exception> getInterruptionExceptionClass() {
					return ReasonerInterruptedException.class;
				}

			});
}
 
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: AutomaticSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void gatherProperties(OWLIndividual ind, int depth) {
	if (visited.contains(ind))
		return;
	if (depth > 1) {
		return;
		// TODO: create property chains
	}
	LOG.info("Gathering props from: "+ind);
	visited.add(ind);
	for (OWLClassExpression x : OwlHelper.getTypes(ind, inputOntology)) {
		gatherProperties(x);
	}
	Map<OWLObjectPropertyExpression, Set<OWLIndividual>> pvs = OwlHelper.getObjectPropertyValues(ind, inputOntology);
	for (OWLObjectPropertyExpression pe : pvs.keySet()) {
		gatherProperties(pe);
		for (OWLIndividual k : pvs.get(pe)) {
			gatherProperties(ind, depth+1);
		}
	}
}
 
Example #6
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void cacheReverseUnionMap() {
	synchronized (edgeCacheMutex) {
	    extraSubClassOfEdges = new HashMap<OWLObject, Set<OWLGraphEdge>>();
           if (!config.isGraphReasonedAndRelaxed) {
	        for (OWLOntology o : getAllOntologies()) {
	            for (OWLClass cls : o.getClassesInSignature()) {
	                for (OWLEquivalentClassesAxiom eca : o.getEquivalentClassesAxioms(cls)) {
	                    for (OWLClassExpression ce : eca.getClassExpressions()) {
	                        if (ce instanceof OWLObjectUnionOf) {
	                            for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
	                                if (!extraSubClassOfEdges.containsKey(child)) {
	                                    extraSubClassOfEdges.put(child, new OWLGraphEdgeSet());
	                                }
	                                extraSubClassOfEdges.get(child).add(
	                                        createSubClassOfEdge(child,cls,o,eca));
	                            }
	                        }
	                    }
	                }
	            }
	        }
	    }
	}
}
 
Example #7
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 p T
 * @param c
 * @return
 */
protected Set<URI> getNamedSuperPropertiesOrSelf(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)
		|| ex.getClassExpressionType().equals(ClassExpressionType.DATA_SOME_VALUES_FROM)) {
			OWLQuantifiedRestriction rest = (OWLQuantifiedRestriction) ex;
			OWLPropertyExpression prop = rest.getProperty();
			if (!prop.isAnonymous()) {
				if (prop.isDataPropertyExpression()) {
					OWLDataProperty namedProp = (OWLDataProperty) prop;
					ret.add(namedProp.getIRI().toURI());
				} else {
					assert prop.isObjectPropertyExpression() : prop;
					OWLObjectProperty namedProp = (OWLObjectProperty) prop;
					ret.add(namedProp.getIRI().toURI());
				}
			}
			
		}
	}
	return ret;
}
 
Example #8
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 #9
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
protected Set<OWLClassExpression> getCommunSubsumees(
		Set<OWLClassExpression> classes, boolean onlyExistialRestrictions) {
	
	Set<OWLClassExpression> communSubsumees = null;
	for (OWLClassExpression c: classes) {
		Set<OWLClassExpression> subs = classTaxo.getSubsumeesOrSelf(c);
		assert subs!=null : "Not found in class taxonomy: "+c;
		subs.removeAll(classTaxo.getBottomNode().getEquivalentElements());
		if (onlyExistialRestrictions) {
			retainOnlyExistentialRestrictions(subs);
		}
		if (communSubsumees == null) {
			communSubsumees = new HashSet<OWLClassExpression>();
			communSubsumees.addAll(subs);
		} else {
			communSubsumees.retainAll(subs);
		}
		
		if (communSubsumees.isEmpty()) {
			return Collections.EMPTY_SET;
		}
	}
	return communSubsumees == null? new HashSet<OWLClassExpression>() :communSubsumees;
}
 
Example #10
Source File: ProofTest.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
@Test
public void emptyDisjointUnion() throws Exception {
	OWLOntologyManager owlManager = OWLManager
			.createConcurrentOWLOntologyManager();
	// creating an ontology
	final OWLOntology ontology = owlManager.createOntology();
	OWLClass a = factory.getOWLClass(IRI.create("http://example.org/A"));
	OWLClass b = factory.getOWLClass(IRI.create("http://example.org/B"));
	// DisjointUnion(A ) = EquivalentClasses(A owl:Nothing)
	owlManager.addAxiom(ontology, factory.getOWLDisjointUnionAxiom(a,
			Collections.<OWLClassExpression> emptySet()));
	owlManager.addAxiom(ontology, factory.getOWLSubClassOfAxiom(b, b));

	final OWLProver prover = OWLAPITestUtils.createProver(ontology);

	prover.precomputeInferences(InferenceType.CLASS_HIERARCHY);

	ProofTestUtils.provabilityTest(prover,
			factory.getOWLSubClassOfAxiom(a, b));
}
 
Example #11
Source File: CycleCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public List<OWLClass> getAdjacent(OWLClass cls) {
	Set<OWLClass> results = new HashSet<OWLClass>();
	Set<OWLOntology> allOntologies = graph.getAllOntologies();
	for (OWLOntology owlOntology : allOntologies) {
		Set<OWLSubClassOfAxiom> axioms = owlOntology.getSubClassAxiomsForSubClass(cls);
		if (axioms != null && !axioms.isEmpty()) {
			for (OWLSubClassOfAxiom axiom : axioms) {
				OWLClassExpression expression = axiom.getSuperClass();
				if (!expression.isAnonymous()) {
					results.add(expression.asOWLClass());
				}
			}
		}
	}
	if (results.isEmpty()) {
		return Collections.emptyList();
	}
	return new ArrayList<OWLClass>(results);
}
 
Example #12
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 #13
Source File: BasicABox.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void translateGeneAnnotation(GeneAnnotation a) {
	Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
	OWLDataFactory fac = graph.getDataFactory();
	String e = a.getBioentity();

	List<GAFDescription> descriptions = getDescription(a);
	for (GAFDescription gdesc : descriptions) {
		OWLClassExpression svf = gdesc.classExpression;

		//OWLNamedIndividual i = getBioentityIndividual(e);
		OWLNamedIndividual i = null;
		i = emap.get(e);

		axioms.add(fac.getOWLClassAssertionAxiom(svf, i));
	}
	addAxioms(axioms);
}
 
Example #14
Source File: AnnotationExtensionUnfolder.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private OWLClassExpression unfold(OWLOntology ont, OWLClass cls) throws MultipleUnfoldOptionsException {
	OWLClassExpression rx = null;
	for (OWLClassExpression x : OwlHelper.getEquivalentClasses(cls, ont.getImportsClosure())) {
		if (x instanceof OWLClass) {
			continue;
		}
		else {
			if (rx != null) {
				if (isThrowOnMultipleExpressions) {
					throw new MultipleUnfoldOptionsException(x, rx);
				}
			}	
			rx = x;
		}
	}
	return rx;
}
 
Example #15
Source File: ExtendedReasonerTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected Set<OWLClass> findAncestors(String expr, 
		OWLObjectProperty p, boolean direct, Integer numExpected) throws TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException, ReasonerInterruptedException, OWLParserException {
	System.out.println("Query: "+expr+" "+p+" Direct="+direct);
	OWLClassExpression qc = parseOMN(expr);
	System.out.println("QueryC: "+qc);
	//Set<OWLClassExpression> ces = reasoner.getSuperClassExpressions(qc, false);
	//System.out.println("NumX:"+ces.size());
	Set<OWLClass> clzs = reasoner.getSuperClassesOver(qc, p, direct);
	System.out.println("NumD:"+clzs.size());
	for (OWLClass c : clzs) {
		System.out.println("  D:"+c);
	}
	if (numExpected != null) {
		assertEquals(numExpected.intValue(), clzs.size());
	}
	return clzs;
}
 
Example #16
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 #17
Source File: AbstractSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<OWLClass> materializeClassExpressionsReferencedBy(OWLObjectProperty p) {
	Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>();
	for (OWLAxiom ax : outputOntology.getReferencingAxioms(p, Imports.INCLUDED)) {
		if (ax instanceof OWLSubClassOfAxiom) {
			xs.addAll(getClassExpressionReferencedBy(p, ((OWLSubClassOfAxiom)ax).getSuperClass()));
		}
		else if (ax instanceof OWLClassAssertionAxiom) {
			xs.addAll(getClassExpressionReferencedBy(p, ((OWLClassAssertionAxiom)ax).getClassExpression()));
		}
		else if (ax instanceof OWLEquivalentClassesAxiom) {
			for (OWLClassExpression x : ((OWLEquivalentClassesAxiom)ax).getClassExpressions()) {
				xs.addAll(getClassExpressionReferencedBy(p,x));
			}
		}
	}
	return materializeClassExpressions(xs);
}
 
Example #18
Source File: OwlExpectedTestOutputLoader.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
public Collection<QueryTestManifest<OWLClassExpression, SatisfiabilityTestOutput>> getSatisfiabilityManifests(
		final String name, final URL input) {

	final List<QueryTestManifest<OWLClassExpression, SatisfiabilityTestOutput>> result = new ArrayList<QueryTestManifest<OWLClassExpression, SatisfiabilityTestOutput>>(
			queryClasses_.size());

	for (final OWLClassExpression queryClass : queryClasses_) {
		final OWLClassNode node = equivalent_.get(queryClass);
		// If the query class is equivalent to bottom, node is NOT null!
		result.add(
				new QueryTestManifest<OWLClassExpression, SatisfiabilityTestOutput>(
						name, input, queryClass,
						new BaseSatisfiabilityTestOutput(
								node == null || !node.isBottomNode())));
	}

	return result;
}
 
Example #19
Source File: QueryingWithNamedClasses.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
public Set<OWLClass> getSubClasses(String expression) {
	// Convert the class expression (string) into an OWL class expression,
	// which is used to retrieved the named class.
	// In principle, this allows for parsing arbitrary class expressions in
	// OWL, not just named classes (for which a simple
	// OWLDataFactory.getOWLClass(..) would do. However, Elk currently
	// doesn't yet implement getSubClasses for class expressions.
	// It will be supported in a future release.
	OWLClassExpression classExpression = parseClassExpression(expression
			.trim());
	// The flag "true" means that we want to retrieve only the direct
	// subclasses. The flag set in "false" should retrieve the descendant
	// classes.
	NodeSet<OWLClass> subClasses = reasoner.getSubClasses(classExpression,
			true);
	// IMPORTANT: This method will stop the reasoning process and free the
	// Elk threads/workers.
	reasoner.dispose();

	return subClasses.getFlattened();
}
 
Example #20
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Reverse all {@code OWLObjectUnionOf}s, that are operands in 
 * an {@code OWLEquivalentClassesAxiom}, into individual {@code OWLSubClassOfAxiom}s, where 
 * the classes part of the {@code OWLObjectUnionOf} become subclasses, and 
 * the original first operand of the {@code OWLEquivalentClassesAxiom} superclass. 
 * <p>
 * Note that such {@code OWLEquivalentClassesAxiom}s are not removed from the ontology, 
 * only {@code OWLSubClassOfAxiom}s are added. The axioms containing 
 * {@code OWLObjectUnionOf}s will be removed by calling {@link #removeOWLObjectUnionOfs()}, 
 * in order to give a chance to {@link #convertEquivalentClassesToSuperClasses()} 
 * to do its job before.
 * 
 * @see #performDefaultModifications()
 * @see #removeOWLObjectUnionOfs()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void reverseOWLObjectUnionOfs() {
    log.info("Reversing OWLObjectUnionOfs into OWLSubClassOfAxioms");
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLClass cls : ont.getClassesInSignature()) {
            for (OWLEquivalentClassesAxiom eca : ont.getEquivalentClassesAxioms(cls)) {
                for (OWLClassExpression ce : eca.getClassExpressions()) {
                    if (ce instanceof OWLObjectUnionOf) {
                        for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
                            //we reverse only named classes
                            if (child instanceof OWLClass) {
                                this.getOwlGraphWrapper().getManager().addAxiom(ont, 
                                        ont.getOWLOntologyManager().getOWLDataFactory().
                                            getOWLSubClassOfAxiom((OWLClass) child, cls));
                            }
                        }
                    }
                }
            }
        }
    }
    this.triggerWrapperUpdate();
    log.info("OWLObjectUnionOf reversion done.");
}
 
Example #21
Source File: ChEBIParser.java    From act with GNU General Public License v3.0 6 votes vote down vote up
private Set<OWLClass> get_has_role_parents(OWLClass clazz) {
  Set<OWLClass> roles = new HashSet<OWLClass>();
  for (OWLClassExpression sup: clazz.getSuperClasses(ontology)) {
    ClassExpressionType typ = sup.getClassExpressionType();
    switch (typ) {
      case OBJECT_SOME_VALUES_FROM:
        Set<OWLObjectProperty> properties = sup.getObjectPropertiesInSignature();
        Set<OWLClass> classes = sup.getClassesInSignature();
        if (singletonPropertyHasRole(properties) && classes.size() == 1) {
          OWLClass has_role_parent = classes.toArray(new OWLClass[0])[0];
          roles.add(has_role_parent);
          // err.println("\t\t Added parent: " + has_role_parent);
        }
        // else {
        //   err.println("Was expecting singleton sets for properties and classes.");
        //   err.println("Got more/less: " + properties + " " + classes);
        //   System.exit(-1);
        // }
        break;
      default:
        // err.println("\t Default (SubClassOf): " + sup);
        break;
    }
  }
  return roles;
}
 
Example #22
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct)
throws ReasonerInterruptedException, TimeOutException,
FreshEntitiesException, InconsistentOntologyException,
ClassExpressionNotInProfileException {
	if (ce.isAnonymous()) {
		OWLClass c = materializeExpression(ce);
		return getSubClasses(c, direct);
	}
	return getWrappedReasoner().getSubClasses(ce, direct);
}
 
Example #23
Source File: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public Set<OWLClassExpression> getMostGeneralSubsumees(
		Set<OWLClassExpression> classes,
		Set<OWLPropertyExpression> properties) {
	 Set<OWLClassExpression> existentialRestCandidates = getCommunSubsumees(classes, true);
	 Set<OWLPropertyExpression> roleCandidates = new HashSet<OWLPropertyExpression>();
	 Boolean isDataRole = null;
	 for (OWLClassExpression sub: existentialRestCandidates) {
		 assert sub.getClassExpressionType().equals(ClassExpressionType.DATA_SOME_VALUES_FROM)
		 || sub.getClassExpressionType().equals(ClassExpressionType.OBJECT_SOME_VALUES_FROM): sub;
		 OWLQuantifiedRestriction qSub = (OWLQuantifiedRestriction) sub;
		 OWLPropertyExpression subRole =  qSub.getProperty();
		 assert subRole!=null : "Unkown role : "+ qSub; 
		 roleCandidates.add(subRole);
		 isDataRole = subRole.isDataPropertyExpression();
	 }
	 if (roleCandidates.isEmpty()) {
		 return Collections.EMPTY_SET;
	 }
	 roleCandidates.retainAll(getCommunSubproperty(properties));
	 if (roleCandidates.isEmpty()) {
		 return Collections.EMPTY_SET;
	 }
	
	 // check maximality wrt inverse
	 Set<OWLClassExpression> ret = getMaximum(roleCandidates);
	 //
	return ret;
	

}
 
Example #24
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 #25
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLClassExpression> getSuperClasses(OWLClass subCls, Set<OWLOntology> ontologies) {
	Set<OWLClassExpression> result;
	if (subCls != null && ontologies != null && ontologies.isEmpty() == false) {
		result = new HashSet<>();
		for(OWLOntology ont : ontologies) {
			result.addAll(getSuperClasses(subCls, ont));
		}
	}
	else {
		result = Collections.emptySet();
	}
	return result;
}
 
Example #26
Source File: OldSimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Set<Node<OWLClass>> getNamedReflexiveSubsumers(OWLClassExpression a) {
	if (superclassMap != null && superclassMap.containsKey(a)) {
		return new HashSet<Node<OWLClass>>(superclassMap.get(a));
	}
	Set<Node<OWLClass>> nodes =  getReasoner().getSuperClasses(a, false).getNodes();
	nodes.add(getReasoner().getEquivalentClasses(a));
	if (superclassMap == null) {
		superclassMap = new HashMap<OWLClassExpression,Set<Node<OWLClass>>>();
	}
	superclassMap.put(a, new HashSet<Node<OWLClass>>(nodes));
	return nodes;
}
 
Example #27
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 #28
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Void visit(OWLObjectIntersectionOf desc) {
  long subject =
      getOrCreateNode(getIri(desc), OwlLabels.OWL_INTERSECTION_OF, OwlLabels.OWL_ANONYMOUS);
  for (OWLClassExpression expression : desc.getOperands()) {
    long object = getOrCreateNode(getIri(expression));
    getOrCreateRelationship(subject, object, OwlRelationships.OPERAND);
  }
  return null;
}
 
Example #29
Source File: OwlApiClassExpressionSatisfiabilityQueryTest.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Config
public static Configuration getConfig()
		throws IOException, URISyntaxException {

	return ConfigurationUtils.loadFileBasedTestConfiguration(
			ElkTestUtils.TEST_INPUT_LOCATION, BaseQueryTest.class,
			new ConfigurationUtils.ManifestCreator<TestManifestWithOutput<QueryTestInput<OWLClassExpression>, SatisfiabilityTestOutput>>() {

				@Override
				public Collection<? extends TestManifestWithOutput<QueryTestInput<OWLClassExpression>, SatisfiabilityTestOutput>> createManifests(
						final String name, final List<URL> urls)
						throws IOException {

					if (urls == null || urls.size() < 2) {
						// Not enough inputs. Probably forgot something.
						throw new IllegalArgumentException(
								"Need at least 2 URL-s!");
					}
					if (urls.get(0) == null || urls.get(1) == null) {
						// No inputs, no manifests.
						return Collections.emptySet();
					}

					InputStream outputIS = null;
					try {
						outputIS = urls.get(1).openStream();

						return OwlExpectedTestOutputLoader.load(outputIS)
								.getSatisfiabilityManifests(name,
										urls.get(0));

					} finally {
						IOUtils.closeQuietly(outputIS);
					}

				}

			}, "owl", "classquery");

}
 
Example #30
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLClassExpression> getEquivalentClasses(OWLClass cls, OWLOntology ont) {
	Set<OWLClassExpression> expressions;
	if (cls != null && ont != null) {
		Set<OWLEquivalentClassesAxiom> axioms = ont.getEquivalentClassesAxioms(cls);
		expressions = new HashSet<>(axioms.size());
		for(OWLEquivalentClassesAxiom ax : axioms) {
			expressions.addAll(ax.getClassExpressions());
		}
		expressions.remove(cls); // set should not contain the query cls
	}
	else {
		expressions = Collections.emptySet();
	}
	return expressions;
}