Skip to content

Commit

Permalink
Merge pull request #152 from williampma/RegexConstant
Browse files Browse the repository at this point in the history
Allow regex in R2L rules' constants
  • Loading branch information
amebel committed Aug 11, 2014
2 parents 598041b + c157a08 commit 029e85d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions data/relex2logic-rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
# ============================================
# passive verb rules
# ============================================
[PASSIVE1] {1} <PASSIVE2> _obj($A,$B) & by($A,$C) & tense($A,past_passive) => (passive-rule1 $A (get-instance-name $A word_index sentence_index) $B (get-instance-name $B word_index sentence_index) $C (get-instance-name $C word_index sentence_index))
[PASSIVE1] {1} <PASSIVE2> _obj($A,$B) & by($A,$C) & tense($A, (.*)passive) => (passive-rule1 $A (get-instance-name $A word_index sentence_index) $B (get-instance-name $B word_index sentence_index) $C (get-instance-name $C word_index sentence_index))

[PASSIVE2] {1} <PASSIVE1> _obj($A,$B) & tense($A,present_passive) => (passive-rule2 $A (get-instance-name $A word_index sentence_index) $B (get-instance-name $B word_index sentence_index))
[PASSIVE2] {1} <PASSIVE1> _obj($A,$B) & tense($A, (.*)passive) => (passive-rule2 $A (get-instance-name $A word_index sentence_index) $B (get-instance-name $B word_index sentence_index))


# ============================================
Expand Down
7 changes: 5 additions & 2 deletions src/java/relex/logic/Criterium.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ public Criterium(String criterium)
{
_criteriumString = criterium;

_criteriumLabel = criterium.substring(0, criterium.indexOf("("));
// store the name of the RelEx relation
_criteriumLabel = criterium.substring(0, criterium.indexOf('('));

String criteriumVariables[] = criterium.substring(criterium.indexOf("(") + 1).replace(" ", "").replace(")", "").split(",");
// retrieve the variables and constants
String temp = criterium.substring(criterium.indexOf('(') + 1, criterium.lastIndexOf(')')).replace(" ", "");
String criteriumVariables[] = temp.split(",");

_variables = Arrays.asList(criteriumVariables);
}
Expand Down
12 changes: 9 additions & 3 deletions src/java/relex/output/LogicProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ private RuleResult checkValues(Rule thisRule, Stack<ChildParentPair> matchedPair
{
// the first variable will always be the 'name' of the parent node
// XXX can also add checks to UUID, but would requires more logic for constants
if (!ruleResult.valuesMap.get(thisCriterium.getFirstVariableName()).equals(thisParent.get("name").getValue()))
if (!thisParent.get("name").getValue().matches(ruleResult.valuesMap.get(thisCriterium.getFirstVariableName())))
{
allMatched = false;
break;
Expand All @@ -671,9 +671,15 @@ private RuleResult checkValues(Rule thisRule, Stack<ChildParentPair> matchedPair
// check the 2nd variable of this criterium
if (ruleResult.valuesMap.get(thisCriterium.getSecondVariableName()) != null)
{
String secondValue;

// the second value is at different place depends on whether the node is valued
if (!(thisNode.isValued() && ruleResult.valuesMap.get(thisCriterium.getSecondVariableName()).equals(thisNode.getValue()))
&& !(!thisNode.isValued() && ruleResult.valuesMap.get(thisCriterium.getSecondVariableName()).equals(thisNode.get("name").getValue())))
if (thisNode.isValued())
secondValue = thisNode.getValue();
else
secondValue = thisNode.get("name").getValue();

if (!secondValue.matches(ruleResult.valuesMap.get(thisCriterium.getSecondVariableName())))
{
allMatched = false;
break;
Expand Down

0 comments on commit 029e85d

Please sign in to comment.