@Test public void testFindTaggedWords() { String input ="[[\"What\",\"WP\"],[\"is\",\"VBZ\"],[\"the\",\"DT\"],[\"area\",\"NN\"],[\"of\",\"IN\"],[\"the\",\"DT\"],[[\"United\",\"NNP\"],[\"States\",\"NNPS\"]],[\"?\",\".\"]]"; String inputs = "[[\"Who\",\"WP\"],[\"is\",\"VBZ\"],[[\"Bill\",\"NNP\"],[\"Clinton\",\"NNP\"]],[\"'s\",\"POS\"],[\"daughter\",\"NN\"],[\"?\",\".\"]]"; }
public static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags) { ArrayList<String> result = new ArrayList<>(); int size = rootNode.size(); for (int i = 0; i < size; i++) { JsonNode child = rootNode.get(i); List<String> words = findTaggedWords(child, lookForSequence, tags); boolean foundFirstWordInPossibleSequence = false; if (words.size() > 0) { return words; } else { String word = null; if ((word = checkForTaggedWord(child, tags)) != null) { foundFirstWordInPossibleSequence = true; result.add(word); if (!lookForSequence) { return result; } } else { foundFirstWordInPossibleSequence = false; } if ((result.size() > 0) && (!foundFirstWordInPossibleSequence)) { return result; } } } return result; }
NLPUtils { public static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags) { ArrayList<String> result = new ArrayList<>(); int size = rootNode.size(); for (int i = 0; i < size; i++) { JsonNode child = rootNode.get(i); List<String> words = findTaggedWords(child, lookForSequence, tags); boolean foundFirstWordInPossibleSequence = false; if (words.size() > 0) { return words; } else { String word = null; if ((word = checkForTaggedWord(child, tags)) != null) { foundFirstWordInPossibleSequence = true; result.add(word); if (!lookForSequence) { return result; } } else { foundFirstWordInPossibleSequence = false; } if ((result.size() > 0) && (!foundFirstWordInPossibleSequence)) { return result; } } } return result; } }
NLPUtils { public static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags) { ArrayList<String> result = new ArrayList<>(); int size = rootNode.size(); for (int i = 0; i < size; i++) { JsonNode child = rootNode.get(i); List<String> words = findTaggedWords(child, lookForSequence, tags); boolean foundFirstWordInPossibleSequence = false; if (words.size() > 0) { return words; } else { String word = null; if ((word = checkForTaggedWord(child, tags)) != null) { foundFirstWordInPossibleSequence = true; result.add(word); if (!lookForSequence) { return result; } } else { foundFirstWordInPossibleSequence = false; } if ((result.size() > 0) && (!foundFirstWordInPossibleSequence)) { return result; } } } return result; }  }
NLPUtils { public static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags) { ArrayList<String> result = new ArrayList<>(); int size = rootNode.size(); for (int i = 0; i < size; i++) { JsonNode child = rootNode.get(i); List<String> words = findTaggedWords(child, lookForSequence, tags); boolean foundFirstWordInPossibleSequence = false; if (words.size() > 0) { return words; } else { String word = null; if ((word = checkForTaggedWord(child, tags)) != null) { foundFirstWordInPossibleSequence = true; result.add(word); if (!lookForSequence) { return result; } } else { foundFirstWordInPossibleSequence = false; } if ((result.size() > 0) && (!foundFirstWordInPossibleSequence)) { return result; } } } return result; }  static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags); static String checkForTaggedWord(JsonNode child, String... tags); }
NLPUtils { public static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags) { ArrayList<String> result = new ArrayList<>(); int size = rootNode.size(); for (int i = 0; i < size; i++) { JsonNode child = rootNode.get(i); List<String> words = findTaggedWords(child, lookForSequence, tags); boolean foundFirstWordInPossibleSequence = false; if (words.size() > 0) { return words; } else { String word = null; if ((word = checkForTaggedWord(child, tags)) != null) { foundFirstWordInPossibleSequence = true; result.add(word); if (!lookForSequence) { return result; } } else { foundFirstWordInPossibleSequence = false; } if ((result.size() > 0) && (!foundFirstWordInPossibleSequence)) { return result; } } } return result; }  static List<String> findTaggedWords(JsonNode rootNode, boolean lookForSequence, String... tags); static String checkForTaggedWord(JsonNode child, String... tags);  }