Search in sources :

Example 16 with Resource

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());
}
Also used : CreoleResource(gate.creole.metadata.CreoleResource) Resource(gate.Resource) URL(java.net.URL)

Example 17 with Resource

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);
        }
    }
}
Also used : CreoleResource(gate.creole.metadata.CreoleResource) Resource(gate.Resource) URI(java.net.URI)

Example 18 with 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);
        }
    }
}
Also used : FeatureMap(gate.FeatureMap) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) CreoleResource(gate.creole.metadata.CreoleResource) Resource(gate.Resource) TestDocument(gate.corpora.TestDocument) Document(org.jdom.Document)

Example 19 with Resource

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());
        }
    }
}
Also used : Resource(gate.Resource) CreoleResource(gate.creole.metadata.CreoleResource) AbstractVisualResource(gate.creole.AbstractVisualResource) EventObject(java.util.EventObject) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Corpus(gate.Corpus)

Example 20 with Resource

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);
}
Also used : GateXMLExporter(gate.corpora.export.GateXMLExporter) Resource(gate.Resource) DocumentExporter(gate.DocumentExporter)

Aggregations

Resource (gate.Resource)26 LanguageResource (gate.LanguageResource)9 CreoleResource (gate.creole.metadata.CreoleResource)9 FeatureMap (gate.FeatureMap)8 ProcessingResource (gate.ProcessingResource)8 VisualResource (gate.VisualResource)6 GateException (gate.util.GateException)5 GateRuntimeException (gate.util.GateRuntimeException)5 URL (java.net.URL)5 AbstractVisualResource (gate.creole.AbstractVisualResource)4 Corpus (gate.Corpus)3 AbstractResource (gate.creole.AbstractResource)3 ResourceData (gate.creole.ResourceData)3 ResourceInstantiationException (gate.creole.ResourceInstantiationException)3 PersistenceException (gate.persist.PersistenceException)3 ArrayList (java.util.ArrayList)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Controller (gate.Controller)2 Document (gate.Document)2 ResourceInfo (gate.Gate.ResourceInfo)2