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

Allow regex in R2L rules' constants #152

Merged
merged 1 commit into from
Aug 11, 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
4 changes: 2 additions & 2 deletions data/relex2logic-rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,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