Repository: natasha/yargy

Issue:
Allow define custom value in interpretation rules
Like this
```python
{
    'interpretation': {
        'attribute': Object.attribute,
        'value': SomeEnum.value,
    }
}
```

Discussion:

Patch:
diff --git a/yargy/interpretation/attribute.py b/yargy/interpretation/attribute.py
index 6f6c264..ca320c6 100644
--- a/yargy/interpretation/attribute.py
+++ b/yargy/interpretation/attribute.py
@@ -55,16 +55,6 @@ class FactAttributeBase(Record):
         )
 
 
-def prepare_normalized(attribute, item):
-    if item is not None:
-        if callable(item):
-            return FunctionFactAttribute(attribute, item)
-        else:
-            return ConstFactAttribute(attribute, item)
-    else:
-        return NormalizedFactAttribute(attribute)
-
-
 class FactAttribute(FactAttributeBase):
     __attributes__ = ['fact', 'name', 'default']
 
@@ -76,8 +66,14 @@ class FactAttribute(FactAttributeBase):
     def inflected(self, grammemes=None):
         return InflectedFactAttribute(self, grammemes)
 
-    def normalized(self, item=None):
-        return prepare_normalized(self, item)
+    def normalized(self):
+        return NormalizedFactAttribute(self)
+
+    def const(self, value):
+        return ConstFactAttribute(self, value)
+
+    def custom(self, function):
+        return FunctionFactAttribute(self, function)
 
 
 class RepeatableFactAttribute(FactAttributeBase):


Test patch:
diff --git a/yargy/tests/test_attribute.py b/yargy/tests/test_attribute.py
new file mode 100644
index 0000000..ea52d61
--- /dev/null
+++ b/yargy/tests/test_attribute.py
@@ -0,0 +1,29 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+
+from yargy import Parser, rule, fact
+from yargy.predicates import gram, dictionary
+
+Money = fact(
+    'Money',
+    ['count', 'base', 'currency']
+)
+
+
+def test_constant_attribute():
+    MONEY_RULE = rule(
+        gram('INT').interpretation(
+            Money.count
+        ),
+        dictionary({'тысяча'}).interpretation(
+            Money.base.const(10**3)
+        ),
+        dictionary({'рубль', 'доллар'}).interpretation(
+            Money.currency
+        ),
+    ).interpretation(Money)
+
+    parser = Parser(MONEY_RULE)
+    matches = list(parser.match('1 тысяча рублей'))
+    assert matches[0].fact == Money(count=1, base=1000, currency='рублей')