/** * Resolve a location (which can be many things) to an URL. If the location starts with * {@code classpath:} the location is interpreted as a classpath location. Otherwise it is tried * as a URL, file and at last UIMA resource. If the location is treated as a classpath or file * location, an URL is only returned if the target exists. If it is an URL, it is possible that * the target may not actually exist. * * @param aLocation * a location (classpath, URL, file or UIMA resource location). * @return the resolved URL. * @throws IOException * if the target could not be found. */ public static URL resolveLocation(String aLocation) throws IOException { return resolveLocation(aLocation, null, null); }
public CharacterNGramMeasure(int n, String idfValuesFile) throws IOException { this.n = n; URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null); idf = new HashMap<String, Double>(); for (String line : FileUtils.readLines(new File(resourceUrl.getFile()))) { String[] linesplit = line.split("\t"); idf.put(linesplit[0], Double.parseDouble(linesplit[1])); } }
public CharacterNGramMeasure(int n, String idfValuesFile) throws IOException { this.n = n; URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null); idf = new HashMap<String, Double>(); try (InputStream is = resourceUrl.openStream()) { for (String line : IOUtils.readLines(is, StandardCharsets.UTF_8)) { String[] linesplit = line.split("\t"); idf.put(linesplit[0], Double.parseDouble(linesplit[1])); } } }
public CharacterNGramMeasure(int n, String idfValuesFile) throws IOException { this.n = n; URL resourceUrl = ResourceUtils.resolveLocation(idfValuesFile, this, null); idf = new HashMap<String, Double>(); try (InputStream is = resourceUrl.openStream()) { for (String line : IOUtils.readLines(is, StandardCharsets.UTF_8)) { String[] linesplit = line.split("\t"); idf.put(linesplit[0], Double.parseDouble(linesplit[1])); } } }
public static Set<String> getStopwords(String inputFile, boolean toLowerCase) throws IOException { Set<String> stopwords = new HashSet<String>(); if (inputFile != null) { URL stopUrl = ResourceUtils.resolveLocation(inputFile, null); InputStream is = stopUrl.openStream(); for (String stopword : IOUtils.readLines(is, "UTF-8")) { if (toLowerCase) { stopwords.add(stopword.toLowerCase()); } else { stopwords.add(stopword); } } } return stopwords; }
public static Set<String> getStopwords(String inputFile, boolean toLowerCase) throws IOException { Set<String> stopwords = new HashSet<String>(); if (inputFile != null) { URL stopUrl = ResourceUtils.resolveLocation(inputFile, null); InputStream is = stopUrl.openStream(); for (String stopword : IOUtils.readLines(is, "UTF-8")) { if (toLowerCase) { stopwords.add(stopword.toLowerCase()); } else { stopwords.add(stopword); } } } return stopwords; }
private void init(String functionWordListLocation) throws IOException { functionWords = new ArrayList<String>(); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(functionWordListLocation, this, null); is = url.openStream(); String content = IOUtils.toString(is, "UTF-8"); for (String line : Arrays.asList(content.split("\n"))) { if (line.length() > 0) { functionWords.add(line); } } } finally{ IOUtils.closeQuietly(is); } }
public StopwordNGramContainmentMeasure(int n, String stopwordList) throws IOException { this.n = n; stopwords = new ArrayList<String>(); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(stopwordList, this, null); is = url.openStream(); String content = IOUtils.toString(is, "UTF-8"); for (String line : Arrays.asList(content.split("\n"))) { if (line.length() > 0) stopwords.add(line); } } finally{ IOUtils.closeQuietly(is); } }
public StopwordNGramContainmentMeasure(int n, String stopwordList) throws IOException { this.n = n; stopwords = new ArrayList<String>(); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(stopwordList, this, null); is = url.openStream(); String content = IOUtils.toString(is, "UTF-8"); for (String line : Arrays.asList(content.split("\n"))) { if (line.length() > 0) stopwords.add(line); } } finally{ IOUtils.closeQuietly(is); } }
private void init(String functionWordListLocation) throws IOException { functionWords = new ArrayList<String>(); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(functionWordListLocation, this, null); is = url.openStream(); String content = IOUtils.toString(is, "UTF-8"); for (String line : Arrays.asList(content.split("\n"))) { if (line.length() > 0) { functionWords.add(line); } } } finally{ IOUtils.closeQuietly(is); } }
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); try { URL url = ResourceUtils.resolveLocation(modelLocation); try (InputStream is = url.openStream()) { dict = new HashSet<>(IOUtils.readLines(is ,modelEncoding)); } } catch (IOException e) { throw new ResourceInitializationException(e); } }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } try { URL ngramUrl = ResourceUtils.resolveLocation(ngramLocation, this, null); URL indexUrl = ResourceUtils.resolveLocation(indexLocation, this, null); finder = new Finder(new File(indexUrl.toURI()), new File(ngramUrl.toURI())); } catch (IOException e) { throw new ResourceInitializationException(e); } catch (URISyntaxException e) { throw new ResourceInitializationException(e); } return true; }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } try { final URL uri = ResourceUtils.resolveLocation(resourcePath, this, null); readFileToMap(new BufferedReader(new InputStreamReader(uri.openStream()))); } catch (IOException e) { throw new ResourceInitializationException(e); } return true; }
@Override public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException { if (!super.initialize(aSpecifier, aAdditionalParams)) { return false; } try { final URL uri = ResourceUtils.resolveLocation(resourcePath, this, null); readFileToMap(new BufferedReader(new InputStreamReader(uri.openStream()))); } catch (IOException e) { throw new ResourceInitializationException(e); } return true; }
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); try { mappings = readMappings(ResourceUtils.resolveLocation(modelLocation)); } catch (IOException e) { throw new ResourceInitializationException(e); } }
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); if (xslt != null) { TransformerFactory tf = TransformerFactory.newInstance(); try { URL url = ResourceUtils.resolveLocation(xslt, this, getContext()); transformer = tf.newTransformer(new StreamSource(url.openStream())); } catch (Exception e) { throw new ResourceInitializationException(e); } } cas2xml = new CasToInlineXml(); }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); try { senseMap = WSDUtils.readMap( ResourceUtils.resolveLocation(fileName, this, context), keyColumn, String.class, valueColumn, String.class, delimiterRegex); } catch (Exception e) { throw new ResourceInitializationException(e); } }
@Override public void initialize(final UimaContext context) throws ResourceInitializationException { super.initialize(context); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(dictPath, this, context); this.getLogger().debug("Loading dictionary from " + url); is = url.openStream(); dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding)); } catch (IOException e) { throw new ResourceInitializationException(e); } finally { closeQuietly(is); } }
@Override public void initialize(final UimaContext context) throws ResourceInitializationException { super.initialize(context); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(dictPath, this, context); this.getLogger().debug("Loading dictionary from " + url); is = url.openStream(); dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding)); } catch (IOException e) { throw new ResourceInitializationException(e); } finally { closeQuietly(is); } }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); if (indexSenseFile != null && sourceInventory != null) { throw new ResourceInitializationException( new AnnotatorConfigurationException( AnnotatorConfigurationException.MUTUALLY_EXCLUSIVE_PARAMS, new String[] { PARAM_INDEX_SENSE_FILE + ", " + SOURCE_SENSE_INVENTORY_RESOURCE })); } if (indexSenseFile != null) { try { senseMap = getSenseMap(ResourceUtils.resolveLocation( indexSenseFile, this, context)); } catch (Exception e) { throw new ResourceInitializationException(e); } } }