2

I'm trying to figure out how I would go about creating a synonym finder in Prolog.


I have some words here...

word(likes).
word(house).
word(chair).

If the input was likes, I would want to output a synonym such as 'loves'. Or for house I would want to output 'home'.

I want to do this with the synonym predicate instead of adding the alternative words as a new word().

I've got as far as doing this:

synonym (house,[home]).

I'm not sure where to go from here.

Joseph
  • 120
  • 9
  • 3
    What you want is [WordNet](https://wordnet.princeton.edu/), which is conveniently available as a Prolog database. – Daniel Lyons Dec 07 '17 at 23:14

1 Answers1

4

If you're willing to enumerate your cases manually I would consider having a predicate that "normalizes" or "simplifies" vocabulary. For instance, something like this:

%% synonym(Synonym, CanonicalTerm) :- Synonym is a synonym for CanonicalTerm
synonym(loves,  enjoys).
synonym(likes,  enjoys).
synonym(enjoys, enjoys).

Prologs usually index on the first argument, so this lookup will be fast (certainly faster than enumerating the whole database and doing a member/2 lookup). And then you can simply perform this step after parsing or on-demand, and code your rules around the canonical term.

WordNet probably does not consider love and like to be synonyms, really, so it is probably overkill for your needs.

Let's apply this to the earlier question:

?- phrase(sentence(np(Noun,_), vp(Verb, np(Object, _))),
   [a,teenage,boy,loves,a,big,problem]), 
   synonym(Verb, CanonicalVerb),
   present(Suggestion, Noun, CanonicalVerb, Object).
Noun = boy,
Verb = loves,
CanonicalVerb = enjoys,
Object = problem,
Suggestion = 'construction kit' 

This of course assumes you update the present/4 fact as well.

Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77