Commits

Pierre Carbonnelle committed f5eab75

create_atoms --> create_terms

  • Participants
  • Parent commits d828a71

Comments (0)

Files changed (13)

pyDatalog/examples/Mongo.py

 from pyDatalog import pyDatalog
 
 print("\n *** combined SQLite and Mongo query :\n")
-pyDatalog.create_atoms('X, N, Diploma')
+pyDatalog.create_terms('X, N, Diploma')
 
 # Who has a salary of 6800 and a MSc. diploma
 (Employee.salary[X]==6800) & (Employee.diploma[X]=="MSc.")

pyDatalog/examples/SQLAlchemy.py

 session.commit()
 
 """ 4. Query the objects using the datalog engine """
-pyDatalog.create_atoms('X, Y, N, lowest')
+pyDatalog.create_terms('X, Y, N, lowest')
 
 # the following python statements implicitly use the datalog clauses in the class definition
 

pyDatalog/examples/hashtag.py

 from pyDatalog import pyDatalog, pyEngine
 import time
 
-pyDatalog.create_atoms('star, move,solution,X,Y,N,N1,N2')
-pyDatalog.create_atoms('X1,X2,X3,X4,X5,X6,X7,X8,X9')
-pyDatalog.create_atoms('Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9')
+pyDatalog.create_terms('star, move,solution,X,Y,N,N1,N2')
+pyDatalog.create_terms('X1,X2,X3,X4,X5,X6,X7,X8,X9')
+pyDatalog.create_terms('Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9')
 
 # X has a star in position N1 or N2
 star(X,N1,N2) <= (X[N1]=='*')

pyDatalog/examples/hashtag_optimized.py

 from pyDatalog import pyDatalog, pyEngine
 import time
 
-pyDatalog.create_atoms('solution,move,X,Y,Z,N,N1,N2')
+pyDatalog.create_terms('solution,move,X,Y,Z,N,N1,N2')
 
 # valid moves are exchange of 1<->2, 1<->4, ... 
 @pyDatalog.predicate()

pyDatalog/examples/multiModel.py

 import threading
 import time
 
-pyDatalog.create_atoms('N,X0,X1,X2,X3,X4,X5,X6,X7')
-pyDatalog.create_atoms('ok,queens, next_queen')
+pyDatalog.create_terms('N,X0,X1,X2,X3,X4,X5,X6,X7')
+pyDatalog.create_terms('ok,queens, next_queen')
 
 def add_logic(n):
     ok(X1, N, X2) <= (X1!=X2) & (X1!= X2+N) & (X1!=X2-N)

pyDatalog/examples/python.py

 print(John.salary_class) # prints 6
 
 # who has a salary of 6300 ?
-pyDatalog.create_atoms('X')
+pyDatalog.create_terms('X')
 Employee.salary[X] == 6300 # notice the similarity to a pyDatalog query
 print(X) # prints [Mary]
 print(X.v()) # prints Mary

pyDatalog/examples/queens.py

 from pyDatalog import pyDatalog
 import time
 
-pyDatalog.create_atoms('N,X0,X1,X2,X3,X4,X5,X6,X7')
-pyDatalog.create_atoms('ok,queens,next_queen')
+pyDatalog.create_terms('N,X0,X1,X2,X3,X4,X5,X6,X7')
+pyDatalog.create_terms('ok,queens,next_queen')
 
 # when is it ok to have a queen in row X1 and another in row X2, separated by N columns
 # this is memoized !

pyDatalog/examples/queens_N.py

 import time
 from pyDatalog import pyEngine
 
-pyDatalog.create_atoms('N,N1, X,Y, X0,X1,X2,X3,X4,X5,X6,X7')
-pyDatalog.create_atoms('ok,queens, next_queen, pred, pred2')
+pyDatalog.create_terms('N,N1, X,Y, X0,X1,X2,X3,X4,X5,X6,X7')
+pyDatalog.create_terms('ok,queens, next_queen, pred, pred2')
 
 size=8
 

pyDatalog/examples/test.py

     pyDatalog.clear()
     @pyDatalog.program()
     def factorial(): 
-        (factorial[N] == F) <= (F == N*factorial[N-1]) # most general clause first
-        + (factorial[1]==1)
+        factorial[N] = N*factorial[N-1] # most general clause first
+        factorial[1] = 1
         (factorial[N] == F) <= (N < 1) & (F== -factorial[-N])
         assert ask(factorial[1] == F) == set([(1,)])
         assert ask(factorial[4] == F) == set([(24,)])
     # string manipulation
     @pyDatalog.program()
     def _lambda(): 
+        assert ask((X=='world') & (Y==(lambda X: 'hello ' + X))) == set([('world', 'hello world')])
         split(X, Y,Z) <= (X == Y+'-'+Z)
         assert ask(split(X, 'a', 'b')) == set([('a-b',)])
         split(X, Y,Z) <= (Y == (lambda X: X.split('-')[0])) & (Z == (lambda X: X.split('-')[1]))
     p(X) & (X=='b')
     assert (X._value() == [])
     
+    assert ((X=='world') & (Y=='hello ' + X)) == [('world', 'hello world')]
+    #TODO print((X=='world') & (Y==(lambda X: 'hello ' + X)))
+    
     pyDatalog.create_atoms('p2')
     
     def test2():

pyDatalog/examples/threadSafe.py

 import random
 import threading
 
-pyDatalog.create_atoms('N,X0,X1,X2,X3,X4,X5,X6,X7')
-pyDatalog.create_atoms('ok,queens, next_queen')
+pyDatalog.create_terms('N,X0,X1,X2,X3,X4,X5,X6,X7')
+pyDatalog.create_terms('ok,queens, next_queen')
 
 @pyDatalog.predicate()
 def ok3(X1, N, X2):

pyDatalog/examples/tutorial.py

 """
 
 from pyDatalog import pyDatalog
-pyDatalog.create_atoms('parent,bill,ancestor,descendents,manager, X,Y,Z,N,N1,F,  factorial, first_remainder, odd,even, _split')
+pyDatalog.create_terms('parent,bill,ancestor,descendents,manager, X,Y,Z,N,N1,F,  factorial, first_remainder, odd,even, _split')
 
 + parent(bill,'John Adams')
 
 Mary = Employee('Mary', John, 6300)
 Sam = Employee('Sam', Mary, 5900)
 
-pyDatalog.create_atoms('has_car, X')
+pyDatalog.create_terms('has_car, X')
 + has_car(Mary)
 print(has_car(X)) # prints [(Mary,)]
 

pyDatalog/pyDatalog.py

   * ask(code) : returns the result of the query contained in the code string
   * variables(n) : convenience function to create multiple variables in one statement
   * clear() : resets the datalog database
-  * create_atoms() : creates atoms for in-line queries
+  * create_terms() : creates terms for in-line queries
   * variables() : creates variables for in-line queries
 Variable : a class to define Variable, for use in datalog queries. (defined in pyParser)
 Answer class defines the object returned by ask()
 ATOMS = ['_sum','sum_','_min','min_','_max','max_', '_len','len_','concat','concat_','rank','rank_',
          'running_sum','running_sum_','range_','tuple_', 'format_']
 
-def create_atoms(*args):
+def create_terms(*args):
     """ create atoms for in-line clauses and queries """
     stack = inspect.stack()
     try:
     finally:
         del stack
 
+create_atoms = create_terms # for backward compatibility
+
 def variables(n):
     """ create variables for in-line clauses and queries """
     return [pyParser.Variable() for i in range(n)]

pyDatalog/version.py

-__version__ = "0.14.0c1"
+__version__ = "0.14.0"