use of gate.FeatureMap in project gate-core by GateNLP.
the class TestPersist method testSaveRestore.
// tearDown
/**
* Test resource save and restore
*/
public void testSaveRestore() throws Exception {
File storageDir = File.createTempFile("TestPersist__", "__StorageDir");
// get rid of the temp file
storageDir.delete();
// create an empty dir of same name
storageDir.mkdir();
SerialDataStore sds = new SerialDataStore(storageDir.toURI().toURL().toString());
sds.create();
sds.open();
// create a document
String server = TestDocument.getTestServerName();
assertNotNull(server);
Document doc = Factory.newDocument(new URL(server + "tests/doc0.html"));
assertNotNull(doc);
doc.getFeatures().put("hi there", new Integer(23232));
doc.getAnnotations().add(new Long(0), new Long(20), "thingymajig", Factory.newFeatureMap());
// check that we can't save a resource without adopting it
boolean cannotSync = false;
try {
sds.sync(doc);
} catch (PersistenceException e) {
cannotSync = true;
}
if (!cannotSync)
assertTrue("doc synced ok before adoption", false);
// check that we can't adopt a resource that's stored somewhere else
doc.setDataStore(new SerialDataStore(new File("z:\\").toURI().toURL().toString()));
try {
sds.adopt(doc);
} catch (PersistenceException e) {
cannotSync = true;
}
if (!cannotSync)
assertTrue("doc adopted but in other datastore already", false);
doc.setDataStore(null);
doc.setName("Alicia Tonbridge, a Document");
// save the document
Document persDoc = (Document) sds.adopt(doc);
sds.sync(persDoc);
Object lrPersistenceId = persDoc.getLRPersistenceId();
// test the getLrTypes method
List<String> lrTypes = sds.getLrTypes();
assertTrue("wrong number of types in SDS", lrTypes.size() == 1);
assertTrue("wrong type LR in SDS", lrTypes.get(0).equals("gate.corpora.DocumentImpl"));
// test the getLrNames method
Iterator<String> iter = sds.getLrNames("gate.corpora.DocumentImpl").iterator();
String name = iter.next();
assertEquals(name, "Alicia Tonbridge, a Document");
// 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);
Document doc3 = (Document) sds.getLr("gate.corpora.DocumentImpl", lrPersistenceId);
try {
boolean value = TestEqual.documentsEqual(doc3, doc2);
assertTrue(TestEqual.message, value);
value = TestEqual.documentsEqual(persDoc, doc2);
assertTrue(TestEqual.message, value);
} finally {
// delete the datastore
sds.delete();
}
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestDiffer method testDiffer.
// tearDown
public void testDiffer() throws Exception {
Document doc = Factory.newDocument(new URL(gate.corpora.TestDocument.getTestServerName() + "tests/ft-bt-03-aug-2001.html"), "windows-1252");
AnnotationSet annSet = doc.getAnnotations();
// create 100 annotations
FeatureMap features = Factory.newFeatureMap();
features.put("type", "BAR");
for (int i = 0; i < 100; i++) {
annSet.add(new Long(i * 10), new Long((i + 1) * 10), "Foo", features);
}
List<Annotation> keySet = new ArrayList<Annotation>(annSet);
List<Annotation> responseSet = new ArrayList<Annotation>(annSet);
// check 100% Precision and recall
AnnotationDiffer differ = new AnnotationDiffer();
differ.setSignificantFeaturesSet(null);
differ.calculateDiff(keySet, responseSet);
differ.sanityCheck();
if (DEBUG)
differ.printMissmatches();
double value = differ.getPrecisionStrict();
Assert.assertEquals("Precision Strict: " + value + " instead of 1!", 1, value, 0);
value = differ.getRecallStrict();
Assert.assertEquals("Recall Strict: " + value + " instead of 1!", 1, value, 0);
value = differ.getPrecisionLenient();
Assert.assertEquals("Precision Lenient: " + value + " instead of 1!", 1, value, 0);
value = differ.getRecallLenient();
Assert.assertEquals("Recall Lenient: " + value + " instead of 1!", 1, value, 0);
// check low precision
Integer id = annSet.add(new Long(2), new Long(4), "Foo", features);
Annotation falsePositive = annSet.get(id);
responseSet.add(falsePositive);
differ.calculateDiff(keySet, responseSet);
differ.sanityCheck();
if (DEBUG)
differ.printMissmatches();
value = differ.getPrecisionStrict();
Assert.assertEquals("Precision Strict: " + value + " instead of .99!", .99, value, .001);
// recall should still be 100%
value = differ.getRecallStrict();
Assert.assertEquals("Recall Strict: " + value + " instead of 1!", 1, value, 0);
value = differ.getRecallLenient();
Assert.assertEquals("Recall Lenient: " + value + " instead of 1!", 1, value, 0);
// check low recall
responseSet.remove(falsePositive);
keySet.add(falsePositive);
differ.calculateDiff(keySet, responseSet);
differ.sanityCheck();
if (DEBUG)
differ.printMissmatches();
value = differ.getRecallStrict();
Assert.assertEquals("Recall Strict: " + value + " instead of .99!", .99, value, .001);
// precision should still be 100%
value = differ.getPrecisionStrict();
Assert.assertEquals("Precision Strict: " + value + " instead of 1!", 1, value, 0);
value = differ.getPrecisionLenient();
Assert.assertEquals("Precision Lenient: " + value + " instead of 1!", 1, value, 0);
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestCreole method testLoading.
// testToolsAndPrivate()
/**
* Test resource loading
*/
public void testLoading() throws Exception {
// get some res data from the register
assertEquals("wrong number of resources in the register: " + reg.size(), 9, reg.size());
ResourceData pr1rd = reg.get("testpkg.TestPR1");
ResourceData pr2rd = reg.get("testpkg.TestPR2");
assertTrue("couldn't find PR1/PR2 res data", pr1rd != null && pr2rd != null);
assertTrue("wrong name on PR1", pr1rd.getName().equals("Sheffield Test PR 1"));
// instantiation
ProcessingResource pr1 = (ProcessingResource) Factory.createResource("testpkg.TestPR1", Factory.newFeatureMap());
ProcessingResource pr2 = (ProcessingResource) Factory.createResource("testpkg.TestPR2", Factory.newFeatureMap());
// run the beasts
FeatureMap pr1features = pr1.getFeatures();
FeatureMap pr2features = pr2.getFeatures();
assertNotNull("PR1 features are null", pr1features);
assertTrue("PR2 got wrong features: " + pr2features, pr2features != null && pr2features.size() != 1);
pr1.execute();
pr2.execute();
assertTrue("PR1 feature not present", pr1.getFeatures().get("I").equals("have been run, thankyou"));
assertTrue("PR2 feature not present", pr2.getFeatures().get("I").equals("am in a bad mood"));
reg.clear();
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestCreole method testFactory.
// testIntrospection
/**
* Test the Factory resource creation provisions
*/
public void testFactory() throws Exception {
FeatureMap params = Factory.newFeatureMap();
params.put("features", Factory.newFeatureMap());
params.put(Document.DOCUMENT_URL_PARAMETER_NAME, new URL(TestDocument.getTestServerName() + "tests/doc0.html"));
Resource res = Factory.createResource("gate.corpora.DocumentImpl", params);
assertNotNull("unable to create document", res);
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestCreole method testInstanceLists.
// tearDown
/**
* Test the getInstances methods on CreoleRegister
*/
public void testInstanceLists() throws Exception {
// misc locals
List<? extends Resource> l;
CreoleRegister cr = Gate.getCreoleRegister();
int numLrInstances = 0;
// The only instances of any type should be autoloading ones
l = cr.getVrInstances();
if (!allAutoloaders(l))
fail(" non-autoloading resources already present (1)");
l = cr.getLrInstances();
numLrInstances = l.size();
if (!allAutoloaders(l))
fail(" non-autoloading resources already present (2)");
l = cr.getPrInstances();
if (!allAutoloaders(l))
fail(" non-autoloading resources already present (3)");
// Create an LR
FeatureMap params = Factory.newFeatureMap();
params.put("features", Factory.newFeatureMap());
params.put(Document.DOCUMENT_URL_PARAMETER_NAME, new URL(TestDocument.getTestServerName() + "tests/doc0.html"));
Factory.createResource("gate.corpora.DocumentImpl", params);
// lr instances list should be one longer now
if (!(cr.getLrInstances().size() == numLrInstances + 1))
fail("wrong number of LRs");
// Create another LR
params = Factory.newFeatureMap();
params.put("features", Factory.newFeatureMap());
params.put(Document.DOCUMENT_URL_PARAMETER_NAME, new URL(TestDocument.getTestServerName() + "tests/doc0.html"));
Factory.createResource("gate.corpora.DocumentImpl", params);
// lr instances list should be two longer now
if (!(cr.getLrInstances().size() == numLrInstances + 2))
fail("wrong number of LRs");
// we should have two instances of type document
l = cr.getLrInstances("gate.corpora.DocumentImpl");
if (l.size() != 2)
fail("wrong number of documents");
}
Aggregations