if (rule == null || inside.isEmpty()) {
return null;
}
// create base 1 and base 2:
WhiskRule base1 = rule.copy(); // slot filler rule
TextRulerSlotPattern slotPattern = base1.getPatterns().get(slotIndex);
// questionable restriction:
if (inside.size() <= windowSize) { // TODO add parameter for this!
slotPattern.fillerPattern.addAll(inside);
} else {
for (int i = 0; i < inside.size(); i++)
if (i == 0 || (i == inside.size() - 1))
slotPattern.fillerPattern.add(inside.get(i).copy());
else if (inside.size() > 2 && i < 2)
slotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
}
List<WhiskRuleItem> beforeList = getTermsBefore(inside.get(0), example);
List<WhiskRuleItem> afterList = getTermsAfter(inside.get(inside.size() - 1), example);
beforeList.add(null);
afterList.add(null);
Collection<WhiskRule> tempRules = new HashSet<WhiskRule>();
// workaround for better rules:
// only inner begin
for (WhiskRuleItem eachBefore : beforeList) {
for (WhiskRuleItem eachAfter : afterList) {
WhiskRule copy = rule.copy();
TextRulerSlotPattern textRulerSlotPattern = copy.getPatterns().get(slotIndex);
if (eachBefore != null) {
textRulerSlotPattern.preFillerPattern.add(eachBefore);
}
textRulerSlotPattern.fillerPattern.add(inside.get(0).copy());
textRulerSlotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
if (eachAfter != null) {
textRulerSlotPattern.postFillerPattern.add(eachAfter);
}
tempRules.add(copy);
}
}
// only inner end
for (WhiskRuleItem eachBefore : beforeList) {
for (WhiskRuleItem eachAfter : afterList) {
WhiskRule copy = rule.copy();
TextRulerSlotPattern textRulerSlotPattern = copy.getPatterns().get(slotIndex);
if (eachBefore != null) {
textRulerSlotPattern.preFillerPattern.add(eachBefore);
}
textRulerSlotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
textRulerSlotPattern.fillerPattern.add(inside.get(inside.size() - 1).copy());
if (eachAfter != null) {
textRulerSlotPattern.postFillerPattern.add(eachAfter);
}
tempRules.add(copy);
}
}
if (!beforeList.isEmpty()) {
if (!afterList.isEmpty()) {
for (WhiskRuleItem eachBefore : beforeList) {
for (WhiskRuleItem eachAfter : afterList) {
WhiskRule copy = rule.copy();
TextRulerSlotPattern textRulerSlotPattern = copy.getPatterns().get(slotIndex);
if (eachBefore != null) {
textRulerSlotPattern.preFillerPattern.add(eachBefore);
}
textRulerSlotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
if (eachAfter != null) {
textRulerSlotPattern.postFillerPattern.add(eachAfter);
}
tempRules.add(copy);
}
}
} else {
for (WhiskRuleItem eachBefore : beforeList) {
WhiskRule copy = rule.copy();
TextRulerSlotPattern textRulerSlotPattern = copy.getPatterns().get(slotIndex);
textRulerSlotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
if (eachBefore != null) {
textRulerSlotPattern.preFillerPattern.add(eachBefore);
}
tempRules.add(copy);
}
}
} else {
for (WhiskRuleItem eachAfter : afterList) {
WhiskRule copy = rule.copy();
TextRulerSlotPattern textRulerSlotPattern = copy.getPatterns().get(slotIndex);
textRulerSlotPattern.fillerPattern.add(WhiskRuleItem.newWildCardItem());
if (eachAfter != null) {
textRulerSlotPattern.postFillerPattern.add(eachAfter);
}
tempRules.add(copy);