/** * Name of core base trait, defaulting to authority name. * * @return */ protected String getBaseTraitName() { return getAuthorityId(); }
@Override protected String sanitizeID(String id) { // TODO use engine service return super.sanitizeID(id).replaceAll("\\(", "op").replaceAll("\\)", "cp").replaceAll("\\,", "cm"); }
IConcept ret = getOntology().getConcept(getBaseTraitName()); if (ret == null) { ArrayList<IAxiom> ax = new ArrayList<IAxiom>(); ax.add(Axiom.ClassAssertion(getBaseTraitName())); ax.add(Axiom.SubClass(getTraitType(), getBaseTraitName())); ax.add(Axiom .AnnotationAssertion(getBaseTraitName(), NS.BASE_DECLARATION, "true")); ax.add(Axiom .AnnotationAssertion(getBaseTraitName(), NS.AUTHORITY_ID_PROPERTY, getAuthorityId())); String pName = getTraitPropertyName(); String pProp = null; switch (getTraitType()) { case NS.CORE_IDENTITY_TRAIT: pProp = NS.HAS_IDENTITY_PROPERTY; ax.add(Axiom.SubObjectProperty(pProp, pName)); ax.add(Axiom .AnnotationAssertion(getBaseTraitName(), NS.TRAIT_RESTRICTING_PROPERTY, getAuthorityId() .toLowerCase() + ":" + getTraitPropertyName())); getOntology().define(ax); ret = getOntology().getConcept(getBaseTraitName());
@Override public IConcept getIdentity(String id, String authorityId) { /* * check and if necessary, create the trait in our ontology. TODO we should cache * all the info related to the ID so that online search is minimized. For now we * don't do anything online anyway. */ String cId = getAuthorityId() + "_" + sanitizeID(id); IOntology o = getOntology(); IConcept ret = o.getConcept(cId); if (ret == null) { ArrayList<IAxiom> ax = new ArrayList<IAxiom>(); ax.add(Axiom.ClassAssertion(cId)); ax.add(Axiom.SubClass(getBaseTrait(id).toString(), cId)); ax.add(Axiom .AnnotationAssertion(cId, NS.AUTHORITY_ID_PROPERTY, getAuthorityId())); /* * TODO get descriptor, add label and other metadata to identify the * authority. */ o.define(ax); ret = o.getConcept(cId); } return ret; }
protected IOntology getOntology() { if (_ontology == null) { _ontology = KLAB.KM.requireOntology(getAuthorityId().toLowerCase()); } return _ontology; }
@Override public String validateCoreConcept(IKnowledge knowledge, String id) { if (!knowledge.is(KLAB.c(NS.CORE_IDENTITY_TRAIT))) { return "Concepts identified by the " + getAuthorityId() + " authority must be identities"; } return null; }