Last active
August 26, 2017 19:02
-
-
Save itsthatguy/b2cbe38787fc20e7246a4932366a48ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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