use of org.openstreetmap.osmosis.tagtransform.Matcher in project osmosis by openstreetmap.
the class TransformLoader method parseTranslation.
private Translation parseTranslation(File parentDir, Element element) {
String name = "";
String description = "";
Matcher matcher = null;
Matcher finder = null;
List<Output> output = new ArrayList<>();
Map<String, DataSource> dataSources = Collections.emptyMap();
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element)) {
continue;
}
Element child = (Element) children.item(i);
String nodeName = child.getNodeName();
if (nodeName.equals("name")) {
name = child.getTextContent();
} else if (nodeName.equals("description")) {
description = child.getTextContent();
} else if (nodeName.equals("match")) {
matcher = parseMatcher(child);
} else if (nodeName.equals("find")) {
finder = parseMatcher(child);
} else if (nodeName.equals("data")) {
dataSources = parseDataSources(parentDir, child);
} else if (nodeName.equals("output")) {
NodeList outputs = child.getChildNodes();
for (int j = 0; j < outputs.getLength(); j++) {
if (!(outputs.item(j) instanceof Element)) {
continue;
}
Output o = parseOutput((Element) outputs.item(j));
if (o != null) {
output.add(o);
}
}
}
}
if (matcher != null) {
LOG.info("New translation: " + name);
return new TranslationImpl(name, description, matcher, finder, dataSources, output);
} else {
return null;
}
}
use of org.openstreetmap.osmosis.tagtransform.Matcher in project osmosis by openstreetmap.
the class TransformLoader method parseMatcher.
private Matcher parseMatcher(Element matcher) {
String name = matcher.getNodeName();
if (name.equals("match") || name.equals("find")) {
NodeList children = matcher.getChildNodes();
List<Matcher> matchers = new ArrayList<Matcher>();
String uname = null;
int uid = 0;
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element)) {
continue;
}
Element child = (Element) children.item(i);
Matcher m = parseMatcher(child);
if (m != null) {
matchers.add(m);
}
}
TTEntityType type = getType(matcher.getAttribute("type"));
if (matcher.getAttribute("user") != null && !matcher.getAttribute("user").isEmpty()) {
uname = matcher.getAttribute("user");
}
if (matcher.getAttribute("uid") != null && !matcher.getAttribute("uid").isEmpty()) {
uid = Integer.parseInt(matcher.getAttribute("uid"));
}
String mode;
if (name.equals("find")) {
mode = "or";
} else {
mode = matcher.getAttribute("mode");
}
if (mode == null || mode.equals("") || mode.equals("and")) {
return new AndMatcher(matchers, type, uname, uid);
} else if (mode.equals("or")) {
return new OrMatcher(matchers, type, uname, uid);
}
} else if (name.equals("tag")) {
String k = matcher.getAttribute("k");
String v = matcher.getAttribute("v");
String id = matcher.getAttribute("match_id");
return new TagMatcher(id, k, v);
} else if (name.equals("notag")) {
String k = matcher.getAttribute("k");
String v = matcher.getAttribute("v");
return new NoTagMatcher(k, v);
}
return null;
}
use of org.openstreetmap.osmosis.tagtransform.Matcher in project osmosis by openstreetmap.
the class AndMatcher method match.
@Override
public Collection<Match> match(Map<String, String> tags, TTEntityType entityType, String entityUname, int entityUid) {
if (this.type != null && this.type != entityType) {
return null;
}
if (this.uname != null && !this.uname.equals(entityUname)) {
return null;
}
if (this.uid != 0 && this.uid != entityUid) {
return null;
}
List<Match> allMatches = new ArrayList<Match>();
for (Matcher matcher : matchers) {
Collection<Match> matches = matcher.match(tags, entityType, entityUname, entityUid);
if (matches == null || matches.isEmpty()) {
return null;
}
allMatches.addAll(matches);
}
matchHits++;
return allMatches;
}
use of org.openstreetmap.osmosis.tagtransform.Matcher in project osmosis by openstreetmap.
the class AndMatcher method outputStats.
@Override
public void outputStats(StringBuilder output, String indent) {
output.append(indent);
output.append("And: ");
output.append(matchHits);
output.append('\n');
for (Matcher matcher : matchers) {
matcher.outputStats(output, indent + " ");
}
}
use of org.openstreetmap.osmosis.tagtransform.Matcher in project osmosis by openstreetmap.
the class OrMatcher method outputStats.
@Override
public void outputStats(StringBuilder output, String indent) {
output.append(indent);
output.append("Or: ");
output.append(matchHits);
output.append('\n');
for (Matcher matcher : matchers) {
matcher.outputStats(output, indent + " ");
}
}
Aggregations