如何以编程方式将新Lookup添加到DefaultGazetteer中

时间:2015-06-01 09:09:09

标签: java gate

我想以编程方式将新的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, "@"));

1 个答案:

答案 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);