Search in sources :

Example 21 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class AnnotationDiffGUI method populateGUI.

protected void populateGUI() {
    try {
        documents = Gate.getCreoleRegister().getAllInstances("gate.Document");
    } catch (GateException ge) {
        throw new GateRuntimeException(ge);
    }
    List<String> documentNames = new ArrayList<String>(documents.size());
    for (Resource document : documents) {
        documentNames.add(document.getName());
    }
    Object keyDocSelectedItem = keyDocCombo.getSelectedItem();
    Object resDocSelectedItem = resDocCombo.getSelectedItem();
    keyDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
    resDocCombo.setModel(new DefaultComboBoxModel<String>(documentNames.toArray(new String[documentNames.size()])));
    if (!documents.isEmpty()) {
        keyDocCombo.setSelectedItem(keyDocSelectedItem);
        if (keyDocCombo.getSelectedIndex() == -1) {
            keyDocCombo.setSelectedIndex(0);
        }
        resDocCombo.setSelectedItem(resDocSelectedItem);
        if (resDocCombo.getSelectedIndex() == -1) {
            resDocCombo.setSelectedIndex(0);
        }
        statusLabel.setText(documents.size() + " documents loaded");
        if (annTypeCombo.getSelectedItem() == null) {
            statusLabel.setText(statusLabel.getText() + ". Choose two annotation sets to compare.");
        }
        statusLabel.setForeground(Color.BLACK);
    } else {
        statusLabel.setText("You must load at least one document.");
        statusLabel.setForeground(Color.RED);
    }
}
Also used : GateException(gate.util.GateException) GateRuntimeException(gate.util.GateRuntimeException) ArrayList(java.util.ArrayList) Resource(gate.Resource)

Example 22 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class NameBearerHandle method getPopup.

@Override
public JPopupMenu getPopup() {
    JPopupMenu popup = new XJPopupMenu();
    // first add the static items
    Iterator<JComponent> itemIter = staticPopupItems.iterator();
    while (itemIter.hasNext()) {
        JComponent anItem = itemIter.next();
        if (anItem == null)
            popup.addSeparator();
        else
            popup.add(anItem);
    }
    // next add the dynamic list from the target and its editors
    Iterator<ActionsPublisher> publishersIter = actionPublishers.iterator();
    while (publishersIter.hasNext()) {
        ActionsPublisher aPublisher = publishersIter.next();
        if (aPublisher.getActions() != null) {
            Iterator<Action> actionIter = aPublisher.getActions().iterator();
            while (actionIter.hasNext()) {
                Action anAction = actionIter.next();
                if (anAction == null)
                    popup.addSeparator();
                else {
                    popup.add(new XJMenuItem(anAction, sListenerProxy));
                }
            }
        }
    }
    if (target instanceof Resource) {
        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 ResourceHelper) {
                    Iterator<Action> actionIter = ((ResourceHelper) res).getActions(NameBearerHandle.this).iterator();
                    while (actionIter.hasNext()) {
                        Action anAction = actionIter.next();
                        if (anAction == null)
                            popup.addSeparator();
                        else {
                            popup.add(new XJMenuItem(anAction, sListenerProxy));
                        }
                    }
                }
            }
        }
    }
    return popup;
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) JComponent(javax.swing.JComponent) VisualResource(gate.VisualResource) Resource(gate.Resource) ProcessingResource(gate.ProcessingResource) AbstractResource(gate.creole.AbstractResource) LanguageResource(gate.LanguageResource) XJPopupMenu(gate.swing.XJPopupMenu) JPopupMenu(javax.swing.JPopupMenu) XJPopupMenu(gate.swing.XJPopupMenu) XJMenuItem(gate.swing.XJMenuItem)

Example 23 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class PRPersistence method extractDataFromSource.

/**
 * Populates this Persistence with the data that needs to be stored from the
 * original source object.
 */
@Override
public void extractDataFromSource(Object source) throws PersistenceException {
    if (!(source instanceof ProcessingResource)) {
        throw new UnsupportedOperationException(getClass().getName() + " can only be used for " + ProcessingResource.class.getName() + " objects!\n" + source.getClass().getName() + " is not a " + ProcessingResource.class.getName());
    }
    super.extractDataFromSource(source);
    Resource res = (Resource) source;
    ResourceData rData = Gate.getCreoleRegister().get(res.getClass().getName());
    if (rData == null)
        throw new PersistenceException("Could not find CREOLE data for " + res.getClass().getName());
    // now get the runtime params
    ParameterList params = rData.getParameterList();
    try {
        // get the values for the init time parameters
        runtimeParams = Factory.newFeatureMap();
        // this is a list of lists
        Iterator<List<Parameter>> parDisjIter = params.getRuntimeParameters().iterator();
        while (parDisjIter.hasNext()) {
            Iterator<Parameter> parIter = parDisjIter.next().iterator();
            while (parIter.hasNext()) {
                Parameter parameter = parIter.next();
                String parName = parameter.getName();
                Object parValue = res.getParameterValue(parName);
                if (storeParameterValue(parValue, parameter.getDefaultValue())) {
                    ((FeatureMap) runtimeParams).put(parName, parValue);
                }
            }
        }
        runtimeParams = PersistenceManager.getPersistentRepresentation(runtimeParams);
    } catch (ResourceInstantiationException | ParameterException rie) {
        throw new PersistenceException(rie);
    }
}
Also used : ResourceData(gate.creole.ResourceData) ProcessingResource(gate.ProcessingResource) Resource(gate.Resource) ProcessingResource(gate.ProcessingResource) ResourceInstantiationException(gate.creole.ResourceInstantiationException) FeatureMap(gate.FeatureMap) PersistenceException(gate.persist.PersistenceException) ParameterList(gate.creole.ParameterList) Parameter(gate.creole.Parameter) ParameterList(gate.creole.ParameterList) List(java.util.List) ParameterException(gate.creole.ParameterException)

Example 24 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class SerialCorpusImpl method resourceUnloaded.

@Override
public void resourceUnloaded(CreoleEvent e) {
    Resource res = e.getResource();
    if (res instanceof Document) {
        Document doc = (Document) res;
        if (DEBUG)
            Out.prln("resource Unloaded called ");
        // remove from the corpus too, if a transient one
        if (doc.getDataStore() != this.getDataStore()) {
            this.remove(doc);
        } else {
            // unload all occurences
            int index = indexOf(res);
            if (index < 0)
                return;
            documents.set(index, null);
            if (DEBUG)
                Out.prln("corpus: document " + index + " unloaded and set to null");
        }
    // if
    }
}
Also used : Resource(gate.Resource) CreoleResource(gate.creole.metadata.CreoleResource) AbstractLanguageResource(gate.creole.AbstractLanguageResource) Document(gate.Document)

Example 25 with Resource

use of gate.Resource in project gate-core by GateNLP.

the class CreoleRegisterImpl method unregisterPlugin.

// put(key, value)
@Override
public void unregisterPlugin(Plugin plugin) {
    if (plugins.remove(plugin)) {
        int prCount = 0;
        for (ResourceInfo rInfo : plugin.getResourceInfoList()) {
            ResourceData rData = get(rInfo.getResourceClassName());
            if (rData != null && rData.getReferenceCount() == 1) {
                // remove the plugin
                try {
                    List<Resource> loaded = getAllInstances(rInfo.getResourceClassName(), true);
                    prCount += loaded.size();
                    for (Resource r : loaded) {
                        // System.out.println(r);
                        Factory.deleteResource(r);
                    }
                } catch (GateException e) {
                    // not much we can do here other than dump the exception
                    e.printStackTrace();
                }
            }
            remove(rInfo.getResourceClassName());
        }
        try {
            Gate.getClassLoader().forgetClassLoader(new URL(plugin.getBaseURL(), "creole.xml").toExternalForm(), plugin);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("CREOLE plugin unloaded: " + plugin.getName());
        if (prCount > 0)
            log.warn(prCount + " resources were deleted as they relied on the " + plugin.getName() + " plugin");
        firePluginUnloaded(plugin);
    }
}
Also used : ResourceInfo(gate.Gate.ResourceInfo) GateException(gate.util.GateException) VisualResource(gate.VisualResource) Resource(gate.Resource) LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) URL(java.net.URL) GateRuntimeException(gate.util.GateRuntimeException) JDOMException(org.jdom.JDOMException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) GateException(gate.util.GateException)

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