This will add a Lookup only:
Lookup l = new Lookup("glossary.lst", "major", "minor", "en", "AnnotType");
l.features = new HashMap<>();
l.features.put("someFeatureName", "some value");
gazetter.add("string to be found", l);
This will update the linear definition (.def
& .lst
files):
LinearDefinition ld = gazetter.getLinearDefinition();
//add .lst record
LinearNode ln = new LinearNode("glossary.lst", "minor", "major", "en", "AnnotType");
ld.add(ln);
//add Lookup record
Map<String, Object> features = new HashMap<>();
features.put("someFeatureName", "some value");
GazetteerNode gn = new GazetteerNode("string to be found", features);
gn.setSeparator("@");
GazetteerList theList = ld.getListsByNode().get(ln);
theList.add(gn);
//save updated files
theList.store();
ld.store();
//optionally re-init the gazetteer to make changes to work
gazetter.reInit();
If your gazetteer configuration is consistent (mainly the separator), then
theList.store(); ld.store(); gazetter.reInit();
will load the updated configuration. You do not necessarily have to combine the second approach with the first one. But because store()
and reInit()
are very expensive operations compared to Lookup addition, I do not recommend calling it frequently. I would prefer some kind of combination (as you mentioned in the comments) or do the Lookup addition only if you do not care about the .def
& .lst
files (you may be persisting your lookups already somehow/somewhere).
Removing Lookup(s)
Lookup only:
//This will remove all Lookups for given string
gazetteer.remove("string to be found");
//This will remove a specific Lookup only
//The method is not included in the Gazetteer interface
((DefaultGazetteer) gazetter).removeLookup("string to be found", l);
Linear definition only:
theList.remove(gn);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…