Skip to content

Commit

Permalink
Merge pull request #154 from williampma/Maybe
Browse files Browse the repository at this point in the history
modified maybe-rule for post-processing
  • Loading branch information
ruiting committed Aug 20, 2014
2 parents 5e8f731 + 6e604ae commit 42d8ec8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
6 changes: 4 additions & 2 deletions data/relex2logic-rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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> _advmod($W, (maybe|possibly|perhaps|probably)) => (maybe-rule $W (get-instance-name $W word_index sentence_index))


# ============================================
# misc rules
Expand Down Expand Up @@ -132,8 +136,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))


Expand Down
52 changes: 15 additions & 37 deletions src/java/relex/output/LogicProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,12 @@ public ChildParentPair(Criterium r, FeatureNode c, FeatureNode p)
private static class RuleResult
{
public Boolean passed;
public Boolean maybeCheck;
public HashMap<String, String> valuesMap;
public HashMap<String, String> uuidsMap;

public RuleResult()
{
passed = false;
maybeCheck = false;
valuesMap = new HashMap<String, String>();
uuidsMap = new HashMap<String, String>();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -650,23 +645,6 @@ private RuleResult checkValues(Rule thisRule, Stack<ChildParentPair> 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<String> sVar = new ArrayList<String>();
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)
{
Expand Down

0 comments on commit 42d8ec8

Please sign in to comment.