use of org.openstreetmap.osmosis.tagtransform.Match in project osmosis by openstreetmap.
the class TagMatcher method match.
@Override
public Collection<Match> match(Map<String, String> tags, TTEntityType type, String uname, int uid) {
List<Match> matches = new ArrayList<Match>();
// loop through the tags to find matches
for (Entry<String, String> tag : tags.entrySet()) {
java.util.regex.Matcher keyMatch = keyPattern.matcher(tag.getKey());
java.util.regex.Matcher valueMatch = valuePattern.matcher(tag.getValue());
if (keyMatch.matches() && valueMatch.matches()) {
MatchResult keyRes = keyMatch.toMatchResult();
MatchResult valueRes = valueMatch.toMatchResult();
matches.add(new MatchResultMatch(matchID, keyRes, valueRes));
}
}
matchHits += matches.size();
return matches;
}
use of org.openstreetmap.osmosis.tagtransform.Match 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.Match in project osmosis by openstreetmap.
the class TagOutput method apply.
@Override
public void apply(Map<String, String> originalTags, Map<String, String> tags, Collection<Match> matches, Map<String, DataSource> dataSources) {
// each and every matching match
if (fromMatch != null) {
DataSource keyDataSourceImpl = this.keyDataSource != null && dataSources.containsKey(this.keyDataSource) ? dataSources.get(this.keyDataSource) : dummyDataSource;
DataSource valueDataSourceImpl = this.valueDataSource != null && dataSources.containsKey(this.valueDataSource) ? dataSources.get(this.valueDataSource) : dummyDataSource;
for (Match match : matches) {
String matchID = match.getMatchID();
if (matchID != null && matchID.equals(fromMatch)) {
// process key args
String[] args = new String[match.getKeyGroupCount()];
for (int i = 0; i < args.length; i++) {
args[i] = match.getKey(i);
}
String key = keyFormat.format(keyDataSourceImpl.transform(args));
// process value args
args = new String[match.getValueGroupCount()];
for (int i = 0; i < args.length; i++) {
args[i] = match.getValue(i);
}
String value = valueFormat.format(valueDataSourceImpl.transform(args));
// put the tag
tags.put(key, value);
}
}
} else {
// simple case
tags.put(keyFormat.format(null), valueFormat.format(null));
}
}
use of org.openstreetmap.osmosis.tagtransform.Match in project osmosis by openstreetmap.
the class TransformHelper method processEntityContainer.
/**
* Transforms entity container according to configFile.
*
* @param entityContainer
* The entity to be processed.
* @return transformed (if needed) entityContainer
*/
protected EntityContainer processEntityContainer(EntityContainer entityContainer) {
// Entities may have been made read-only at some point in the pipeline.
// We want a writeable instance so that we can update the tags.
EntityContainer writeableEntityContainer = entityContainer.getWriteableInstance();
Entity entity = entityContainer.getEntity();
Collection<Tag> entityTags = entity.getTags();
EntityType entityType = entity.getType();
// Store the tags in a map keyed by tag key.
Map<String, String> tagMap = new HashMap<String, String>();
for (Tag tag : entity.getTags()) {
tagMap.put(tag.getKey(), tag.getValue());
}
// Apply tag transformations.
for (Translation translation : translations) {
Collection<Match> matches = translation.match(tagMap, TTEntityType.fromEntityType06(entityType), entity.getUser().getName(), entity.getUser().getId());
if (matches == null || matches.isEmpty()) {
continue;
}
if (translation.isDropOnMatch()) {
return null;
}
Map<String, String> newTags = new HashMap<String, String>();
for (Output output : translation.getOutputs()) {
output.apply(tagMap, newTags, matches, translation.getDataSources());
}
tagMap = newTags;
}
// Replace the entity tags with the transformed values.
entityTags.clear();
for (Entry<String, String> tag : tagMap.entrySet()) {
entityTags.add(new Tag(tag.getKey(), tag.getValue()));
}
return writeableEntityContainer;
}
use of org.openstreetmap.osmosis.tagtransform.Match in project osmosis by openstreetmap.
the class CopyUnmatched method apply.
@Override
public void apply(Map<String, String> originalTags, Map<String, String> tags, Collection<Match> matches, Map<String, DataSource> dataSources) {
// copy the original, then remove the matches
Map<String, String> toCopy = new HashMap<String, String>(originalTags);
for (Match match : matches) {
if (match.getKeyGroupCount() > 0) {
toCopy.remove(match.getKey(0));
}
}
// apply the copy
tags.putAll(toCopy);
}
Aggregations