/** * Get the context ('within') for the passed quality or trait. If the passed concept * is an attribute, configuration, class or realm, the context is the one specified * for the quality/configuration under "describes". For identities and processes, * context is found in 'applies to'. If the context is not specified but there is an * inherent concept, the context of the inherent, if any, is returned. * * @param concept * @return */ public static IConcept getContextType(IKnowledge concept) { return getContextType(concept, true); }
/** * True if observable has a stated context (mandatory for qualities) and context * isCompatible with the stated context for observable. * * @param observable * @param context * @return */ public static boolean isContextCompatible(IConcept observable, IConcept context) { IConcept ctx = getContextType(observable); return ctx != null && isCompatible(context, ctx); }
/** * Analyze an observable concept and return the main observable with all the original * identities and realms but no attributes; separately, return the list of the * attributes that were removed. * * @param observable * @return attribute profile * @throws KlabValidationException */ public static Pair<IConcept, Collection<IConcept>> separateAttributes(IKnowledge observable) throws KlabValidationException { IKnowledge obs = getBaseObservable(observable); ArrayList<IConcept> tret = new ArrayList<>(); ArrayList<IConcept> keep = new ArrayList<>(); for (IConcept zt : getTraits(observable)) { if (zt.is(KLAB.c(NS.CORE_IDENTITY_TRAIT)) || zt.is(KLAB.c(NS.CORE_REALM_TRAIT))) { keep.add(zt); } else { tret.add(zt); } } return new Pair<>(Observables.declareObservable((IConcept) (obs == null ? observable : obs), keep, Observables.getContextType(observable), Observables .getInherentType(observable)), tret); }
private static IConcept getContextType(IKnowledge concept, boolean recurse) { if (!(concept instanceof IConcept)) { return null; } IConcept ret = null; if (recurse && (NS.isAttribute(concept) || NS.isRealm(concept) || NS.isClass(concept) || NS.isConfiguration(concept))) { IConcept described = getDescribedQuality((IConcept) concept); ret = described == null ? null : getContextType(described, false); } else if (recurse && (NS.isIdentity(concept) || NS.isProcess(concept))) { Collection<IConcept> described = getApplicableObservables(concept); ret = described.size() > 0 ? NS.getLeastGeneralCommonConcept(described) : null; } else { Collection<IConcept> cls = OWL .getRestrictedClasses((IConcept) concept, KLAB .p(NS.HAS_CONTEXT_PROPERTY)); ret = cls.isEmpty() ? null : cls.iterator().next(); } if (ret == null && NS.isObservable(concept)) { IConcept inherent = getInherentType(concept); if (inherent != null) { ret = getContextType(inherent, false); } } return ret; }
/** * 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; }
IConcept context = getContextType(trait); if (context != null) { OWL.restrictSome(ret, KLAB.p(NS.HAS_CONTEXT_PROPERTY), context);
IConcept other = Observables.getContextType(concept); if (other != null && !context.is(other)) { throw new KlabValidationException("cannot add context " + context + " to concept " + concept
IConcept context = Observables.getContextType(observable); if (context != null) { OWL.restrictSome(ret, KLAB.p(NS.HAS_CONTEXT_PROPERTY), context);
IConcept other = getContextType(main); if (other != null && !isCompatible(context, other)) { throw new KlabValidationException("cannot add context " + context
&& !(this instanceof KIMModel && ((KIMModel) this).isInstantiator)) ? getObservable().getType() : Observables.getContextType(getObservable().getType()); IConcept ctx = Observables.getContextType(ko.getType()); if (ctx != null) {
IConcept cc1 = getContextType(o1); IConcept cc2 = getContextType(o2);
.getContextType(getObservable().getType());
private void observeConcept(IConcept concept, IMonitor monitor) throws KlabException { IConcept context = Observables.getContextType(concept); IConcept inherent = Observables.getInherentType(concept); boolean distributed = false;
.getExposedTraits(model.getObservable().getType()); IConcept context = Observables .getContextType(model.getObservable().getType()); IConcept inherent = Observables .getInherentType(model.getObservable().getType());
IConcept restrictedContextType = getContextType(concept); IConcept actualContextType = context == null ? null : (IConcept) context.getObservable().getType();
IConcept context = Observables.getContextType(k);
: Observables.getContextType(ko.getType()); IConcept ctx = Observables.getContextType(ko.getType()); if (ctx != null) { if (!Observables
IConcept ctx = Observables.getContextType(knowledge); if (ctx == null && !isInternal) { context.error("any non-abstract quality must identify a context", getFirstLineNumber()); && NS.isTrait(knowledge) && !context.getNamespace().getProject().isWorldview()) { IConcept ctx = Observables.getContextType(knowledge); if (ctx == null && !isInternal) { context.error("non-abstract traits without a context (stated in 'describes' or 'applies to') are only allowed in worldviews", getFirstLineNumber());