use of nl.basjes.parse.useragent.analyze.Matcher in project yauaa by nielsbasjes.
the class AbstractUserAgentAnalyzerDirect method getAllPossibleFieldNames.
public Set<String> getAllPossibleFieldNames() {
if (allPossibleFieldNamesCache == null) {
synchronized (this) {
if (allPossibleFieldNamesCache == null) {
Set<String> names = new TreeSet<>(CORE_SYSTEM_GENERATED_FIELDS);
if (wantedFieldNames == null) {
for (Matcher matcher : allMatchers) {
names.addAll(matcher.getAllPossibleFieldNames());
}
for (FieldCalculator calculator : fieldCalculators) {
names.add(calculator.getCalculatedFieldName());
}
} else {
for (Matcher matcher : allMatchers) {
// Not all wanted fields are possible !
for (String possibleFieldName : matcher.getAllPossibleFieldNames()) {
if (wantedFieldNames.contains(possibleFieldName)) {
names.add(possibleFieldName);
}
}
}
for (FieldCalculator calculator : fieldCalculators) {
String possibleFieldName = calculator.getCalculatedFieldName();
if (wantedFieldNames.contains(possibleFieldName)) {
names.add(possibleFieldName);
}
}
names.remove(SET_ALL_FIELDS);
}
allPossibleFieldNamesCache = names;
}
}
}
return allPossibleFieldNamesCache;
}
use of nl.basjes.parse.useragent.analyze.Matcher in project yauaa by nielsbasjes.
the class AbstractUserAgentAnalyzerDirect method initializeMatchers.
public synchronized void initializeMatchers() {
if (matchersHaveBeenInitialized) {
return;
}
LOG.info("Initializing Analyzer data structures");
if (allMatchers.isEmpty()) {
throw new InvalidParserConfigurationException("No matchers were loaded at all.");
}
long start = System.nanoTime();
allMatchers.forEach(Matcher::initialize);
long stop = System.nanoTime();
matchersHaveBeenInitialized = true;
LOG.info("Built in {} msec : Hashmap {}, Ranges map:{}", (stop - start) / 1000000, informMatcherActions.size(), informMatcherActionRanges.size());
for (Matcher matcher : allMatchers) {
if (matcher.getActionsThatRequireInput() == 0) {
zeroInputMatchers.add(matcher);
}
}
// Reset all Matchers
for (Matcher matcher : allMatchers) {
matcher.reset();
}
touchedMatchers = new MatcherList(32);
}
use of nl.basjes.parse.useragent.analyze.Matcher 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