Skip to content

Instantly share code, notes, and snippets.

@itsthatguy
Last active August 26, 2017 19:02
Show Gist options
  • Save itsthatguy/b2cbe38787fc20e7246a4932366a48ef to your computer and use it in GitHub Desktop.
Save itsthatguy/b2cbe38787fc20e7246a4932366a48ef to your computer and use it in GitHub Desktop.
var nlp = require('compromise')
function parseCommand (input) {
var doc = nlp(input)
var cmd = doc.verbs().out('array');
var objects = doc.nouns().out('array');
console.log(cmd);
console.log(objects);
}
parseCommand(look)
// => [ 'look' ]
// => []
parseCommand(look at your butt)
// => [ 'look' ]
// => [ 'your butt' ]
parseCommand(look at your butt inside the table)
// => [ 'look' ]
// => [ 'your butt', 'table' ]
parseCommand(look at your butt on top of the table)
// => [ 'look' ]
// => [ 'your butt', 'table' ]
parseCommand(take key)
// => [ 'take' ]
// => [ 'key' ]
parseCommand(take key from the table)
// => [ 'take' ]
// => [ 'key', 'table' ]
parseCommand(take key from the box)
// => [ 'take' ]
// => [ 'key', 'box' ]
parseCommand(take key from the box on the table)
// => [ 'take' ]
// => [ 'key', 'box', 'table' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment