/** * @param filter * @return individual ids * @throws UnknownFilterException */ public List<String> applyFilter(Filter filter) throws UnknownFilterException { if (filter == null) { return new ArrayList<String>(knowledgeBase.getIndividualIdsInSignature()); } List<String> ids = new ArrayList<String>(); for (String id : knowledgeBase.getIndividualIdsInSignature()) { if (test(id, filter)) { ids.add(id); } } return ids; }
/** * Calculate the comparison of all x all individuals. Since all individuals are being compared, * and will be necessary for evaluating statistics we will store in an array. * * @throws IncoherentStateException * @throws UnknownFilterException */ public void computeIxI() throws UnknownFilterException, IncoherentStateException { Set<String> individualIds = kb.getIndividualIdsInSignature(); for (String iid : individualIds) { int ibit = kb.getIndividualIndex(iid); EWAHCompressedBitmap ibm = kb.getDirectTypesBM(iid); Set<String> iids = kb.getClassIds(ibm); ProfileQuery q = ProfileQueryFactory.createQuery(iids); // compare against all other individuals q.setLimit(-1); MatchSet ms = profileMatcher.findMatchProfile(q); matchScores[ibit] = ms.getScores(); } }
// returns true if id has properties that match Filter private boolean test(String id, Filter filter) throws UnknownFilterException { if (filter instanceof FilterSet) { FilterSet fs = (FilterSet) filter; for (Filter f2 : fs.getFilters()) { if (!test(id, f2)) { return false; } } return true; } else if (filter instanceof PropertyValueFilter) { PropertyValueFilter fpv = (PropertyValueFilter) filter; Set<Object> values = knowledgeBase.getPropertyValues(id, fpv.getPropertySymbol()); LOG.info(id + " VALs=" + values); boolean contains = false; if (values.contains(fpv.getFiller())) contains = true; if (fpv.isNegated()) return !contains; else return contains; } /* else if (filter instanceof TypeFilter) { //TODO //int tix = knowledgeBase.get ((TypeFilter)filter).getTypeId(); //EWAHCompressedBitmap typeBM = knowledgeBase.getTypesBM(id); //if (typeBM.getPositions().contains(filter)) return false; }*/ else if (filter instanceof IdFilter) { IdFilter idf = (IdFilter) filter; if (idf.getIds().contains(id)) { return true; } else { return false; } } else { throw new UnknownFilterException(filter.toString()); } }
public KBMatcherCalculator(ProfileMatcher pm) { this.profileMatcher = pm; this.kb = pm.getKnowledgeBase(); matchScores = new DescriptiveStatistics[kb.getIndividualIdsInSignature().size()]; }