Search in sources :

Example 1 with IREngine

use of gate.creole.ir.IREngine in project gate-core by GateNLP.

the class SerialCorpusImpl method setIndexDefinition.

// readObject
@Override
public void setIndexDefinition(IndexDefinition definition) {
    if (definition != null) {
        this.getFeatures().put(GateConstants.CORPUS_INDEX_DEFINITION_FEATURE_KEY, definition);
        String className = definition.getIrEngineClassName();
        try {
            // Class aClass = Class.forName(className);
            Class<?> aClass = Class.forName(className, true, Gate.getClassLoader());
            IREngine engine = (IREngine) aClass.newInstance();
            this.indexManager = engine.getIndexmanager();
            this.indexManager.setIndexDefinition(definition);
            this.indexManager.setCorpus(this);
        } catch (Exception e) {
            e.printStackTrace(Err.getPrintWriter());
        }
        // switch (definition.getIndexType()) {
        // case GateConstants.IR_LUCENE_INVFILE:
        // this.indexManager = new LuceneIndexManager();
        // this.indexManager.setIndexDefinition(definition);
        // this.indexManager.setCorpus(this);
        // break;
        // }
        this.addedDocs = new Vector<Document>();
        this.removedDocIDs = new Vector<String>();
        this.changedDocs = new Vector<Document>();
    }
}
Also used : IREngine(gate.creole.ir.IREngine) Document(gate.Document) GateRuntimeException(gate.util.GateRuntimeException) ResourceInstantiationException(gate.creole.ResourceInstantiationException) IOException(java.io.IOException) IndexException(gate.creole.ir.IndexException) MethodNotImplementedException(gate.util.MethodNotImplementedException) PersistenceException(gate.persist.PersistenceException)

Example 2 with IREngine

use of gate.creole.ir.IREngine in project gate-core by GateNLP.

the class CreateIndexGUI method initGUIComponents.

protected void initGUIComponents() {
    setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(2, 5, 2, 5);
    // first line
    constraints.gridy = 0;
    constraints.gridwidth = 2;
    add(new JLabel("IR Engine type:"), constraints);
    constraints.gridwidth = 4;
    irEngineCombo = new JComboBox<String>();
    add(irEngineCombo, constraints);
    // second line
    constraints.gridy = 1;
    constraints.gridwidth = 2;
    add(new JLabel("Index location:"), constraints);
    constraints.gridwidth = 4;
    indexLocationTextField = new JTextField(40);
    add(indexLocationTextField, constraints);
    constraints.gridwidth = 1;
    add(new JButton(new SelectDirAction()), constraints);
    // third line
    constraints.gridy = 2;
    constraints.gridwidth = 2;
    add(new JLabel("Features to index:"), constraints);
    featuresListTextField = new JTextField(40);
    featuresListTextField.setEditable(false);
    constraints.gridwidth = 4;
    add(featuresListTextField, constraints);
    constraints.gridwidth = 1;
    add(new JButton(new EditFeatureListAction()), constraints);
    // fourth line
    constraints.gridy = 3;
    constraints.gridwidth = 4;
    useContentChk = new JCheckBox("Use document content", true);
    add(useContentChk, constraints);
    // populate engine names combo
    String oldIREngineName = (String) irEngineCombo.getSelectedItem();
    List<String> irEngines = new ArrayList<String>(Gate.getRegisteredIREngines());
    engineByName.clear();
    for (int i = 0; i < irEngines.size(); i++) {
        String anIREngineClassName = irEngines.get(i);
        try {
            Class<?> aClass = Class.forName(anIREngineClassName, true, Gate.getClassLoader());
            IREngine engine = (IREngine) aClass.newInstance();
            engineByName.put(engine.getName(), engine);
        } catch (ClassNotFoundException cnfe) {
        } catch (IllegalAccessException iae) {
        } catch (InstantiationException ie) {
        }
    }
    String[] names = new String[engineByName.size()];
    int i = 0;
    Iterator<String> namesIter = engineByName.keySet().iterator();
    while (namesIter.hasNext()) {
        names[i++] = namesIter.next();
    }
    irEngineCombo.setModel(new DefaultComboBoxModel<String>(names));
    if (oldIREngineName != null && engineByName.containsKey(oldIREngineName)) {
        irEngineCombo.setSelectedItem(oldIREngineName);
    } else if (engineByName.size() > 0)
        irEngineCombo.setSelectedIndex(0);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) IREngine(gate.creole.ir.IREngine)

Aggregations

IREngine (gate.creole.ir.IREngine)2 Document (gate.Document)1 ResourceInstantiationException (gate.creole.ResourceInstantiationException)1 IndexException (gate.creole.ir.IndexException)1 PersistenceException (gate.persist.PersistenceException)1 GateRuntimeException (gate.util.GateRuntimeException)1 MethodNotImplementedException (gate.util.MethodNotImplementedException)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JTextField (javax.swing.JTextField)1