1 | static new ThreadLocal<Bool> applyNLLogicFacts_v2_verbose; |
2 | |
3 | svoid applyNLLogicFacts_v2(S input, VF1<? super S> postMessage) { |
4 | applyNLLogicFacts_v2(input, postMessage, mL_facts()); |
5 | } |
6 | |
7 | svoid applyNLLogicFacts_v2(S input, VF1<? super S> postMessage, LS facts) { |
8 | applyNLLogicFacts_v2(input, postMessage, facts, ai_mL_parsedLogicExamples()); |
9 | } |
10 | |
11 | svoid applyNLLogicFacts_v2(S input, VF1<? super S> postMessage, LS facts, L<Pair<S, IfThen>> rules) { |
12 | new NLLogicChecker_v2 c; |
13 | c.matcher = new NLStringMatcher_dollarVars; |
14 | addAll(c.facts, facts); |
15 | c.input = input; |
16 | |
17 | applyNLLogicFacts_v2(c, postMessage, rules); |
18 | } |
19 | |
20 | svoid applyNLLogicFacts_v2(NLLogicChecker_v2 c, VF1<? super S> postMessage, L<Pair<S, IfThen>> rules) { |
21 | for (Pair<S, IfThen> idAndRule : rules) pcall { |
22 | IfThen rule = idAndRule.b; |
23 | new NLLogicChecker_v2.Matching m; |
24 | m.verbose = isTrue(applyNLLogicFacts_v2_verbose!); |
25 | if (m.verbose) |
26 | print("Checking rule: " + rule); |
27 | if (c.checkRule(rule, m)) { |
28 | print("Matched " + quote(c.input) + " with rule " + quote(rule)); |
29 | printStruct(m.matches); |
30 | |
31 | new SS matches; // matches made in evaluating RHS of rule |
32 | for (Exp out : m.output) |
33 | for (Exp e : nlLogic_unrollAnd(out)) |
34 | if (e cast Func) { |
35 | if (eq(e.name, "output") && e.arg instanceof Sentence) |
36 | callF(postMessage, addAndReturn(c.posted, replaceVars(nlLogic_text(e.arg), matches))); |
37 | } /*else if (e cast Eq) { // any sf as operator - disabled for security reasons, use eval() |
38 | Exp r = e.right; |
39 | S var = nlLogic_text(e.left); |
40 | if (r cast Func) |
41 | if (isStandardFunction(r.name) && r.arg instanceof Sentence && noJavaTokens(nlLogic_text(r.arg))) |
42 | matches.put(var, str(callAndMake(r.name))); |
43 | }*/ |
44 | } |
45 | } |
46 | } |
Began life as a copy of #1017647
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017652 |
Snippet name: | applyNLLogicFacts_v2 - with evaluating standard functions |
Eternal ID of this version: | #1017652/14 |
Text MD5: | fc353d644ee9d1df5f4f2d164c9ff1b8 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-08-20 17:43:29 |
Source code size: | 1875 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 417 / 491 |
Version history: | 13 change(s) |
Referenced in: | [show references] |