本文整理汇总了Java中gate.util.Files.fileFromURL方法的典型用法代码示例。如果您正苦于以下问题:Java Files.fileFromURL方法的具体用法?Java Files.fileFromURL怎么用?Java Files.fileFromURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gate.util.Files
的用法示例。
在下文中一共展示了Files.fileFromURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PrivateRepositoryFeed
import gate.util.Files; //导入方法依赖的package包/类
public PrivateRepositoryFeed(URL configFileUrl, String query, int settingsHash, Options opt) {
this.configFile = Files.fileFromURL(configFileUrl);
this.query = query;
this.settingsHash = settingsHash;
dictionaryPath = configFile.getParentFile().getAbsoluteFile();
this.username = opt.getMap().get("username");
this.password = opt.getMap().get("password");
if (!verifyHash(dictionaryPath, settingsHash)) {
boolean deleteSuccesful = new File(dictionaryPath, "kim.trusted.entities.cache").delete();
if (deleteSuccesful) {
log.info("Cache is going to be refreshed due to a configuration change.");
}
else {
log.warn("Cache needed to be refreshed due to a configuration change, but the system denied deleting it.");
}
}
}
示例2: init
import gate.util.Files; //导入方法依赖的package包/类
public Resource init() throws ResourceInstantiationException {
// check that the tokenizer is in the resource
// directory
ResourceData thisRD =
(ResourceData)Gate.getCreoleRegister().get(this.getClass().getName());
URL myCreoleXML = thisRD.getXmlFileUrl();
if(!"file".equals(myCreoleXML.getProtocol())) {
throw new ResourceInstantiationException(
"Tokenizer plugin must be loaded from a file: URL");
}
File myCreoleXMLFile = Files.fileFromURL(myCreoleXML);
tokenExecutable = myCreoleXMLFile.getParent()+ File.separator + "resources" + File.separator + "tokenise"
+ File.separator + "token."
+ com.digitalpebble.util.Utilities.getArch();
// check that the file exists
File scriptfile = new File(tokenExecutable);
if (scriptfile.exists() == false)
throw new ResourceInstantiationException(new Exception(
"Executable " + scriptfile.getAbsolutePath()
+ " does not exist"));
return super.init();
}
示例3: write
import gate.util.Files; //导入方法依赖的package包/类
/**
* Write out the (possibly modified) GAPP file to its new location.
*
* @throws IOException if an I/O error occurs.
*/
public void write() throws IOException {
finish();
File newGappFile = Files.fileFromURL(gappFileURL);
FileOutputStream fos = new FileOutputStream(newGappFile);
BufferedOutputStream out = new BufferedOutputStream(fos);
XMLOutputter outputter = new XMLOutputter(Format.getRawFormat());
outputter.output(gappDocument, out);
}
示例4: loadModel
import gate.util.Files; //导入方法依赖的package包/类
@Override
public void loadModel(URL directory, String parms) {
if(!"file".equals(directory.getProtocol()))
throw new GateRuntimeException("The dataDirectory URL must be a file: URL for LibSVM");
try {
File directoryFile = Files.fileFromURL(directory);
svm_model svmModel = svm.svm_load_model(new File(directoryFile, FILENAME_MODEL).getAbsolutePath());
System.out.println("Loaded LIBSVM model, nrclasses=" + svmModel.nr_class);
model = svmModel;
} catch (Exception ex) {
throw new GateRuntimeException("Error loading the LIBSVM model from directory "+directory, ex);
}
}
示例5: loadModel
import gate.util.Files; //导入方法依赖的package包/类
@Override
protected void loadModel(URL directoryURL, String parms) {
ArrayList<String> finalCommand = new ArrayList<String>();
// Instead of loading a model, this establishes a connection with the
// external sklearn process.
if(!"file".equals(directoryURL.getProtocol()))
throw new GateRuntimeException("The dataDirectory URL must be a file: URL for sklearn");
File directory = Files.fileFromURL(directoryURL);
File commandFile = findWrapperCommand(directory, true);
String modelFileName = new File(directory,MODEL_BASENAME).getAbsolutePath();
finalCommand.add(commandFile.getAbsolutePath());
finalCommand.add(modelFileName);
// if we have a shell command prepend that, and if we have shell parms too, include them
if(shellcmd != null) {
finalCommand.add(0,shellcmd);
if(shellparms != null) {
String[] sps = shellparms.trim().split("\\s+");
int i=0; for(String sp : sps) { finalCommand.add(++i,sp); }
}
}
//System.err.println("Running: "+finalCommand);
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
model = MODEL_INSTANCE;
Map<String,String> env = new HashMap<>();
env.put(ENV_WRAPPER_HOME, wrapperhome);
process = Process4JsonStream.create(directory,env,finalCommand);
}
示例6: loadModel
import gate.util.Files; //导入方法依赖的package包/类
@Override
protected void loadModel(URL directoryURL, String parms) {
File directory = null;
if("file".equals(directoryURL.getProtocol())) directory = Files.fileFromURL(directoryURL);
else throw new GateRuntimeException("The dataDirectory for WekaWrapper must be a file: URL not "+directoryURL);
ArrayList<String> finalCommand = new ArrayList<String>();
// we need the corpus representation here! Normally this is done from loadEngine and after
// load model, but we do it here. The load crm method only loads anything if it is still
// null, so we will do this only once anyway.
loadAndSetCorpusRepresentation(directoryURL);
CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
SimpleEntry<String,Integer> modeAndNrC = findOutMode(data);
String mode = modeAndNrC.getKey();
Integer nrClasses = modeAndNrC.getValue();
// Instead of loading a model, this establishes a connection with the
// external wrapper process.
File commandFile = findWrapperCommand(directory, true);
String modelFileName = new File(directory,MODEL_BASENAME).getAbsolutePath();
finalCommand.add(commandFile.getAbsolutePath());
finalCommand.add(modelFileName);
finalCommand.add(mode);
finalCommand.add(nrClasses.toString());
// if we have a shell command prepend that, and if we have shell parms too, include them
if(shellcmd != null) {
finalCommand.add(0,shellcmd);
if(shellparms != null) {
String[] sps = shellparms.trim().split("\\s+");
int i=0; for(String sp : sps) { finalCommand.add(++i,sp); }
}
}
//System.err.println("Running: "+finalCommand);
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
model = MODEL_INSTANCE;
Map<String,String> env = new HashMap<>();
env.put(ENV_WRAPPER_HOME, wrapperhome);
process = Process4JsonStream.create(directory,env,finalCommand);
}
示例7: afterLastDocument
import gate.util.Files; //导入方法依赖的package包/类
@Override
public void afterLastDocument(Controller arg0, Throwable t) {
File outDir = Files.fileFromURL(getDataDirectory());
if(!haveSequenceAlg) {
corpusRepresentationTarget.finish();
Exporter.export(corpusRepresentationTarget, exporter, outDir, getInstanceType(), getAlgorithmParameters());
} else {
corpusRepresentationSeq.finish();
Exporter.export(corpusRepresentationSeq, exporter, outDir, getInstanceType(), getAlgorithmParameters());
}
}
示例8: setTarget
import gate.util.Files; //导入方法依赖的package包/类
public void setTarget(Object target) {
// make sure we are being given a target that we know how to display
if(target == null) return;
if(!(target instanceof ScriptPR)) { throw new GateRuntimeException(this
.getClass().getName()
+ " can only be used to display "
+ ScriptPR.class.getName()
+ "\n"
+ target.getClass().getName()
+ " is not a " + ScriptPR.class.getName() + "!"); }
// if this VR is being reused then stop listening to changes from the
// previous target
if(pr != null) {
pr.removeProgressListener(this);
}
// store the PR we are displaying so we can keep refering to it
pr = (ScriptPR)target;
// get the script file or null if loaded from a non-file url
try {
file = Files.fileFromURL(pr.getScriptURL());
} catch(Exception e) {
file = null;
}
// get the editor to display the script
editor.getTextEditor().setText(pr.getGroovySrc());
// disable editing if we loaded from a URL
editor.getTextEditor().setEditable(file != null);
btnSave.setEnabled(false);
btnRevert.setEnabled(false);
// listen out for updates to the PR so we can keep in sync
pr.addProgressListener(this);
}
示例9: init
import gate.util.Files; //导入方法依赖的package包/类
@Override
public Resource init() {
// create a new instance of MutationFinder using the supplied file
finder = new MutationFinder(Files.fileFromURL(regexpURL));
return this;
}
示例10: controllerExecutionStarted
import gate.util.Files; //导入方法依赖的package包/类
public void controllerExecutionStarted(Controller c)
throws ExecutionException {
// check that the URL of the fingerprint we want to generate is a file://
try {
fingerprintFile = Files.fileFromURL(fingerprintURL);
} catch(Exception e) {
throw new ExecutionException(
"Location of fingerprint must be a file based URL!", e);
}
// create a new place holder for the text we are going to process
text = new StringBuilder();
}
示例11: loadModel
import gate.util.Files; //导入方法依赖的package包/类
@Override
protected void loadModel(URL directoryURL, String parms) {
ArrayList<String> finalCommand = new ArrayList<String>();
// TODO: for now, we only allow URLs which are file: URLs here.
// This is because the script wrapping Weka is currently not able to access
// the model from any other location. Also, we need to export the
// data and currently this is done into the directoryURL.
// At some later point, we may be able to e.g. copy the model into
// a temporary directory and use the demporary directory also to store
// the data!
File directoryFile = null;
if("file".equals(directoryURL.getProtocol())) directoryFile = Files.fileFromURL(directoryURL);
else throw new GateRuntimeException("The dataDirectory for WekaWrapper must be a file: URL");
// Instead of loading a model, this establishes a connection with the
// external weka process. For this, we expect an additional file in the
// directory, weka.yaml, which describes how to run the weka wrapper
File commandFile = findWrapperCommand(directoryFile, true);
// If the directoryURL
String modelFileName = new File(directoryFile,FILENAME_MODEL).getAbsolutePath();
if(!new File(modelFileName).exists()) {
throw new GateRuntimeException("File not found: "+modelFileName);
}
String header = new File(directoryFile,"header.arff").getAbsolutePath();
if(!new File(header).exists()) {
throw new GateRuntimeException("File not found: "+header);
}
if(shellcmd != null) {
finalCommand.add(shellcmd);
if(shellparms != null) {
String[] sps = shellparms.trim().split("\\s+");
for(String sp : sps) { finalCommand.add(sp); }
}
}
finalCommand.add(commandFile.getAbsolutePath());
finalCommand.add(modelFileName);
finalCommand.add(header);
//System.err.println("Running: "+finalCommand);
// Create a fake Model jsut to make LF_Apply... happy which checks if this is null
model = "ExternalWekaWrapperModel";
Map<String,String> env = new HashMap<>();
env.put(ENV_WRAPPER_HOME,wrapperhome);
// NOTE: if the directoryFile is null, the current Java process' directory is used
process = Process4ObjectStream.create(directoryFile,env,finalCommand);
}
示例12: loadDataFromDef
import gate.util.Files; //导入方法依赖的package包/类
protected void loadDataFromDef(URL configFileURL) throws IOException {
String configFileName = configFileURL.toExternalForm();
String gazbinFileName = configFileName.replaceAll("\\.def$", ".gazbin");
if (configFileName.equals(gazbinFileName)) {
throw new GateRuntimeException("Config file must have def or defyaml extension, not "+configFileURL);
}
URL gazbinURL = new URL(gazbinFileName);
if (UrlUtils.exists(gazbinURL)) {
gazStore = new GazStoreTrie3();
gazStore = gazStore.load(gazbinURL);
} else {
gazStore = new GazStoreTrie3();
try (BufferedReader defReader = new BomStrippingInputStreamReader((configFileURL).openStream(), UTF8)) {
String line;
//logger.info("Loading data");
while (null != (line = defReader.readLine())) {
String[] fields = line.split(":");
if (fields.length == 0) {
System.err.println("Empty line in file " + configFileURL);
} else {
String listFileName = "";
String majorType = "";
String minorType = "";
String languages = "";
String annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE;
listFileName = fields[0];
if (fields.length > 1) {
majorType = fields[1];
}
if (fields.length > 2) {
minorType = fields[2];
}
if (fields.length > 3) {
languages = fields[3];
}
if (fields.length > 4) {
annotationType = fields[4];
}
if (fields.length > 5) {
defReader.close();
throw new GateRuntimeException("Line has more that 5 fields in def file " + configFileURL);
}
logger.debug("Reading from " + listFileName + ", " + majorType + "/" + minorType + "/" + languages + "/" + annotationType);
//logger.info("DEBUG: loading data from "+listFileName);
loadListFile(listFileName, majorType, minorType, languages, annotationType);
}
} //while
} // try
gazStore.compact();
logger.info("Gazetteer loaded from list files");
// only write the cache if we loaded the def file from an actual file, not
// some other URL
if(UrlUtils.isFile(gazbinURL)) {
File gazbinFile = Files.fileFromURL(gazbinURL);
gazStore.save(gazbinFile);
}
} // gazbinFile exists ... else
}
示例13: loadDataFromYaml
import gate.util.Files; //导入方法依赖的package包/类
protected void loadDataFromYaml(URL configFileURL) throws IOException {
String configFileName = configFileURL.toExternalForm();
String gazbinFileName = configFileName.replaceAll("\\.defyaml$", ".gazbin");
if (configFileName.equals(gazbinFileName)) {
throw new GateRuntimeException("Config file must have def or defyaml extension");
}
URL gazbinURL = new URL(gazbinFileName);
String gazbinDir = UrlUtils.getParent(gazbinURL);
String gazbinName = UrlUtils.getName(gazbinURL);
// Always read the yaml file so we can get any special location of the cache
// file or figure out that we should not try to load the cache file
Yaml yaml = new Yaml();
BufferedReader yamlReader =
new BomStrippingInputStreamReader((configFileURL).openStream(), UTF8);
Object configObject = yaml.load(yamlReader);
List<Map> configListFiles = null;
if (configObject instanceof Map) {
Map<String, Object> configMap = (Map<String, Object>) configObject;
String configCacheDirName = (String) configMap.get("cacheDir");
if (configCacheDirName != null) {
gazbinDir = configCacheDirName;
}
String configCacheFileName = (String) configMap.get("chacheFile");
if (configCacheFileName != null) {
gazbinName = configCacheFileName;
}
gazbinURL = UrlUtils.newURL(new URL(gazbinDir), gazbinName);
configListFiles = (List<Map>) configMap.get("listFiles");
} else if (configObject instanceof List) {
configListFiles = (List<Map>) configObject;
} else {
throw new GateRuntimeException("Strange YAML format for the defyaml file " + configFileURL);
}
// if we want to load the cache and it exists, load it
if (UrlUtils.exists(gazbinURL)) {
gazStore = new GazStoreTrie3();
gazStore = gazStore.load(gazbinURL);
} else {
gazStore = new GazStoreTrie3();
// go through all the list and tsv files to load and load them
for (Map configListFile : configListFiles) {
// TODO!!!
//logger.debug("Reading from "+listFileName+", "+majorType+"/"+minorType+"/"+languages+"/"+annotationType);
//logger.info("DEBUG: loading data from "+listFileName);
//loadListFile(listFileName,majorType,minorType,languages,annotationType);
} //while
gazStore.compact();
logger.info("Gazetteer loaded from list files");
if(UrlUtils.isFile(gazbinURL)) {
File gazbinFile = Files.fileFromURL(gazbinURL);
gazStore.save(gazbinFile);
}
}
}
示例14: buildCommandLine
import gate.util.Files; //导入方法依赖的package包/类
/**
* This method constructs an array of Strings which will be used as
* the command line for executing the external tagger through a call
* to Runtime.exec(). This uses the tagger binary and flags to build
* the command line. If the system property <code>shell.path</code>
* has been set then the command line will be built so that the tagger
* is run by the provided shell. This is useful on Windows where you
* will usually need to run the tagger under Cygwin or the Command
* Prompt.
*
* @param textfile the file containing the input to the tagger
* @return a String array containing the correctly assembled command
* line
* @throws ExecutionException if an error occurs whilst building the
* command line
*/
protected String[] buildCommandLine(File textfile) throws ExecutionException {
// check that the file exists
File scriptfile = Files.fileFromURL(taggerBinary);
if(scriptfile.exists() == false)
throw new ExecutionException("Script " + scriptfile.getAbsolutePath()
+ " does not exist");
// a pointer to where to stuff the flags
int index = 0;
// the array we are buiding
String[] taggerCmd;
// the bath to a shell under which to run the script
String shPath = System.getProperty("shell.path");
if(shPath != null) {
// if there is a shell then use that as the first command line
// argument
taggerCmd = new String[3 + taggerFlags.size()];
taggerCmd[0] = shPath;
index = 1;
}
else {
// there is no shell so we only need an array long enough to hold
// the binary, flags and file
taggerCmd = new String[2 + taggerFlags.size()];
}
// get an array from the list of flags
String[] flags = taggerFlags.toArray(new String[0]);
// copy the flags into the array we are building
System.arraycopy(flags, 0, taggerCmd, index + 1, flags.length);
// add the binary and input file to the command line
taggerCmd[index] = scriptfile.getAbsolutePath();
taggerCmd[taggerCmd.length - 1] = textfile.getAbsolutePath();
if(debug) {
// if we are doing debug work then echo the command line
StringBuilder sanityCheck = new StringBuilder();
for(String s : taggerCmd)
sanityCheck.append(" ").append(s);
System.out.println(sanityCheck.toString());
}
// return the fully constructed command line
return taggerCmd;
}
示例15: init
import gate.util.Files; //导入方法依赖的package包/类
/** Initialise this resource, and return it. */
public Resource init() throws ResourceInstantiationException {
// set up the source URL and create the content
if(markupAware == null) {
throw new ResourceInstantiationException(
"The markupAware cannot be null.");
}
if(collectRepositioningInfo == null) {
throw new ResourceInstantiationException(
"The collectRepositioningInfo is null!");
}
if(preserveOriginalContent == null) {
throw new ResourceInstantiationException(
"The preserveOriginalContent is null!");
}
if(sourceUrl != null) {
if(documentIDs == null || documentIDs.isEmpty()) {
throw new ResourceInstantiationException(
"You must provide atleast one document id");
}
// source URL can be a file
File file = Files.fileFromURL(sourceUrl);
if(file.isDirectory()) {
throw new ResourceInstantiationException(
"You must select one of the files!");
}
// instancetiate all documents
createDocuments(file);
}
else {
documents = new HashMap<String, Document>();
documentIDs = new ArrayList<String>();
}
currentDocument = null;
return this;
}