在Drools中,如何找到匹配次数最少的关键字?
In Drools, how to find the keyword with the least number of matches?
我有一些这样的标记化字符串
declare UserAddress
tokens : List
end
我有一个像这样的可识别标记列表
rule "Count Frequency of RealTokens occurrence in RealAddresses"
salience -10
when
$token : RealToken();
$count : List() from collect(RealAddress(tokens contains $token.getToken()));
then
modify($token) { setCount($count) };
end
使用 drools,我如何确定给定 UserAddress
中的哪个 tokens
与 $count
值可能最低的 RealToken
相匹配?
我已经试过了:
rule "Find the Most Statistically Significant Token for each User Address"
salience -20
$ua : UserAddress();
$ut : String( length() > 0) from $ua.getTokens().subList(1, $ua.getTokens().size());
$rt : RealToken(token == $ut);
not(RealToken(token == $ut && this.count < $rt.count));
then
System.out.println("MSST: " + $ua.toString() + " = " + $rt.toString());
end
但无法解决 DRL 语法问题:
java.lang.IllegalArgumentException: Found errors in package builder
[85,1]: [ERR 102] Line 85:1 mismatched input '$ua' in rule "Find the Most Statistically Significant Token for each User Address"
[0,0]: Parser returned a null Package
错误信息很清楚,如果你不厌其烦地看第 85 行,你会发现
rule "Find the Most Statistically Significant Token for each User Address"
salience -20
$ua : UserAddress(); ############################### line 85
$ut : String( length() > 0) from $ua.getTokens().subList(1, $ua.getTokens().size());
$rt : RealToken(token == $ut);
第一个模式之前没有关键字 when
。
我有一些这样的标记化字符串
declare UserAddress
tokens : List
end
我有一个像这样的可识别标记列表
rule "Count Frequency of RealTokens occurrence in RealAddresses"
salience -10
when
$token : RealToken();
$count : List() from collect(RealAddress(tokens contains $token.getToken()));
then
modify($token) { setCount($count) };
end
使用 drools,我如何确定给定 UserAddress
中的哪个 tokens
与 $count
值可能最低的 RealToken
相匹配?
我已经试过了:
rule "Find the Most Statistically Significant Token for each User Address"
salience -20
$ua : UserAddress();
$ut : String( length() > 0) from $ua.getTokens().subList(1, $ua.getTokens().size());
$rt : RealToken(token == $ut);
not(RealToken(token == $ut && this.count < $rt.count));
then
System.out.println("MSST: " + $ua.toString() + " = " + $rt.toString());
end
但无法解决 DRL 语法问题:
java.lang.IllegalArgumentException: Found errors in package builder
[85,1]: [ERR 102] Line 85:1 mismatched input '$ua' in rule "Find the Most Statistically Significant Token for each User Address"
[0,0]: Parser returned a null Package
错误信息很清楚,如果你不厌其烦地看第 85 行,你会发现
rule "Find the Most Statistically Significant Token for each User Address"
salience -20
$ua : UserAddress(); ############################### line 85
$ut : String( length() > 0) from $ua.getTokens().subList(1, $ua.getTokens().size());
$rt : RealToken(token == $ut);
第一个模式之前没有关键字 when
。