How to obtain all possible words from given hunspell dictionary?
Asked Answered
P

3

8

I would like to parse open office supporting hunspell formatted aff and dic files.

English aff and dic files can be downloaded from here for example : http://extensions.openoffice.org/en/project/english-dictionaries-apache-openoffice

I want to scan each line of the given .dic file and generate every possible word of the each line with the provided .aff file

How can i do that?

I have installed NHunspell framework but it does not have that feature : https://www.nuget.org/packages/NHunspell/

For example for the english language lets consider

make/UAGS

make can be make, made, makes, making etc

Now i need parser to give me all these combinations. How can i obtain them? Ty very much

So basically i want to scan each line of the dictionary and generate all possible words from the word of that line and i dont know how can i do that

I can also write my own parsers, but it seems to me rules are pretty complex and there are no detailed and easy documentation about this

Here what i want basically. The image explains very clearly

Giving analyze/ADSG, en.dic and en.aff file and obtaining all the following words

analyze, analyzes, analyzing, analyzed, reanalyze, reanalyzes, reanalyzing, reanalyzed

enter image description here

Peruke answered 2/3, 2017 at 22:5 Comment(9)
I don't know if that's viable without a third party library, even if you wrote your own parsers there would be a lot of exception. What do you need all forms of the word forRigobertorigor
so i can have a static list of all words in that particular language and keep associations of words (e.g. makes is composed from make). that is necessary for my application. i mean these applications already has to be obtaining all forms of the given words in dictionary to do particular actions. so i believe there must be a way to do thisKreg
There is a stand way in which most languages convert words, I.E Future Tense Make -> Present tense -> Making. Shake -> Shaking, you can create rules future->present tense end in e drop the e and add ing. This will generally work for most words, but things going from future tense to past however differ a lot of the time. Make -> Made, Shake -> Shook, Run -> Ran, Where there may be rules that you can create but there will still be a lot of exceptions. I think your best bet would be to look for a pre-existing DB of associated words, or to look for a third party library who will handle thatRigobertorigor
@johnny5 i really need to solve this problem :( i have updated my question. I am pretty sure what i want is possible. Check the updated question tyKreg
I see so all of the rules are already included and mapped with the dictionary this is way easier to understandRigobertorigor
I don't see a function to translate this based on a rule but then again I'm on my phone. The parser doesn't look too hard to write. Just store a dictionary of string to list of prefix data, match a prefix to the applied regexRigobertorigor
@johnny5 i found the command :) it is wordforms. however i dont know how to call it yet :( github.com/kris7t/hunspell/blob/master/src/tools/wordforms . i need to write output to a fileKreg
@MonsterMMORPG Did you find a way to export all the words from the DIC and AFF files? I'm dealing with this problem too.Geodetic
maybe related: github.com/en-wl/wordlist/tree/master/agidFootcandle
G
9

If you want the entire database you may execute unmunch:

unmunch dictionary.dic dictionary.aff

Note that the current implementation of unmunch in hunspell has a limitation of maximum number of words, affs, and length of generated words. So, unmunch may fail if the target language is beyond the limits of unmunch.

If you want just the list of possible words that can be generated from an entry, you may use wordforms:

wordforms dictionary.aff dictionary.dic word
Gujarati answered 20/2, 2020 at 12:41 Comment(0)
J
0

As Kartal Tabak pointed out, what you are looking for are the command-line tools wordforms and unmunch, which are distributed with Hunspell. But wordforms is for just one stem, and unmunch is very buggy. See this answer for alternatives.

Furthermore, it seems that Hunspell does not expose this feature as library functions. If you want to use this feature programmatically (as you mentioned C# and NHunspell), then you probably need to spawn these external programs and parse their output.

Juglandaceous answered 10/7, 2023 at 23:51 Comment(0)
I
0

CSpell's hunspell-reader package allows you to get a full word list from a dictionary:

From their website:

Converting Hunspell to word list

To convert a Hunspell dictionary to a word list, you will need both the .dic and .aff files. For example en_US comes with two files: en_US.dic and en_US.aff. This tool assumes they are both in the same directory.

Assuming these files are in the current directory, the following command will write the words to en_US.txt.

hunspell-reader words ./en_US.dic -o en_US.txt
Ides answered 18/12, 2023 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.