我想以编程方式将新的Lookup添加到已加载的DefaultGazetteer
中。
如果我通过文件添加此字符串,它可以正常工作
任何帮助都会受到欢迎。感谢
String test="hello@code=555.5@code_asociated_description=World@code1=@code2=@code3=@code4=@code5=@code6=@code7=";
gazetter.add(test, new Lookup("glossary.lst", "test", "test", "en"));
theList.add(new GazetteerNode(test, "@"));
答案 0 :(得分:3)
这将仅添加查找:
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
&amp; .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
&amp ;;我希望某种组合(如您在评论中提到的那样)或仅添加Lookup 。 .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);