If you could choose the database you want and have to store (query and update) word synonyms then what database would you choose? And how would you store them? Let's assume that there will be a lot of synonyms (but I guess data size won't be a problem here).
Asked
Active
Viewed 3,281 times
3
-
1It might be helpful to know how you want to access the synonyms to help guide an answer to this question. – Norman H Apr 05 '11 at 19:12
-
I have a word and want to fetch all synonyms of it. I also want to remove a synonym sometimes. – medihack Apr 05 '11 at 19:16
-
The previous responses are great examples of how this has been solved (many times) in the past. To go along with that, I'd recommend that you take a look at [Berkeley DB](http://www.oracle.com/technetwork/database/berkeleydb/overview/index-085366.html) or [Berkeley DB Java Edition](http://www.oracle.com/technetwork/database/berkeleydb/overview/index-093405.html). Berkeley DB is often used as the data store for this kind of solution. It's fast, it's easy to use, the key-value pair API is simple and it's embedded so that it can be part of a dictionary application or service without requiring add – dsegleau Apr 06 '11 at 16:16
2 Answers
10
Keeping it very simple, you could create a table of words and a relationship table for synonyms. You could consider adding a restriction like WordID1 < WordID2
to prevent repeating pairs of words (e.g, (1,2) and (2,1)).

Joe Stefanelli
- 132,803
- 19
- 237
- 235
-
1i like the way you think Joe... +1 even though its the same as my answer :) – Randy Apr 05 '11 at 19:15
-
Wouldn't be such a design excellent for a key value store? Does someone know of any using a HTTP REST interface? I think Riak would be one. Others? – medihack Apr 05 '11 at 19:20
-
this is an interesting vote study... i'll have to break out my Visio more often :) – Randy Apr 05 '11 at 19:24
-
@Randy: The psychology of voting behaviors on SO as a whole is a fascinating topic (at least to me). :-) – Joe Stefanelli Apr 05 '11 at 19:30
-
Suppose our requirements is to given an input word, get all the synonyms of that word, including the word itself as well as the parent word (because this table structure implies that word1 is a parent word). How would you redesign the table structure then ? Because using this answer's table structure, I am getting minimum 4 Joins, usage of `OR` (which inhibits the usage of index in MySQL) – Madhur Bhaiya Dec 24 '19 at 12:41
3
a simple relational structure might be like this:
word
------
word_id
text
synonym
---------
word_1_id
word_2_id

Randy
- 16,480
- 1
- 37
- 55