List of usage examples for com.google.common.io Resources readLines
public static List<String> readLines(URL url, Charset charset) throws IOException
From source file:nl.matching.app.webapp.MatchingApp.java
private static String readLines(final String resourceName) { try {/* w ww .j a v a 2 s .com*/ List<String> readLines = Resources.readLines(Resources.getResource(MatchingApp.class, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (IOException e) { return "This is Quick Start"; } }
From source file:edu.cmu.lti.oaqa.bioasq.concept.rerank.scorers.GoPubMedConceptRetrievalScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); String conf = String.class.cast(getParameterValue("conf")); PropertiesConfiguration gopubmedProperties = new PropertiesConfiguration(); try {/*from ww w . j av a2 s .com*/ gopubmedProperties.load(getClass().getResourceAsStream(conf)); } catch (ConfigurationException e) { throw new ResourceInitializationException(e); } service = new GoPubMedService(gopubmedProperties); pages = Integer.class.cast(getParameterValue("pages")); hits = Integer.class.cast(getParameterValue("hits")); timeout = Integer.class.cast(getParameterValue("timeout")); String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try { stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream().map(String::trim) .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } uri2conf2score = HashBasedTable.create(); uri2conf2rank = HashBasedTable.create(); return true; }
From source file:webapp.SimpleApplication.java
private static String readLines(final String resourceName) { try {// ww w .j a va2s.c o m List<String> readLines = Resources.readLines( Resources.getResource(SimpleApplication.class, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (IOException e) { return "This is Quick Start"; } }
From source file:edu.cmu.lti.oaqa.baseqa.passage.rerank.scorers.LuceneInMemoryPassageScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); hits = Integer.class.cast(getParameterValue("hits")); // query constructor String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try {/*from w w w . ja va2 s. com*/ stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream().map(String::trim) .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } analyzer = new StandardAnalyzer(); parser = new QueryParser("text", analyzer); return true; }
From source file:webapp.InformaticaApplication.java
private static String readLines(final String resourceName) { try {//from w ww .ja v a 2 s . co m List<String> readLines = Resources.readLines( Resources.getResource(InformaticaApplication.class, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (IOException e) { return "This is Quick Start"; } }
From source file:org.incode.eurocommercial.contactapp.webapp.ContactApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {/*from w w w . j av a2 s . c om*/ final List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (final IOException e) { return "This is the ECP Contact App"; } }
From source file:edu.cmu.lti.oaqa.baseqa.document.rerank.LogRegDocumentReranker.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); hits = UimaContextHelper.getConfigParameterIntValue(context, "hits", 100); analyzer = UimaContextHelper.createObjectFromConfigParameter(context, "query-analyzer", "query-analyzer-params", StandardAnalyzer.class, Analyzer.class); queryStringConstructor = UimaContextHelper.createObjectFromConfigParameter(context, "query-string-constructor", "query-string-constructor-params", LuceneQueryStringConstructor.class, QueryStringConstructor.class); parser = new QueryParser("text", analyzer); // load parameters String param = UimaContextHelper.getConfigParameterStringValue(context, "doc-logreg-params"); try {//from ww w . ja v a 2s .c o m docFeatWeights = Resources.readLines(getClass().getResource(param), UTF_8).stream().limit(1) .map(line -> line.split("\t")).flatMap(Arrays::stream).mapToDouble(Double::parseDouble) .toArray(); } catch (IOException e) { throw new ResourceInitializationException(e); } }
From source file:edu.cmu.lti.oaqa.baseqa.document.rerank.scorers.LuceneDocumentScorer.java
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { super.initialize(aSpecifier, aAdditionalParams); hits = Integer.class.cast(getParameterValue("hits")); // query constructor String stoplistPath = String.class.cast(getParameterValue("stoplist-path")); try {// w ww .j a v a 2 s. c om stoplist = Resources.readLines(getClass().getResource(stoplistPath), UTF_8).stream().map(String::trim) .collect(toSet()); } catch (IOException e) { throw new ResourceInitializationException(e); } // load index parameters idFieldName = String.class.cast(getParameterValue("id-field")); //noinspection unchecked fields = Iterables.toArray((Iterable<String>) getParameterValue("fields"), String.class); uriPrefix = String.class.cast(getParameterValue("uri-prefix")); String index = String.class.cast(getParameterValue("index")); // create lucene analyzer = new StandardAnalyzer(); try { reader = DirectoryReader.open(NIOFSDirectory.open(Paths.get(index))); } catch (IOException e) { throw new ResourceInitializationException(e); } searcher = new IndexSearcher(reader); return true; }
From source file:org.isisaddons.module.poly.webapp.PolyApplication.java
private static String readLines(final Class<?> contextClass, final String resourceName) { try {//w w w . jav a2s . c o m List<String> readLines = Resources.readLines(Resources.getResource(contextClass, resourceName), Charset.defaultCharset()); final String aboutText = Joiner.on("\n").join(readLines); return aboutText; } catch (IOException e) { return "This is the polymorphic references demo app"; } }
From source file:com.google.zxing.web.DecodeServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { Logger logger = Logger.getLogger("com.google.zxing"); ServletContext context = servletConfig.getServletContext(); logger.addHandler(new ServletContextLogHandler(context)); URL blockURL = context.getClassLoader().getResource("/private/uri-block-substrings.txt"); if (blockURL == null) { blockedURLSubstrings = Collections.emptyList(); } else {/* w w w.j a va 2s. c om*/ try { blockedURLSubstrings = Resources.readLines(blockURL, StandardCharsets.UTF_8); } catch (IOException ioe) { throw new ServletException(ioe); } log.info("Blocking URIs containing: " + blockedURLSubstrings); } }