@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } return foundSoFar; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (Map.Entry<String, JsonNode> entry : _children.entrySet()) { if (fieldName.equals(entry.getKey())) { if (foundSoFar == null) { foundSoFar = new ArrayList<String>(); } foundSoFar.add(entry.getValue().asText()); } else { // only add children if parent not added foundSoFar = entry.getValue().findValuesAsText(fieldName, foundSoFar); } } return foundSoFar; }
@Override public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException { if (!this.isAvailable) return text; Response response = client.accept(MediaType.APPLICATION_JSON) .query("key", apiKey).query("source", sourceLanguage) .query("target", targetLanguage).query("q", text).get(); BufferedReader reader = new BufferedReader(new InputStreamReader( (InputStream) response.getEntity(), UTF_8)); String line = null; StringBuffer responseText = new StringBuffer(); while ((line = reader.readLine()) != null) { responseText.append(line); } ObjectMapper mapper = new ObjectMapper(); JsonNode jsonResp = mapper.readTree(responseText.toString()); return jsonResp.findValuesAsText("translatedText").get(0); }
@Override public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException { if (!this.isAvailable) return text; Response response = client.accept(MediaType.APPLICATION_JSON) .query("user_key", userKey).query("source", sourceLanguage) .query("target", targetLanguage).query("q", text).get(); BufferedReader reader = new BufferedReader(new InputStreamReader( (InputStream) response.getEntity(), UTF_8)); String line = null; StringBuffer responseText = new StringBuffer(); while ((line = reader.readLine()) != null) { responseText.append(line); } ObjectMapper mapper = new ObjectMapper(); JsonNode jsonResp = mapper.readTree(responseText.toString()); if (jsonResp.findValuesAsText("errors").isEmpty()) { return jsonResp.findValuesAsText("translation").get(0); } else { throw new TikaException(jsonResp.findValue("errors").get(0).asText()); } }
JsonNode jsonResp = mapper.readTree(responseText.toString()); if (!jsonResp.findValuesAsText("code").isEmpty()) { String code = jsonResp.findValuesAsText("code").get(0); if (code.equals("200")) { return jsonResp.findValue("text").get(0).asText();
JsonNode jsonResp = responseMapper.readTree(responseText.toString()); if (jsonResp.findValuesAsText("outputText") != null) { return jsonResp.findValuesAsText("outputText").get(0); } else { throw new TikaException(jsonResp.findValue("message").get(0).asText());
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } return foundSoFar; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } return foundSoFar; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } return foundSoFar; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { if (_children != null) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } } return foundSoFar; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { if (_children != null) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } } return foundSoFar; }
@Override public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) { for (JsonNode node : _children) { foundSoFar = node.findValuesAsText(fieldName, foundSoFar); } return foundSoFar; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
/** * Similar to {@link #findValues}, but will additionally convert * values into Strings, calling {@link #asText}. */ public final List<String> findValuesAsText(String fieldName) { List<String> result = findValuesAsText(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; }
@Override public List<String> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); return node.findValuesAsText("prefix"); } }
private static List<String> getNames(JsonNode node) { List<String> names = new ArrayList<>(); names.addAll(node.findValuesAsText("common")); names.addAll(node.findValuesAsText("official")); return names.stream().filter(s -> !Strings.isNullOrEmpty(s)).collect(Collectors.toList()); }