use of gate.FeatureMap in project gate-core by GateNLP.
the class TestRepositioningInfo method setUp.
/**
* This method sets up the parameters for the files to be tested
*/
@Override
protected void setUp() throws Exception {
if (!Gate.isInitialised()) {
Gate.runInSandbox(true);
Gate.init();
}
testFile = TestDocument.getTestServerName() + "tests/test-inline.xml";
// creating documents
try {
FeatureMap params = Factory.newFeatureMap();
params.put("sourceUrl", new URL(testFile));
params.put("preserveOriginalContent", new Boolean("true"));
params.put("collectRepositioningInfo", new Boolean("true"));
doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", params);
} catch (MalformedURLException murle) {
fail("Document cannot be created ");
} catch (ResourceInstantiationException rie) {
fail("Resources cannot be created for the test document");
}
}
use of gate.FeatureMap 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();
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestCreole method testIntrospection.
// testArbitraryMetadata()
/**
* Test resource introspection
*/
@SuppressWarnings("unused")
public void testIntrospection() throws Exception {
// get the gate.Document resource and its class
ResourceData docRd = reg.get("gate.corpora.DocumentImpl");
assertNotNull("couldn't find document res data (2)", docRd);
Class<?> resClass = docRd.getResourceClass();
// get the beaninfo and property descriptors for the resource
BeanInfo docBeanInfo = Introspector.getBeanInfo(resClass, Object.class);
PropertyDescriptor[] propDescrs = docBeanInfo.getPropertyDescriptors();
// print all the properties in the reource's bean info;
// remember the setFeatures method
Method setFeaturesMethod = null;
for (int i = 0; i < propDescrs.length; i++) {
Method getMethodDescr = null;
Method setMethodDescr = null;
Class<?> propClass = null;
PropertyDescriptor propDescr = propDescrs[i];
propClass = propDescr.getPropertyType();
getMethodDescr = propDescr.getReadMethod();
setMethodDescr = propDescr.getWriteMethod();
if (setMethodDescr != null && setMethodDescr.getName().equals("setFeatures"))
setFeaturesMethod = setMethodDescr;
if (DEBUG)
printProperty(propDescrs[i]);
}
// try setting the features property
// invoke(Object obj, Object[] args)
LanguageResource res = (LanguageResource) resClass.newInstance();
FeatureMap feats = Factory.newFeatureMap();
feats.put("things are sunny in sunny countries", "aren't they?");
Object[] args = new Object[1];
args[0] = feats;
setFeaturesMethod.invoke(res, args);
assertTrue("features not added to resource properly", res.getFeatures().get("things are sunny in sunny countries").equals("aren't they?"));
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestResourceReference method checkPersistence.
public void checkPersistence(File xgappFile, ResourceReference rr1, String expected) throws Exception {
Resource resource = null, restored = null;
try {
FeatureMap params = Factory.newFeatureMap();
params.put("param", rr1);
resource = Factory.createResource(TestResource.class.getName(), params);
PersistenceManager.saveObjectToFile(resource, xgappFile);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xgappFile);
Element entry = doc.getRootElement().getChild("application").getChild("initParams").getChild("localMap").getChild("entry");
assertEquals("couldn't find the paramameter entry", "param", entry.getChildText("string"));
Element value = entry.getChild("gate.util.persistence.PersistenceManager-RRPersistence");
assertNotNull("We couldn't find the RRPersistence wrapper", value);
assertEquals("The URI was not as expected", expected, value.getChildText("uriString"));
restored = (Resource) PersistenceManager.loadObjectFromFile(xgappFile);
ResourceReference rr2 = (ResourceReference) restored.getParameterValue("param");
assertEquals(rr1, rr2);
} finally {
if (xgappFile != null)
xgappFile.deleteOnExit();
if (resource != null) {
Factory.deleteResource(resource);
}
if (restored != null) {
Factory.deleteResource(restored);
}
}
}
use of gate.FeatureMap in project gate-core by GateNLP.
the class TestSgml method testSgmlLoading.
// setUp
public void testSgmlLoading() throws Exception {
assertTrue(true);
// create the markupElementsMap map
Map<String, String> markupElementsMap = null;
gate.Document doc = null;
/*
markupElementsMap = new HashMap();
// populate it
markupElementsMap.put ("S","Sentence");
markupElementsMap.put ("s","Sentence");
markupElementsMap.put ("W","Word");
markupElementsMap.put ("w","Word");
*/
FeatureMap params = Factory.newFeatureMap();
params.put(Document.DOCUMENT_URL_PARAMETER_NAME, new URL(TestDocument.getTestServerName() + "tests/sgml/Hds.sgm"));
params.put(Document.DOCUMENT_MARKUP_AWARE_PARAMETER_NAME, "false");
doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", params);
// get the docFormat that deals with it.
// the parameter MimeType doesn't affect right now the behaviour
// *
gate.DocumentFormat docFormat = gate.DocumentFormat.getDocumentFormat(doc, doc.getSourceUrl());
assertTrue("Bad document Format was produced. SgmlDocumentFormat was expected", docFormat instanceof gate.corpora.SgmlDocumentFormat);
// set's the map
docFormat.setMarkupElementsMap(markupElementsMap);
docFormat.unpackMarkup(doc, "DocumentContent");
AnnotationSet annotSet = doc.getAnnotations(GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
assertEquals("For " + doc.getSourceUrl() + " the number of annotations" + " should be:1022", 1022, annotSet.size());
// Verfy if all annotations from the default annotation set are consistent
gate.corpora.TestDocument.verifyNodeIdConsistency(doc);
}
Aggregations