Relationship entities: isA and hasA

An entity with relationship collection method has a specific relationship to one or more existing entities, either an “isA” or a “hasA” relationship.

isA relationship entities

An isA relationship states that ENTITY_X is a type of ENTITY_Y. The definition of Y is inherited by X, such as Y’s list of literals, as well as any applicable grammars and relationships. Note that while the definition of the child entity is the same as the parent entity, the child entity picks up differences because of its different role in your samples.

For example, say you have a train schedule app and you want to accept queries such as “When is the next train from Boston to New York.” Both “Boston” and “New York” are instances of the STATION entity. If you annotated the query using STATION for both cases, then you would have no way of determining which is the origin and which is the destination. To resolve this, you could instead define two list-type entities, FROM_STATION and TO_STATION, and associate each with the same list of literals. This would, of course, be time consuming and difficult to manage. The better solution is to define one list-type entity STATION with an associated list of cities/stations, and then define FROM_STATION isA STATION, and TO_STATION isA STATION. Now, you only have one list of stations to manage. The model interprets queries and returns FROM_STATION or TO_STATION as appropriate for the roles they play in the query, and returns literals and values from the list associated with the STATION entity.

You can also make isA relationships to predefined entities. For example, AGE is a nuance_CARDINAL_NUMBER.

In Mix, an entity can only have an isA relationship with one entity.

hasA relationship entities

A hasA relationship states that ENTITY_Y is a property or a part of ENTITY_X. That is, ENTITY_X has a ENTITY_Y. For example, the entity FULL_NAME might have the sub-entities GIVEN_NAME and FAMILY_NAME as part of it. The entity DRINK might have COFFEE_TYPE and SIZE as part of it. Note that unlike an isA relationship, an entity can have multiple hasA relationships.

You would use hasA relationships if the entities in your queries have structure. However, Nuance recommends that you use hasA relationships only if you have a definite need, since they can be tricky to work with, and the complexity means the NLU models may be less accurate than desired. An example of a definite need is to be able to interpret a query like “put the red block into the green box”.

In this case you need a way to associate the color red with the block and the color green with the box. Without using hasA relationships the JSON object returned would be flat and you would not know which color went with which object. Using hasA, you would define an OBJECT that has a COLOR and SHAPE. Then the following annotation becomes possible: “put the [OBJECT][COLOR]red[/][SHAPE]block[/][/] into the [OBJECT][COLOR]green[/][SHAPE]box[/][/]”.

Create a new relationship entity

This procedure assumes the entities to which the new relationship entity is related already exist.

  1. Create a new entity and give it a name.

  2. Click on the new entity in the Entities panel to open the editor.

  3. Set the data type and set the collection type to Relationship.

    Select relationships entity type

    A relationships definition editor appears underneath.

    Relationship editor

  4. Click the + icon for the type of relationship entity you want to create, isA or hasA. A dropdown will open allowing you to pick from the existing custom and predefined entities. For isA, you can only select one entity here, while for hasA you can select multiple entities

    Choose related entity

  5. Select one of the sub-entities to which your new entity is related.

  6. Repeat steps 4 and 5 for any other sub-entities in the relationship definition.

The relationship is now defined.

Relationship defined

This procedure assumes that the hasA relationship entity has been defined. It also assumes that you have created an intent that is linked to the hasA relationship entity.

  1. Go to the Develop tab and open the intent containing the sentence.

  2. Click to select the portion of the sentence containing the (outer) hasA entity.

    Select outer entity

    In the entity selection menu that appears, you can see both the outer, hasA entity, as well as the sub-entities to which it is related by a hasA relationship.

  3. Select the hasA entity from the menu. The outer entity will be annotated.

    Annotate outer entity

  4. For each of the inner sub-entities, select the portion of the sentence containing the entity, and select the entity from the menu.

    Annotate inner entities

The sentence is now fully annotated.

Sample annotated

Relationship entities and sensitive flag

Note that an entity defined in relationship to custom entities via isA or hasA does not automatically inherit the sensitive flag from the original entities. You need to separately mark the new entity as sensitive.