java - How to add new Lookup into DefaultGazetteer programatically -


i want add new lookup loaded defaultgazetteer programatically.

if add string via file, works perfectly

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

this add 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 found", l); 

this update 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 found", features);     gn.setseparator("@");     gazetteerlist thelist = ld.getlistsbynode().get(ln);     thelist.add(gn);      //save updated files      thelist.store();     ld.store();      //optionally re-init gazetteer make changes work      gazetter.reinit(); 

if gazetteer configuration consistent (mainly separator), then

thelist.store(); ld.store(); gazetter.reinit(); 

will load updated configuration. not have combine second approach first one. because store() , reinit() expensive operations compared lookup addition, not recommend calling frequently. prefer kind of combination (as mentioned in comments) or do lookup addition only if not care .def & .lst files (you may persisting lookups somehow/somewhere).

removing lookup(s)

lookup only:

//this remove lookups given string gazetteer.remove("string found");  //this remove specific lookup //the method not included in gazetteer interface ((defaultgazetteer) gazetter).removelookup("string found", l); 

linear definition only:

thelist.remove(gn); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -