use of com.google.cloud.dialogflow.cx.v3beta1.EntityType in project osmosis by openstreetmap.
the class AreaFilter method emitRelation.
/**
* Sends a relation to the sink. This will perform any necessary transformations on the way before
* sending it.
*
* @param relationContainer
* Relation to be sent.
*/
private void emitRelation(RelationContainer relationContainer) {
if (clipIncompleteEntities) {
RelationContainer filteredRelationContainer;
Relation filteredRelation;
filteredRelationContainer = relationContainer.getWriteableInstance();
filteredRelation = filteredRelationContainer.getEntity();
// Remove members for entities that are unavailable.
for (Iterator<RelationMember> i = filteredRelation.getMembers().iterator(); i.hasNext(); ) {
RelationMember member = i.next();
EntityType memberType;
long memberId;
memberType = member.getMemberType();
memberId = member.getMemberId();
switch(memberType) {
case Node:
if (!availableNodes.get(memberId)) {
i.remove();
}
break;
case Way:
if (!availableWays.get(memberId)) {
i.remove();
}
break;
case Relation:
if (!availableRelations.get(memberId)) {
i.remove();
}
break;
default:
break;
}
}
// Only add relations that contain entities.
if (filteredRelation.getMembers().size() > 0) {
sink.process(filteredRelationContainer);
}
} else {
sink.process(relationContainer);
}
}
use of com.google.cloud.dialogflow.cx.v3beta1.EntityType 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 com.google.cloud.dialogflow.cx.v3beta1.EntityType in project osmosis by openstreetmap.
the class FastXmlParser method readRelationMember.
private RelationMember readRelationMember() throws Exception {
long id;
EntityType type;
String role;
id = Long.parseLong(reader.getAttributeValue(null, ATTRIBUTE_NAME_REF));
type = memberTypeParser.parse(reader.getAttributeValue(null, ATTRIBUTE_NAME_TYPE));
role = reader.getAttributeValue(null, ATTRIBUTE_NAME_ROLE);
RelationMember relationMember = new RelationMember(id, type, role);
reader.nextTag();
reader.nextTag();
return relationMember;
}
use of com.google.cloud.dialogflow.cx.v3beta1.EntityType in project entity-service by hypertrace.
the class EntityTypeDocumentTest method testProtoConversion.
@Test
public void testProtoConversion() {
EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").setTimestampAttributeKey("timestamp").addRequiredConditions(EntityFormationCondition.newBuilder().setRequiredKey("other")).build();
Assertions.assertEquals(entityType, EntityTypeDocument.fromProto("testTenant", entityType).toProto());
}
use of com.google.cloud.dialogflow.cx.v3beta1.EntityType in project entity-service by hypertrace.
the class EntityTypeDocumentTest method testFromJsonMissingField.
@Test
public void testFromJsonMissingField() throws InvalidProtocolBufferException, JsonProcessingException {
EntityType entityType = EntityType.newBuilder().setName("API").setAttributeScope("API").setIdAttributeKey("id").setNameAttributeKey("name").build();
String entityTypeJson = JsonFormat.printer().print(entityType);
Assertions.assertEquals(entityType, EntityTypeDocument.fromJson(entityTypeJson).toProto());
}
Aggregations