# Welcome to Logica Playground!
# Go ahead and edit this program. Start with editing book names and prices.
# You can write new predicates, specify which predicate you want to
# run in the input box below.
Book("From Caves to Stars", 120);
Book("Morning of Juliet", 40);
Book("Dawn of the Apes", 45);
Book("Tragedy and Discord", 124);
Book("How to Get Rich Writing Books for $5", 5);
Book("I Wrote a Book for $5, Guess What Happened Next!", 4);
Book("Breakfast at Paris", 30);
Book("My Friend: Dragon", 102);

ExpensiveBook(book_name) :-
  Book(book_name, price),
  price > 100;
Predicate to run:
Loading Logical engine...
packages = ["logica", "sqlite3"] from logica.parser_py import parse from logica.compiler import universe from logica.compiler import rule_translate from logica.common import logica_lib from logica.common import color color.CHR_WARNING = '{logica error}-*' color.CHR_END = '*-{logica error}' import csv def CreateBooksCsvFile(): with open('books.csv', 'w') as w: writer = csv.writer(w) # It's easier to parse without header and it is # impossible to use the header anyway. # writer.writerow(['name', 'author', 'price']) writer.writerow(['From Caves to Stars', 'Beans A.A.', 120]) writer.writerow(['Morning of Juliet', 'Smitey E.', 40]) writer.writerow(['Dawn of the Apes', 'Mon K.', 45]) writer.writerow(['Tragedy and Discord', 'Tarklor D.', 124]) writer.writerow(['How to Get Rich Writing Book for $5', 'Getri C. H.', 5]) writer.writerow(['I Wrote a Book for $5 - Guess What Happened Next!', 'Getri C. H.', 4]) writer.writerow(['Breakfast at Paris', 'Degaul C.', 30]) writer.writerow(['My Friend: Dragon', 'Tame R.', 102]) CreateBooksCsvFile() def RunPredicate(program, predicate): try: rules = parse.ParseFile(program)['rule'] except parse.ParsingException as e: before, error, after = e.location.Pieces() error_context = before + "{logica error}-*" + error + "*-{logica error}" + after; return {"result": "", "error_context": error_context, "error_message": str(e), "status": "error", "predicate_name": predicate} try: u = universe.LogicaProgram(rules) sql = u.FormattedPredicateSql(predicate) except rule_translate.RuleCompileException as e: return {"result": "", "error_context": e.rule_str, "error_message": str(e), "status": "error", "predicate_name": predicate} try: data = logica_lib.RunQuery(sql, engine='sqlite') except Exception as e: return {"result": "", "error_context": sql, "error_message": "Error while executing SQL:\n%s" % e, "status": "error", "predicate_name": predicate} return {"result": data, "error_message": "", "error_context": "", "status": "OK", "predicate_name": predicate}