use of gate.Resource in project gate-core by GateNLP.
the class TestResourceReference method testCreateFromURL.
public void testCreateFromURL() throws Exception {
Resource resource = new TestResource();
URL url = new URL("http://gate.ac.uk");
resource.setParameterValue("param", url);
assertEquals("References do not match", url, ((ResourceReference) resource.getParameterValue("param")).toURL());
}
use of gate.Resource in project gate-core by GateNLP.
the class TestResourceReference method testDefaultValue.
public void testDefaultValue() throws Exception {
Resource resource = null;
try {
resource = Factory.createResource(TestResource.class.getName());
ResourceReference rr = (ResourceReference) resource.getParameterValue("param");
assertNotNull("ResourceReference param should not be null", rr);
assertEquals("References do not match", new URI("creole://group;artifact;version/resources/file.txt"), rr.toURI());
} finally {
if (resource != null) {
Factory.deleteResource(resource);
}
}
}
use of gate.Resource in project gate-core by GateNLP.
the class TestResourceReference method checkPersistence.
public void checkPersistence(File xgappFile, ResourceReference rr1, String expected) throws Exception {
Resource resource = null, restored = null;
try {
FeatureMap params = Factory.newFeatureMap();
params.put("param", rr1);
resource = Factory.createResource(TestResource.class.getName(), params);
PersistenceManager.saveObjectToFile(resource, xgappFile);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xgappFile);
Element entry = doc.getRootElement().getChild("application").getChild("initParams").getChild("localMap").getChild("entry");
assertEquals("couldn't find the paramameter entry", "param", entry.getChildText("string"));
Element value = entry.getChild("gate.util.persistence.PersistenceManager-RRPersistence");
assertNotNull("We couldn't find the RRPersistence wrapper", value);
assertEquals("The URI was not as expected", expected, value.getChildText("uriString"));
restored = (Resource) PersistenceManager.loadObjectFromFile(xgappFile);
ResourceReference rr2 = (ResourceReference) restored.getParameterValue("param");
assertEquals(rr1, rr2);
} finally {
if (xgappFile != null)
xgappFile.deleteOnExit();
if (resource != null) {
Factory.deleteResource(resource);
}
if (restored != null) {
Factory.deleteResource(restored);
}
}
}
use of gate.Resource in project gate-core by GateNLP.
the class LuceneDataStoreSearchGUI method resourceWritten.
/**
* This method is called when a resource is written into the datastore
*/
@Override
public void resourceWritten(DatastoreEvent de) {
Resource resource = de.getResource();
if (resource instanceof Corpus) {
// lets check if it is already available in our list
Object id = de.getResourceID();
if (!corpusIds.contains(id)) {
// we need to add its name to the combobox
corpusIds.add(id);
((DefaultComboBoxModel<String>) corpusToSearchIn.getModel()).addElement(resource.getName());
}
}
}
use of gate.Resource in project gate-core by GateNLP.
the class DocumentExportMenu method init.
private void init() {
DocumentExporter gateXMLExporter = (DocumentExporter) Gate.getCreoleRegister().get(GateXMLExporter.class.getCanonicalName()).getInstantiations().iterator().next();
addExporter(gateXMLExporter);
Set<String> toolTypes = Gate.getCreoleRegister().getToolTypes();
for (String type : toolTypes) {
List<Resource> instances = Gate.getCreoleRegister().get(type).getInstantiations();
for (Resource res : instances) {
if (res instanceof DocumentExporter) {
addExporter((DocumentExporter) res);
}
}
}
Gate.getCreoleRegister().addCreoleListener(this);
}
Aggregations