org.semanticweb.owlapi.model.OWLClassAssertionAxiom Java Examples
The following examples show how to use
org.semanticweb.owlapi.model.OWLClassAssertionAxiom.
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: PhenoSimHQEPreProcessor.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #2
Source File: ABoxUtils.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void randomizeClassAssertions(OWLOntology ont, int num) { Set<OWLClassAssertionAxiom> caas = new HashSet<OWLClassAssertionAxiom>(); Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>(); Set<OWLNamedIndividual> inds = ont.getIndividualsInSignature(Imports.INCLUDED); OWLNamedIndividual[] indArr = (OWLNamedIndividual[]) inds.toArray(); for (OWLNamedIndividual ind : inds) { caas.addAll( ont.getClassAssertionAxioms(ind) ); } for (OWLClassAssertionAxiom caa : caas) { OWLIndividual randomIndividual = null; caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(caa.getClassExpression(), randomIndividual)); } ont.getOWLOntologyManager().removeAxioms(ont, caas); ont.getOWLOntologyManager().addAxioms(ont, caasNew); }
Example #3
Source File: AbstractSimPreProcessor.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #4
Source File: Sim2CommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@CLIMethod("--remove-dangling-annotations") public void removeDangningAnnotations(Opts opts) throws Exception { OWLOntology ont = g.getSourceOntology(); int n = 0; Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLNamedIndividual i : ont.getIndividualsInSignature()) { for (OWLClassAssertionAxiom ca : ont.getClassAssertionAxioms(i)) { OWLClassExpression cx = ca.getClassExpression(); if (cx instanceof OWLClass) { OWLClass c = (OWLClass) cx; String label = g.getLabel(c); if (label == null) rmAxioms.add(ca); else n++; } } } LOG.info("Removing " + rmAxioms.size() + " axioms"); ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms); LOG.info("Remaining: " + n + " axioms"); }
Example #5
Source File: LegoTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public List<LegoNode> createLegoNodes(Collection<OWLNamedIndividual> individuals) throws UnExpectedStructureException { List<LegoNode> nodes = new ArrayList<LegoNode>(individuals.size()); Set<OWLOntology> ontologies = new HashSet<OWLOntology>(graph.getAllOntologies()); for (OWLNamedIndividual individual : individuals) { Set<OWLClassAssertionAxiom> axioms = getClassAxioms(individual, ontologies); final LegoNode node = createNode(individual, axioms, ontologies); if (node != null) { // links List<LegoLink> links = new ArrayList<LegoLink>(); Set<OWLObjectPropertyAssertionAxiom> propertyAxioms = getPropertyAxioms(individual, ontologies); for (OWLObjectPropertyAssertionAxiom propertyAxiom : propertyAxioms) { OWLIndividual object = propertyAxiom.getObject(); if (object instanceof OWLNamedIndividual == false) { throw new UnExpectedStructureException("Expected a named individual for a link: "+propertyAxiom); } OWLNamedIndividual namedTarget = (OWLNamedIndividual) object; OWLObjectPropertyExpression property = propertyAxiom.getProperty(); LegoLink link = new LegoLink(individual, namedTarget, property); LegoMetadata.extractMetadata(link, propertyAxiom); links.add(link); } if (!links.isEmpty()) { node.setLinks(links); } nodes.add(node); } } return nodes; }
Example #6
Source File: OwlHelper.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static Set<OWLClassExpression> getTypes(OWLNamedIndividual i, OWLOntology ont) { Set<OWLClassExpression> types; if (i != null && ont != null) { types = new HashSet<>(); for (OWLClassAssertionAxiom axiom : ont.getClassAssertionAxioms(i)) { types.add(axiom.getClassExpression()); } } else { types = Collections.emptySet(); } return types; }
Example #7
Source File: LegoTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Set<OWLClassAssertionAxiom> getClassAxioms(OWLNamedIndividual individual, Set<OWLOntology> ontologies) { Set<OWLClassAssertionAxiom> allAxioms = new HashSet<OWLClassAssertionAxiom>(); for(OWLOntology o : ontologies) { allAxioms.addAll(o.getClassAssertionAxioms(individual)); } return allAxioms; }
Example #8
Source File: ABoxUtils.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void createRandomClassAssertions(OWLOntology ont, int num, int maxAssertionsPerInstance) { Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>(); Vector<OWLClass> clist = new Vector<OWLClass>(ont.getClassesInSignature(Imports.INCLUDED)); for (int i=0; i<num; i++) { OWLNamedIndividual ind = ont.getOWLOntologyManager().getOWLDataFactory(). getOWLNamedIndividual(IRI.create("http://x.org/"+i)); for (int j=0; j< Math.random() * maxAssertionsPerInstance; j++) { OWLClass c = clist.get((int)(Math.random() * clist.size())); caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory(). getOWLClassAssertionAxiom(c, ind)); } } ont.getOWLOntologyManager().addAxioms(ont, caasNew); }
Example #9
Source File: ModelAnnotationSolrDocumentLoader.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLClass findFirstType(OWLNamedIndividual relevant) { Set<OWLClassAssertionAxiom> axioms = model.getClassAssertionAxioms(relevant); for (OWLClassAssertionAxiom axiom : axioms) { OWLClassExpression ce = axiom.getClassExpression(); if (ce.isAnonymous() == false) { return ce.asOWLClass(); } } return null; }
Example #10
Source File: InferredClassAssertionAxiomGeneratorDirectOnly.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected void addAxioms( @Nonnull OWLNamedIndividual entity, @Nonnull OWLReasoner reasoner, @Nonnull OWLDataFactory dataFactory, @Nonnull Set<OWLClassAssertionAxiom> result) { for (OWLClass type : reasoner.getTypes(entity, true).getFlattened()) { result.add(dataFactory.getOWLClassAssertionAxiom(type, entity)); } }
Example #11
Source File: LegoUnitTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Set<OWLClassAssertionAxiom> getClassAxioms(OWLNamedIndividual individual) { Set<OWLClassAssertionAxiom> allAxioms = new HashSet<OWLClassAssertionAxiom>(); for(OWLOntology o : graph.getAllOntologies()) { allAxioms.addAll(o.getClassAssertionAxioms(individual)); } return allAxioms; }
Example #12
Source File: GraphOwlVisitor.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public Void visit(OWLClassAssertionAxiom axiom) { long individual = getOrCreateNode(getIri(axiom.getIndividual())); if (axiom.getIndividual().isAnonymous()) { graph.addLabel(individual, OwlLabels.OWL_ANONYMOUS); } long type = getOrCreateNode(getIri(axiom.getClassExpression())); getOrCreateRelationship(individual, type, OwlRelationships.RDF_TYPE); return null; }
Example #13
Source File: ReasonerUtilTest.java From SciGraph with Apache License 2.0 | 5 votes |
@Test public void doesNotReason_whenOntologyIsInconsistent() throws Exception{ OWLClass c0 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLClass c1 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLDisjointClassesAxiom disjoint = dataFactory.getOWLDisjointClassesAxiom(c0, c1); OWLIndividual i1 = dataFactory.getOWLNamedIndividual(IRI.generateDocumentIRI()); OWLClassAssertionAxiom a1 = dataFactory.getOWLClassAssertionAxiom(c0, i1); OWLClassAssertionAxiom a2 = dataFactory.getOWLClassAssertionAxiom(c1, i1); manager.addAxioms(ont, newHashSet(disjoint, a1, a2)); util.flush(); assertThat(util.shouldReason(), is(false)); }
Example #14
Source File: OWLView.java From relex with Apache License 2.0 | 5 votes |
/** * Print out RelEx relations. All relations shown * in a binary form. * * Example: * _subj(throw, John) * _obj(throw, ball) * tense(throw, past) * definite-FLAG(ball, T) * noun_number(ball, singular) */ public void printRelations(ParsedSentence parse, String sentence, int sentence_id, String ontologyname) { try { sent = sentence; //Add the sentence to Sentence Class this.sentence_id = sentence_id; sentenceInd = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + "sentence_" + sentence_id)); //OWLAnnotationProperty p = new OWLAnnotationPropertyImpl(IRI.create(sentence)); //OWLAnnotation label = factory.getOWLAnnotation(sentence); OWLOntologyFormat ontologyFormat = manager.getOntologyFormat(ontology); OWLAnnotation label = (OWLAnnotation) factory.getOWLAnnotationProperty(sentence, (PrefixManager) ontologyFormat); OWLClassAssertionAxiom sentClass = factory.getOWLClassAssertionAxiom(this.sentence,sentenceInd); OWLAnnotationAssertionAxiom labelClass = factory.getOWLAnnotationAssertionAxiom((OWLAnnotationSubject) sentClass, label); manager.applyChange(new AddAxiom(ontology, sentClass)); manager.applyChange(new AddAxiom(ontology, labelClass)); printRelations(parse, null); } catch (OWLOntologyChangeException ex) { Logger.getLogger(OWLView.class.getName()).log(Level.SEVERE, null, ex); } }
Example #15
Source File: AbstractOwlAxiomConverterVisitor.java From elk-reasoner with Apache License 2.0 | 5 votes |
@Override public T visit(OWLClassAssertionAxiom axiom) { throw new IllegalArgumentException( OWLClassAssertionAxiom.class.getSimpleName() + " cannot be converted to " + getTargetClass().getSimpleName()); }
Example #16
Source File: ABoxUtils.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void mapClassAssertionsUp(OWLOntology ont, OWLReasoner reasoner, Set<OWLClass> targetClasses, Set<OWLClass> inputClasses) { Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>(); Map<OWLClass, Set<OWLClass>> cmap = new HashMap<OWLClass, Set<OWLClass>>(); LOG.info("Target classes: "+targetClasses.size()); int n=0; for (OWLClassAssertionAxiom ca : ont.getAxioms(AxiomType.CLASS_ASSERTION)) { if (ca.getClassExpression().isAnonymous()) continue; OWLClass c = (OWLClass) ca.getClassExpression(); n++; if (inputClasses == null || inputClasses.contains(c)) { if (targetClasses.contains(c)) continue; Set<OWLClass> supers; if (cmap.containsKey(c)) { supers = cmap.get(c); } else { supers = reasoner.getSuperClasses(c, false).getFlattened(); supers.addAll(reasoner.getEquivalentClasses(c).getEntities()); LOG.info(c+" has #supers: "+supers.size()); LOG.info(c + " ===> "+supers); supers.retainAll(targetClasses); LOG.info(c+" has #supersInTargetSet: "+supers.size()); supers = getNonRedundant(supers, reasoner); //LOG.info(c+" has #NRsupers: "+supers.size()); //LOG.info(c + " ===> "+supers); cmap.put(c, supers); if (supers.size() > 0) { LOG.info(c + " ===> "+supers); } } rmAxioms.add(ca); OWLIndividual individual = ca.getIndividual(); for (OWLClass sc : supers) { newAxioms.add(ont.getOWLOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(sc, individual)); } } } LOG.info("named class assertions (start): "+n); LOG.info("rm:"+rmAxioms.size()); LOG.info("new:"+newAxioms.size()); ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms); ont.getOWLOntologyManager().addAxioms(ont, newAxioms); }
Example #17
Source File: PropertyViewOntologyBuilderTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * In this test we filter view classes based on the individuals in the ontology * * @throws IOException * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException */ @Test public void testPhenoViewWithIndividuals() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { ParserWrapper pw = new ParserWrapper(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLDataFactory df = manager.getOWLDataFactory(); OWLOntology sourceOntol = pw.parseOWL(getResourceIRIString("q-in-e.omn")); OWLObjectProperty viewProperty = df.getOWLObjectProperty(IRI.create("http://x.org#has_phenotype_inheres_in")); PropertyViewOntologyBuilder pvob = new PropertyViewOntologyBuilder(sourceOntol, sourceOntol, viewProperty); pvob.setClassifyIndividuals(true); pvob.setFilterUnused(true); pvob.setViewLabelPrefix("involves "); pvob.setViewLabelSuffix(""); pvob.setAssumeOBOStyleIRIs(false); //pvob.setUseOriginalClassIRIs(true); pvob.buildViewOntology(IRI.create("http://x.org"), IRI.create("http://y.org")); OWLOntology avo = pvob.getAssertedViewOntology(); if (RENDER_ONTOLOGY_FLAG) { for (OWLAxiom a : avo.getAxioms()) { LOG.info("ASSERTED_VIEW_ONT: " + a); } } OWLReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner reasoner = rf.createReasoner(avo); try { OWLGraphWrapper g = new OWLGraphWrapper(pvob.getInferredViewOntology()); OWLPrettyPrinter pp = new OWLPrettyPrinter(g); g.addSupportOntology(pvob.getAssertedViewOntology()); LOG.info("Building inferred view"); pvob.buildInferredViewOntology(reasoner); boolean ok1 = false; int numClassAssertions = 0; // iterate through all view entities - this should be the filtered set of view classes plus individuals. for (OWLEntity e : pvob.getViewEntities()) { if (RENDER_ONTOLOGY_FLAG) { LOG.info(" VE: " + e + " LABEL:" + g.getLabel(e)); } if (e instanceof OWLClass) { if (g.getLabel(e) != null && g.getLabel(e).equals("involves limb")) { ok1 = true; } } else { if (e instanceof OWLNamedIndividual) { Set<OWLClassAssertionAxiom> caas = pvob.getInferredViewOntology().getClassAssertionAxioms((OWLNamedIndividual) e); for (OWLClassAssertionAxiom caa : caas) { if (RENDER_ONTOLOGY_FLAG) { LOG.info(" CAA:" + pp.render(caa)); } numClassAssertions++; } } } } assertTrue(ok1); LOG.info("class assertions:"+numClassAssertions); //assertEquals(12, numClassAssertions); // TODO - CHECK LOG.info(pvob.getViewEntities().size()); //assertEquals(23, pvob.getViewEntities().size()); } finally { reasoner.dispose(); } }
Example #18
Source File: OWLView.java From relex with Apache License 2.0 | 4 votes |
public Boolean BinaryRelationCB(String relName, FeatureNode srcNode, FeatureNode tgtNode) { String srcName = srcNode.get("name").getValue(); FeatureNode tgt = tgtNode.get("name"); if (tgt == null) { System.out.println("Error: No target! rel=" + relName + " and src=" + srcName); return false; } String tgtName = tgt.getValue(); if (id_map != null) { srcName = id_map.get(srcNode); tgtName = id_map.get(tgtNode); } //Optimize using StringBuilder //Get the Individual type (noun, etc.) and the type_property System.out.println("\n\tRELATION (binary) = " + relName + "(" + srcName + ", " + tgtName + ")\n"); //Cleaning if (relName.charAt(0)=='_') relName = relName.replaceFirst("_", ""); if (relName.length()>1) if (relName.charAt(1)=='%') relName = relName.replaceFirst("%", ""); if (tgtName.contains("[") || tgtName.contains("]") || srcName.contains("[") || srcName.contains("]") || tgtName.equals("WORD") || srcName.equals("WORD") || tgtName.contains("misc-") || srcName.contains("misc-")) return false; if (srcName.length()>0 && tgtName.length()>0) { //1º Add the first term to Word Class srcName=srcName.replaceAll("[\\%\\s]", ""); //System.out.println("srcName = " + srcName); OWLIndividual src_word = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + srcName)); OWLClassAssertionAxiom addSrcWord = factory.getOWLClassAssertionAxiom(word,src_word); manager.applyChange(new AddAxiom(ontology, addSrcWord)); //2º Create the property relName = relName.replaceAll("[\\%\\ss]", ""); OWLObjectProperty rel = factory.getOWLObjectProperty(IRI.create(ontologyURI + "#" + relName)); //3º Add the second term to Word Class tgtName = tgtName.replaceAll("[\\%\\s]", ""); OWLIndividual dst_word = factory.getOWLNamedIndividual(IRI.create(ontologyURI + "#" + tgtName)); OWLClassAssertionAxiom addDstWord = factory.getOWLClassAssertionAxiom(word,dst_word ); manager.applyChange(new AddAxiom(ontology, addDstWord)); //4º Create axiom for the relation OWLObjectPropertyAssertionAxiom addrel = factory.getOWLObjectPropertyAssertionAxiom(rel,src_word, dst_word); manager.applyChange(new AddAxiom(ontology, addrel)); //5º Add the words (Class) to the sentence (Class) OWLObjectPropertyAssertionAxiom addw1 = factory.getOWLObjectPropertyAssertionAxiom(has,sentenceInd, src_word); //OWLObjectPropertyAssertionAxiom addw2 = factory.getOWLObjectPropertyAssertionAxiom(sentenceInd, has, //dst_word); manager.applyChange(new AddAxiom(ontology, addw1)); //manager.applyChange(new AddAxiom(ontology, addw2)); } return false; }
Example #19
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void visit(OWLClassAssertionAxiom axiom) { }
Example #20
Source File: AxiomAnnotationTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public OWLAxiom visit(OWLClassAssertionAxiom axiom) { return factory.getOWLClassAssertionAxiom(axiom.getClassExpression(), axiom.getIndividual(), annotations); }
Example #21
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
private boolean isDeclaredIndividual(OWLIndividual individual) { return owlOntology.axioms(OWLClassAssertionAxiom.class, OWLIndividual.class, individual, Imports.INCLUDED, Navigation.IN_SUB_POSITION).count() > 0; }
Example #22
Source File: FailingOwlAxiomVisitor.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Override public void visit(OWLClassAssertionAxiom axiom) { defaultVisit(axiom); }
Example #23
Source File: OwlIndividualAxiomConverterVisitor.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Override public ElkAssertionAxiom visit(OWLClassAssertionAxiom axiom) { return CONVERTER.convert(axiom); }
Example #24
Source File: OwlAxiomConverterVisitor.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Override public ElkAxiom visit(OWLClassAssertionAxiom axiom) { return CONVERTER.convert(axiom); }
Example #25
Source File: OwlConverter.java From elk-reasoner with Apache License 2.0 | 4 votes |
@SuppressWarnings("static-method") public ElkClassAssertionAxiom convert( OWLClassAssertionAxiom owlClassAssertionAxiom) { return new ElkClassAssertionAxiomWrap<OWLClassAssertionAxiom>( owlClassAssertionAxiom); }
Example #26
Source File: AbstractElkObjectConverter.java From elk-reasoner with Apache License 2.0 | 4 votes |
@Override public OWLClassAssertionAxiom visit(ElkClassAssertionAxiom axiom) { return owlFactory_.getOWLClassAssertionAxiom( convert(axiom.getClassExpression()), convert(axiom.getIndividual())); }