protected AxiomScore computeScore(int total, int success){ return computeScore(total, success, false); }
@Override public List<T> getCurrentlyBestAxioms(int nrOfAxioms) { return getCurrentlyBestAxioms(nrOfAxioms, 0.0); }
@Override public List<EvaluatedAxiom<T>> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { return getCurrentlyBestEvaluatedAxioms(nrOfAxioms, 0.0); }
private List<EvaluatedAxiom<OWLAxiom>> applyAlgorithm(AxiomType<? extends OWLAxiom> axiomType, SparqlEndpointKS ks) throws ComponentInitException{ Class<? extends AbstractAxiomLearningAlgorithm<? extends OWLAxiom, ? extends OWLObject, ? extends OWLEntity>> algorithmClass = AxiomAlgorithms.getAlgorithmClass(axiomType); AbstractAxiomLearningAlgorithm learner = null; try { learner = algorithmClass.getConstructor(SparqlEndpointKS.class).newInstance(ks); } catch (Exception e) { e.printStackTrace(); } learner.setEntityToDescribe(entity); learner.setUseSampling(false); learner.setProgressMonitor(progressMonitor); learner.init(); learner.start(); algorithms.put(axiomType, learner); return learner.getCurrentlyBestEvaluatedAxioms(); }
learner.setEntityToDescribe(entity); learner.setUseSampling(false); learner.setProgressMonitor(progressMonitor); learner.init(); learner.start(); return new TreeSet<>(learner.getCurrentlyBestAxioms(accuracyThreshold)); } catch (Exception e) { throw new Exception("Generation of " + axiomType.getName() + " axioms failed.", e);
getExistingAxioms(); generateSample(); } else { qef = ksQef; popularity = getPopularity(); learnAxioms(); } catch (Exception e) { progressMonitor.learningFailed(axiomType); + " " + entityToDescribe.toStringID() + " in {}ms.", (System.currentTimeMillis() - startTime)); showResult();
@SuppressWarnings("unchecked") protected Set<S> getExamples(ParameterizedSparqlString queryTemplate, EvaluatedAxiom<T> evAxiom) { ResultSet rs = executeSelectQuery(queryTemplate.toString()); Set<OWLObject> negExamples = new TreeSet<>(); while(rs.hasNext()){ RDFNode node = rs.next().get("s"); if(node.isResource()){ negExamples.add(df.getOWLNamedIndividual(IRI.create(node.asResource().getURI()))); } else if(node.isLiteral()){ negExamples.add(convertLiteral(node.asLiteral())); } } return (Set<S>) negExamples; }
@SuppressWarnings("unchecked") public Set<S> getPositiveExamples(EvaluatedAxiom<T> evAxiom) { return getExamples(posExamplesQueryTemplate, evAxiom); }
public Set<OWLObject> getNegatives(AxiomType<? extends OWLAxiom> axiomType, EvaluatedAxiom<OWLAxiom> axiom){ AbstractAxiomLearningAlgorithm la = algorithms.get(axiomType); return la.getNegativeExamples(axiom); }
@SuppressWarnings("unchecked") public Set<S> getNegativeExamples(EvaluatedAxiom<T> evAxiom) { return getExamples(negExamplesQueryTemplate, evAxiom); }
public List<EvaluatedAxiom<T>> getCurrentlyBestEvaluatedAxioms(double accuracyThreshold) { return getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, accuracyThreshold); }
@Override public List<T> getCurrentlyBestAxioms() { return getCurrentlyBestAxioms(Integer.MAX_VALUE); }
public List<T> getCurrentlyBestAxioms(double accuracyThreshold) { return getCurrentlyBestEvaluatedAxioms(accuracyThreshold) .stream() .map(EvaluatedAxiom<T>::getAxiom) .collect(Collectors.toList()); }
public List<T> getCurrentlyBestAxioms(int nrOfAxioms, double accuracyThreshold) { return getCurrentlyBestEvaluatedAxioms(nrOfAxioms, accuracyThreshold) .stream() .map(EvaluatedAxiom<T>::getAxiom) .collect(Collectors.toList()); }
@Override public List<EvaluatedAxiom<T>> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms, double accuracyThreshold) { List<EvaluatedAxiom<T>> returnList = new ArrayList<>(); //get the currently best evaluated axioms List<EvaluatedAxiom<T>> currentlyBestEvAxioms = getCurrentlyBestEvaluatedAxioms(); for(EvaluatedAxiom<T> evAx : currentlyBestEvAxioms){ if(evAx.getScore().getAccuracy() >= accuracyThreshold && returnList.size() < nrOfAxioms){ if(returnOnlyNewAxioms){ if(!existingAxioms.contains(evAx.getAxiom())){ returnList.add(evAx); } } else { returnList.add(evAx); } } } return returnList; }