本文整理匯總了Java中org.semanticweb.owlapi.model.OWLOntology.getClassesInSignature方法的典型用法代碼示例。如果您正苦於以下問題:Java OWLOntology.getClassesInSignature方法的具體用法?Java OWLOntology.getClassesInSignature怎麽用?Java OWLOntology.getClassesInSignature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.semanticweb.owlapi.model.OWLOntology
的用法示例。
在下文中一共展示了OWLOntology.getClassesInSignature方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildSimpleDefMap
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private void buildSimpleDefMap() {
simpleDefMap = new HashMap<OWLClass,Set<OWLClassExpression>>();
OWLOntology o = getGraph().getSourceOntology();
for (OWLClass c : o.getClassesInSignature()) {
for (OWLEquivalentClassesAxiom eca : o.getEquivalentClassesAxioms(c)) {
Set<OWLClassExpression> elts = new HashSet<OWLClassExpression>();
for (OWLClassExpression x : eca.getClassExpressions()) {
// assume one logical definitionper class - otherwise choose arbitrary
if (x instanceof OWLObjectIntersectionOf) {
if (getReachableOWLClasses(x, elts) && elts.size() > 0) {
//LOG.info(c+" def= "+elts);
simpleDefMap.put(c, elts);
}
}
}
}
}
}
示例2: buildClassMap
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
public void buildClassMap(OWLGraphWrapper g) {
IRI x = Obo2OWLVocabulary.IRI_OIO_hasDbXref.getIRI();
for (OWLOntology ont : g.getAllOntologies()) {
for (OWLClass c : ont.getClassesInSignature()) {
for (OWLAnnotationAssertionAxiom aa : ont.getAnnotationAssertionAxioms(c.getIRI())) {
if (aa.getProperty().getIRI().equals(x)) {
OWLAnnotationValue v = aa.getValue();
if (v instanceof OWLLiteral) {
String xid =((OWLLiteral)v).getLiteral();
OWLClass xc = (OWLClass) g.getOWLObjectByIdentifier(xid);
if (xc == null) {
LOG.error("Cannot get class for: "+xid);
}
else {
config.classMap.put(xc, c);
}
//LOG.info(c + " ===> "+xid);
}
}
}
}
}
}
示例3: removeSubsetComplementClasses
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Remove all classes *not* in subset.
*
* This means:
* * remove all annotation assertions for that class
* * remove all logical axioms about that class
*
* If removeDangling is true, also remove all axioms that reference this class
*
* @param subset
* @param removeDangling
*/
public void removeSubsetComplementClasses(Set<OWLClass> subset, boolean removeDangling) {
OWLOntology o = getOntology();
Set<OWLClass> rmSet = o.getClassesInSignature();
rmSet.removeAll(subset); // remove all classes not in subset
Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
LOG.info("Num of classes to be removed = "+rmSet.size());
for (OWLClass c : rmSet) {
rmAxioms.addAll(o.getAnnotationAssertionAxioms(c.getIRI()));
rmAxioms.addAll(o.getAxioms(c, Imports.EXCLUDED));
}
graph.getManager().removeAxioms(o, rmAxioms);
if (removeDangling) {
removeDanglingAxioms(o);
}
}
示例4: removeRedundantSubClassAxioms
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Remove the redundant and marked as inferred super class assertions for
* each class in the ontology signature. Uses the reasoner to infer the
* direct super classes.
*
* @param ontology
* @param reasoner
* @return map of class to set of redundant axioms
*/
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
Iterable<OWLClass> classes = ontology.getClassesInSignature();
Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
if (!axioms.isEmpty()) {
Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
for(OWLClass cls : axioms.keySet()) {
for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
allAxioms.add(redundantAxiom.getAxiom());
}
}
OWLOntologyManager manager = ontology.getOWLOntologyManager();
manager.removeAxioms(ontology, allAxioms);
LOG.info("Removed "+axioms.size()+" redundant axioms.");
}
return axioms;
}
示例5: reverseOWLObjectUnionOfs
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* 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.");
}
示例6: removeObsoleteClassRels
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Remove all relations incoming to or outgoing from obsolete classes. This is
* because we need to keep obsolete classes in the ontology for valuable replaced_by
* annotations, yet we do not want their relations to interfere with relation reduction,
* etc (obsolete classes should have no relations, but it often happen
* that they have some).
*
* @see #performDefaultModifications()
*/
private void removeObsoleteClassRels() {
log.info("Removing all relations incoming to or outgoing from obsolete classes...");
for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
for (OWLClass cls: ont.getClassesInSignature()) {
if (this.getOwlGraphWrapper().isObsolete(cls) ||
this.getOwlGraphWrapper().getIsObsolete(cls)) {
Set<OWLGraphEdge> edges = this.getOwlGraphWrapper().getOutgoingEdges(cls);
edges.addAll(this.getOwlGraphWrapper().getIncomingEdges(cls));
this.removeEdges(edges);
}
}
}
log.info("Done removing relations of obsolete classes.");
}
示例7: filterClasses
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Filter from the ontologies all {@code OWLClass}es
* present in {@code classesToKeep},
* and then update the {@code OWLGraphWrapper} container.
*
* @param classesToKeep a {@code Set} of {@code OWLClass}s
* that are classes to be kept in the ontology.
* @return A {@code Set} of {@code OWLClass}es representing the classes
* actually removed as a result.
*/
public Set<OWLClass> filterClasses(Set<OWLClass> classesToKeep) {
//now remove all classes not included in classesToKeep
Set<OWLClass> classesRemoved = new HashSet<OWLClass>();
for (OWLOntology o : this.getOwlGraphWrapper().getAllOntologies()) {
for (OWLClass iterateClass: o.getClassesInSignature()) {
log.info(iterateClass);
//don't delete OBO alt IDs nor owl:Nothing and owl:Thing
if (this.getOwlGraphWrapper().isOboAltId(iterateClass) ||
iterateClass.isTopEntity() || iterateClass.isBottomEntity()) {
continue;
}
if (!classesToKeep.contains(iterateClass) &&
this.removeClass(iterateClass)) {
classesRemoved.add(iterateClass);
}
}
}
return classesRemoved;
}
示例8: isBridgingOntology
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private boolean isBridgingOntology(OWLOntology ont) {
for (OWLClass c : ont.getClassesInSignature(Imports.INCLUDED)) {
if (ont.getDeclarationAxioms(c).size() > 0) {
if (mooncat.getOntology().getDeclarationAxioms(c).size() >0) {
// class already declared in main ontology - a 2ary ontology MUST
// declare at least one of its own classes if it is a bone-fide non-bridging ontology
}
else if (mooncat.isDangling(ont, c)) {
// a dangling class has no OWL annotations.
// E.g. bp_xp_cl contains CL classes as dangling
}
else {
logInfo(c+" has declaration axioms, is not in main, and is not dangling, therefore "+ont+" is NOT a bridging ontology");
return false;
}
}
}
logInfo(ont+" is a bridging ontology");
return true;
}
示例9: getURIFromClasses
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private String getURIFromClasses(OWLOntology ontology){
for (OWLClass cls : ontology.getClassesInSignature()){
return Utilities.getNameSpaceFromURI(cls.getIRI().toString());
}
//Just in case we return default IRI
return "http://logmap.cs.ox.ac.uk/ontology.owl";
}
示例10: main
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* @param args
* @throws OWLOntologyCreationException
*/
public static void main(String[] args) throws OWLOntologyCreationException {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
// Load your ontology.
OWLOntology ont = man
.loadOntologyFromOntologyDocument(new File(args[0]));
// Create an ELK reasoner.
OWLReasonerFactory reasonerFactory = new ElkReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
// Precompute instances for each named class in the ontology
reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);
// List representative instances for each class.
for (OWLClass clazz : ont.getClassesInSignature()) {
for (Node<OWLNamedIndividual> individual : reasoner.getInstances(
clazz, true)) {
System.out.println(clazz + "("
+ individual.getRepresentativeElement() + ")");
}
}
// Terminate the worker threads used by the reasoner.
reasoner.dispose();
}
示例11: removeUnreachableAxioms
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
private Set<OWLClass> removeUnreachableAxioms(OWLOntology src,
Set<OWLClass> seedClasses) {
Stack<OWLClass> stack = new Stack<OWLClass>();
stack.addAll(seedClasses);
Set<OWLClass> visited = new HashSet<OWLClass>();
visited.addAll(stack);
while (!stack.isEmpty()) {
OWLClass elt = stack.pop();
Set<OWLClass> parents = new HashSet<OWLClass>();
Set<OWLClassExpression> xparents = OwlHelper.getSuperClasses(elt, src);
xparents.addAll(OwlHelper.getEquivalentClasses(elt, src));
for (OWLClassExpression x : xparents) {
parents.addAll(x.getClassesInSignature());
}
//parents.addAll(getReasoner().getSuperClasses(elt, true).getFlattened());
//parents.addAll(getReasoner().getEquivalentClasses(elt).getEntities());
parents.removeAll(visited);
stack.addAll(parents);
visited.addAll(parents);
}
LOG.info("# in closure set to keep: "+visited.size());
Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
for (OWLClass c : src.getClassesInSignature()) {
if (!visited.contains(c)) {
//LOG.info("removing axioms for EL-unreachable class: "+c);
rmAxioms.addAll(src.getAxioms(c, Imports.EXCLUDED));
rmAxioms.add(src.getOWLOntologyManager().getOWLDataFactory().getOWLDeclarationAxiom(c));
}
}
src.getOWLOntologyManager().removeAxioms(src, rmAxioms);
LOG.info("Removed "+rmAxioms.size()+" axioms. Remaining: "+src.getAxiomCount());
return visited;
}
示例12: check
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
@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;
}
示例13: getAllRealOWLClasses
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
/**
* Get all <code>OWLClass</code>es from all ontologies,
* that are neither top entity (owl:thing), nor bottom entity (owl:nothing),
* nor deprecated ({@link OWLGraphWrapperExtended#isObsolete(OWLObject)}
* returns {@code false}), nor an OBO alt ID.
*
* @return a <code>Set</code> containing all "real" <code>OWLClass</code>es
* from all ontologies.
*/
public Set<OWLClass> getAllRealOWLClasses() {
//maybe classes can be shared between ontologies?
//use a Set to check
Set<OWLClass> allClasses = new HashSet<OWLClass>();
for (OWLOntology ont : this.getAllOntologies()) {
for (OWLClass cls: ont.getClassesInSignature()) {
if (this.isRealClass(cls)) {
allClasses.add(cls);
}
}
}
return allClasses;
}
示例14: getExpressions
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
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();
}
}
示例15: testConvertXPs
import org.semanticweb.owlapi.model.OWLOntology; //導入方法依賴的package包/類
@Test
public void testConvertXPs() throws Exception {
ParserWrapper pw = new ParserWrapper();
OWLGraphWrapper g =
pw.parseToOWLGraph(getResourceIRIString("lcstest1.owl"));
OWLOntology ont = g.getSourceOntology();
OWLObject o2 = g.getOWLObject("http://example.org#o2");
System.out.println("getting ancestors for: "+o2);
for (OWLGraphEdge e : g.getOutgoingEdgesClosure(o2)) {
System.out.println(e);
}
for (OWLClass c : ont.getClassesInSignature()) {
System.out.println("getting individuals for "+c+" "+g.getLabel(c));
for (OWLIndividual i : g.getInstancesFromClosure(c)) {
System.out.println(" "+i);
}
}
/*
for (OWLClass c : ont.getClassesInSignature()) {
System.out.println("c="+c+" "+g.getLabel(c));
for (OWLGraphEdge e : g.getOutgoingEdgesClosure(c)) {
System.out.println("CLOSURE: "+e);
}
}
*/
/*
OWLObject s = g.getOWLObjectByIdentifier("CARO:0000014");
OWLObject t = g.getOWLObjectByIdentifier("CARO:0000000");
assertTrue(g.getEdgesBetween(s, t).size() > 0);
*/
}