Fixed #101 : Implement PLURIAL
Fixed #103 : Implement PlurialNodeParser Fixed #104 : Implement dynamic concept Fixed #107 : PrepareEvalxxxEvaluator: context hints are lost on a second evaluation
This commit is contained in:
@@ -546,11 +546,12 @@ class Sheerka(Concept):
|
||||
|
||||
return new_instances(concept, recognized_by, is_instance, is_evaluated) if return_new else concept
|
||||
|
||||
def new(self, concept_key, **kwargs):
|
||||
def new(self, concept_key, allow_dynamic=False, **kwargs):
|
||||
"""
|
||||
Returns an instance of a new concept
|
||||
When the concept is supposed to be unique, returns the same instance
|
||||
:param concept_key:
|
||||
:param allow_dynamic:
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
@@ -561,7 +562,8 @@ class Sheerka(Concept):
|
||||
else:
|
||||
concept_id = None
|
||||
|
||||
template = self.get_by_id(concept_id) if not concept_key else self.get_by_key(concept_key, concept_id)
|
||||
template = self.get_by_id(concept_id, allow_dynamic) if not concept_key else \
|
||||
self.get_by_key(concept_key, concept_id)
|
||||
|
||||
# manage concept not found
|
||||
if self.isinstance(template, BuiltinConcepts.UNKNOWN_CONCEPT) and \
|
||||
@@ -610,6 +612,43 @@ class Sheerka(Concept):
|
||||
concept.get_hints().is_evaluated = True # because we have manually set the variables
|
||||
return concept
|
||||
|
||||
def new_dynamic(self, concept_or_key, id_suffix, name=None, props=None, attrs=None):
|
||||
"""
|
||||
Create a dynamic concept with the given props and attrs
|
||||
A dynamic concept is a concept that is not declared by 'def concept' but can be deduced from another one
|
||||
ex: 'boys' can be deduced from 'boy' (given that it's its plural).
|
||||
dynamic concept are a convenient way not to define all possible concepts
|
||||
:param concept_or_key:
|
||||
:param id_suffix:
|
||||
:param name: new name and key for the concept
|
||||
:param props:
|
||||
:param attrs:
|
||||
:return:
|
||||
"""
|
||||
if not isinstance(concept_or_key, Concept):
|
||||
concept = self.fast_resolve(concept_or_key, return_new=True)
|
||||
else:
|
||||
concept = Concept().update_from(concept_or_key, update_value=False)
|
||||
|
||||
if hasattr(concept, "__iter__"):
|
||||
# TODO: replace exception by the Concept TOO_MANY_SUCCESS and make sure that it is correctly manage
|
||||
raise NotImplementedError("Too many concepts")
|
||||
|
||||
concept.get_metadata().id = f"{concept.id}-{id_suffix}"
|
||||
if name:
|
||||
concept.get_metadata().name = name
|
||||
concept.get_metadata().key = name
|
||||
|
||||
if props:
|
||||
for k, v in props.items():
|
||||
concept.set_prop(k, v)
|
||||
|
||||
if attrs:
|
||||
for k, v in attrs.items():
|
||||
concept.set_value(k, v)
|
||||
|
||||
return concept
|
||||
|
||||
def push_ontology(self, context, name, cache_only=False):
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user