/** * Translate the given text InputStream to the given language, attempting to auto-detect the source language. * This does not close the stream, so the caller has the responsibility of closing it. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param targetLanguage The desired output language (for example, "en"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
/** * Translate the given text InputStream to and from the given languages. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param sourceLanguage The input text language (for example, "hi"). * @param targetLanguage The desired output language (for example, "fr"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String sourceLanguage, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
private String readStream(InputStream stream) throws IOException { return IOUtils.toString(stream, UTF_8.name()); }
/** * Loads the class to * * @param stream label index stream * @return Map of integer -> label name * @throws IOException when the stream breaks unexpectedly * @throws ParseException when the input doesn't contain a valid JSON map */ public Map<Integer, String> loadClassIndex(InputStream stream) throws IOException, ParseException { String content = IOUtils.toString(stream); JSONObject jIndex = (JSONObject) new JSONParser().parse(content); Map<Integer, String> classMap = new HashMap<>(); for (Object key : jIndex.keySet()) { JSONArray names = (JSONArray) jIndex.get(key); classMap.put(Integer.parseInt(key.toString()), names.get(names.size() - 1).toString()); } return classMap; }
public static void main(String[] args) throws IOException, JSONException { if (args.length != 1) { System.err.println("Error: Invalid Args"); System.err.println("This tool finds names inside text"); System.err.println("Usage: <path/to/text/file>"); return; } try (FileInputStream stream = new FileInputStream(args[0])) { String text = IOUtils.toString(stream); CoreNLPNERecogniser ner = new CoreNLPNERecogniser(); Map<String, Set<String>> names = ner.recognise(text); JSONObject jNames = new JSONObject(names); System.out.println(jNames.toString(2)); } } }
String replyMessage = IOUtils.toString(reply); if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);
String replyMessage = IOUtils.toString(reply); if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = new JSONObject(replyMessage);
private List<Metadata> generateListFromTextFile(Reader reader, FileSuffixes fileSuffixes) throws IOException { List<Metadata> metadataList = new ArrayList<>(); String content = IOUtils.toString(reader); Metadata m = new Metadata(); m.set(AbstractRecursiveParserWrapperHandler.TIKA_CONTENT, content); if (fileSuffixes.format == FileSuffixes.FORMAT.HTML) { m.set(RecursiveParserWrapperHandler.TIKA_CONTENT_HANDLER, ToXMLContentHandler.class.getSimpleName()); } else if (fileSuffixes.format == FileSuffixes.FORMAT.TXT) { m.set(RecursiveParserWrapperHandler.TIKA_CONTENT_HANDLER, ToTextContentHandler.class.getSimpleName()); } //Let's hope the file name has a suffix that can //be used to determine the mime. Could be wrong or missing, //but better than nothing. m.set(TikaCoreProperties.RESOURCE_NAME_KEY, fileSuffixes.originalFileName); MediaType mimeType = tikaConfig.getMimeRepository().detect(null, m); if (mimeType != null) { m.set(Metadata.CONTENT_TYPE, mimeType.toString()); } metadataList.add(m); return metadataList; }
contents = IOUtils.toString(reader);
/** * Translate the given text InputStream to and from the given languages. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param sourceLanguage The input text language (for example, "hi"). * @param targetLanguage The desired output language (for example, "fr"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String sourceLanguage, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
/** * Translate the given text InputStream to the given language, attempting to auto-detect the source language. * This does not close the stream, so the caller has the responsibility of closing it. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param targetLanguage The desired output language (for example, "en"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
/** * Translate the given text InputStream to and from the given languages. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param sourceLanguage The input text language (for example, "hi"). * @param targetLanguage The desired output language (for example, "fr"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String sourceLanguage, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), sourceLanguage, targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
/** * Translate the given text InputStream to the given language, attempting to auto-detect the source language. * This does not close the stream, so the caller has the responsibility of closing it. * @see org.apache.tika.language.translate.Translator * @param text The text to translate. * @param targetLanguage The desired output language (for example, "en"). * @return The translated text. If translation is unavailable (client keys not set), returns the same text back. */ public String translate(InputStream text, String targetLanguage){ try { return translator.translate(IOUtils.toString(text), targetLanguage); } catch (Exception e){ throw new IllegalStateException("Error translating data.", e); } }
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Error: Invalid Args"); System.err.println("This tool finds names inside text"); System.err.println("Usage: <path/to/text/file>"); return; } try (FileInputStream stream = new FileInputStream(args[0])) { String text = IOUtils.toString(stream); CoreNLPNERecogniser ner = new CoreNLPNERecogniser(); Map<String, Set<String>> names = ner.recognise(text); JSONObject jNames = new JSONObject(names); System.out.println(jNames.toString(2)); } } }
public static void main(String[] args) throws IOException, JSONException { if (args.length != 1) { System.err.println("Error: Invalid Args"); System.err.println("This tool finds names inside text"); System.err.println("Usage: <path/to/text/file>"); return; } try (FileInputStream stream = new FileInputStream(args[0])) { String text = IOUtils.toString(stream); CoreNLPNERecogniser ner = new CoreNLPNERecogniser(); Map<String, Set<String>> names = ner.recognise(text); JSONObject jNames = new JSONObject(names); System.out.println(jNames.toString(2)); } } }
static String htmlHeader(String title) { String header = "<html>\n"; header += " <head>\n"; header += " <title>Migration report" + (StringUtils.isBlank(title) ? "" : ": " + title) + "</title>\n"; String style = null; try { String[] resources = ClasspathResourcesUtil.findResources("/report-generator/migration-report.css"); if (resources != null && resources.length > 0) { InputStream in = DefaultReportGenerator.class.getResourceAsStream(resources[0]); style = IOUtils.toString(in); IOUtils.closeQuietly(in); } } catch (IOException e) { log.error("Cannot load CSS style: "+e.getMessage()); log.debug("Cannot load CSS style.", e); } if (style!=null) { header += "<style>\n"; header += style; header += "</style>\n"; } header += " </head>\n"; header += " <body>\n"; header += " <h1>Migration report</h1>\n\n"; return header; }
public List<String> getReferenceFiles(Node rootNode,String path,String searchText) throws Exception{ List<String> referenceFiles=new ArrayList<String>(); List<String> files=getFiles(rootNode, path); for(String nodePath:files){ InputStream inputStream=repositoryService.readFile(nodePath,null); try { String content = IOUtils.toString(inputStream); inputStream.close(); boolean containPath=content.contains(path); boolean containText=content.contains(searchText); if(containPath && containText){ referenceFiles.add(nodePath); } } catch (IOException e) { throw new RuleException(e); } } return referenceFiles; }
String replyMessage = IOUtils.toString(reply); if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = new JSONObject(replyMessage);
String replyMessage = IOUtils.toString(reply); if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage);
String replyMessage = IOUtils.toString(reply); if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = new JSONObject(replyMessage);