public static <T extends OWLAxiom> String prettyPrint(EvaluatedAxiom<T> axiom) { double acc = axiom.getScore().getAccuracy() * 100; String accs = dfPercent.format(acc); if(accs.length()==3) { accs = " " + accs; } if(accs.length()==4) { accs = " " + accs; } String str = accs + "%\t" + axiom.getAxiom(); // String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, PrefixCCMap.getInstance()); //TODO fix rendering return str; }
@Override protected void run() { boolean declared = !existingAxioms.isEmpty(); int frequency = getPositiveExamplesFrequency(); currentlyBestAxioms.add(new EvaluatedAxiom<>( getAxiom(entityToDescribe), computeScore(popularity, frequency, useSampling), declared)); }
EvaluatedAxiom<T> bestAxiom = currentlyBestAxioms.last(); String s = "Best axiom candidate is " + bestAxiom.hypothesis + " with an accuracy of " + format.format(bestAxiom.getAccuracy()); if(returnOnlyNewAxioms) { if(existingAxioms.contains(bestAxiom.hypothesis)) { if(bestNewAxiom.isPresent()) { s += " The best new one is " + bestNewAxiom.get().hypothesis + " with an accuracy of " + format.format(bestNewAxiom.get().getAccuracy());
@Override public Set<OWLDataPropertyAssertionAxiom> getPositiveExamples(EvaluatedAxiom<OWLDataPropertyRangeAxiom> evAxiom) { OWLDataPropertyRangeAxiom axiom = evAxiom.getAxiom(); posExamplesQueryTemplate.setIri("dt", axiom.getRange().toString()); return super.getPositiveExamples(evAxiom); }
public static <T extends OWLAxiom> List<EvaluatedAxiom<T>> getBestEvaluatedAxioms(Set<EvaluatedAxiom<T>> evaluatedAxioms, int nrOfAxioms, double accuracyThreshold) { List<EvaluatedAxiom<T>> returnList = new ArrayList<>(); //get the currently best evaluated axioms Set<EvaluatedAxiom<T>> orderedEvaluatedAxioms = new TreeSet<>(evaluatedAxioms); for(EvaluatedAxiom<T> evAx : orderedEvaluatedAxioms){ if(evAx.getScore().getAccuracy() >= accuracyThreshold && returnList.size() < nrOfAxioms){ returnList.add(evAx); } } return returnList; }
public static <T extends OWLAxiom> List<EvaluatedAxiom<T>> getBestEvaluatedAxioms(Set<EvaluatedAxiom<T>> evaluatedAxioms, double accuracyThreshold) { return getBestEvaluatedAxioms(evaluatedAxioms, Integer.MAX_VALUE, accuracyThreshold); }
public T getAxiom() { return getDescription(); }
public static <T extends OWLAxiom> String prettyPrint(List<EvaluatedAxiom<T>> learnedAxioms) { String str = "suggested axioms and their score in percent:\n"; if(learnedAxioms.isEmpty()) { return " no axiom suggested\n"; } else { for (EvaluatedAxiom<T> learnedAxiom : learnedAxioms) { str += " " + prettyPrint(learnedAxiom) + "\n"; } } return str; }
Map<OWLIndividual, List<OWLAxiom>> map = evAx.toRDF(defaultNamespace); ind2Axioms = map.entrySet().iterator().next(); ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasSuggestion, ind, ind2Axioms.getKey());
@Override public Set<OWLDataPropertyAssertionAxiom> getNegativeExamples(EvaluatedAxiom<OWLDataPropertyRangeAxiom> evAxiom) { OWLDataPropertyRangeAxiom axiom = evAxiom.getAxiom(); negExamplesQueryTemplate.setIri("dt", axiom.getRange().toString()); return super.getNegativeExamples(evAxiom); }
public List<EvaluatedAxiom<OWLAxiom>> getCurrentlyBestEvaluatedAxioms(AxiomType<? extends OWLAxiom> axiomType, double accuracyThreshold) { List<EvaluatedAxiom<OWLAxiom>> result = results.get(axiomType); // throw exception if computation failed if(result == null) { return Collections.emptyList(); // throw new NoResult } // get all axioms above threshold List<EvaluatedAxiom<OWLAxiom>> bestAxioms = new ArrayList<>(); for (EvaluatedAxiom<OWLAxiom> axiom : result) { if(axiom.getScore().getAccuracy() >= accuracyThreshold){ bestAxioms.add(axiom); } } return bestAxioms; }
public static <T extends OWLAxiom> List<EvaluatedAxiom<T>> getBestEvaluatedAxioms(Set<EvaluatedAxiom<T>> evaluatedAxioms, int nrOfAxioms) { return getBestEvaluatedAxioms(evaluatedAxioms, nrOfAxioms, 0.0); }
private String prettyPrint(EvaluatedAxiom<OWLAxiom> axiom) { double acc = axiom.getScore().getAccuracy() * 100; String accs = df.format(acc); if(accs.length()==3) { accs = " " + accs; } if(accs.length()==4) { accs = " " + accs; } String str = accs + "%\t" + OWLAPIRenderers.toManchesterOWLSyntax(axiom.getAxiom()); return str; }
@Override protected void run() { boolean declared = !existingAxioms.isEmpty(); int frequency = getCountValue(POS_FREQUENCY_QUERY.toString()); currentlyBestAxioms.add(new EvaluatedAxiom<>( df.getOWLFunctionalDataPropertyAxiom(entityToDescribe), computeScore(popularity, frequency, useSampling), declared)); } }
learnedEvaluatedAxioms.addAll(learnedAxioms); for(EvaluatedAxiom<OWLAxiom> evAx : learnedAxioms){ learnedOWLAxioms.add(evAx.getAxiom());
@Test public void testSubPropertyOfAxiomLearning() throws Exception { SubObjectPropertyOfAxiomLearner l = new SubObjectPropertyOfAxiomLearner(ks); l.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); l.setEntityToDescribe(op1); l.init(); l.start(); EvaluatedAxiom<OWLSubObjectPropertyOfAxiom> evAxiom = l.getCurrentlyBestEvaluatedAxiom(); System.out.println(evAxiom); double actualScore = evAxiom.getScore().getAccuracy(); int cntOp1 = 130; int cntOp2 = 70; int cntOp1_Op2 = 60; double beta = 3.0; double precision = Heuristics.getConfidenceInterval95WaldAverage(cntOp2, cntOp1_Op2); double recall = Heuristics.getConfidenceInterval95WaldAverage(cntOp1, cntOp1_Op2); double expectedScore = Heuristics.getFScore(recall, precision, beta); // update Feb 2015: seems to be incorrect to require those values to be the same as one is exact and the other an approximation // assertEquals("", expectedScore, actualScore, 0d); }
@Override public JSONObject call() throws Exception { JSONObject result = new JSONObject(); JSONArray axiomArray = new JSONArray(); List<EvaluatedAxiom> axioms = getEvaluatedAxioms(ks, reasoner, entity, axiomType, maxExecutionTimeInSeconds, threshold, maxNrOfReturnedAxioms, useInference); for(EvaluatedAxiom ax : axioms){ JSONObject axiomObject = new JSONObject(); OWLAxiom axiom = ax.getAxiom(); axiomObject.put("axiom", axiom); axiomObject.put("axiom_rendered", renderer.render(axiom)); axiomObject.put("axiom_sparul", getSPARUL(axiom)); axiomObject.put("confidence", ax.getScore().getAccuracy()); axiomArray.put(axiomObject); } result.put("axiom_type", axiomType); result.put("axioms", axiomArray); return result; }
@Override public List<EvaluatedAxiom<OWLSubClassOfAxiom>> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { currentlyBestAxioms = new TreeSet<>(); for (EvaluatedDescription<? extends Score> ed : getCurrentlyBestEvaluatedDescriptions(nrOfAxioms)) { currentlyBestAxioms.add(new EvaluatedAxiom<>(df.getOWLSubClassOfAxiom(entityToDescribe, ed.getDescription()), new AxiomScore(ed.getAccuracy()))); } return new ArrayList<>(currentlyBestAxioms); }
@Override public Set<OWLObjectPropertyAssertionAxiom> getPositiveExamples(EvaluatedAxiom<T> evAxiom) { T axiom = evAxiom.getAxiom(); posExamplesQueryTemplate.setIri("p", axiom.getProperty().asOWLObjectProperty().toStringID()); Set<OWLObjectPropertyAssertionAxiom> posExamples = new TreeSet<>(); ResultSet rs = executeSelectQuery(posExamplesQueryTemplate.toString()); List<String> vars = rs.getResultVars(); boolean onlySubject = vars.size() == 1; while (rs.hasNext()) { QuerySolution qs = rs.next(); OWLIndividual subject = df.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); OWLIndividual object = df.getOWLNamedIndividual(IRI.create(qs.getResource(onlySubject ? "s" : "o").getURI())); posExamples.add(df.getOWLObjectPropertyAssertionAxiom(entityToDescribe, subject, object)); } return posExamples; }
@Test public void testEquivalentObjectPropertiesAxiomLearning() throws Exception { EquivalentObjectPropertyAxiomLearner l = new EquivalentObjectPropertyAxiomLearner(ks); l.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); l.setEntityToDescribe(op1); l.init(); l.start(); EvaluatedAxiom<OWLEquivalentObjectPropertiesAxiom> evAxiom = l.getCurrentlyBestEvaluatedAxiom(); System.out.println(evAxiom); double actualScore = evAxiom.getScore().getAccuracy(); int cntOp1 = 130; int cntOp2 = 70; int cntOp1_Op2 = 60; double beta = 1.0; double precision = Heuristics.getConfidenceInterval95WaldAverage(cntOp2, cntOp1_Op2); double recall = Heuristics.getConfidenceInterval95WaldAverage(cntOp1, cntOp1_Op2); double expectedScore = Heuristics.getFScore(recall, precision, beta); // update Feb 2015: seems to be incorrect to require those values to be the same as one is exact and the other an approximation // assertEquals("", expectedScore, actualScore, 0d); // set strict mode, i.e. if for the property explicit domain and range is given // we only consider properties with same range and domain }