Search in sources :

Example 1 with Corpus

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

the class LuceneDataStoreSearchGUI method resourceDeleted.

/**
 * This method is called by datastore when an existing resource is
 * deleted
 */
@Override
public void resourceDeleted(DatastoreEvent de) {
    Resource resource = de.getResource();
    if (resource instanceof Corpus) {
        // lets check if it is already available in our list
        Object id = de.getResourceID();
        int index = corpusIds.indexOf(id);
        if (index < 0) {
            return;
        }
        // skip the first element in combo box that is "EntireDataStore"
        index++;
        // now lets remove it from the comboBox as well
        ((DefaultComboBoxModel<String>) corpusToSearchIn.getModel()).removeElementAt(index);
    }
// Added a refresh button which user should click to refresh types
// updateSetsTypesAndFeatures();
}
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 2 with Corpus

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

the class DocumentExportMenu method addExporter.

private void addExporter(final DocumentExporter de) {
    if (itemByResource.containsKey(de))
        return;
    final ResourceData rd = Gate.getCreoleRegister().get(de.getClass().getCanonicalName());
    if (DocumentExportMenu.this.getItemCount() == 1) {
        DocumentExportMenu.this.addSeparator();
    }
    JMenuItem item = DocumentExportMenu.this.add(new AbstractAction(de.getFileType() + " (." + de.getDefaultExtension() + ")", MainFrame.getIcon(rd.getIcon(), rd.getResourceClassLoader())) {

        @Override
        public void actionPerformed(ActionEvent ae) {
            List<List<Parameter>> params = rd.getParameterList().getRuntimeParameters();
            final FeatureMap options = Factory.newFeatureMap();
            final File selectedFile = getSelectedFile(params, de, options);
            if (selectedFile == null)
                return;
            Runnable runnable = new Runnable() {

                public void run() {
                    if (handle.getTarget() instanceof Document) {
                        long start = System.currentTimeMillis();
                        listener.statusChanged("Saving as " + de.getFileType() + " to " + selectedFile.toString() + "...");
                        try {
                            de.export((Document) handle.getTarget(), selectedFile, options);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        long time = System.currentTimeMillis() - start;
                        listener.statusChanged("Finished saving as " + de.getFileType() + " into " + " the file: " + selectedFile.toString() + " in " + ((double) time) / 1000 + "s");
                    } else {
                        // corpus
                        if (de instanceof CorpusExporter) {
                            long start = System.currentTimeMillis();
                            listener.statusChanged("Saving as " + de.getFileType() + " to " + selectedFile.toString() + "...");
                            try {
                                ((CorpusExporter) de).export((Corpus) handle.getTarget(), selectedFile, options);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            long time = System.currentTimeMillis() - start;
                            listener.statusChanged("Finished saving as " + de.getFileType() + " into " + " the file: " + selectedFile.toString() + " in " + ((double) time) / 1000 + "s");
                        } else {
                            // not a CorpusExporter
                            try {
                                File dir = selectedFile;
                                // create the top directory if needed
                                if (!dir.exists()) {
                                    if (!dir.mkdirs()) {
                                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Could not create top directory!", "GATE", JOptionPane.ERROR_MESSAGE);
                                        return;
                                    }
                                }
                                MainFrame.lockGUI("Saving...");
                                Corpus corpus = (Corpus) handle.getTarget();
                                // iterate through all the docs and save
                                // each of
                                // them
                                Iterator<Document> docIter = corpus.iterator();
                                boolean overwriteAll = false;
                                int docCnt = corpus.size();
                                int currentDocIndex = 0;
                                Set<String> usedFileNames = new HashSet<String>();
                                while (docIter.hasNext()) {
                                    boolean docWasLoaded = corpus.isDocumentLoaded(currentDocIndex);
                                    Document currentDoc = docIter.next();
                                    URL sourceURL = currentDoc.getSourceUrl();
                                    String fileName = null;
                                    if (sourceURL != null) {
                                        fileName = sourceURL.getPath();
                                        fileName = Files.getLastPathComponent(fileName);
                                    }
                                    if (fileName == null || fileName.length() == 0) {
                                        fileName = currentDoc.getName();
                                    }
                                    // makes sure that the filename does not
                                    // contain
                                    // any
                                    // forbidden character
                                    fileName = fileName.replaceAll("[\\/:\\*\\?\"<>|]", "_");
                                    if (fileName.toLowerCase().endsWith("." + de.getDefaultExtension())) {
                                        fileName = fileName.substring(0, fileName.length() - de.getDefaultExtension().length() - 1);
                                    }
                                    if (usedFileNames.contains(fileName)) {
                                        // name clash -> add unique ID
                                        String fileNameBase = fileName;
                                        int uniqId = 0;
                                        fileName = fileNameBase + "-" + uniqId++;
                                        while (usedFileNames.contains(fileName)) {
                                            fileName = fileNameBase + "-" + uniqId++;
                                        }
                                    }
                                    usedFileNames.add(fileName);
                                    if (!fileName.toLowerCase().endsWith("." + de.getDefaultExtension()))
                                        fileName += "." + de.getDefaultExtension();
                                    File docFile = null;
                                    boolean nameOK = false;
                                    do {
                                        docFile = new File(dir, fileName);
                                        if (docFile.exists() && !overwriteAll) {
                                            // ask the user if we can overwrite
                                            // the file
                                            Object[] opts = new Object[] { "Yes", "All", "No", "Cancel" };
                                            MainFrame.unlockGUI();
                                            int answer = JOptionPane.showOptionDialog(MainFrame.getInstance(), "File " + docFile.getName() + " already exists!\n" + "Overwrite?", "GATE", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, opts, opts[2]);
                                            MainFrame.lockGUI("Saving...");
                                            switch(answer) {
                                                case 0:
                                                    {
                                                        nameOK = true;
                                                        break;
                                                    }
                                                case 1:
                                                    {
                                                        nameOK = true;
                                                        overwriteAll = true;
                                                        break;
                                                    }
                                                case 2:
                                                    {
                                                        // user said NO, allow them to
                                                        // provide
                                                        // an
                                                        // alternative name;
                                                        MainFrame.unlockGUI();
                                                        fileName = (String) JOptionPane.showInputDialog(MainFrame.getInstance(), "Please provide an alternative file name", "GATE", JOptionPane.QUESTION_MESSAGE, null, null, fileName);
                                                        if (fileName == null) {
                                                            handle.processFinished();
                                                            return;
                                                        }
                                                        MainFrame.lockGUI("Saving");
                                                        break;
                                                    }
                                                case 3:
                                                    {
                                                        // user gave up; return
                                                        handle.processFinished();
                                                        return;
                                                    }
                                            }
                                        } else {
                                            nameOK = true;
                                        }
                                    } while (!nameOK);
                                    // save the file
                                    try {
                                        // do the actual exporting
                                        de.export(currentDoc, docFile, options);
                                    } catch (Exception ioe) {
                                        MainFrame.unlockGUI();
                                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Could not create write file:" + ioe.toString(), "GATE", JOptionPane.ERROR_MESSAGE);
                                        ioe.printStackTrace(Err.getPrintWriter());
                                        return;
                                    }
                                    listener.statusChanged(currentDoc.getName() + " saved");
                                    // loaded
                                    if (!docWasLoaded) {
                                        corpus.unloadDocument(currentDoc);
                                        Factory.deleteResource(currentDoc);
                                    }
                                    handle.progressChanged(100 * currentDocIndex++ / docCnt);
                                }
                                // while(docIter.hasNext())
                                listener.statusChanged("Corpus Saved");
                                handle.processFinished();
                            } finally {
                                MainFrame.unlockGUI();
                            }
                        }
                    }
                }
            };
            Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Document Exporter Thread");
            thread.setPriority(Thread.MIN_PRIORITY);
            thread.start();
        }
    });
    itemByResource.put(de, item);
}
Also used : ResourceData(gate.creole.ResourceData) Set(java.util.Set) HashSet(java.util.HashSet) ActionEvent(java.awt.event.ActionEvent) CorpusExporter(gate.CorpusExporter) IOException(java.io.IOException) Document(gate.Document) Corpus(gate.Corpus) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) InvalidOffsetException(gate.util.InvalidOffsetException) IOException(java.io.IOException) ParameterException(gate.creole.ParameterException) FeatureMap(gate.FeatureMap) Iterator(java.util.Iterator) Parameter(gate.creole.Parameter) List(java.util.List) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) File(java.io.File)

Example 3 with Corpus

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

the class SerialControllerEditor method initGuiComponents.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void initGuiComponents() {
    // we use a JSplitPane for most of the content, and add the Run button to
    // the South area
    setLayout(new BorderLayout());
    JPanel topSplit = new JPanel();
    topSplit.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridy = 0;
    loadedPRsTableModel = new LoadedPRsTableModel();
    loadedPRsTable = new XJTable();
    loadedPRsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    loadedPRsTable.setSortable(false);
    loadedPRsTable.setModel(loadedPRsTableModel);
    loadedPRsTable.setDragEnabled(true);
    loadedPRsTable.setDefaultRenderer(ProcessingResource.class, new ResourceRenderer());
    // create a renderer that doesn't mind being extended horizontally.
    loadedPRsTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() {

        @Override
        public Dimension getMaximumSize() {
            // we don't mind being extended horizontally
            Dimension dim = super.getMaximumSize();
            if (dim != null) {
                dim.width = Integer.MAX_VALUE;
                setMaximumSize(dim);
            }
            return dim;
        }

        @Override
        public Dimension getMinimumSize() {
            // we don't like being squashed!
            return getPreferredSize();
        }
    });
    final int width1 = new JLabel("Loaded Processing resources").getPreferredSize().width + 30;
    JScrollPane scroller = new JScrollPane() {

        @Override
        public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            dim.width = Math.max(dim.width, width1);
            return dim;
        }

        @Override
        public Dimension getMinimumSize() {
            Dimension dim = super.getMinimumSize();
            dim.width = Math.max(dim.width, width1);
            return dim;
        }
    };
    scroller.getViewport().setView(loadedPRsTable);
    scroller.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Loaded Processing resources "));
    // adding a scrollable table
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.insets = new Insets(0, 0, 0, 5);
    topSplit.add(scroller, constraints);
    addButton = new JButton(addPRAction);
    addButton.setText("");
    addButton.setEnabled(false);
    removeButton = new JButton(removePRAction);
    removeButton.setText("");
    removeButton.setEnabled(false);
    Box buttonsBox = Box.createVerticalBox();
    buttonsBox.add(Box.createVerticalGlue());
    buttonsBox.add(addButton);
    buttonsBox.add(Box.createVerticalStrut(5));
    buttonsBox.add(removeButton);
    buttonsBox.add(Box.createVerticalGlue());
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = new Insets(0, 0, 0, 5);
    topSplit.add(buttonsBox, constraints);
    memberPRsTableModel = new MemberPRsTableModel();
    memberPRsTable = new XJTable();
    memberPRsTable.setSortable(false);
    memberPRsTable.setModel(memberPRsTableModel);
    memberPRsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    memberPRsTable.setDefaultRenderer(ProcessingResource.class, new ResourceRenderer());
    memberPRsTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() {

        @Override
        public Dimension getMaximumSize() {
            // we don't mind being extended horizontally
            Dimension dim = super.getMaximumSize();
            if (dim != null) {
                dim.width = Integer.MAX_VALUE;
                setMaximumSize(dim);
            }
            return dim;
        }

        @Override
        public Dimension getMinimumSize() {
            // we don't like being squashed!
            return getPreferredSize();
        }
    });
    memberPRsTable.setDefaultRenderer(Icon.class, new IconRenderer());
    memberPRsTable.setDragEnabled(true);
    final int width2 = new JLabel("Selected Processing resources").getPreferredSize().width + 30;
    scroller = new JScrollPane() {

        @Override
        public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            dim.width = Math.max(dim.width, width2);
            return dim;
        }

        @Override
        public Dimension getMinimumSize() {
            Dimension dim = super.getMinimumSize();
            dim.width = Math.max(dim.width, width2);
            return dim;
        }
    };
    scroller.getViewport().setView(memberPRsTable);
    scroller.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Selected Processing resources "));
    // adding a scrollable table
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.insets = new Insets(0, 0, 0, 5);
    topSplit.add(scroller, constraints);
    moveUpButton = new JButton(MainFrame.getIcon("up"));
    moveUpButton.setMnemonic(KeyEvent.VK_UP);
    moveUpButton.setToolTipText("Move the selected resources up.");
    moveUpButton.setEnabled(false);
    moveDownButton = new JButton(MainFrame.getIcon("down"));
    moveDownButton.setMnemonic(KeyEvent.VK_DOWN);
    moveDownButton.setToolTipText("Move the selected resources down.");
    moveDownButton.setEnabled(false);
    buttonsBox = Box.createVerticalBox();
    buttonsBox.add(Box.createVerticalGlue());
    buttonsBox.add(moveUpButton);
    buttonsBox.add(Box.createVerticalStrut(5));
    buttonsBox.add(moveDownButton);
    buttonsBox.add(Box.createVerticalGlue());
    // adding a scrollable table
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.insets = new Insets(0, 0, 0, 0);
    topSplit.add(buttonsBox, constraints);
    // =========== BOTTOM Half ===========
    JPanel bottomSplit = new JPanel();
    bottomSplit.setLayout(new GridBagLayout());
    // first row
    constraints.gridy = 0;
    if (conditionalMode) {
        strategyPanel = new JPanel();
        strategyPanel.setLayout(new BoxLayout(strategyPanel, BoxLayout.X_AXIS));
        strategyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
        runBtnGrp = new ButtonGroup();
        yes_RunRBtn = new JRadioButton("Yes", true);
        yes_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
        runBtnGrp.add(yes_RunRBtn);
        no_RunRBtn = new JRadioButton("No", false);
        no_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
        runBtnGrp.add(no_RunRBtn);
        conditional_RunRBtn = new JRadioButton("If value of feature", false);
        conditional_RunRBtn.setHorizontalTextPosition(AbstractButton.LEFT);
        runBtnGrp.add(conditional_RunRBtn);
        featureNameTextField = new JTextField("", 25);
        featureNameTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE, featureNameTextField.getPreferredSize().height));
        featureValueTextField = new JTextField("", 25);
        featureValueTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE, featureValueTextField.getPreferredSize().height));
        strategyPanel.add(new JLabel(MainFrame.getIcon("greenBall")));
        strategyPanel.add(yes_RunRBtn);
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyPanel.add(new JLabel(MainFrame.getIcon("redBall")));
        strategyPanel.add(no_RunRBtn);
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyPanel.add(new JLabel(MainFrame.getIcon("yellowBall")));
        strategyPanel.add(conditional_RunRBtn);
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyPanel.add(featureNameTextField);
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyPanel.add(new JLabel("is"));
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyPanel.add(featureValueTextField);
        strategyPanel.add(Box.createHorizontalStrut(5));
        strategyBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " No processing resource selected... ");
        strategyPanel.setBorder(strategyBorder);
        constraints.weightx = 1;
        constraints.weighty = 0;
        constraints.insets = new Insets(0, 0, 0, 0);
        bottomSplit.add(strategyPanel, constraints);
        constraints.gridy++;
    }
    if (corpusControllerMode) {
        // we need to add the corpus combo
        corpusCombo = new JComboBox(corpusComboModel = new CorporaComboModel());
        corpusCombo.setRenderer(new ResourceRenderer());
        corpusCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, corpusCombo.getPreferredSize().height));
        Corpus corpus = null;
        if (controller instanceof CorpusController) {
            corpus = ((CorpusController) controller).getCorpus();
        } else {
            throw new GateRuntimeException("Controller editor in corpus " + "controller mode " + "but the target controller is not an " + "CorpusController!");
        }
        if (corpus != null) {
            corpusCombo.setSelectedItem(corpus);
        } else {
            if (corpusCombo.getModel().getSize() > 1)
                corpusCombo.setSelectedIndex(1);
            else
                corpusCombo.setSelectedIndex(0);
        }
        JPanel horBox = new JPanel();
        horBox.setLayout(new BoxLayout(horBox, BoxLayout.X_AXIS));
        horBox.setAlignmentX(Component.LEFT_ALIGNMENT);
        horBox.add(new JLabel("Corpus:"));
        horBox.add(Box.createHorizontalStrut(5));
        horBox.add(corpusCombo);
        horBox.add(Box.createHorizontalStrut(5));
        constraints.weightx = 1;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.weighty = 0;
        constraints.insets = new Insets(0, 0, 0, 0);
        bottomSplit.add(horBox, constraints);
        // all the following rows have one element only
        constraints.gridwidth = 1;
        constraints.gridy++;
    }
    // if(corpusControllerMode)
    parametersPanel = new JPanel();
    parametersPanel.setLayout(new BoxLayout(parametersPanel, BoxLayout.Y_AXIS));
    parametersPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    parametersBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " No selected processing resource ");
    parametersPanel.setBorder(parametersBorder);
    parametersEditor = new ResourceParametersEditor();
    parametersEditor.init(null, null);
    parametersPanel.add(new JScrollPane(parametersEditor));
    // parametersPanel.add(parametersEditor, constraints);
    constraints.weighty = 1;
    constraints.weightx = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(0, 0, 0, 0);
    bottomSplit.add(parametersPanel, constraints);
    constraints.gridy++;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.CENTER;
    bottomSplit.add(new JButton(runAction), constraints);
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, bottomSplit);
    splitPane.addAncestorListener(new AncestorListener() {

        @Override
        public void ancestorRemoved(AncestorEvent event) {
        }

        @Override
        public void ancestorMoved(AncestorEvent event) {
        }

        /**
         * One-shot ancestor listener that places the divider location on first
         * show, and then de-registers self.
         */
        @Override
        public void ancestorAdded(AncestorEvent event) {
            // This seems to work more reliably if queued rather than executed
            // directly.
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    splitPane.setDividerLocation(0.5);
                }
            });
            splitPane.removeAncestorListener(this);
        }
    });
    add(splitPane, BorderLayout.CENTER);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) XJTable(gate.swing.XJTable) BoxLayout(javax.swing.BoxLayout) CorpusController(gate.CorpusController) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) AncestorEvent(javax.swing.event.AncestorEvent) Corpus(gate.Corpus) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) BorderLayout(java.awt.BorderLayout) GateRuntimeException(gate.util.GateRuntimeException) AncestorListener(javax.swing.event.AncestorListener) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) Dimension(java.awt.Dimension) ButtonGroup(javax.swing.ButtonGroup) JSplitPane(javax.swing.JSplitPane)

Example 4 with Corpus

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

the class NameBearerHandle method buildStaticPopupItems.

protected void buildStaticPopupItems() {
    // build the static part of the popup
    staticPopupItems = new ArrayList<JComponent>();
    if (target instanceof ProcessingResource && !(target instanceof Controller)) {
        // actions for PRs (but not Controllers)
        staticPopupItems.add(null);
        staticPopupItems.add(new XJMenuItem(new ReloadAction(), sListenerProxy));
        staticPopupItems.add(new XJMenuItem(new ApplicationWithPRAction(), sListenerProxy));
    } else if (target instanceof LanguageResource) {
        // Language Resources
        staticPopupItems.add(null);
        if (target instanceof Document) {
            staticPopupItems.add(new XJMenuItem(new CreateCorpusForDocAction(), sListenerProxy));
        }
        if (target instanceof gate.TextualDocument) {
            staticPopupItems.add(null);
            staticPopupItems.add(new DocumentExportMenu(this));
        } else if (target instanceof Corpus) {
            corpusFiller = new CorpusFillerComponent();
            scfInputDialog = new SingleConcatenatedFileInputDialog();
            staticPopupItems.add(new XJMenuItem(new PopulateCorpusAction(), sListenerProxy));
            staticPopupItems.add(new XJMenuItem(new PopulateCorpusFromSingleConcatenatedFileAction(), sListenerProxy));
            staticPopupItems.add(null);
            staticPopupItems.add(new DocumentExportMenu(this));
        }
        if (((LanguageResource) target).getDataStore() != null) {
            // this item can be used only if the resource belongs to a
            // datastore
            staticPopupItems.add(new XJMenuItem(new SaveAction(), sListenerProxy));
        }
        if (!(target instanceof AnnotationSchema)) {
            staticPopupItems.add(new XJMenuItem(new SaveToAction(), sListenerProxy));
        }
    }
    if (target instanceof Controller) {
        // Applications
        staticPopupItems.add(null);
        if (target instanceof SerialAnalyserController) {
            staticPopupItems.add(new XJMenuItem(new MakeConditionalAction(), sListenerProxy));
        }
        staticPopupItems.add(new XJMenuItem(new DumpToFileAction(), sListenerProxy));
        staticPopupItems.add(new XJMenuItem(new ExportApplicationAction(), sListenerProxy));
    }
}
Also used : LanguageResource(gate.LanguageResource) ProcessingResource(gate.ProcessingResource) Document(gate.Document) IndexedCorpus(gate.creole.ir.IndexedCorpus) Corpus(gate.Corpus) AnnotationSchema(gate.creole.AnnotationSchema) SerialAnalyserController(gate.creole.SerialAnalyserController) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) JComponent(javax.swing.JComponent) SerialAnalyserController(gate.creole.SerialAnalyserController) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) CorpusController(gate.CorpusController) ConditionalController(gate.creole.ConditionalController) XJMenuItem(gate.swing.XJMenuItem)

Example 5 with Corpus

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

the class SerialDataStore method adopt.

// delete(lr)
/**
 * Adopt a resource for persistence.
 */
@Override
public LanguageResource adopt(LanguageResource lr) throws PersistenceException {
    // ignore security info
    // check the LR's current DS
    DataStore currentDS = lr.getDataStore();
    if (currentDS == null) {
        // an orphan - do the adoption
        LanguageResource res = lr;
        if (lr instanceof Corpus) {
            FeatureMap features1 = Factory.newFeatureMap();
            features1.put("transientSource", lr);
            try {
                // here we create the persistent LR via Factory, so it's registered
                // in GATE
                res = (LanguageResource) Factory.createResource("gate.corpora.SerialCorpusImpl", features1);
            // Here the transient corpus is not deleted from the CRI, because
            // this might not always be the desired behaviour
            // since we chose that it is for the GUI, this functionality is
            // now move to the 'Save to' action code in NameBearerHandle
            } catch (gate.creole.ResourceInstantiationException ex) {
                throw new GateRuntimeException(ex.getMessage());
            }
        }
        res.setDataStore(this);
        // let the world know
        fireResourceAdopted(new DatastoreEvent(this, DatastoreEvent.RESOURCE_ADOPTED, lr, null));
        return res;
    } else if (// adopted already here
    currentDS.equals(this))
        return lr;
    else {
        // someone else's child
        throw new PersistenceException("Can't adopt a resource which is already in a different datastore");
    }
}
Also used : FeatureMap(gate.FeatureMap) LanguageResource(gate.LanguageResource) DataStore(gate.DataStore) GateRuntimeException(gate.util.GateRuntimeException) DatastoreEvent(gate.event.DatastoreEvent) Corpus(gate.Corpus)

Aggregations

Corpus (gate.Corpus)15 Document (gate.Document)7 CorpusController (gate.CorpusController)4 LanguageResource (gate.LanguageResource)4 ProcessingResource (gate.ProcessingResource)4 GateRuntimeException (gate.util.GateRuntimeException)4 FeatureMap (gate.FeatureMap)3 Resource (gate.Resource)3 File (java.io.File)3 AbstractVisualResource (gate.creole.AbstractVisualResource)2 ResourceData (gate.creole.ResourceData)2 IndexedCorpus (gate.creole.ir.IndexedCorpus)2 CreoleResource (gate.creole.metadata.CreoleResource)2 DatastoreEvent (gate.event.DatastoreEvent)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 EventObject (java.util.EventObject)2 Controller (gate.Controller)1 CorpusExporter (gate.CorpusExporter)1