Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified maybe-rule for post-processing #154

Merged
merged 2 commits into from
Aug 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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))


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 @@ -634,23 +629,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