Dialogflow: match multiple entity entries on a single query - dialogflow-es

I have a entity type of say "Example", its type is "map"
Say I have two properties under it: entityA and entityB
entityA and entityB have the same synonym "Textdata"
I have an intent which has a training phrase of #Example
Now when I query "Textdata" only entityA gets matched
I want dialogflow to return all the entities matched which in this case would include entityB as well since entityB also have the textdata synonym
Example EntityType

This isn't possible, Dialogflow only returns one entity per located match. So getting back both entityA and entityB while providing only a single word in your phrase isn't possible.
It could detect both entities if your bot supports phrases where a user mentions both entities in a single phrase. (For example: "Give me all documents named TextData(EntityA) of type TextData(EntityB)). Dialogflow can do this because it also pays attention to the position of words in a sentence when recognizing intents. This does require well defined examples and extra attention to model training.

Related

DDD value object composite identifier

I was trying to understand DDD value objects and entities, and have a minor doubt in that. I've read in a lot of articles that value objects does not have identity. I wanted clarity on whether that the identity referred here is a single attribute or a any composite attributes.
Lets say I have an inventory management service which has a business transaction called "Inventory Adjustment", what it does is simply adjusts the quantity of items at your warehouse. You can create an adjustment with multiple line items, each line item will have an ItemID and Quantity fields.
Note: Lets assume that an item can occur only once in an adjustment, meaning an adjustment cannot have multiple line items with same Item ID.
The user can edit an adjustment line item, delete line items and add new line items as well.
In this context, is adjustmentLineItem a value object OR an entity inside adjustment root aggregate?
The confusion I have is when we say VOs should not have an identity, does that mean it should not have an ID field or a composite identity as well. Because in my case, I would not need an ID field for the line item object, the AdjustmentID + ItemID serves as an identifier for me.
Also, is it fine to have the parent entity identifier inside a VO (like adjustmentID)?
Not related to this context, in general what is the reason why VOs should not have identities?
NOTE: I am relatively new to DDD and my understandings might be wrong.
There's a difference between identifier and identity.
An identifier is a value that identify something, is what an entity use to track its identity.
The identity instead is what tells you that an entity is different from another one, you can use a number to do it (like in case of sql db sequences) or some UUID, or basically use a value that acts as an identifier
Difference between value objects and entities reside in the identity of the latter.
If we have an entity, let's say a Person, and we do a change (mutate) to it (eg. change name), it still remain the same entity (a person changing name still remain the same person). That is not true for value objects, if we have an Address and we change its street it is a different Address.
When we reify this abstraction into code, we need something to track the identity of an entity, to be able to check and confront it with another one. In these cases we add a value in the entity that acts as an identifier, something that we know will stay the same for the entire lifecycle of the entity.
So the identifier can be seen as a value and it can be treat as such.
Then going back to the questions:
It seems to me that in your case the InventoryAdjustment is the entity (it has its own identity), and it contains the list of AdjustmentLineItem that could be seen as a value, containing the ItemId that is also a value.
AdjustmentLineItem is a VO itself
Code to work with things not having an identity is simpler as they can easily be immutable, avoiding a lot of issues (you can look for the immutability topic to understand them, or there's this famous talk about Values)
A final note about this rule:
Lets assume that an item can occur only once in an adjustment
This enforce the fact that the InventoryAdjustment is an entity, and this rule is one of its invariants.
The InventoryAdjustment has a value in it being a List<AdjustmentLineItem>, and could check the rule when someone try to mutate it. When doing domain models, the access for editing purposes to the state of the entity should be disallowed, no setter methods and make impossible for external code of the InventoryAdjustment to do things like:
inventoryAdjustment.getAdjustmentLineItemList().add(anAdjustmentLineItem)
but rather expose methods to do mutation, and internally check invariants:
inventoryAdjustment.addAdjustmentLineItem(anAdjustmentLineItem)

What is the difference between a trait, freetext and keyword and which should I use in wit.ai

I was wondering if somebody could elaborate on the difference between trait, freetext and keywords as search strategies in wit.ai entities? I don't see that much about it on the docs and haven't been able to find anything about it elsewhere. Could somebody please give a few use cases of when each would be the best choice?
Trait: When the entity value is not inferred from a keyword or specific phrase in the sentence. There is no obvious association between certain words in the sentence and the value of the entity, but rather you need the sentence as a whole to determine the value.
Ex: Intent, Sentiment, Politeness
Free Text: When you need to extract a sub string of the message, and this sub string does not belong to a predefined list of possible values.
Ex: Message Body, Contact Name etc.
Keywords: When the entity value belongs to a predefined list, and you just need sub string matching to look it up in the sentence.
Ex: Country, Car Make, Colours, cuisines etc.

Core data model - relationships

I am confused about how to design a Core Data Model for a particular trio of entities -- specifically, the relationships between them.
"Place" is an entity comprised of a name (String) and an address (String).
"Leg" is an entity comprised of a start (Place) and an end (Place).
"Route" is an entity comprised of an arbitrary number of legs (Leg) in a particular order.
In sum, a Route consists of an ordered list of Legs which themselves simply represent straight lines between two Places.
How would I model the relationship between the Leg and Place entities in the data model? Each Leg has exactly two Places (start and end); and any Place could be associated with an unlimited number of Legs, either as a start or an end.
In the Leg entity Add two relationships , one for startPlace and another for endPlace , make their type "To One"
In the Place entity add two inverse relationships (legsByStartPlaceInverse and legsByEndPlaceInverse) and make their type "To Many".
Make sure delete rules are not "Cascade".

DDD: Can an entity have attributes of primitive data types?

The domain driven design differentiates two model types: entities and value objects. In the most examples the attributes of an entity are value objects or other entities, while the attributes of a value object are mostly simple strings, integers etc. (i. e. primitive data types).
That leads me to the question: Can an entity also have attributes of primitive data types? Or do you normally model each attribute of an entity as a value object or another entity?
The following might be an example to answer this question: We have an entity Comment with an attribute text. Is text simply a string variable or a value object?
While it is common attitude to compose an entity of another entities or value objects, it is not necessary. Please remember that you should think about an abstraction. Primitive types are ok when there is no business logic involved in using them. For example:
public class User {
private UserId id;
private String nickname;
private Date joinDate;
}
As you can see, nickname is an primitive type, because we can't do anything special with nickname. On the other hand joinDate should be Value Object, because dates has some logic (as comparing dates, adding, subtracting etc.)
Even in "Implemeting Domain-Driven Design" by Vaughn Vernon are examples of entities composed of primitive types.

Solr How to Populate mutlivalued field from a tokenstream in an analyzer?

How to Populate mutlivalued field from a tokenstream in an analyzer?
I'm relatively new to solr. I understand that multivalued fields are populated before going into the analyzer. However, what I want to do is store particular words from the token stream as multivalued fields after passing through the analyzer.
For example:
I love to eat chicken bacon(token stream) ---> Analyzer ---> eat bacon(after filtering out other words) ---> (store in same but separate field tags) chicken, bacon
You cannot do that.
In fact, multivalued field after tokenizer is one collection of tokens just with appropriate gap offset to avoid overeager matching (that's what positionIncrementGap does).
On the other hand, try faceting on your target field. Facets operate on tokenized (rather than stored values), so you will get a breakdown count separately for chicken and for bacon.

Resources