如何以编程方式将新的Lookup添加到DefaultGazetteer [英] How to add new Lookup into DefaultGazetteer programatically

查看:78
本文介绍了如何以编程方式将新的Lookup添加到DefaultGazetteer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式将新的Lookup添加到已加载的DefaultGazetteer中.

I want to add new Lookup into loaded DefaultGazetteer programatically.

如果我通过文件添加此字符串,则效果很好

If I add this string via file, it works perfectly

任何帮助都会受到欢迎.谢谢

Any help will be much welcomed. Thanks

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, "@"));

推荐答案

这将仅添加查找:

    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文件):

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();

将加载更新的配置.您不一定必须将第二种方法与第一种方法结合起来.但是,由于store()reInit()与Lookup加法相比是非常昂贵的操作,因此我不建议您频繁调用它.如果您对.def& .lst文件(您可能已经以某种方式/某处持久保存了查找).

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).

查找:

//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);

这篇关于如何以编程方式将新的Lookup添加到DefaultGazetteer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆