// Path: src/deplambda/util/Sentence.java
// 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)) {
//       JsonArray entities = sentence.get(SentenceKeys.ENTITIES).getAsJsonArray();
//       for (JsonElement entityElement : entities) {
//         JsonObject entity = entityElement.getAsJsonObject();
// 
//         Preconditions.checkArgument(
//             entity.has(SentenceKeys.ENTITY_INDEX)
//                 || (entity.has(SentenceKeys.START) && entity
//                     .has(SentenceKeys.END)),
//             "An entity should have an index, or a start and an end.");
// 
//         if (!entity.has(SentenceKeys.START)) {
//           int entityIndex = entity.get(SentenceKeys.ENTITY_INDEX).getAsInt();
//           entity.addProperty(SentenceKeys.START, entityIndex);
//           entity.addProperty(SentenceKeys.END, entityIndex);
//         }
// 
//         int start = entity.get(SentenceKeys.START).getAsInt();
//         int end = entity.get(SentenceKeys.END).getAsInt();
// 
//         if (!entity.has(SentenceKeys.ENTITY_INDEX)) {
//           // The last word is the index of the whole entity.
//           entity.addProperty(SentenceKeys.ENTITY_INDEX, end);
//         }
// 
//         while (start <= end) {
//           wordIndexToEntity.put(start, entity);
//           start++;
//         }
//       }
//     }
//   }
// 
//   public JsonArray getWords() {
//     return words;
//   }
// 
//   public DependencyTree getRootNode() {
//     return rootNode;
//   }
// 
//   public String getLemma(int index) {
//     JsonObject word = getWords().get(index).getAsJsonObject();
//     return word.has(SentenceKeys.LEMMA_KEY)
//         && !word.get(SentenceKeys.LEMMA_KEY).getAsString().equals("_") ? word
//         .get(SentenceKeys.LEMMA_KEY).getAsString().toLowerCase() : word
//         .get(SentenceKeys.WORD_KEY).getAsString().toLowerCase();
//   }
// }


import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import deplambda.util.Sentence;
/**
 * 
 */
package deplambda.util;





/**
 * @author Siva Reddy
 *
 */
public class SentenceTest {

  private static JsonParser json = new JsonParser();

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() {
  }

  /**
   * Test method for
   * {@link deplambda.util.Sentence#Sentence(com.google.gson.JsonObject)}.
   */
  @Test
  public void testSentence() {
    JsonObject jsonSentence = json
        .parse(
            "{\"entities\": [{\"start\": 0, \"ner\": \"ORGANIZATION\", \"end\": 1, \"entity\": \"m.0k8z\"}, {\"start\": 3, \"ner\": \"PERSON\", \"end\": 4, \"entity\": \"m.06y3r\"}, {\"start\": 8, \"ner\": \"MISC\", \"end\": 9, \"entity\": \"m.04yg_s\"}], \"words\": [{\"word\":\"Apple\",\"head\":2,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"Inc.\",\"head\":8,\"pos\":\"NNP\",\"dep\":\"nsubj\"}, {\"word\":\"which\",\"head\":6,\"pos\":\"WP\",\"dep\":\"dobj\"}, {\"word\":\"Steve\",\"head\":5,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"Jobs\",\"head\":6,\"pos\":\"NNP\",\"dep\":\"nsubj\"}, {\"word\":\"founded\",\"head\":2,\"pos\":\"VBD\",\"dep\":\"rcmod\", \"lemma\":\"found\"}, {\"word\":\",\",\"head\":2,\"pos\":\".\",\"dep\":\"p\"}, {\"word\":\"developed\",\"head\":0,\"pos\":\"VBD\",\"dep\":\"ROOT\"}, {\"word\":\"iPod\",\"head\":10,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"shuffle\",\"head\":8,\"pos\":\"NN\",\"dep\":\"dobj\"}, {\"word\":\".\",\"head\":8,\"pos\":\".\",\"dep\":\"p\"}]}")
        .getAsJsonObject();
// Path: src/deplambda/util/Sentence.java
// 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)) {
//       JsonArray entities = sentence.get(SentenceKeys.ENTITIES).getAsJsonArray();
//       for (JsonElement entityElement : entities) {
//         JsonObject entity = entityElement.getAsJsonObject();
// 
//         Preconditions.checkArgument(
//             entity.has(SentenceKeys.ENTITY_INDEX)
//                 || (entity.has(SentenceKeys.START) && entity
//                     .has(SentenceKeys.END)),
//             "An entity should have an index, or a start and an end.");
// 
//         if (!entity.has(SentenceKeys.START)) {
//           int entityIndex = entity.get(SentenceKeys.ENTITY_INDEX).getAsInt();
//           entity.addProperty(SentenceKeys.START, entityIndex);
//           entity.addProperty(SentenceKeys.END, entityIndex);
//         }
// 
//         int start = entity.get(SentenceKeys.START).getAsInt();
//         int end = entity.get(SentenceKeys.END).getAsInt();
// 
//         if (!entity.has(SentenceKeys.ENTITY_INDEX)) {
//           // The last word is the index of the whole entity.
//           entity.addProperty(SentenceKeys.ENTITY_INDEX, end);
//         }
// 
//         while (start <= end) {
//           wordIndexToEntity.put(start, entity);
//           start++;
//         }
//       }
//     }
//   }
// 
//   public JsonArray getWords() {
//     return words;
//   }
// 
//   public DependencyTree getRootNode() {
//     return rootNode;
//   }
// 
//   public String getLemma(int index) {
//     JsonObject word = getWords().get(index).getAsJsonObject();
//     return word.has(SentenceKeys.LEMMA_KEY)
//         && !word.get(SentenceKeys.LEMMA_KEY).getAsString().equals("_") ? word
//         .get(SentenceKeys.LEMMA_KEY).getAsString().toLowerCase() : word
//         .get(SentenceKeys.WORD_KEY).getAsString().toLowerCase();
//   }
// }


// Path: test/deplambda/util/SentenceTest.java
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import deplambda.util.Sentence;

/**
 * 
 */
package deplambda.util;





/**
 * @author Siva Reddy
 *
 */
public class SentenceTest {

  private static JsonParser json = new JsonParser();

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() {
  }

  /**
   * Test method for
   * {@link deplambda.util.Sentence#Sentence(com.google.gson.JsonObject)}.
   */
  @Test
  public void testSentence() {
    JsonObject jsonSentence = json
        .parse(
            "{\"entities\": [{\"start\": 0, \"ner\": \"ORGANIZATION\", \"end\": 1, \"entity\": \"m.0k8z\"}, {\"start\": 3, \"ner\": \"PERSON\", \"end\": 4, \"entity\": \"m.06y3r\"}, {\"start\": 8, \"ner\": \"MISC\", \"end\": 9, \"entity\": \"m.04yg_s\"}], \"words\": [{\"word\":\"Apple\",\"head\":2,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"Inc.\",\"head\":8,\"pos\":\"NNP\",\"dep\":\"nsubj\"}, {\"word\":\"which\",\"head\":6,\"pos\":\"WP\",\"dep\":\"dobj\"}, {\"word\":\"Steve\",\"head\":5,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"Jobs\",\"head\":6,\"pos\":\"NNP\",\"dep\":\"nsubj\"}, {\"word\":\"founded\",\"head\":2,\"pos\":\"VBD\",\"dep\":\"rcmod\", \"lemma\":\"found\"}, {\"word\":\",\",\"head\":2,\"pos\":\".\",\"dep\":\"p\"}, {\"word\":\"developed\",\"head\":0,\"pos\":\"VBD\",\"dep\":\"ROOT\"}, {\"word\":\"iPod\",\"head\":10,\"pos\":\"NNP\",\"dep\":\"nn\"}, {\"word\":\"shuffle\",\"head\":8,\"pos\":\"NN\",\"dep\":\"dobj\"}, {\"word\":\".\",\"head\":8,\"pos\":\".\",\"dep\":\"p\"}]}")
        .getAsJsonObject();
    Sentence sent = new Sentence(jsonSentence);