// Path: src/deplambda/others/SentenceKeys.java
// public class SentenceKeys extends in.sivareddy.util.SentenceKeys {
//   public static String DEPLAMBDA_OBLIQUE_TREE = "deplambda_oblique_tree";
//   public static String DEPLAMBDA_EXPRESSION = "deplambda_expression";
// }


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import deplambda.others.SentenceKeys;
package deplambda.util;




/**
 * @author Siva Reddy
 *
 */
public class Sentence {
  private List<DependencyTree> nodes;
  private DependencyTree rootNode;
  private Map<Integer, JsonObject> wordIndexToEntity;
  private JsonArray words;

  /**
   * Constructs {@link Sentence} from json object.
   * 
   * @param sentence
   */
  public Sentence(JsonObject sentence) {
    wordIndexToEntity = new HashMap<>();
    nodes = new ArrayList<>();
    buildWordToEntityMap(sentence, wordIndexToEntity);
    Preconditions.checkArgument(sentence.has("words"),
        "Sentence should have the key 'words'");
    words = sentence.get("words").getAsJsonArray();
    rootNode = DependencyTree.parse(words, wordIndexToEntity, nodes);
  }

  public JsonObject getEntityAtWordIndex(int index) {
    return wordIndexToEntity.containsKey(index) ? wordIndexToEntity.get(index)
        : null;
  }

  /**
   * Constructs a map from word index to entity object.
   * 
   * @param sentence
   * @param wordIndexToEntity
   */
  private static void buildWordToEntityMap(JsonObject sentence,
      Map<Integer, JsonObject> wordIndexToEntity) {
// Path: src/deplambda/others/SentenceKeys.java
// public class SentenceKeys extends in.sivareddy.util.SentenceKeys {
//   public static String DEPLAMBDA_OBLIQUE_TREE = "deplambda_oblique_tree";
//   public static String DEPLAMBDA_EXPRESSION = "deplambda_expression";
// }


// Path: src/deplambda/util/Sentence.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import deplambda.others.SentenceKeys;

package deplambda.util;




/**
 * @author Siva Reddy
 *
 */
public class Sentence {
  private List<DependencyTree> nodes;
  private DependencyTree rootNode;
  private Map<Integer, JsonObject> wordIndexToEntity;
  private JsonArray words;

  /**
   * Constructs {@link Sentence} from json object.
   * 
   * @param sentence
   */
  public Sentence(JsonObject sentence) {
    wordIndexToEntity = new HashMap<>();
    nodes = new ArrayList<>();
    buildWordToEntityMap(sentence, wordIndexToEntity);
    Preconditions.checkArgument(sentence.has("words"),
        "Sentence should have the key 'words'");
    words = sentence.get("words").getAsJsonArray();
    rootNode = DependencyTree.parse(words, wordIndexToEntity, nodes);
  }

  public JsonObject getEntityAtWordIndex(int index) {
    return wordIndexToEntity.containsKey(index) ? wordIndexToEntity.get(index)
        : null;
  }

  /**
   * Constructs a map from word index to entity object.
   * 
   * @param sentence
   * @param wordIndexToEntity
   */
  private static void buildWordToEntityMap(JsonObject sentence,
      Map<Integer, JsonObject> wordIndexToEntity) {
    if (sentence.has(SentenceKeys.ENTITIES)) {