I am trying to get a list with all the possible combinations of words that total a number of syllables. For example:
w(cat, noun, 1).
w(boy, noun, 1).
w(pet, noun, 1).
w(eats, verb, 1).
w(woman, noun, 2).
w(nature, noun, 2).
w(apple, noun, 2).
w(watches, verb, 2).
w(family, noun, 3).
has_5_syllables(L) :-
w(X, _, N0),
w(Y, _, N1),
plus(N0, N1, 5),
append([X], [Y], L).
In this case has_5_syllables
returns a combinations of two words:
?- has_5_syllables(X).
X = [woman, family] ;
X = [nature, family] ;
X = [apple, family] ;
...
So the question is, how can I extend the predicate so it returns also combinations of more than 2 words, for example [cat, boy, family], [cat, boy, pet, apple]
?
Ideally I would also like to make it generic, so you can pass N as the sum of syllables to the predicate: has_n_syllables(L, N).