use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class CalculateAgentName method calculate.
@Override
public void calculate(MutableUserAgent userAgent) {
// Cleanup the name of the useragent
AgentField name = userAgent.get(AGENT_NAME);
if (name.isDefaultValue()) {
name = userAgent.get(DEVICE_BRAND);
if (name.isDefaultValue()) {
userAgent.setForced(AGENT_NAME, NULL_VALUE, name.getConfidence());
} else {
userAgent.setForced(AGENT_NAME, name.getValue(), name.getConfidence());
}
return;
}
String value = name.getValue();
if (isLowerCase(value)) {
userAgent.setForced(AGENT_NAME, Normalize.brand(value), name.getConfidence());
}
}
use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class DebugUserAgent method toMatchTrace.
String toMatchTrace(List<String> highlightNames) {
StringBuilder sb = new StringBuilder(4096);
sb.append('\n');
sb.append("+=========================================+\n");
sb.append("| Matcher results that have been combined |\n");
sb.append("+=========================================+\n");
sb.append('\n');
appliedMatcherResults.sort((o1, o2) -> {
Matcher m1 = o1.getValue();
Matcher m2 = o2.getValue();
return m1.getMatcherSourceLocation().compareTo(m2.getMatcherSourceLocation());
});
for (Pair<UserAgent, Matcher> pair : appliedMatcherResults) {
sb.append('\n');
sb.append("+================\n");
sb.append("+ Applied matcher\n");
sb.append("+----------------\n");
UserAgent result = pair.getLeft();
Matcher matcher = pair.getRight();
sb.append(matcher.toString());
sb.append("+----------------\n");
sb.append("+ Results\n");
sb.append("+----------------\n");
for (String fieldName : result.getAvailableFieldNamesSorted()) {
AgentField field = result.get(fieldName);
if (field.getConfidence() >= 0) {
String marker = "";
if (highlightNames.contains(fieldName)) {
marker = " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
}
sb.append("| ").append(fieldName).append('(').append(field.getConfidence());
if (field.isDefaultValue()) {
sb.append(" => isDefaultValue");
}
sb.append(") = ").append(field.getValue()).append(marker).append('\n');
}
}
sb.append("+================\n");
}
return sb.toString();
}
Aggregations