Search in sources :

Example 6 with AgentField

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());
    }
}
Also used : AgentField(nl.basjes.parse.useragent.AgentField)

Example 7 with AgentField

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();
}
Also used : Matcher(nl.basjes.parse.useragent.analyze.Matcher) AgentField(nl.basjes.parse.useragent.AgentField) UserAgent(nl.basjes.parse.useragent.UserAgent) MutableUserAgent(nl.basjes.parse.useragent.UserAgent.MutableUserAgent)

Aggregations

AgentField (nl.basjes.parse.useragent.AgentField)7 UserAgent (nl.basjes.parse.useragent.UserAgent)2 MutableUserAgent (nl.basjes.parse.useragent.UserAgent.MutableUserAgent)2 Matcher (nl.basjes.parse.useragent.analyze.Matcher)2 HashMap (java.util.HashMap)1