[libvoikko] Relation between spelling and grammar checkers
Harri Pitkänen
hatapitk at iki.fi
Mon Sep 23 20:01:46 EEST 2013
On Sunday 22 September 2013 16:00:53 Francis Tyers wrote:
> El dg 22 de 09 de 2013 a les 18:58 +0300, en/na Harri Pitkänen va
> escriure:
> > Unless you have already started to implement the loader (there are no
> > changes towards that in Git) I could do the refactoring early next week.
> > Would that be OK? Then it should be much easier for you to implement your
> > loader.
> I haven't started yet, no, and yes that would be a great help, thanks :)
The refactoring is now complete. Hopefully I did not break anything, at least
it looks like things are working as they should. In fact I even fixed one edge
case bug that affected the variant matching for ZHFST spellers. So if you have
had problems with using ZHFST spellers in LibreOffice, please pull the latest
changes from Git master, rebuild and see if it works now.
Now you can add a new dictionary loader quite easily. Create a class
setup::V4DictionaryLoader. There are two existing examples for V2 and V3. V3
may be quite close to what you need. Basically you just need to implement one
method
findDictionaries(const string & path)
which must look for available dictionaries within the given path. The path
here will be "/home/username/.voikko", "/usr/lib/voikko" or something similar.
There is a helper method for listing available subdirectories so you don't
need to think about how to do that (it is platform dependent). Construct a
Dictionary object for each valid dictionary you find (perhaps reading the
index file is enough here). Finally call addDictionary on each of them. So the
code will look something like
string mainPath(path);
mainPath.append("/4");
list<string> subDirectories = getListOfSubentries(mainPath);
for (list<string>::iterator i = subDirectories.begin(); i !=
subDirectories.end(); ++i) {
// read your index file and build the Dictionary object
addDictionary(dict);
}
You don't need to think about interactions with other dictionary formats or
what happens if there are multiple dictionaries for the same language code.
The common code will take care of that.
Of course we still need to add new attribute
std::string grammarCheckerBackend;
to the Dictionary class to contain the necessary information for instantiating
the grammar checker. But I think it is best to do that after changes in
gramchk branch have been merged to avoid conflicts.
Harri
More information about the Libvoikko
mailing list