nemonik / intellect Goto Github PK
View Code? Open in Web Editor NEWDSL and Rules Engine For Python
Home Page: http://pypi.python.org/pypi/Intellect
License: Other
DSL and Rules Engine For Python
Home Page: http://pypi.python.org/pypi/Intellect
License: Other
Hi,
Sorry to intrude ....
Trying to figure out how applicable is intellect to this type of functionality:
I am trying to work with simple to complex emulation of transformations on csv typ of data (colmunar)
In most cases read and rule execution is happening on the row at the time.
sometimes requirement will be to lookup forward the whole file and do some sofisticated changes on columns and on temp data.
One thing is the intellect is operating on objects via getters and setters.
I am not sure if rule can be based on input variable
something like this:
call is made to class that has tons of input params
class A(object):
def init(self, in1=None, in2=None, in3=None, inN=None)
....
ruls will be tied up to this specific object, however calls are made to take some action on the passed input variable at one time
so basically, I am not understanding, what I need to do to enable in ruleset confiuration, execution of one of thise rules at any give time.
Everytime i do this all the rules are executed in one shot.
I want to trigger oen rule per passed input param
i defenetelly don't completly understand the whole intellect paradigm, but documentation is a bit wage on examples and there is number of things that need to be in sync to get simple examples working...
is it possible to get an example that signifies execution of the rul per input parameter....
under Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] in Win8.1
I get this when try to pip install Intellect
Could not find a version that satisfies the requirement antlr-python-runtime>=
3.1.3 (from intellect) (from versions: )
Hello!
I downloaded all of the example files and tried running them. Below are my error results. I'm using:
Output when running the example code:
File "//anaconda/lib/python2.7/site-packages/intellect/grammar/PolicyParser.py", line 129, in PolicyParser
antlr_version = version_str_to_tuple("3.1.3 Mar 17, 2009 19:23:44")
NameError: name 'version_str_to_tuple' is not defined
Is there something I can do to remedy this?
Thanks!
Not sure how committed to ANTLR you are, but after reviewing the work you had done, and then even going down the path of using ANTLR directly and the lack of a python runtime that is not so out dated, I started looking for alternatives.
You could easily replace ANTLR with pyparsing (http://pyparsing.wikispaces.com/) such that it is used to express the grammar and handle parsing, and the corresponding creation of your objects, such that you focus on the other aspects while avoiding the need to completely rewrite the runtime for ANTLR.
Just wanted to share. Good luck!
Hi
I need to check mulitple facts in the when part of the rule. Is it possible to combine them?
I cannot find any example how to do this for Intellect so I am not sure if it is supported.
It would be nice if rules could return an output value for use after reasoning. My own use case is for rules-based permissions. I would like to reason against a rule and an object, and return either True or False, depending on a user's ability to access the object.
Seems to be an issue in '''- and """-based comments in rules.
When I run : pip install Intellect
Using cached Intellect-1.4.9.tar.gz (83 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [7 lines of output]
Traceback (most recent call last):
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
How Can I overcome this?
I've also tried several other methods of installation but they don't seem to work.
Is there any timeline when this library will support Python 3 / Django 2.1.x?
I have a sequence of rules as below. Even though I'm inserting a new AlarmFact and I can see it was created with the proper name, the next rule "We got a new alarm" is still executed so I end up with two AlarmFacts one with count=2 and another with count=1
rule "Process an incoming alarm":
agenda-group "process alarm 1"
when:
$alarm := Alarm()
then:
log("We got an alarm with name {0}".format($alarm.name))
attribute current_alarm_name = $alarm.name
forget $alarm
rule "We got an alarm already existent":
agenda-group "process alarm 2"
when:
$alarm_fact := AlarmFact( name == current_alarm_name)
then:
log("We got another alarm with name {0}".format($alarm_fact.name))
modify $alarm_fact:
count = $alarm_fact.count + 1
rule "We got a new alarm":
agenda-group "process alarm 3"
when:
not exists $alarm_fact := AlarmFact( name == current_alarm_name)
then:
log("We got a new alarm with name {0}".format(current_alarm_name))
insert AlarmFact(current_alarm_name)
Can I ask for comment about scalability of rule count and complexity?
How would this compare to production rule algos like Rete? https://en.wikipedia.org/wiki/Rete_algorithm
when rule is not working properly for me
Variables i am passing to fact is being detected
helloworld.policy
import logging
from helloworld import Check
first_sum = 0
second_sum = 0
location = ["China", "Malaysia"]
rule "restrict who are under 18":
agenda-group "test_d"
when:
$check := Check(age < 18)
then:
print($check)
log("{0} is with age {1} from {2}, no access allowed".format($check.name, $check.age, $check.country),
"example", logging.DEBUG)
#$check.getDetails()
rule "restrict who are from restricted countries":
agenda-group "test_d"
when:
$check := Check(country in location)
then:
print($check)
log("{0} is with age {1} from {2}, no access allowed".format($check.name, $check.age, $check.country),
"example", logging.DEBUG)
#$check.getDetails()
helloworld.py
# import ipdb;ipdb.set_trace()
import sys, logging
from intellect.Intellect import Intellect
from intellect.Intellect import Callable
class MyIntellect(Intellect):
pass
class Check():
def __init__(self, name, age, country) :
self.name = name
self.age = age
self.country = country
@Callable
def getDetails(self):
print("{0} is with {1} and from {2}".format(name, age, country))
if __name__ == "__main__" :
# set up logging for the example
logger = logging.getLogger('example')
logger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler(stream=sys.stdout)
consoleHandler.setFormatter(logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s%(message)s'))
logger.addHandler(consoleHandler)
# training with rules
myIntellect = MyIntellect()
policyHelloWorld = myIntellect.learn(Intellect.local_file_uri("helloworld.policy"))
logging.getLogger("example").debug("Asking the engine to learn a BuyOrder for {0} sheep.".format(Check))
# age, country input from user
name = raw_input("Enter your name:")
age = int(input("Enter your age:"))
country = raw_input("Enter your country:")
print(name, age,country)
myIntellect.learn(Check(name, age, country))
# executing the rules
myIntellect.reason(["test_d"])
But when i am initializing variables "age", "country" in helloworld.policy,
then fact checking in while is taking these values instead of taking from actual instance attributes
helloworld.policy
import logging
from helloworld import Check
first_sum = 0
second_sum = 0
age=0
country=""
location = ["China", "Malaysia"]
rule "restrict who are under 18":
agenda-group "test_d"
when:
$check := Check(age < 18)
then:
print($check)
log("{0} is with age {1} from {2}, no access allowed".format($check.name, $check.age, $check.country),
"example", logging.DEBUG)
#$check.getDetails()
rule "restrict who are from restricted countries":
agenda-group "test_d"
when:
$check := Check(country in location)
then:
print($check)
log("{0} is with age {1} from {2}, no access allowed".format($check.name, $check.age, $check.country),
"example", logging.DEBUG)
#$check.getDetails()
In above output, inside "while", age=0 nd country="" are being treated which makes rule1 True and rule2 False
But in examples given in offical git doc()
instance attributes are directly used in "while" checking
Where its going wrong ?
hi, I went to use two class to activate a rule but it seems don't work anyway.
part of the code is like :
rule "should never get here":
agenda-group "test_d"
when:
$lineB := Line()
$pointA := Point()
then:
bar()
and error is
Traceback (most recent call last):
File "D:/CODE/Python/Test/firstapp/Intellect_test/Intellect_test.py", line 25, in <module>
policy_d = myIntellect.learn(Intellect.local_file_uri("./rule.policy"))
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\Intellect.py", line 190, in learn
return self.learn_policy(identifier)
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\Intellect.py", line 247, in learn_policy
file_node = parser.file()
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\grammar\PolicyParser.py", line 245, in file
statement1 = self.statement()
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\grammar\PolicyParser.py", line 338, in statement
ruleStmt4 = self.ruleStmt()
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\grammar\PolicyParser.py", line 975, in ruleStmt
object.append_child( then26 )
File "C:\Python27\lib\site-packages\intellect-1.4.9-py2.7.egg\intellect\Node.py", line 152, in append_child
raise TypeError("Parameter 'child' cannot be None.")
Exception: line 46:12 mismatched input u'$pointA' expecting DEDENT
may i wrong?
or it don't support this kind of syntax?
thanks!!
Hi,
I need to understand if I can somehow execute a rule inside the "then" part of another rule, for example:
Define rule_b and rule_a inside a policy, but execute rule_b only if rule_a conditions are met:
rule rule_b:
then:
print('rule_b fired!')
rule rule_a:
when:
exists $classB := ClassB(property1.startswith("apple"))
then:
execute rule_b
Please, can you suggest me if there is any way I can do this?
Thank you!
I can't seem to find a way to evaluate a rule based on multiple conditions For example, the following does not work:
when:
$ClassA := ClassA()
$ClassB := ClassB()
Can we get compound conditions?
Calling learn_policy is throwing an Attribute error.
-> intel.learn_policy("./basic_rules.policy")
(Pdb)
Exception AttributeError: "'NoneType' object has no attribute 'path'" in <function _remove at 0x10ad4d410> ignored
The offending code can be seen below:
import pdb
from intellect.Intellect import Intellect
from wobbit import ColoredWobbit
if __name__ == '__main__':
print 'Running...'
intel = Intellect()
#pdb.set_trace()
intel.learn_policy("./basic_rules.policy")
blue_wobbit = ColoredWobbit(5, 'blue')
print blue_wobbit.color
intel.learn(blue_wobbit)
intel.reason()
Commenting out the intel.learn_policy("./basic_rules.policy")
causes the code to continue to run, meaning output is printed, etc.
All the code is here:
https://gist.github.com/2484156
I will keep mucking with it, as it might be something silly I am doing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.