ExactConceptParser can now recognize concepts by their names
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE, simplec
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE, simplec, CMV
|
||||
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
|
||||
from parsers.BaseNodeParser import SyaAssociativity
|
||||
from parsers.BnfNodeParser import Sequence, StrMatch, OrderedChoice, Optional, ConceptExpression
|
||||
@@ -226,9 +226,9 @@ as:
|
||||
|
||||
def test_i_can_recognize_duplicate_concepts_with_same_value(self):
|
||||
sheerka = self.get_sheerka()
|
||||
self.create_concept_lite(sheerka, Concept(name="hello a", body="'hello ' + a"), variables=["a"])
|
||||
self.create_concept_lite(sheerka, Concept(name="hello foo", body="'hello foo'"))
|
||||
self.create_concept_lite(sheerka, Concept(name="foo", body="'foo'"))
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="hello a", body="'hello ' + a"), variables=["a"])
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="hello foo", body="'hello foo'"))
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="foo", body="'foo'"))
|
||||
|
||||
res = sheerka.evaluate_user_input("hello foo")
|
||||
assert len(res) == 1
|
||||
@@ -238,9 +238,9 @@ as:
|
||||
|
||||
def test_i_cannot_manage_duplicate_concepts_when_the_values_are_different(self):
|
||||
sheerka = self.get_sheerka()
|
||||
self.create_concept_lite(sheerka, Concept(name="hello a", body="'hello ' + a"), variables=["a"])
|
||||
self.create_concept_lite(sheerka, Concept(name="hello foo", body="'hello foo'"))
|
||||
self.create_concept_lite(sheerka, Concept(name="foo", body="'another value'"))
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="hello a", body="'hello ' + a"), variables=["a"])
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="hello foo", body="'hello foo'"))
|
||||
self.create_and_add_in_cache_concept(sheerka, Concept(name="foo", body="'another value'"))
|
||||
|
||||
res = sheerka.evaluate_user_input("hello foo")
|
||||
assert len(res) == 1
|
||||
@@ -894,9 +894,31 @@ as:
|
||||
res = sheerka.evaluate_user_input("eval four > three")
|
||||
assert res[0].status
|
||||
|
||||
res = sheerka.evaluate_user_input("get_concepts_weights('some_prop')")
|
||||
assert sheerka.get_concepts_weights("some_prop") == {'1001': 1, '1002': 2, '1003': 3, '1004': 4}
|
||||
|
||||
def test_i_can_evaluate_expression_when_using_token_concept(self):
|
||||
sheerka, context, one, two, plus = self.init_concepts(
|
||||
Concept("one", body="1"),
|
||||
Concept("two", body="2"),
|
||||
self.from_def_concept("<", "a < b", ["a", "b"], body="is_less_than('some_prop', a, b)")
|
||||
)
|
||||
|
||||
expression = "c:one: < c:two:"
|
||||
res = sheerka.evaluate_user_input(expression)
|
||||
assert res[0].status
|
||||
assert res[0].body == {'1001': 1, '1002': 2, '1003': 3, '1004': 4}
|
||||
assert res[0].body == CMV(plus, a="c:one:", b="c:two:")
|
||||
assert res[0].body.a is None # concept is not evaluated
|
||||
assert res[0].body.b is None # concept is not evaluated
|
||||
|
||||
expression = "eval c:one: < c:two:"
|
||||
res = sheerka.evaluate_user_input(expression)
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, BuiltinConcepts.SUCCESS)
|
||||
assert sheerka.get_concepts_weights("some_prop") == {'1001': 1, '1002': 2}
|
||||
|
||||
expression = "eval one < two"
|
||||
res = sheerka.evaluate_user_input(expression)
|
||||
assert not res[0].status
|
||||
|
||||
|
||||
class TestSheerkaNonRegFile(TestUsingFileBasedSheerka):
|
||||
|
||||
Reference in New Issue
Block a user