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);
}
}
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;
}
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);
}
}
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
}
}
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);
}
}
Aggregations