private boolean isDisjointInstanceBased(OWLClassExpression d1, OWLClassExpression d2) { SortedSet<OWLIndividual> d1Instances = reasoner.getIndividuals(d1); SortedSet<OWLIndividual> d2Instances = reasoner.getIndividuals(d2); for(OWLIndividual d1Instance : d1Instances) { if(d2Instances.contains(d1Instance)) return false; } return true; }
private boolean isDisjointInstanceBased(OWLClassExpression d1, OWLClassExpression d2) { if(reasoner instanceof SPARQLReasoner) { SortedSet<OWLIndividual> individuals = reasoner.getIndividuals(df.getOWLObjectIntersectionOf(d1, d2)); return individuals.isEmpty(); } else { SortedSet<OWLIndividual> d1Instances = reasoner.getIndividuals(d1); SortedSet<OWLIndividual> d2Instances = reasoner.getIndividuals(d2); for(OWLIndividual d1Instance : d1Instances) { if(d2Instances.contains(d1Instance)) return false; } return true; } }
public void makePositiveExamplesFromConcept(OWLClassExpression concept){ logger.debug("making Positive Examples from Concept: "+concept); this.posExamples.clear(); this.posExamples.addAll(reasoningService.getIndividuals(concept)); //this.posExamples = sparqltasks.retrieveInstancesForClassDescription(conceptKBSyntax, 0); logger.debug("pos Example size: "+posExamples.size()); }
public DescriptionLinearClassifier(ClassLearningProblem lp, AbstractReasonerComponent rc) { this(rc.getIndividuals(lp.getClassToDescribe()), Sets.difference(rc.getIndividuals(),rc.getIndividuals(lp.getClassToDescribe())), rc); }
/** * just takes all other instances from the ontology, except the ones * in the fullPositiveSet (see Constructor) */ public void makeNegativeExamplesFromAllOtherInstances() { logger.debug("making random examples "); fromAllOther.clear(); fromAllOther.addAll(reasoningService.getIndividuals()); fromAllOther.removeAll(fullPositiveSet); logger.debug("|-negExample size from random: " + fromAllOther.size()); }
@Override public OWLNamedIndividual getOWLIndividual(String name) { return find(name, (Set<OWLNamedIndividual>)(Set<?>)rc.getIndividuals()); }
@Override public void init() throws ComponentInitException { super.init(); // compute neutral examples, i.e. those which are neither positive // nor negative (we have to take care to copy sets instead of // modifying them) neutralExamples = Sets.intersection(getReasoner().getIndividuals(), positiveExamples); neutralExamples.retainAll(negativeExamples); initialized = true; }
/** * if pos ex derive from one class, then neg ex are taken from a superclass * CURRENTLY SAME METHOD AS makeNegativeExamplesFromSuperClasses(OWLClass concept) * but works quite often * @param concept * @param depth PARAMETER CURRENTLY NOT USED, ONLY DIRECT SUPERCLASSES */ public void makeNegativeExamplesFromSuperClasses(OWLClass concept, int depth) { fromSuperclasses.clear(); SortedSet<OWLClassExpression> superClasses = reasoningService.getSuperClasses(concept); logger.debug("making neg Examples from " + superClasses.size() + " superclasses"); for (OWLClassExpression oneSuperClass : superClasses) { logger.debug(oneSuperClass); fromSuperclasses.addAll(reasoningService.getIndividuals(oneSuperClass)); } this.fromSuperclasses.removeAll(fullPositiveSet); logger.debug("|-neg Example from superclass: " + fromSuperclasses.size()); }
@Override public ScorePosOnly computeScore(OWLClassExpression description, double noise) { Set<OWLIndividual> retrieval = getReasoner().getIndividuals(description); Set<OWLIndividual> instancesCovered = new TreeSet<>(); Set<OWLIndividual> instancesNotCovered = new TreeSet<>(); for(OWLIndividual ind : positiveExamples) { if(retrieval.contains(ind)) { instancesCovered.add(ind); } else { instancesNotCovered.add(ind); } } double coverage = instancesCovered.size()/(double)positiveExamples.size(); double protusion = retrieval.size() == 0 ? 0 : instancesCovered.size()/(double)retrieval.size(); // pass only additional instances to score object retrieval.removeAll(instancesCovered); return new ScorePosOnly(instancesCovered, instancesNotCovered, coverage, retrieval, protusion, getAccuracy(coverage, protusion)); }
public MILES(AbstractCELA la, ClassLearningProblem lp, AbstractReasonerComponent rc) { this.la = la; this.rc = rc; // we convert to PosNegLP because we need at least the distinction between pos and neg examples // for the sampling // TODO do this in the PosNegLP constructor this.lp = new PosNegLPStandard(rc); SortedSet<OWLIndividual> posExamples = rc.getIndividuals(lp.getClassToDescribe()); Set<OWLIndividual> negExamples = Sets.difference(rc.getIndividuals(), posExamples); this.lp.setPositiveExamples(posExamples); this.lp.setNegativeExamples(negExamples); }
this.fromParallelClasses.addAll(reasoningService.getIndividuals(oneClass)); }catch (Exception e) { logger.warn("not implemented in "+this.getClass());
public double getAccuracyOrTooWeakExact(OWLClassExpression description, double noise) { nanoStartTime = System.nanoTime(); SortedSet<OWLIndividual> individualsC = reasoner.getIndividuals(description); // computing R(C) restricted to relevant instances int additionalInstances = Sets.difference(individualsC, positiveExamples).size(); // computing R(A) int coveredInstances = Sets.intersection(individualsC, positiveExamples).size(); double recall = coveredInstances / (double) positiveExamples.size(); // noise computation is incorrect // if(recall < 1 - noise) { // return -1; // } double precision = (additionalInstances + coveredInstances == 0) ? 0 : coveredInstances / (double) (coveredInstances + additionalInstances); // best reachable concept has same recall and precision 1: if (((1 + Math.sqrt(coverageFactor)) * recall) / (Math.sqrt(coverageFactor) + 1) < 1 - noise) { return -1; } else { return Heuristics.getFScore(recall, precision, coverageFactor); } }
@WebMethod public String[] getInstances(int id) throws ClientNotKnownException { ClientState state = getState(id); Set<OWLIndividual> individuals = state.getReasonerComponent().getIndividuals(); return Datastructures.sortedSet2StringListIndividuals(individuals); }
Set<OWLIndividual> posEx = reasonerComponent.getIndividuals(positiveExamples); if (positiveRandomCount > 0) { ArrayList<OWLIndividual> sample = new ArrayList<>(posEx); negEx = ((SPARQLReasoner) reasonerComponent).getIndividuals(negativeExamples, negativeRandomCount); } else { negEx = reasonerComponent.getIndividuals(negativeExamples);
@Override public void init() throws ComponentInitException { ExampleLoader exampleLoaderHelper = this.getExampleLoaderHelper(); if (exampleLoaderHelper != null && !exampleLoaderHelper.isInitialized()) { logger.info("Loading examples by expression"); exampleLoaderHelper.setPosOnlyLP(this); exampleLoaderHelper.init(); } Random rand = new Random(1); if(getReasoner()!=null) { individuals = new LinkedList<>(getReasoner().getIndividuals()); Collections.shuffle(individuals, rand); } positiveExamplesShuffled = new LinkedList<>(positiveExamples); Collections.shuffle(positiveExamplesShuffled, rand); initialized = true; }
@WebMethod public String[] retrieval(int id, String conceptString) throws ClientNotKnownException, ParseException { ClientState state = getState(id); // call parser to parse concept OWLClassExpression concept = KBParser.parseConcept(conceptString); Set<OWLIndividual> individuals = state.getReasonerComponent().getIndividuals(concept); return Datastructures.sortedSet2StringListIndividuals(individuals); }
SortedSet<OWLIndividual> tmp = reasoner.getIndividuals(index); tmp.removeAll(reasoner.getIndividuals(negatedCandidate)); meaningful = tmp.size() != 0; } else {
classInstances = new LinkedList<>(getReasoner().getIndividuals(classToDescribe)); TreeSet<OWLIndividual> superClassInstancesTmp = new TreeSet<>(getReasoner().getIndividuals()); for (OWLClassExpression superClass : superClasses) { superClassInstancesTmp.retainAll(getReasoner().getIndividuals(superClass));
private void updateLearningProblem(EvaluatedDescription<? extends Score> partialSolution) { // get individuals covered by the solution SortedSet<OWLIndividual> coveredExamples = la.getReasoner().getIndividuals(partialSolution.getDescription()); // remove from pos examples as those are already covered currentPosExamples.removeAll(coveredExamples); // remove from neg examples as those will always be covered in the combined solution currentNegExamples.removeAll(coveredExamples); // update the learning problem itself // TODO do we need some re-init of the lp afterwards? if(lp instanceof PosNegLP) { ((PosNegLP) la.getLearningProblem()).setPositiveExamples(currentPosExamples); ((PosNegLP) la.getLearningProblem()).setNegativeExamples(currentNegExamples); } else if(lp instanceof PosOnlyLP) { ((PosOnlyLP) la.getLearningProblem()).setPositiveExamples(currentPosExamples); } else if(lp instanceof ClassLearningProblem){ // TODO } }
SortedSet<OWLIndividual> posExamples = rc.getIndividuals(classToDescribe); SortedSet<OWLIndividual> negExamples = rc.getIndividuals(); negExamples.removeAll(posExamples);