use of nl.basjes.parse.useragent.config.MatcherConfig.ConfigLine in project yauaa by nielsbasjes.
the class ConfigLoader method loadYamlMatcher.
private void loadYamlMatcher(MappingNode entry, String filename) {
int matcherSourceLineNumber = entry.getStartMark().getLine();
String matcherSourceLocation = filename + ':' + matcherSourceLineNumber;
// List of 'attribute', 'confidence', 'expression'
List<ConfigLine> configLines = new ArrayList<>(16);
List<String> options = null;
for (NodeTuple nodeTuple : entry.getValue()) {
String name = getKeyAsString(nodeTuple, matcherSourceLocation);
switch(name) {
case "options":
options = YamlUtils.getStringValues(nodeTuple.getValueNode(), matcherSourceLocation);
break;
case "variable":
for (String variableConfig : YamlUtils.getStringValues(nodeTuple.getValueNode(), matcherSourceLocation)) {
String[] configParts = variableConfig.split(":", 2);
if (configParts.length != 2) {
throw new InvalidParserConfigurationException("Invalid variable config line: " + variableConfig);
}
String variableName = configParts[0].trim();
String config = configParts[1].trim();
configLines.add(new ConfigLine(VARIABLE, variableName, null, config));
}
break;
case "require":
for (String requireConfig : YamlUtils.getStringValues(nodeTuple.getValueNode(), matcherSourceLocation)) {
requireConfig = requireConfig.trim();
if (requireConfig.startsWith("IsNull[")) {
// FIXME: Nasty String manipulation code: Cleanup
String failIfFoundConfig = requireConfig.replaceAll("^IsNull\\[", "").replaceAll("]$", "");
configLines.add(new ConfigLine(FAIL_IF_FOUND, null, null, failIfFoundConfig));
} else {
configLines.add(new ConfigLine(REQUIRE, null, null, requireConfig));
}
}
break;
case "extract":
for (String extractConfig : YamlUtils.getStringValues(nodeTuple.getValueNode(), matcherSourceLocation)) {
String[] configParts = extractConfig.split(":", 3);
if (configParts.length != 3) {
throw new InvalidParserConfigurationException("Invalid extract config line: " + extractConfig);
}
String attribute = configParts[0].trim();
Long confidence = Long.parseLong(configParts[1].trim());
String config = configParts[2].trim();
configLines.add(new ConfigLine(EXTRACT, attribute, confidence, config));
}
break;
default:
}
}
analyzerConfig.addMatcherConfigs(matcherSourceLocation, new MatcherConfig(filename, matcherSourceLineNumber, options, configLines));
}
Aggregations