Search in sources :

Example 26 with Document

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

the class TestXml method testUnpackMarkup.

// runCompleteTestWithAFormat
/**
 * A test
 */
public void testUnpackMarkup() throws Exception {
    // create the markupElementsMap map
    // Map markupElementsMap = null;
    gate.Document doc = null;
    /*
    markupElementsMap = new HashMap();
    // populate it
    markupElementsMap.put ("S","Sentence");
    markupElementsMap.put ("s","Sentence");
    */
    // Create the element2String map
    Map<String, String> anElement2StringMap = new HashMap<String, String>();
    // Populate it
    anElement2StringMap.put("S", "\n");
    anElement2StringMap.put("s", "\n");
    doc = gate.Factory.newDocument(new URL(TestDocument.getTestServerName() + "tests/xml/xces.xml"), workingEncoding);
    AnnotationSet annotSet = doc.getAnnotations(GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
    assertEquals("For " + doc.getSourceUrl() + " the number of annotations" + " should be:758", 758, annotSet.size());
    gate.corpora.TestDocument.verifyNodeIdConsistency(doc);
    // Verifies if the maximum annotation ID on the GATE doc is less than the
    // Annotation ID generator of the document.
    verifyAnnotationIDGenerator(doc);
}
Also used : HashMap(java.util.HashMap) AnnotationSet(gate.AnnotationSet) Document(gate.Document) URL(java.net.URL)

Example 27 with Document

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

the class TestAnnic method testAnnicIndexing.

/**
 * Testing the annic indexing functionalities
 *
 * @throws Exception
 */
public void testAnnicIndexing() throws Exception {
    // lets create a corpus
    testCorpus = Factory.newCorpus("TestAnnic");
    File directory = new File(new File(new File(new File(new File(new File(new File(Gate.getGateHome(), "src"), "test"), "gate"), "resources"), "gate.ac.uk"), "tests"), "annic");
    File[] files = directory.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isFile()) {
            Document doc = Factory.newDocument(files[i].toURI().toURL(), "ISO-8859-1");
            testCorpus.add(doc);
        }
    }
    AnnicIndexing annicPR = new AnnicIndexing();
    LanguageAnalyser splitter = (LanguageAnalyser) Factory.createResource("gate.creole.splitter.SentenceSplitter");
    splitter.setParameterValue("inputASName", "Key");
    splitter.setParameterValue("outputASName", "Key");
    // splitter.setOutputASName("Key");
    for (int i = 0; i < testCorpus.size(); i++) {
        splitter.setDocument(testCorpus.get(i));
        splitter.execute();
    }
    // index
    annicPR.setAnnotationSetName("Key");
    annicPR.setBaseTokenAnnotationType("Token");
    annicPR.setCorpus(testCorpus);
    annicPR.setIndexUnitAnnotationType("Sentence");
    annicPR.setIndexOutputDirectoryLocation(indexURL.toURI().toURL());
    annicPR.execute();
    Factory.deleteResource(testCorpus);
}
Also used : LanguageAnalyser(gate.LanguageAnalyser) Document(gate.Document) File(java.io.File)

Example 28 with Document

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

the class DynamicRegistrationTest method testDynamicRegistration.

public void testDynamicRegistration() throws Exception {
    Gate.getCreoleRegister().registerPlugin(new Plugin.Component(TestResource.class));
    SerialAnalyserController controller = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController", Factory.newFeatureMap(), Factory.newFeatureMap(), "basicRun");
    ProcessingResource testResource = (ProcessingResource) Factory.createResource(TestResource.class.getName());
    controller.add(testResource);
    Corpus corpus = Factory.newCorpus("basicTestCorpus");
    String engText = "This is the cereal shot from gnus.";
    Document doc = Factory.newDocument(engText);
    corpus.add(doc);
    controller.setCorpus(corpus);
    controller.setDocument(doc);
    controller.execute();
}
Also used : ProcessingResource(gate.ProcessingResource) Document(gate.Document) Corpus(gate.Corpus)

Example 29 with Document

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

the class TestPersist method testSimple.

// testSaveRestore()
/**
 * Simple test
 */
public void testSimple() throws Exception {
    // create a temporary directory; because File.createTempFile actually
    // writes the bloody thing, we need to delete it from disk before calling
    // DataStore.create
    File storageDir = File.createTempFile("TestPersist__", "__StorageDir");
    storageDir.delete();
    // create and open a serial data store
    DataStore sds = Factory.createDataStore("gate.persist.SerialDataStore", storageDir.toURI().toURL().toString());
    // check we can get empty lists from empty data stores
    @SuppressWarnings("unused") List<String> lrTypes = sds.getLrTypes();
    // create a document with some annotations / features on it
    String server = TestDocument.getTestServerName();
    Document doc = Factory.newDocument(new URL(server + "tests/doc0.html"));
    doc.getFeatures().put("hi there", new Integer(23232));
    doc.getAnnotations().add(new Long(5), new Long(25), "ThingyMaJig", Factory.newFeatureMap());
    // save the document
    Document persDoc = (Document) sds.adopt(doc);
    sds.sync(persDoc);
    // remember the persistence ID for reading back
    // (in the normal case these ids are obtained by DataStore.getLrIds(type))
    Object lrPersistenceId = persDoc.getLRPersistenceId();
    // read the document back
    FeatureMap features = Factory.newFeatureMap();
    features.put(DataStore.LR_ID_FEATURE_NAME, lrPersistenceId);
    features.put(DataStore.DATASTORE_FEATURE_NAME, sds);
    Document doc2 = (Document) Factory.createResource("gate.corpora.DocumentImpl", features);
    // parameters should be different
    // check that the version we read back matches the original
    assertTrue(TestEqual.documentsEqual(persDoc, doc2));
    // delete the datastore
    sds.delete();
}
Also used : FeatureMap(gate.FeatureMap) DataStore(gate.DataStore) TestDocument(gate.corpora.TestDocument) Document(gate.Document) File(java.io.File) URL(java.net.URL)

Example 30 with Document

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

the class TestPersist method testDelete.

// testMultipleLrs()
/**
 * Test LR deletion
 */
public void testDelete() throws Exception {
    // create a temporary directory; because File.createTempFile actually
    // writes the bloody thing, we need to delete it from disk before calling
    // DataStore.create
    File storageDir = File.createTempFile("TestPersist__", "__StorageDir");
    if (DEBUG)
        Out.prln("Corpus stored to: " + storageDir.getAbsolutePath());
    storageDir.delete();
    // create and open a serial data store
    SerialDataStore sds = new SerialDataStore();
    sds.setStorageUrl(storageDir.toURI().toURL().toString());
    sds.create();
    sds.open();
    // create a document with some annotations / features on it
    String server = TestDocument.getTestServerName();
    Document doc = Factory.newDocument(new URL(server + "tests/doc0.html"));
    doc.getFeatures().put("hi there", new Integer(23232));
    doc.getAnnotations().add(new Long(5), new Long(25), "ThingyMaJig", Factory.newFeatureMap());
    // save the document
    Document persDoc = (Document) sds.adopt(doc);
    sds.sync(persDoc);
    // remember the persistence ID for reading back
    // (in the normal case these ids are obtained by DataStore.getLrIds(type))
    Object lrPersistenceId = persDoc.getLRPersistenceId();
    // delete document back
    sds.delete("gate.corpora.DocumentImpl", lrPersistenceId);
    // check that there are no LRs left in the DS
    assertTrue(sds.getLrIds("gate.corpora.DocumentImpl").size() == 0);
    // delete the datastore
    sds.delete();
}
Also used : TestDocument(gate.corpora.TestDocument) Document(gate.Document) File(java.io.File) URL(java.net.URL)

Aggregations

Document (gate.Document)47 File (java.io.File)17 FeatureMap (gate.FeatureMap)16 URL (java.net.URL)12 AnnotationSet (gate.AnnotationSet)9 TestDocument (gate.corpora.TestDocument)9 Annotation (gate.Annotation)7 Corpus (gate.Corpus)7 ResourceInstantiationException (gate.creole.ResourceInstantiationException)7 PersistenceException (gate.persist.PersistenceException)6 DataStore (gate.DataStore)5 LanguageResource (gate.LanguageResource)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 LanguageAnalyser (gate.LanguageAnalyser)4 SerialDataStore (gate.persist.SerialDataStore)4 GateRuntimeException (gate.util.GateRuntimeException)4 ActionEvent (java.awt.event.ActionEvent)4 List (java.util.List)4 AbstractAction (javax.swing.AbstractAction)4