Search code examples
javascriptalgorithmnlpnlg

Generate valid English sentence structure for a given word length


Does a library exist, preferably JavaScript (by no means a hard requirement), that will output an English sentence structure for a given length?

For example:

> sentenceGenerator({ length: 4 })
< DETERMINER NOUN VERB NOUN

> sentenceGenerator({ length: 8 })
< PRONOUN NOUN VERB NOUN CONJUNCTION PRONOUN VERB ADVERB

The reason I'm looking for this is because I'd like to generate sentences using my own wordlist. Existing NLG libraries don't fit my needs since I'd like to specify a letter for each index (e.g. mnemonics).


Solution

  • I managed to get this working using markov chains and a part-of-speech tagging library.

    markov-strings and pos respectively on npm.