这将只添加一个查找:
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);
这将更新线性定义(.def & .lst 文件):
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();
如果你的地名词典配置是一致的(主要是分隔符),那么
theList.store(); ld.store(); gazetter.reInit();
将加载更新的配置。您不一定必须将第二种方法与第一种方法结合起来。但是因为store() 和reInit() 相比 Lookup 加法来说是非常昂贵的操作,所以我不建议经常调用它。如果您不关心 .def 和 .lst 文件(您可能会持续查找已经不知何故/某处)。
删除查找
仅查找:
//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);
线性定义仅:
theList.remove(gn);