public List<RapierRule> specializePreFiller(RapierRule curRule, int n) {
RapierRule baseRule1 = curRule.getParent1();
RapierRule baseRule2 = curRule.getParent2();
int n1 = curRule.getParent1PreFiller_n();
int n2 = curRule.getParent2PreFiller_n();
TextRulerRulePattern preFiller1 = baseRule1.getPreFillerPattern();
TextRulerRulePattern preFiller2 = baseRule2.getPreFillerPattern();
int preFiller1MaxIndex = preFiller1.size() - n1 - 1;
int preFiller2MaxIndex = preFiller2.size() - n2 - 1;
// generate 3 different possible sets for generalizations:
// 1. n vs. n-1 (n elements of baserule1, n-1 of baserule2)
TextRulerRulePattern consideredPreFiller1 = new TextRulerRulePattern();
TextRulerRulePattern consideredPreFiller2 = new TextRulerRulePattern();
for (int i = preFiller1.size() - n; i >= 0 && i <= preFiller1MaxIndex; i++)
consideredPreFiller1.add(preFiller1.get(i));
for (int i = preFiller2.size() - n + 1; i >= 0 && i <= preFiller2MaxIndex; i++)
consideredPreFiller2.add(preFiller2.get(i));
List<TextRulerRulePattern> genList1 = null;
if (consideredPreFiller1.size() + consideredPreFiller2.size() > 0)
genList1 = RapierGeneralizationHelper.getGeneralizationsForRuleItemPatterns(
consideredPreFiller1, consideredPreFiller2);
List<TextRulerRulePattern> genList2 = null;
List<TextRulerRulePattern> genList3 = null;
if (useAllGenSetsAtSpecialization) // due to performance reasons the
// user can switch this off
{
// 2. n-1 vs. n (n-1 elements of baserule1, n of baserule2)
consideredPreFiller1.clear();
consideredPreFiller2.clear();
for (int i = preFiller1.size() - n + 1; i >= 0 && i <= preFiller1MaxIndex; i++)
consideredPreFiller1.add(preFiller1.get(i));
for (int i = preFiller2.size() - n; i >= 0 && i <= preFiller2MaxIndex; i++)
consideredPreFiller2.add(preFiller2.get(i));
if (consideredPreFiller1.size() + consideredPreFiller2.size() > 0)
genList2 = RapierGeneralizationHelper.getGeneralizationsForRuleItemPatterns(
consideredPreFiller1, consideredPreFiller2);
// 3. n vs. n (n elements of baserule1, n of baserule2)
consideredPreFiller1.clear();
consideredPreFiller2.clear();
for (int i = preFiller1.size() - n; i >= 0 && i <= preFiller1MaxIndex; i++)
consideredPreFiller1.add(preFiller1.get(i));
for (int i = preFiller2.size() - n; i >= 0 && i <= preFiller2MaxIndex; i++)
consideredPreFiller2.add(preFiller2.get(i));
if (consideredPreFiller1.size() + consideredPreFiller2.size() > 0)
genList3 = RapierGeneralizationHelper.getGeneralizationsForRuleItemPatterns(
consideredPreFiller1, consideredPreFiller2);
}
// TODO optimize and don't store all 3 genLists ! but for debugging