public static double computeTraitConcordance(Model model, IResolutionScope context) { /* * list of traits in common. Don't check the trait value - assumed the same * because of the search strategy. */ try { IKnowledge c = model.getObservableConcept(); // getWantedObservable(model, // context); if (c == null) { // TODO issues here - just a hack, should not happen return 0; } Collection<IConcept> attrs = Traits.separateAttributes(c).getSecond(); Collection<IConcept> wanted = ((ResolutionScope) context).getTraits(); int common = 0; if (attrs.size() == 0 && wanted.size() == 0) return 100.0; for (IConcept zio : wanted) { if (attrs.contains(zio)) { common++; } } if (wanted.size() > 0) { return 100.0 * ((double) common / (double) wanted.size()); } } catch (Exception e) { } return 0; }
.separateAttributes(observable.getType()); for (IConcept attribute : ast.getSecond()) { IConcept baset = NS.getBaseParentTrait(attribute);
/** * Return the passed knowledge after removing any traits of the passed base type, or * the original knowledge if the trait was absent. * * @param knowledge * @return knowledge without the trait * @throws KlabValidationException */ public static IKnowledge removeTrait(IConcept knowledge, IConcept baseTrait) throws KlabValidationException { Pair<IConcept, Collection<IConcept>> trs = separateAttributes(knowledge); ArrayList<IConcept> traits = new ArrayList<>(); boolean found = false; for (IConcept tr : trs.getSecond()) { if (tr.is(baseTrait)) { found = true; } else { traits.add(tr); } } return found ? Observables.declareObservable(trs.getFirst(), traits, Observables .getContextType(knowledge), Observables .getInherentType(knowledge)) : knowledge; }