Search in sources :

Example 11 with Corpus

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

the class TestAnnotationMerging method testAnnotationMerging.

/**
 * The test for AnnotationMerging.
 */
public void testAnnotationMerging() throws Exception {
    Boolean savedSpaceSetting = Gate.getUserConfig().getBoolean(GateConstants.DOCUMENT_ADD_SPACE_ON_UNPACK_FEATURE_NAME);
    Gate.getUserConfig().put(GateConstants.DOCUMENT_ADD_SPACE_ON_UNPACK_FEATURE_NAME, Boolean.FALSE);
    try {
        // Gate.setGateHome(new File("C:\\svn\\gate"));
        // Gate.setUserConfigFile(new File("C:\\svn\\gate.xml"));
        // Gate.init();
        // Load the documents into a corpus
        Corpus data = Factory.newCorpus("data");
        // Put the annotated document into a matrix for IAA
        String nameAnnSet;
        String nameAnnType = "";
        String nameAnnFeat = "";
        // Use the dataset of one document and three annotators
        data.add(loadDocument("tests/iaa/beijing-opera.xml", "beijing-opera.xml"));
        // ExtensionFileFilter fileFilter = new ExtensionFileFilter();
        // fileFilter.addExtension("xml");
        // data.populate(new File("C:\\yaoyong_h\\work\\iaa\\data\\smallData").toURI().toURL(), fileFilter, "UTF-8", false);
        nameAnnSet = "ann1;ann2;ann3";
        boolean isUsingMajority = false;
        nameAnnType = "sent";
        nameAnnFeat = "Op";
        caseN = 1;
        isUsingMajority = true;
        testWithfeat(nameAnnSet, nameAnnType, nameAnnFeat, data, isUsingMajority);
        caseN = 2;
        isUsingMajority = false;
        testWithfeat(nameAnnSet, nameAnnType, nameAnnFeat, data, isUsingMajority);
        nameAnnType = "Os";
        nameAnnFeat = null;
        caseN = 3;
        isUsingMajority = true;
        testWithfeat(nameAnnSet, nameAnnType, nameAnnFeat, data, isUsingMajority);
        caseN = 4;
        isUsingMajority = false;
        testWithfeat(nameAnnSet, nameAnnType, nameAnnFeat, data, isUsingMajority);
    } finally {
        Gate.getUserConfig().put(GateConstants.DOCUMENT_ADD_SPACE_ON_UNPACK_FEATURE_NAME, savedSpaceSetting);
    }
}
Also used : Corpus(gate.Corpus)

Example 12 with Corpus

use of gate.Corpus 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 13 with Corpus

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

the class CorpusQualityAssurance method setTarget.

@Override
public void setTarget(Object target) {
    if (corpus != null && corpus != target) {
        // we already had a different corpus
        corpus.removeCorpusListener(this);
    }
    if (!(target instanceof Corpus)) {
        throw new IllegalArgumentException("This view can only be used with a GATE corpus!\n" + target.getClass().toString() + " is not a GATE corpus!");
    }
    this.corpus = (Corpus) target;
    corpus.addCorpusListener(this);
    corpusChanged = true;
    if (!isShowing()) {
        return;
    }
    if (timerTask != null) {
        timerTask.cancel();
    }
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    timerTask = new TimerTask() {

        @Override
        public void run() {
            readSetsTypesFeatures(0);
        }
    };
    // add a delay before updating
    timer.schedule(timerTask, timeToRun);
}
Also used : TimerTask(java.util.TimerTask) Corpus(gate.Corpus) Date(java.util.Date)

Example 14 with Corpus

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

the class SerialControllerEditor method resourceUnloaded.

@Override
public void resourceUnloaded(CreoleEvent e) {
    if (Gate.getHiddenAttribute(e.getResource().getFeatures()))
        return;
    if (e.getResource() instanceof ProcessingResource) {
        ProcessingResource pr = (ProcessingResource) e.getResource();
        if (controller != null && controller.getPRs().contains(pr)) {
            controller.remove(pr);
        }
        refreshPRLists();
    } else if (e.getResource() instanceof LanguageResource) {
        if (e.getResource() instanceof Corpus && corpusControllerMode) {
            Corpus c = (Corpus) e.getResource();
            if (controller instanceof CorpusController) {
                if (c == ((CorpusController) controller).getCorpus()) {
                    // setCorpus(null) is also called in the controller's
                    // resourceUnloaded(), but we can't be sure which handler is
                    // called first...
                    ((CorpusController) controller).setCorpus(null);
                }
            } else {
                throw new GateRuntimeException("Controller editor in analyser mode " + "but the target controller is not an " + "analyser!");
            }
            corpusComboModel.fireDataChanged();
        }
    }
}
Also used : LanguageResource(gate.LanguageResource) CorpusController(gate.CorpusController) GateRuntimeException(gate.util.GateRuntimeException) ProcessingResource(gate.ProcessingResource) Corpus(gate.Corpus)

Example 15 with Corpus

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

the class CorpusBenchmarkTool method processDocument.

// evaluateMarkedClean
protected void processDocument(Document doc) {
    try {
        if (application instanceof CorpusController) {
            Corpus tempCorpus = Factory.newCorpus("temp");
            tempCorpus.add(doc);
            ((CorpusController) application).setCorpus(tempCorpus);
            application.execute();
            Factory.deleteResource(tempCorpus);
            tempCorpus = null;
        } else {
            Iterator<ProcessingResource> iter = application.getPRs().iterator();
            while (iter.hasNext()) iter.next().setParameterValue("document", doc);
            application.execute();
        }
    } catch (ResourceInstantiationException ex) {
        throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
    } catch (ExecutionException ex) {
        throw (RuntimeException) new RuntimeException("Error executing application: " + ex.getMessage()).initCause(ex);
    }
}
Also used : CorpusController(gate.CorpusController) ProcessingResource(gate.ProcessingResource) ExecutionException(gate.creole.ExecutionException) Corpus(gate.Corpus) ResourceInstantiationException(gate.creole.ResourceInstantiationException)

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