From c157a081160167c0c5a7b3ac0a05b69efbc04aba Mon Sep 17 00:00:00 2001 From: William Ma Date: Fri, 1 Aug 2014 12:45:41 +0800 Subject: [PATCH] allow regex in R2L rules' constants --- data/relex2logic-rules.txt | 4 ++-- src/java/relex/logic/Criterium.java | 7 +++++-- src/java/relex/output/LogicProcessor.java | 12 +++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/data/relex2logic-rules.txt b/data/relex2logic-rules.txt index f8a6fe095..42e500c59 100644 --- a/data/relex2logic-rules.txt +++ b/data/relex2logic-rules.txt @@ -93,9 +93,9 @@ # ============================================ # passive verb rules # ============================================ -[PASSIVE1] {1} _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} _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} _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} _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)) # ============================================ diff --git a/src/java/relex/logic/Criterium.java b/src/java/relex/logic/Criterium.java index 3482ce6cb..2789df17e 100644 --- a/src/java/relex/logic/Criterium.java +++ b/src/java/relex/logic/Criterium.java @@ -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); } diff --git a/src/java/relex/output/LogicProcessor.java b/src/java/relex/output/LogicProcessor.java index 994d47f67..a258c1a13 100644 --- a/src/java/relex/output/LogicProcessor.java +++ b/src/java/relex/output/LogicProcessor.java @@ -656,7 +656,7 @@ private RuleResult checkValues(Rule thisRule, Stack 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; @@ -671,9 +671,15 @@ private RuleResult checkValues(Rule thisRule, Stack 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;