rubysynonymsymmetricthesaurus

Data structure for indirect symmetrical synonym


I have a set of synonyms for example like this:

big large large huge small little apple banana

Meaning big is a synonym for large, large is synonym for huge, small for little, apple for banana and vice versa(large is synonym for big, etc). Another thing is "big" is a synonym for "huge" and "huge" is a synonym for "big" because of indirect relationship via "large".

This should be something like thesaurus? But I'm not sure how the data structure should look.


Solution

  • One simple option would be an array of arrays like:

    [
      ['big', 'large', 'huge'],
      ['small', 'little']
    ]
    

    Alternately if e.g. huge is not a synonym of big in your model then you might want a hash like:

    {
      big: ['large'],
      large: ['big', 'huge'],
      huge: ['large'],
      small: ['little', 'tiny'],
      little: ['small'],
      ...
    }
    

    It really depends on what you plan do do with it.