Commits

Pierre Carbonnelle committed 369e9d3

unicode literal for python 2.7, 3.3+

  • Participants
  • Parent commits a8b0b75
  • Tags 0.14.4

Comments (0)

Files changed (3)

File pyDatalog/doc.py

+ďťż# coding=UTF-8
 """
 pyDatalog
 
     (f[Key]==aggregate(Value, for_each=For_each, order_by=Order_by)) <= q(Key, Value, For_each, Order_by)
 
 in knowledge base :
-    (f[Key]==_pyD_X1) <= f!1°(Key, Value, Group_by, For_each, Order_by, _pyD_X1)
-        where f!1° is a literal with aggregate attribute
+    (f[Key]==_pyD_X1) <= f!1°(Key, Value, Group_by, For_each, Order_by, _pyD_X1)
+        where f!1° is a literal with aggregate attribute
               whose argument list has no repetition of variables
     f!1(Key, Value, Group_by, For_each, Order_by) <= q(Key, Value, Group_by, For_each, Order_by)
         where the argument list of f!1 has no repetition of variables
 
-resolution algorithm for f!1°:
+resolution algorithm for f!1°:
     drop the last term
     variabilize Key that are not in Group_by (for rank, running_sum aggregation)
     find all f!(Key, Value, Group_by, For_each, Order_by)
     group by Group_by
     sort by Order_by
     apply aggregate 
-    return f!°(Key, "", "", "", "", _pyD_X1) solutions
+    return f!°(Key, "", "", "", "", _pyD_X1) solutions
 
 """

File pyDatalog/examples/test.py

 USA
 
 """
+
 import cProfile
 from decimal import Decimal
 import math
 import sys
 import datetime
 
+import sys
+if sys.version < '3':
+    import codecs
+    def u(x):
+        return codecs.unicode_escape_decode(x)[0]
+else:
+    def u(x):
+        return x
+
 from pyDatalog import pyDatalog
 def test():
 
     """)
     assert pyDatalog.ask('p(a)') == set([()])
     
-    pyDatalog.assert_fact('p', 'a', u'ĂŠ')
-    assert pyDatalog.ask('p(a, X)') == set([(u'ĂŠ',)])
-    assert pyDatalog.ask(u"p(a, u'ĂŠ')") == set([()])
-    pyDatalog.retract_fact('p', 'a', u'ĂŠ')
-    assert pyDatalog.ask(u'p(a, u"ĂŠ")') == None
-
+    @pyDatalog.program()
+    def unicode_(): 
+        +p(a, u('\xf6'))
+        assert ask(p(X,Y)) == set([('a', u('\xf6'))])
+        assert ask(p(a, X)) == set([(u('\xf6'),)])
+        assert ask(p(a, u('\xf6'))) == set([()])
+        -p(a, u('\xf6'))
+        assert ask(p(a, u('\xf6'))) == None
+        
     """unary facts                                                            """
     
     @pyDatalog.program()
         # strings, integer, float, datetime
         + p('c')
         assert ask(p(c)) == set([()])
-        + p(u'ĂŠ')
-        assert ask(p(u'ĂŠ')) == set([()])
-        - p(u'ĂŠ')
         
         + p(1)
         assert ask(p(1)) == set([()])
     
     pyDatalog.create_atoms('p', 'd, Y, eq, Z')
     +p('a')
-    +p(u'ĂŠ')
+    +p(u('\xf6'))
     
     p(Y)
-    assert (set(Y._value()) == set(['a',u'ĂŠ']))
-    - p(u'ĂŠ')
-    assert ((Y==u'ĂŠ') >= Y) == u'ĂŠ'
+    assert (set(Y._value()) == set(['a',u('\xf6')]))
+    - p(u('\xf6'))
+    assert ((Y==u('\xf6')) >= Y) == u('\xf6')
     
     + d(Decimal(2.0))
     d(Y)

File pyDatalog/version.py

-__version__ = "0.14.1"
+__version__ = "0.14.4"