How do I locate a snippet based on the location data?


Different locations of the response use the same notation to allow finding the relevant text fragments. The three attributes are:

  • sentence_index – a zero-based index of the sentence where the fragment is located
  • offset – a zero-based position of the first character in the text fragment
  • length – a number of characters in the text fragment

In order to obtain the string:

  1. Obtain the sentence text by traversing to the sentence_list node and picking a node with the index attribute equal to the value of sentence_index. (Alternatively, pick the node as an array member from the array of sentences in the sentence list.)
  2. Obtain a substring from the sentence text with the specified offset and length.

The reason we do not provide an absolute offset is because many users need an actual sentence with the snippet for context.