@Override protected File produceResource(URL aUrl) throws IOException { return ResourceUtils.getUrlAsFile(aUrl, true); } };
@Override protected File produceResource(URL aUrl) throws IOException { return ResourceUtils.getUrlAsFile(aUrl, true); } };
@Override protected File produceResource(URL aUrl) throws IOException { return ResourceUtils.getUrlAsFile(aUrl, true); } };
@Override protected File produceResource(URL aUrl) throws IOException { return ResourceUtils.getUrlAsFile(aUrl, true); } };
/** * Make the given URL available as a file. A temporary file is created and deleted upon a * regular shutdown of the JVM. If the parameter {@code aCache} is {@code true}, the temporary * file is remembered in a cache and if a file is requested for the same URL at a later time, * the same file is returned again. If the previously created file has been deleted meanwhile, * it is recreated from the URL. This method should not be used for creating executable * binaries. For this purpose, getUrlAsExecutable should be used. * * @param aUrl * the URL. * @param aCache * use the cache or not. * @return a file created from the given URL. * @throws IOException * if the URL cannot be accessed to (re)create the file. */ public static File getUrlAsFile(URL aUrl, boolean aCache) throws IOException { return getUrlAsFile(aUrl, aCache, false); }
@Override protected Tagger produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); return new Tagger(modelFile.getPath()); // create a MorphTagger } };
@Override protected Lemmatizer produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); return new Lemmatizer(modelFile.getPath(), uppercase); // create a lemmatizer } };
@Override protected SemanticRoleLabeler produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, false); try { ZipFile zipFile = new ZipFile(modelFile); SemanticRoleLabeler srl = Pipeline.fromZipFile(zipFile); zipFile.close(); return srl; } catch (Exception e) { throw new IOException(e); } } };
public static File loadAndPrepareFeatureDataFile(TaskContext aContext, File tmpLocation, String sourceFolder) throws Exception { // Depending on a users' setup, we might exceed the path-length limit of 255 // character, which is a problem on Windows, we provide all needed files in the // folder where the binary is located to enforce short paths File folder = aContext.getFolder(sourceFolder, AccessMode.READONLY); File srcFile = new File(folder, FILENAME_DATA_IN_CLASSIFIER_FORMAT); if (srcFile.getAbsolutePath().length() < 254 || !isWindows()) { return ResourceUtils.getUrlAsFile(srcFile.toURI().toURL(), true); } File trainDestFile = new File(tmpLocation, FILENAME_DATA_IN_CLASSIFIER_FORMAT); try (InputStream is = new FileInputStream(srcFile)) { FileUtils.copyInputStreamToFile(is, trainDestFile); } return ResourceUtils.getUrlAsFile(trainDestFile.toURI().toURL(), true); }
@Override protected TweetTagger produceResource(URL aUrl) throws IOException { try { TweetTagger model = new TweetTagger(); model.loadModel(ResourceUtils.getUrlAsFile(aUrl, false).getAbsolutePath()); return model; } catch (Exception e) { throw new IOException(e); } } };
public static File loadAndPrepareFeatureDataFile(TaskContext aContext, File tmpLocation, String sourceFolder) throws Exception { // Depending on a users' setup, we might exceed the path-length limit of 255 // character, which is a problem on Windows, we provide all needed files in the // folder where the binary is located to enforce short paths File folder = aContext.getFolder(sourceFolder, AccessMode.READONLY); File srcFile = new File(folder, FILENAME_DATA_IN_CLASSIFIER_FORMAT); if (srcFile.getAbsolutePath().length() < 254 || !isWindows()) { return ResourceUtils.getUrlAsFile(srcFile.toURI().toURL(), true); } File trainDestFile = new File(tmpLocation, FILENAME_DATA_IN_CLASSIFIER_FORMAT); InputStream is = null; try { is = new FileInputStream(srcFile); FileUtils.copyInputStreamToFile(is, trainDestFile); } finally { IOUtils.closeQuietly(is); } return ResourceUtils.getUrlAsFile(trainDestFile.toURI().toURL(), true); }
public static File loadAndPrepareFeatureDataFile(TaskContext aContext, File tmpLocation, String sourceFolder) throws Exception { // Depending on a users' setup, we might exceed the path-length limit of 255 // character, which is a problem on Windows, we provide all needed files in the // folder where the binary is located to enforce short paths File folder = aContext.getFolder(sourceFolder, AccessMode.READONLY); File srcFile = new File(folder, FILENAME_DATA_IN_CLASSIFIER_FORMAT); if (srcFile.getAbsolutePath().length() < 254 || !isWindows()) { return ResourceUtils.getUrlAsFile(srcFile.toURI().toURL(), true); } File trainDestFile = new File(tmpLocation, FILENAME_DATA_IN_CLASSIFIER_FORMAT); InputStream is = null; try { is = new FileInputStream(srcFile); FileUtils.copyInputStreamToFile(is, trainDestFile); } finally { IOUtils.closeQuietly(is); } return ResourceUtils.getUrlAsFile(trainDestFile.toURI().toURL(), true); }
public File getExecutable() { String loc = getExecutablePath() + getExecutableName(); URL crfExecUrl = getClass().getResource(loc); crfExecUrl = ClassLoader.getSystemResource(loc); logger.log(Level.FINE, "CrfSuite Location " + loc); logger.log(Level.FINE, "CrfSuite Url: " + crfExecUrl); File f; try { if (crfExecUrl != null) { f = new File(ResourceUtils.getUrlAsFile(crfExecUrl, true).toURI().getPath()); if (!f.exists()) { f = new File(URLDecoder.decode(f.getAbsolutePath(), ("UTF-8"))); } f.setExecutable(true); return f; } logger.log(Level.WARNING, "The executable could not be found at " + loc); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
public File getExecutable() { String loc = getExecutablePath() + getExecutableName(); URL crfExecUrl = getClass().getResource(loc); crfExecUrl = ClassLoader.getSystemResource(loc); logger.log(Level.FINE, "CrfSuite Location " + loc); logger.log(Level.FINE, "CrfSuite Url: " + crfExecUrl); File f; try { if (crfExecUrl != null) { f = new File(ResourceUtils.getUrlAsFile(crfExecUrl, true).toURI().getPath()); if (!f.exists()) { f = new File(URLDecoder.decode(f.getAbsolutePath(), ("UTF-8"))); } f.setExecutable(true); return f; } logger.log(Level.WARNING, "The executable could not be found at " + loc); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
@Override protected Tagger produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); String[] args = { "-model", modelFile.getPath() }; Options option = new Options(args); Tagger tagger = new Tagger(option); // create a POSTagger HashMap<String, HashMap<String, Integer>> featureSet = tagger.mf.getFeatureSet(); SingletonTagset posTags = new SingletonTagset(POS.class, getResourceMetaData() .getProperty("pos.tagset")); HashMap<String, Integer> posTagFeatures = featureSet.get("POS"); posTags.addAll(posTagFeatures.keySet()); posTags.removeAll(asList("<None>", "<root-POS>")); addTagset(posTags); if (printTagSet) { getContext().getLogger().log(INFO, getTagset().toString()); } return tagger; } };
@Override protected TreeTaggerWrapper<Token> produceResource(URL aUrl) throws IOException { Properties meta = getResourceMetaData(); String encoding = modelEncoding != null ? modelEncoding : meta .getProperty("encoding"); String tagset = meta.getProperty("pos.tagset"); File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); // Reconfigure tagger treetagger.setModel(modelFile.getPath() + ":" + encoding); // Get tagset List<String> tags = TreeTaggerModelUtil.getTagset(modelFile, encoding); SingletonTagset posTags = new SingletonTagset(POS.class, tagset); posTags.addAll(tags); addTagset(posTags); if (printTagSet) { getContext().getLogger().log(INFO, getTagset().toString()); } return treetagger; } };
@Override protected Parser produceResource(URL aUrl) throws IOException { File modelFile = ResourceUtils.getUrlAsFile(aUrl, true); String[] args = { "-model", modelFile.getPath() }; Options option = new Options(args); Parser parser = new Parser(option); // create a parser Properties metadata = getResourceMetaData(); HashMap<String, HashMap<String, Integer>> featureSet = MFO.getFeatureSet(); SingletonTagset posTags = new SingletonTagset( POS.class, metadata.getProperty("pos.tagset")); HashMap<String, Integer> posTagFeatures = featureSet.get("POS"); posTags.addAll(posTagFeatures.keySet()); posTags.removeAll(asList("<None>", "<root-POS>")); addTagset(posTags); SingletonTagset depTags = new SingletonTagset( Dependency.class, metadata.getProperty("dependency.tagset")); HashMap<String, Integer> depTagFeatures = featureSet.get("REL"); depTags.addAll(depTagFeatures.keySet()); depTags.removeAll(asList("<None>", "<no-type>", "<root-type>")); addTagset(depTags); if (printTagSet) { getContext().getLogger().log(INFO, getTagset().toString()); } return parser; } };
File modelFile = ResourceUtils.getUrlAsFile(aUrl, true);