wit-ruby

Gem Version

Easy interface for interacting with the Wit.ai natural language parsing API.

This project will expand as the Wit.ai API expands, but as it stands there's a single endpoint. You can hit this endpoint easily with Wit.message([your message]), which uses Wit.ai to convert that phrase or sentence into an object with an intent, and entities if any are available.

You will need to create a Wit.ai account and begin training it.

Installation

gem 'wit-ruby', '>= 0.0.2'

You'll need to set an environment variable named WIT_TOKEN or specify your token with Wit.token = [your token].

export WIT_TOKEN=[your token]

Usage

result = Wit.message('Hi')
result.intent # will be Hello with the default Wit instance.
result.confidence # will be relatively low initially.
result.entities # will be {}, but if there are entities the can accessed as [:name] or .name

Result properties/methods

raw
Raw response hash (parsed JSON)
msgId
The unique message id provided back from Wit.
msgBody
The original message sent.
intent
The intent, as determined by Wit.
confidence
The confidence level that Wit determined.
entities
Hash of entities, which contain the value, and the start/end position within msgBody.

Entity properties/methods

value
The value as determined by Wit (might not be the same as body).
start
The start position index from msgBody.
end
The end position index from msgBody.
body
The actual value as specified in msgBody.

License

Licensed under the MIT License

Copyright 2012 Mode Set

Make Code Not War

crest