use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class DebugUserAgent method analyzeMatchersResult.
boolean analyzeMatchersResult() {
boolean passed = true;
for (String fieldName : getAvailableFieldNamesSorted()) {
Map<Long, String> receivedValues = new HashMap<>(32);
for (Pair<UserAgent, Matcher> pair : appliedMatcherResults) {
UserAgent result = pair.getLeft();
AgentField partialField = result.get(fieldName);
if (partialField != null && partialField.getConfidence() >= 0) {
String previousValue = receivedValues.get(partialField.getConfidence());
if (previousValue != null) {
if (!previousValue.equals(partialField.getValue())) {
if (passed) {
LOG.error("***********************************************************");
LOG.error("*** REALLY IMPORTANT ERRORS IN THE RULESET ***");
LOG.error("*** YOU MUST CHANGE THE CONFIDENCE LEVELS OF YOUR RULES ***");
LOG.error("***********************************************************");
}
passed = false;
LOG.error("Found different value for \"{}\" with SAME confidence {}: \"{}\" and \"{}\"", fieldName, partialField.getConfidence(), previousValue, partialField.getValue());
}
} else {
receivedValues.put(partialField.getConfidence(), partialField.getValue());
}
}
}
}
return passed;
}
use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class CalculateDeviceBrand method determineDeviceBrand.
private String determineDeviceBrand(UserAgent userAgent) {
// If no brand is known but we do have a URL then we assume the hostname to be the brand.
// We put this AFTER the creation of the DeviceName because we choose to not have
// this brandname in the DeviceName.
String deviceBrand = null;
AgentField informationUrl = userAgent.get(AGENT_INFORMATION_URL);
if (!informationUrl.isDefaultValue()) {
deviceBrand = extractBrandFromUrl(informationUrl.getValue());
}
if (deviceBrand != null) {
return deviceBrand;
}
AgentField informationEmail = userAgent.get(AGENT_INFORMATION_EMAIL);
if (!informationEmail.isDefaultValue()) {
deviceBrand = extractBrandFromEmail(informationEmail.getValue());
}
return deviceBrand;
}
use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class MajorVersionCalculator method calculate.
@Override
public void calculate(MutableUserAgent userAgent) {
AgentField agentVersionMajor = userAgent.get(majorVersionName);
if (agentVersionMajor.isDefaultValue()) {
AgentField agentVersion = userAgent.get(versionName);
String version = NULL_VALUE;
if (!agentVersion.isDefaultValue()) {
version = VersionSplitter.getInstance().getSingleSplit(agentVersion.getValue(), 1);
}
userAgent.setForced(majorVersionName, version, agentVersion.getConfidence());
}
}
use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class CalculateDeviceName method calculate.
@Override
public void calculate(MutableUserAgent userAgent) {
// Make sure the DeviceName always starts with the DeviceBrand
AgentField deviceName = userAgent.get(DEVICE_NAME);
if (!deviceName.isDefaultValue()) {
AgentField deviceBrand = userAgent.get(DEVICE_BRAND);
String deviceNameValue = removeBadSubStrings(deviceName.getValue());
String deviceBrandValue = deviceBrand.getValue();
if (deviceName.getConfidence() >= 0 && deviceBrand.getConfidence() >= 0 && !deviceBrandValue.equals(UNKNOWN_VALUE)) {
// In some cases it does start with the brand but without a separator following the brand
deviceNameValue = Normalize.cleanupDeviceBrandName(deviceBrandValue, deviceNameValue);
} else {
deviceNameValue = Normalize.brand(deviceNameValue);
}
userAgent.setForced(DEVICE_NAME, deviceNameValue, deviceName.getConfidence());
}
}
use of nl.basjes.parse.useragent.AgentField in project yauaa by nielsbasjes.
the class ConcatNONDuplicatedCalculator method calculate.
@Override
public void calculate(MutableUserAgent userAgent) {
AgentField firstField = userAgent.get(firstName);
AgentField secondField = userAgent.get(secondName);
String first = firstField.getValue();
long firstConfidence = firstField.getConfidence();
String second = secondField.getValue();
long secondConfidence = secondField.getConfidence();
long confidence = Math.max(firstConfidence, secondConfidence);
if (firstField.isDefaultValue() && secondField.isDefaultValue()) {
userAgent.set(targetName, NULL_VALUE, confidence);
return;
}
if (first.equals(second)) {
userAgent.setForced(targetName, first, firstConfidence);
return;
}
if (second.startsWith(first)) {
userAgent.setForced(targetName, second, secondConfidence);
return;
}
String value = first + " " + second;
userAgent.set(targetName, value, confidence);
}
Aggregations