in ruta-ep-textruler/src/main/java/org/apache/uima/ruta/textruler/learner/rapier/RapierRuleItem.java [63:183]
public String getStringForRuleString(TextRulerRule rule, MLRuleItemType type,
int numberInPattern, int patternSize, int numberInRule, int ruleSize, int slotIndex) {
int listStart = listBeginsAtZero ? 0 : 1;
String quantifierString = isListItem() ? "[" + listStart + "," + (listLen) + "]?" : "";
String anchor = null;
ArrayList<String> constraints = new ArrayList<String>();
if (words.size() > 0) {
ArrayList<TextRulerWordConstraint> regExpConstraints = new ArrayList<TextRulerWordConstraint>();
ArrayList<TextRulerWordConstraint> tmTypeConstraints = new ArrayList<TextRulerWordConstraint>();
for (TextRulerWordConstraint w : this.words) {
if (w.isRegExpConstraint())
regExpConstraints.add(w);
else
tmTypeConstraints.add(w);
}
int regExpCount = regExpConstraints.size();
int tmCount = tmTypeConstraints.size();
String regExpString = null;
for (TextRulerWordConstraint w : regExpConstraints) {
if (regExpString == null)
regExpString = w.toString();
else
regExpString += "|" + w.toString();
}
if (regExpString != null) {
regExpString = "REGEXP(\"" + regExpString + "\")";
}
String tmString = null;
if (tmCount > 1 || (regExpCount > 0 && tmCount > 0)) {
for (TextRulerWordConstraint w : tmTypeConstraints) {
if (tmString == null)
tmString = "IS(" + w.toString() + ")";
else
tmString += ",IS(" + w.toString() + ")";
}
String cString = "OR(" + tmString;
if (regExpCount > 0) {
if (tmCount > 0)
cString += ",";
cString += regExpString;
}
cString += ")";
constraints.add(cString);
} else { // tmCount can here be 0 or 1,
// if it is 1, then regExpCount == 0
// if it is 0, regExpCount can be anything
if (tmCount == 1)
anchor = tmTypeConstraints.get(0).toString(); // +quantifierString;
else {
if (regExpCount > 0)
constraints.add(regExpString);
}
}
}
if (tags.size() > 0) {
if (tags.size() == 1 && anchor == null)
anchor = tags.iterator().next().toString();
else {
String tagsString = null;
for (String w : this.tags) {
if (tagsString == null)
tagsString = "IS(" + w.toString() + ")";
else
tagsString += ",IS(" + w.toString() + ")";
}
tagsString = "OR(" + tagsString + ")";
constraints.add(tagsString);
}
}
if (classes.size() > 0) {
if (classes.size() == 1 && anchor == null)
anchor = classes.iterator().next().toString();
else {
String classesString = null;
for (String w : this.classes) {
if (classesString == null)
classesString = "IS(" + w.toString() + ")";
else
classesString += ",IS(" + w.toString() + ")";
}
classesString = "OR(" + classesString + ")";
constraints.add(classesString);
}
}
if (anchor == null)
anchor = "ALL";
String result = anchor + quantifierString;
if (constraints.size() > 0) {
String cStr = null;
for (String c : constraints) {
if (cStr == null)
cStr = c.toString();
else
cStr += "," + c.toString();
}
// TODO richtig?
result += "{" + cStr;
}
if (type == MLRuleItemType.FILLER && (numberInPattern == 0)) {
if (constraints.size() == 0)
result += "{";
result += "->MARKONCE(" + ((TextRulerSingleSlotRule) rule).getMarkName();
if (patternSize > 1)
result += ", " + (numberInRule + 1) + ", " + (numberInRule + patternSize);
// for(int i=0;i < patternSize;i++) {
// result += ","+(i+numberInRule+1);
// }
result += ")}";
} else if (constraints.size() != 0)
result += "}";
return result;
}