From 478d0a7120b845f158559244485bfcbf96426230 Mon Sep 17 00:00:00 2001 From: William Ma Date: Tue, 12 Aug 2014 14:42:40 +0800 Subject: [PATCH 1/2] modified maybe-rule for post-processing --- data/relex2logic-rules.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/relex2logic-rules.txt b/data/relex2logic-rules.txt index 55e8fb8db..13d874997 100644 --- a/data/relex2logic-rules.txt +++ b/data/relex2logic-rules.txt @@ -46,6 +46,10 @@ # for definite words [DEFINITE] {8} <> definite-FLAG($A, T) => (definite-rule $A (get-instance-name $A word_index sentence_index)) +# maybe rule documented on http://wiki.opencog.org/w/RelEx2Logic_Rules#Maybe_Rule +# Example: "Maybe she eats lunch.", "Perhaps she is nice." +[MAYBE] {3} _advmod($W, $r_maybe) => (maybe-rule $W (get-instance-name $W word_index sentence_index)) + # ============================================ # misc rules @@ -126,8 +130,6 @@ # ============================================ # Unneeded, not working stuff, not completed, etc # ============================================ -[MAYBE] {9} <> _advmod($v1, $r_maybe) => (maybe-rule $v1 (get-instance-name $v1 word_index sentence_index) $r_maybe) - # [WHICHRULE] {10} <> which($N,$V) => (which-rule $N (get-instance-name $N word_index sentence_index) $V (get-instance-name $V word_index sentence_index)) From 6e604aeba0a30f7ba373fdb2a06ad12d97cdb736 Mon Sep 17 00:00:00 2001 From: William Ma Date: Thu, 14 Aug 2014 15:37:49 +0800 Subject: [PATCH 2/2] removed hard-coded maybe varscope check --- data/relex2logic-rules.txt | 2 +- src/java/relex/output/LogicProcessor.java | 52 +++++++---------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/data/relex2logic-rules.txt b/data/relex2logic-rules.txt index 13d874997..624900580 100644 --- a/data/relex2logic-rules.txt +++ b/data/relex2logic-rules.txt @@ -48,7 +48,7 @@ # maybe rule documented on http://wiki.opencog.org/w/RelEx2Logic_Rules#Maybe_Rule # Example: "Maybe she eats lunch.", "Perhaps she is nice." -[MAYBE] {3} _advmod($W, $r_maybe) => (maybe-rule $W (get-instance-name $W word_index sentence_index)) +[MAYBE] {3} _advmod($W, (maybe|possibly|perhaps|probably)) => (maybe-rule $W (get-instance-name $W word_index sentence_index)) # ============================================ diff --git a/src/java/relex/output/LogicProcessor.java b/src/java/relex/output/LogicProcessor.java index a258c1a13..9573e64cf 100644 --- a/src/java/relex/output/LogicProcessor.java +++ b/src/java/relex/output/LogicProcessor.java @@ -94,14 +94,12 @@ public ChildParentPair(Criterium r, FeatureNode c, FeatureNode p) private static class RuleResult { public Boolean passed; - public Boolean maybeCheck; public HashMap valuesMap; public HashMap uuidsMap; public RuleResult() { passed = false; - maybeCheck = false; valuesMap = new HashMap(); uuidsMap = new HashMap(); } @@ -211,29 +209,26 @@ public void applyRules(FeatureNode startNode) if (tempRule.getAllCriteriaSatisfied()) { - if (tempRule.getName().compareTo("MAYBE") != 0 || ruleResult.maybeCheck) - { - Boolean applied = false; + Boolean applied = false; - // dumb way to check this rule against all others and make sure the exact same one was not created - for (Rule otherRule : allAppliedRules) + // dumb way to check this rule against all others and make sure the exact same one was not created + for (Rule otherRule : allAppliedRules) + { + if (tempRule.getSchemeOutput().equals(otherRule.getSchemeOutput())) { - if (tempRule.getSchemeOutput().equals(otherRule.getSchemeOutput())) - { - applied = true; - break; - } + applied = true; + break; } + } - if (!applied) - { - // apply the rule - String schemeOutput = tempRule.getSchemeOutput(); - schemeBuilder.append(schemeOutput); - schemeBuilder.append("\n"); + if (!applied) + { + // apply the rule + String schemeOutput = tempRule.getSchemeOutput(); + schemeBuilder.append(schemeOutput); + schemeBuilder.append("\n"); - allAppliedRules.add(tempRule); - } + allAppliedRules.add(tempRule); } appliedRules.add(tempRule); @@ -634,23 +629,6 @@ private RuleResult checkValues(Rule thisRule, Stack matchedPair FeatureNode thisNode = thisPair.child; FeatureNode thisParent = thisPair.parent; - // special treatment for maybe-rule where different words can be matched - if (!ruleResult.maybeCheck && thisRule.getName().compareTo("MAYBE") == 0) - { - ArrayList sVar = new ArrayList(); - ScopeVariables s = new ScopeVariables (); - sVar = s.loadVarScope(); - int i = 0; - - while (i < sVar.size() && !ruleResult.maybeCheck) - { - if (!thisNode.isValued() && thisNode.get("name").getValue().compareTo(sVar.get(i)) != 0) - i++; - else - ruleResult.maybeCheck = true; - } - } - // if a variable already has a value, check it against the value at the node, else assign it if (ruleResult.valuesMap.get(thisCriterium.getFirstVariableName()) != null) {