Will Take scripts support function calls?

0 views
Skip to first unread message

brigh...@gmail.com

unread,
Mar 14, 2008, 3:44:44 AM3/14/08
to take rule compiler
Will Take scripts support static function calls like JSP with TLD
support, or even object method calls with arbitrary arguments?

Jens Dietrich

unread,
Mar 14, 2008, 4:24:09 AM3/14/08
to take-rule...@googlegroups.com
Hi,

Definitely yes. The compiler is already supporting it (see JFunction)
but not the JSPELParser. I have to check whether the juel parser
supports arbitrary function, if yes, only a relatively small
modification in DefaultFunctionFactory would be required.

This was the good news. The bad news is that I don't have time to add
new features until the (northern) summer. I have a lot of teaching at
the moment and also have to keep my research going. But I will
definitely add these features later this year. Or perhaps somebody else
wants to have a go???

Cheers, Jens

brigh...@gmail.com

unread,
Mar 14, 2008, 11:42:00 AM3/14/08
to take rule compiler
Dear Jens,

I'd like to try my best to make a contribution to Take, now in way of
using Take, and I'll give something like benchmarks or test reports as
our project goes on. I'm a newbie to prolog, knowledge representation
and reasoning, AI, etc, but I won't hesitate to try to add some new
features to Take if I can.

Thanks for your kindly help. I'll continue our project from next
Wednesday.

BTW, I'm a Chinese programmer, and coding to make a living ;)

Cheers, BP

On Mar 14, 4:24 pm, Jens Dietrich <jens.dietr...@gmail.com> wrote:
> Hi,
>
> Definitely yes. The compiler is already supporting it (see JFunction)
> but not the JSPELParser. I have to check whether the juel parser
> supports arbitrary function, if yes, only a relatively small
> modification in DefaultFunctionFactory would be required.
>
> This was the good news. The bad news is that I don't have time to add
> new features until the (northern) summer. I have a lot of teaching at
> the moment and also have to keep my research going. But I will
> definitely add these features later this year. Or perhaps somebody else
> wants to have a go???
>
> Cheers, Jens
>

Jens Dietrich

unread,
Mar 16, 2008, 5:26:56 AM3/16/08
to take-rule...@googlegroups.com
Hi there,

Any help is appreciated, and just documenting the problems and
challenges you face (in blog style) and making them available to us
would definitely help! Writing a benchmark would be even better.

Cheers, Jens

haibo.zheng

unread,
Mar 24, 2008, 11:38:30 PM3/24/08
to take rule compiler
Hi~
Dear Jens,
I'm very interested in how to use object method in take script.
Can you show me some examples about it?


On Mar 16, 5:26 pm, Jens Dietrich <jens.dietr...@gmail.com> wrote:
> Hi there,
>
> Any help is appreciated, and just documenting the problems and
> challenges you face (in blog style) and making them available to us
> would definitely help! Writing a benchmark would be even better.
>
> Cheers, Jens
>

Jens Dietrich

unread,
Mar 25, 2008, 10:32:43 PM3/25/08
to take-rule...@googlegroups.com
Hi there,

I have added another example to the repository that shows how to
interpret arbitrary functions encountered in scripts - see
example.nz.org.take.compiler.example2 package in the repository. Right
now, functions are only working if they occur in terms. E.g., the
example uses the following rule:

rule1: if 100<turnover(c,12) then category[c,"gold"]

I will add an issue (feature to be added in the next release) that
functions returning booleans can also be used directly as predicates.

Hope this helps for now! Jens
<file:///D:/development/workspaces/defaultworkspace/take/src/example/nz/org/take/compiler/example2/>
<file:///D:/development/workspaces/defaultworkspace/take/src/example/nz/org/take/compiler/example2/>

jens

unread,
Mar 26, 2008, 9:36:25 PM3/26/08
to take rule compiler
Hi BP,

I have added the three new "enhancement" issues 12, 13 and 14. Please
review them and let me know whether this is what you need. I think it
makes a lot of sense to add those features. Might take a while to get
it done although its not very complicated.

Cheers, Jens
> > Hi BP,

haibo.zheng

unread,
Mar 26, 2008, 9:49:31 PM3/26/08
to take rule compiler
HI~
Dear Jeans,
Thanks for you help.
I hava updated the example2,
but there may be something wrong in it,
when I run the java application exmaple,
the return value on console is
Exception in thread "main" java.lang.NullPointerException
at example.nz.org.take.compiler.example2.Example.main(Example.java:34)
I don't konw what's wrong with it.
Could you tell me?

Otherwise,I hava seen the scenario 3 in take,
it can support the java function as predicate
when I try to modify this function to support regex,there is something
wrong with it.
I can't get my expected value.

let me show you my code


public class AddrRegex {
public String address;
public String regex;

public AddrRegex(String address,String regex)
{
this.address=address;
this.regex=regex;
}

public String getaddress()
{
return this.address;
}

public String getregex()
{
return this.regex;
}

public boolean isRegex(String regex)
{
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(this.getaddress());
return matcher.find();
}
public boolean regex(AddrRegex addr)
{
return this.isRegex(addr.regex);
}

public boolean equals(AddrRegex addr)
{
return this.getaddress().equals(addr.getaddress());
}
}


the script
//test for regex in take script
@@dc:author=zhenghaibo
@@dc:date=2008.3.25
var com.tigerknows.camal.evaluator.domain.AddrRegex addr1,addr2
@take.compilerhint.class=IsRegex
@take.compilerhint.slots=addr1,addr2,value
@take.compilerhint.method=isRegex
query IsRegex[in,in,out]
rule1: if regex[addr1.address,addr2.regex] then
IsRegex[addr1,addr2,'true']

the test1.java


public class test1 {
public static void main(String[] args) throws Exception{
RegexKnowledgeBase KB = null; // this is the generated interface
BasicConfigurator.configure();

// compile and bind constants referenced in rules
KnowledgeBaseManager<RegexKnowledgeBase> kbm = new
KnowledgeBaseManager<RegexKnowledgeBase>();

InputStream scriptSource = Example.class
.getResourceAsStream("/addr-regex.take");
KB = kbm.getKnowledgeBase(RegexKnowledgeBase.class,
new ScriptKnowledgeSource(scriptSource));
AddrRegex addr1=new AddrRegex("java","java");
AddrRegex addr2=new AddrRegex("java","java");
ResultSet<IsRegex> result = KB.isRegex(addr1, addr2);
if(result.hasNext())
{
System.out.println(result.next().value);
}
else
{
System.out.println("there is something wrong!");
}
}

}

whatever I do,the only return value is "there is something wrong"
I can't get my expected value "true"
Did I make some mistakes in my code?

brigh...@gmail.com

unread,
Mar 27, 2008, 8:37:08 AM3/27/08
to take rule compiler
Dear Jens,

I've reviewed the issues you added. I think TAKE script's support
for functions/methods will be much better when version 1.6 is
available. But it will be a little confusing to use all of the three
kinds of brackets: "()" of function calls, TAKE query's [], and EL's
[] operator (whose meaning varies according to the context).

My blog is http://www.geocoding.cn/MaHaoming, but I'm sorry that I
don't have much time to write new entries. I hope I'll have more time
on it as our company grows.

BTW, I've helped haibo.zheng out with the ugly AddrRegex example,
and he's my colleague. Last week I focused on other work, I'm back to
TAKE now.

Thank you for your kindly help.

Cheers, BP

Jens Dietrich

unread,
Mar 28, 2008, 1:24:29 AM3/28/08
to take-rule...@googlegroups.com
Hi,

Regarding the example: I cannot reproduce the error, it works for me.
Could you check the TAKE version you have (1.5 or latest from
repository) and perhaps send me the stack trace?

Yes, scenario 3 uses functions as predicates but does not use the native
function syntax (it uses [..] instead of (..)).

I think the problem in your example is that you are using regex on the
address fields: regex[addr1.address,addr2.regex]. Therefore the script
parser will try to find a method regex in String (being the type of
addr1.address). This fails because such a method does not exist - regex
will be defined as a predicate that has to be defined by rules).

Cheers, Jens

brigh...@gmail.com

unread,
Mar 28, 2008, 8:31:57 AM3/28/08
to take rule compiler
Hi Jens,

I synchronized example2 with the svn, and got the same error with
haibo.zheng. The full stack trace are here:

Exception in thread "main" java.lang.NullPointerException
at example.nz.org.take.compiler.example2.Example.main(Example.java:
34)

After I ran example.nz.org.take.compiler.example2.GenerateClasses,
example.nz.org.take.compiler.example2.Example worked well.


> I think the problem in your example is that you are using regex on the
> address fields: regex[addr1.address,addr2.regex]. Therefore the script
> parser will try to find a method regex in String (being the type of
> addr1.address). This fails because such a method does not exist - regex
> will be defined as a predicate that has to be defined by rules).

Yes, that's it.


Cheers, BP
Reply all
Reply to author
Forward
0 new messages