TextRulerToolkit.log("ERROR! CALL getGeneralizationsForRuleItemPatternsOfEqualSize instead!");
if (TextRulerToolkit.DEBUG)
return null;
}
TextRulerRulePattern longerPattern = pattern1;
TextRulerRulePattern shorterPattern = pattern2;
if (pattern2.size() > pattern1.size()) {
longerPattern = pattern2;
shorterPattern = pattern1;
}
if (longerPattern.size() <= 1 || shorterPattern.size() <= 1) {
// Special case 1: one of the pattern terms list is empty AND
// special case 2: one has only ONE element
if (longerPattern.size() + shorterPattern.size() == 0) {
TextRulerToolkit.log("ERROR !! BOTH PATTERNS ARE EMPTY!");
if (TextRulerToolkit.DEBUG)
return null;
}
// get all possible generalizations of the two patterns. result of
// each generalization is ONE rule item, so we
// don't use TextRulerRulePattern here since this IS NOT a rule
// pattern! it's a list of possible generalizations:
ArrayList<TextRulerRuleItem> generalizations = getGeneralizationsForRuleItemLists(
longerPattern, shorterPattern);
// create a one element result pattern for each:
for (TextRulerRuleItem item : generalizations) {
TextRulerRulePattern p = new TextRulerRulePattern();
p.add(item);
resultList.add(p);
}
}
// else SPECIAL CASE 3 // TODO make those values configurable ?
else if (((longerPattern.size() - shorterPattern.size()) > 6) || (longerPattern.size() > 10)) {
int resultListLen1 = 0;
for (TextRulerRuleItem rt : shorterPattern)
resultListLen1 += ((RapierRuleItem) rt).isListItem() ? ((RapierRuleItem) rt).listLen() : 1;
int resultListLen2 = 0;
for (TextRulerRuleItem rt : longerPattern)
resultListLen2 += ((RapierRuleItem) rt).isListItem() ? ((RapierRuleItem) rt).listLen() : 1;
RapierRuleItem singleItem = new RapierRuleItem();
singleItem.setListLen(resultListLen1 > resultListLen2 ? resultListLen1 : resultListLen2);
TextRulerRulePattern singleItemPattern = new TextRulerRulePattern();
singleItemPattern.add(singleItem);
resultList.add(singleItemPattern);
} else { // sizes are different and both > 1
// create all possible generalization combinations, that is: how can
// we map elements of the shorter pattern
// to the ones of the longer pattern and then generalize each