Giter VIP home page Giter VIP logo

intellect's People

Contributors

dicato avatar nemonik avatar scotte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

intellect's Issues

rulesets

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....

issue with pip and antlr

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: )

Error when running example code: name 'version_str_to_tuple' is not defined

Hello!

I downloaded all of the example files and tried running them. Below are my error results. I'm using:

  • Python 2.7.9
  • antlr-python-runtime 3.4
  • intellect 1.4.9

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!

  • Robert

ANTLR

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!

when part

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.

Allow rules to return a value

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.

Issue with pip command while installing

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.

Inserted fact not available for next rule

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)

Issue in detecting instance variables in fact checking for "while"

@nemonik
@scotte
@dicato
Hi,

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"])

O/P:
image

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()

O/P:
image

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

image

Where its going wrong ?

Can't match two input in when?

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!!

Can I execute a rule after checking a condition?

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!

Add Support for Multiple Rule Conditions

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?

learn_policy swallows an AttributeError

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.