Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturoaviles/b2dce666533184ab3598d7cbb9ccea10 to your computer and use it in GitHub Desktop.
Save arturoaviles/b2dce666533184ab3598d7cbb9ccea10 to your computer and use it in GitHub Desktop.
Watson Conversation Entities Proximity in an Input String

Watson Conversation Entities Proximity in an Input String

This method can be used when you want to detect if 2 entities are next to each other

Example #1 Negative Number

In this example you get -1 if the entities are next to each other, you can change the order of the operation like in the example 2 to get the positive number 1.

Formula

<? @entity1.location.get(1) - @entity2.location.get(0) ?>

Analysis

  entity1: hello
  entity2: bye
  
  Input: hello bye
  
  entity1.location = [0, 4]
  entity2.location = [5, 7]
  
  entity1.location.get(1) = 4
  entity2.location.get(0) = 5
  
  entity1.location.get(1) - entity2.location.get(0) = -1

Example #2 Positive Number

In this example you get 1 if the entity is next to the other.

Formula

<? @entity2.location.get(0) - @entity1.location.get(1) ?>

Analysis

  entity1: big
  entity2: sun
  
  Input: big sun
  
  entity1.location = [0, 2]
  entity2.location = [3, 5]
  
  entity1.location.get(1) = 2
  entity2.location.get(0) = 3
  
  entity2.location.get(0) - entity1.location.get(1) = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment