Java Code Examples for org.semanticweb.owlapi.model.OWLClass#compareTo()
The following examples show how to use
org.semanticweb.owlapi.model.OWLClass#compareTo() .
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: OldSimpleOwlSim.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void makeAllByAllLowestCommonSubsumer() { LOG.info("all x all..."); Set<OWLClass> atts = getAllAttributeClasses(); for (OWLClass a : atts) { LOG.info(" "+a+" vs ALL"); for (OWLClass b : atts) { // LCS operation is symmetric, only pre-compute one way if (a.compareTo(b) > 0) { OWLClass lcs = this.getLowestCommonSubsumerClass(a, b); //System.out.println("LCS( "+pp(a)+" , "+pp(b)+" ) = "+pp(lcs)); } } } LOG.info("DONE all x all"); reason(); }
Example 2
Source File: LCSEnabledSimPreProcessor.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * generates new LCS grouping classes * * @param leafClasses */ public void generateLeastCommonSubsumers(Set<OWLClass> leafClasses) { LOG.info("Generating LCSs en masse; leaf classes "+leafClasses.size()); LOG.info("Num materialized class expressions (prior) "+materializedClassExpressionMap.size()); for (OWLClass a : leafClasses) { LOG.info(" ALL vs: "+a+" '"+getAnyLabel(a)+"'"); for (OWLClass b : leafClasses) { // LCS operation is symmetric, only pre-compute one way if (a.compareTo(b) > 0) { OWLClass lcs = getLowestCommonSubsumerClass(a, b, leafClasses); } } } LOG.info("DONE all x all"); LOG.info("Num materialized class expressions (post) "+materializedClassExpressionMap.size()); }
Example 3
Source File: Sim2CommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@CLIMethod("--sim-save-lcs-cache") public void simSaveLCSCache(Opts opts) throws Exception { opts.info("[-m ICTHRESHOLD] OUTFILE", "saves a LCS cache to a file. This should be called AFTER --sim-compare-atts"); Double thresh = null; OWLClass debugClass = null; while (opts.hasOpts()) { if (opts.nextEq("-m|--min-ic")) { opts.info("ICTHRESHOLD", "If the IC of the LCS is less than this value, an entry is not written.\n" + "After subsequent loading of the cache, pairs with no entry are equivalent to pairs with a LCS with IC=0"); thresh = Double.valueOf(opts.nextOpt()); } else if (opts.nextEq("--debug-class")) { debugClass = this.resolveClass(opts.nextOpt()); } else { break; } } // No Sim object, so all by all has not yet been calculated if (owlsim == null) { owlsim = getOwlSimFactory().createOwlSim(g.getSourceOntology()); if (debugClass != null) { ((FastOwlSim)owlsim).debugClass = debugClass; } owlsim.createElementAttributeMapFromOntology(); // we have just created a sim object, so the cache is not populated; // therefore we can be more efficient by avoiding lookups owlsim.setNoLookupForLCSCache(true); Set<OWLClass> atts = owlsim.getAllAttributeClasses(); LOG.info("Number of attribute classes: "+atts.size()); for (OWLClass i : atts) { //LOG.info("Comparing "+i+" to all attributes"); for (OWLClass j : atts) { // metric is symmetrical if (i.compareTo(j) < 0) continue; owlsim.getLowestCommonSubsumerWithIC(i, j, thresh); } } } owlsim.saveLCSCache(opts.nextOpt(), thresh); LOG.info("Saved cache"); }
Example 4
Source File: OldSimpleOwlSim.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * gets the LCS. If multiple named LCSs exist in the ontology, then * a class expression is generated from the filtered intersection * * @param a * @param b * @return OWLClassExpression */ public OWLClassExpression getLowestCommonSubsumer(OWLClassExpression a, OWLClassExpression b) { if (a.equals(b)) { return a; } if (a instanceof OWLClass && b instanceof OWLClass) { if (getReasoner().getSuperClasses(a, false).getFlattened().contains(b)) { return b; } if (getReasoner().getSuperClasses(b, false).getFlattened().contains(a)) { return a; } } // returns the set of named LCSs that already exist Set<Node<OWLClass>> ccs = getNamedLowestCommonSubsumers(a,b); // single LCS - return this directly if (ccs.size() == 1) { return ccs.iterator().next().getRepresentativeElement(); } // make a class expression from the filtered intersection of LCSs Set<OWLClass> ops = new HashSet<OWLClass>(); Set<OWLClass> skips = new HashSet<OWLClass>(); OWLClass best = null; double bestIC = 0.0; for (Node<OWLClass> n : ccs) { OWLClass c = n.getRepresentativeElement(); // allows custom filtering; e.g. upper-level classes // note: should be removed at view stage if (this.getVerbotenClasses().contains(c)) continue; // TODO: custom filtering boolean skip = false; Double ic = getInformationContentForAttribute(c); if (ic == null) { // if the attributes classes have not been filtered, then null values // (ie classes with no instances) are possible continue; } if (ic > bestIC) { bestIC = ic; best = c; } if (ic < 2.5) { // TODO: configure //LOG.info("SKIPPING: "+c+" IC="+ic); continue; } if (this.getNamedReflexiveSubsumers(c).size() < 2) { LOG.info("SKIPPING: "+c+" no parents"); // non-grouping attribute continue; } // don't make intersections of similar elements for (Node<OWLClass> n2 : ccs) { OWLClass c2 = n2.getRepresentativeElement(); double ic2 = getInformationContentForAttribute(c2); // prioritize the one with highest IC if (ic < ic2 || (ic==ic2 && c.compareTo(c2) > 0)) { // TODO: configure simj thresh if (this.getAttributeJaccardSimilarity(c, c2) > 0.75) { LOG.info("SKIPPING: "+c+" too similar to "+n2); skip = true; } } } if (skip) continue; // not filtered ops.add(c); } if (ops.size() == 1) { return ops.iterator().next(); } if (ops.size() == 0) { // none pass: choose the best representative of the intersection return best; } return owlDataFactory.getOWLObjectIntersectionOf(ops); }
Example 5
Source File: OwlSimUtil.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void compareLCSWithEnrichmentGrouping(OWLOntology ont, Double pthresh, OWLPrettyPrinter owlpp) throws UnknownOWLClassException, MathException { OwlSimFactory osf = new FastOwlSimFactory(); OwlSim sim = osf.createOwlSim(ont); sim.createElementAttributeMapFromOntology(); OWLClass populationClass = null; if (pthresh == null) pthresh = 0.01; int nHypotheses = ((sim.getAllAttributeClasses().size()-1) * sim.getAllAttributeClasses().size())/2; for (OWLClass c : sim.getAllAttributeClasses()) { for (OWLClass d : sim.getAllAttributeClasses()) { if (c.compareTo(d) > 0) { ScoreAttributeSetPair lcsic = sim.getLowestCommonSubsumerWithIC(c, d); //System.out.println("TEST: "+c+" "+d); EnrichmentResult enr = sim.calculatePairwiseEnrichment(populationClass, c, d); if (enr == null) { //System.err.println("NULL: "+c+" "+d); continue; } double pvc = enr.pValue * nHypotheses; if (pvc < pthresh) { // TODO - place this in OwlSim Set<OWLNamedIndividual> inds = new HashSet<OWLNamedIndividual>(sim.getElementsForAttribute(c)); inds.addAll(sim.getElementsForAttribute(d)); double pu = inds.size() / (double)sim.getCorpusSize(); double ic = - Math.log(pu) / Math.log(2); double foldChange = ic / lcsic.score; if (foldChange < 1.5) continue; if (lcsic.attributeClassSet.size() == 0) { System.err.println("# no LCS for "+c+" "+d); continue; } System.out.println(owlpp.render(c)+"\t"+owlpp.render(d)+"\t"+pvc+"\t"+owlpp.render(lcsic.getArbitraryAttributeClass())+"\t"+lcsic.score+"\t"+ic+"\t"+foldChange); } } } } }