/** * Load the file. * * @param path path to .fex file * @throws Exception */ public FeatureManifest(String path) throws Exception { this(IOUtils.lsResources(FeatureManifest.class, path).get(0).openStream()); }
/** * Load the file. * * @param path path to .fex file * @throws Exception */ public FeatureManifest(String path) throws Exception { this(IOUtils.lsResources(FeatureManifest.class, path).get(0).openStream()); }
public static <T> T readObjectAsResource(Class clazz, String fileName) throws Exception { List<URL> lsResources = IOUtils.lsResources(clazz, fileName); assert lsResources.size() > 0; URL resource = lsResources.get(0); InputStream stream = resource.openStream(); ObjectInputStream in = new ObjectInputStream(stream); @SuppressWarnings("unchecked") T obj = (T) in.readObject(); in.close(); return obj; }
public static <T> T readObjectAsResource(Class clazz, String fileName) throws Exception { List<URL> lsResources = IOUtils.lsResources(clazz, fileName); assert lsResources.size() > 0; URL resource = lsResources.get(0); InputStream stream = resource.openStream(); ObjectInputStream in = new ObjectInputStream(stream); @SuppressWarnings("unchecked") T obj = (T) in.readObject(); in.close(); return obj; }
/** * Lists the contents of a directory that exists either in the local path or in the classpath * * @param resourceDir The name of the directory containing the gazetteers * @return An array of URL objects to be read * @throws IOException * @throws */ public URL[] listGazetteers(String resourceDir) throws IOException { List<URL> files = new ArrayList<>(); try { for (URL url : IOUtils.lsResources(SimpleGazetteerAnnotator.class, resourceDir)) { files.add(url); } } catch (URISyntaxException e) { throw new IOException("URI syntax error.", e); } return files.toArray(new URL[files.size()]); }
/** * Lists the contents of a directory that exists either in the local path or in the classpath * * @param resourceDir The name of the directory containing the gazetteers * @return An array of URL objects to be read * @throws IOException * @throws */ public URL[] listGazetteers(String resourceDir) throws IOException { List<URL> files = new ArrayList<>(); try { for (URL url : IOUtils.lsResources(SimpleGazetteerAnnotator.class, resourceDir)) { files.add(url); } } catch (URISyntaxException e) { throw new IOException("URI syntax error.", e); } return files.toArray(new URL[files.size()]); }
public static BufferedReader getReader( String fileName ) throws IOException { // InputStream inStrm = ClassLoader.getSystemResourceAsStream( fileName ); InputStream inStrm; try { inStrm = IOUtils.lsResources(MappingReader.class, fileName).get(0).openStream(); } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } // InputStream is = this.getClass().getResourceAsStream( name_ ); if (inStrm == null) { // try with a leading slash inStrm = ClassLoader.getSystemResourceAsStream("/" + fileName ); if (inStrm == null) // try as absolute or correct local path inStrm = new FileInputStream( fileName); } BufferedReader reader = new BufferedReader( new InputStreamReader( inStrm, "UTF-8" ) ); return reader; }
public static BufferedReader getReader(String fileName) throws IOException { // InputStream inStrm = ClassLoader.getSystemResourceAsStream( fileName // ); InputStream inStrm; try { inStrm = IOUtils.lsResources(MappingReader.class, fileName).get(0).openStream(); } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } // InputStream is = this.getClass().getResourceAsStream( name_ ); if (inStrm == null) { // try with a leading slash inStrm = ClassLoader.getSystemResourceAsStream("/" + fileName); if (inStrm == null) // try as absolute or correct local path inStrm = new FileInputStream(fileName); } BufferedReader reader = new BufferedReader(new InputStreamReader(inStrm, "UTF-8")); return reader; }
@SuppressWarnings("resource") private void loadClustersFromClassPath() throws Exception { logger.debug("Loading brown clusters from {}", file); List<URL> resources = IOUtils.lsResources(BrownClusterViewGenerator.class, file); InputStream stream; if (resources.size() == 0) { stream = new FileInputStream(file); } else { URL url = resources.get(0); stream = url.openStream(); } if (gzip) stream = new GZIPInputStream(stream); loadFromInputStream(stream); }
@SuppressWarnings("resource") private void loadClustersFromClassPath() throws Exception { logger.debug("Loading brown clusters from {}", file); List<URL> resources = IOUtils.lsResources(BrownClusterViewGenerator.class, file); InputStream stream; if (resources.size() == 0) { stream = new FileInputStream(file); } else { URL url = resources.get(0); stream = url.openStream(); } if (gzip) stream = new GZIPInputStream(stream); loadFromInputStream(stream); }
public static List<String> readFromClasspath(String filename) { List<String> lines = null; try { InputStream resource = IOUtils.lsResources(IllinoisLemmatizer.class, filename).get(0).openStream(); lines = LineIO.read(resource, Charset.defaultCharset().name(), new ITransformer<String, String>() { public String transform(String line) { return line; } }); } catch (IOException | URISyntaxException e) { System.err.println("Error while trying to read " + filename + "."); System.exit(-1); } return lines; }
public NomLexReader(String nomLexFile) throws Exception { InputStream stream; if (!new File(nomLexFile).exists()) { logger.info("Loading {} from classpath", nomLexFile); List<URL> list = IOUtils.lsResources(NomLexReader.class, nomLexFile); if (list.isEmpty()) { logger.error("Could not load " + nomLexFile); System.exit(-1); } stream = list.get(0).openStream(); } else { logger.info("Loading {} from local directory", nomLexFile); stream = new FileInputStream(nomLexFile); } BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); nomLex = new HashMap<>(); pluralToSingularMap = new HashMap<>(); readNomLexLisp(reader); }
VerbLemmaDictionary(Logger log) throws IOException, URISyntaxException, EdisonException { Map<String, String> mm = new HashMap<>(); String file = "verb-lemDict.txt"; InputStream in = IOUtils.lsResources(VerbLemmaDictionary.class, file).get(0).openStream(); log.info("Found file {} in the classpath", file); Scanner scanner = new Scanner(in); int count = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.length() == 0) continue; String[] parts = line.split("\\s+"); String lemma = parts[0]; for (String p : parts) { mm.put(p, lemma); } count++; } log.info("{} verb lemmas found", count); map = Collections.unmodifiableMap(mm); }
public static List<String> readFromClasspath(String filename) { List<String> lines = null; try { InputStream resource = IOUtils.lsResources(IllinoisLemmatizer.class, filename).get(0).openStream(); lines = LineIO.read(resource, Charset.defaultCharset().name(), new ITransformer<String, String>() { public String transform(String line) { return line; } }); } catch (IOException | URISyntaxException e) { System.err.println("Error while trying to read " + filename + "."); System.exit(-1); } return lines; }
private synchronized void loadFromClassPath() throws Exception { if (loaded) return; List<URL> urls = IOUtils.lsResources(RogetThesaurusFeatures.class, fileName); if (urls.size() == 0) throw new EdisonException("Cannot find " + fileName + " in the classpath"); loadWithURL(urls.get(0)); }
public NomLexReader(String nomLexFile) throws Exception { InputStream stream; if (!new File(nomLexFile).exists()) { logger.info("Loading {} from classpath", nomLexFile); List<URL> list = IOUtils.lsResources(NomLexReader.class, nomLexFile); if (list.isEmpty()) { logger.error("Could not load " + nomLexFile); System.exit(-1); } stream = list.get(0).openStream(); } else { logger.info("Loading {} from local directory", nomLexFile); stream = new FileInputStream(nomLexFile); } BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); nomLex = new HashMap<>(); pluralToSingularMap = new HashMap<>(); readNomLexLisp(reader); }
private synchronized void loadFromClassPath() throws Exception { if (loaded) return; List<URL> urls = IOUtils.lsResources(RogetThesaurusFeatures.class, fileName); if (urls.size() == 0) throw new EdisonException("Cannot find " + fileName + " in the classpath"); loadWithURL(urls.get(0)); }
@Deprecated public static VerbClassDictionary getDictionaryFromClassPath() { if (verbClassDictionary == null) { synchronized (LevinVerbClassFeature.class) { if (verbClassDictionary == null) { log.info("Reading verb class dictionary. Looking for " + verbClassFile + " in the classpath"); try { URL url = IOUtils.lsResources(LevinVerbClassFeature.class, verbClassFile).get(0); InputStream resource = url.openStream(); verbClassDictionary = new VerbClassDictionary(resource); } catch (Exception e) { log.error("Unable to read the verb class dictionary", e); System.exit(-1); } List<String> strings = verbClassDictionary.getClass("give"); log.info("Loaded verb class dictionary. Test: classes for 'give' are {}", strings); } } } return verbClassDictionary; }
@Override public Set<Feature> getWordFeatures(TextAnnotation ta, int wordPosition) throws EdisonException { Set<Feature> features = new LinkedHashSet<>(); List<String> nomFrames; try { URL file = IOUtils.lsResources(WordFeatureExtractorFactory.class, "nombank.list.gz") .get(0); nomFrames = LineIO.readGZip(file.getFile()); String lemma = WordHelpers.getLemma(ta, wordPosition); if (nomFrames.contains(lemma)) { features.add(isNom); } } catch (Exception e) { System.err.println("Could not read nombank.list.gz file from classpath"); e.printStackTrace(); } return features; } };
@Override public void initialize(ResourceManager rm) { try { // TODO Ugly hack: SL doesn't accept streams and can't create a file from inside a jar File dest = new File(TEMP_MODEL_FILE_NAME); String modelName = rm.getString(DepConfigurator.MODEL_NAME.key); URL fileURL = IOUtils.lsResources(DepAnnotator.class, modelName).get(0); logger.info("Loading {} into temp file: {}", modelName, TEMP_MODEL_FILE_NAME); FileUtils.copyURLToFile(fileURL, dest); model = SLModel.loadModel(TEMP_MODEL_FILE_NAME); ((LabeledChuLiuEdmondsDecoder) model.infSolver).loadDepRelDict(); if (!dest.delete()) throw new IOException("Could not delete temporary model file " + TEMP_MODEL_FILE_NAME); } catch (IOException | ClassNotFoundException | URISyntaxException e) { e.printStackTrace(); File dest = new File(TEMP_MODEL_FILE_NAME); if (!dest.delete()) throw new RuntimeException("Could not delete temporary model file " + TEMP_MODEL_FILE_NAME); } }