0.0
No commit activity in last 3 years
No release in over 3 years
Charyf intent processor wrapper for MycroftAI/adapt library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
>= 0
~> 10.0
~> 3.0

Runtime

~> 0.2
~> 0.9
~> 1.0.3
 Project Readme

Adapt-Charyf

Adapt-Charyf is a ruby wrapper around Mycroft's Intent parser library mycroft/Adapt. This wrapper provides charyf interface to defining and determining intents.

Getting Started

Installing to existing charyf applicaiton

Add this line to your charyf application's Gemfile:

gem 'adapt-charyf'

And then execute:

$ bundle

Then add the adapt to the applocation loads by adding line to config/load.rb

require 'adapt-charyf'

To generate the intializer run

charyf generate adapt:install

You should be welcomed by the message

      create  config/initializers/adapt.rb
      notice  Adapt installed
		Do not forget to set adapt intent processor in application configuration

You can configure the processor inside config/initializers/adapt.rb which was generated by the installer

Now enable adapt processor inside your application config (config/application.rb) or specific environment config (e.g.: config/environments/development.rb)

config.enabled_intent_processors = [.., :adapt, ..]

Install with new charyf application

You can add adapt as intent processor during generation of new application. Just use --intent-processors=adapt as argument with your charyf new ... command.

When installing adapt along charyf new application, config/loads.rb and configuration inside config/application.rb will be populated automatically.

You can configure the processor inside config/initializers/adapt.rb which was generated by the installer

Dependencies

Make sure the python library is installed pip install -e git+https://github.com/mycroftai/adapt#egg=adapt-parser [or use pip3 if desired]

Adapt-charyf uses pycall gem to handle python calls.

Usage

When launching any ruby application using adapt-charyf, ensure that
ENV['PYTHON'] = /path/to/python/with/adapt/libary
is set to python version that has adapt-parser installed.

Defining the intent is very similiar to original adapt library.

Entities

Firstly we define entites that will occur in our utterances.

Register an keyword entity

Skill.public_routing_for :adapt do |routing|
    routing.register_keywords 'greet', 'Hello', 'Hi'
end

Keyword entity is defined by its name greet and followed by all phrases in this entity. For entity greet we define two works Hi and Hello.

Register regex entity

User may register regex entity as well.

Skill.public_routing_for :adapt do |routing|
    routing.register_regex 'in (?P<location>.*)'
end

Regex entity requires a regex with one named capture. This named capture is then used as the name of the entity. Example above defines new regex entity with name location.

Adapt regex entities use python's syntax as there is no current 1:1 mapping between ruby and python regex syntax. However defining named capture is very similiar.

All defined entities are available in the scope of particular skill and are not visible to other skills. Once can imagine defining entity hello as Skill:Hello, thus not coliding with other skills.

Intent

Once our entities are defined and correctly named we can start building intents.

Skill.public_routing_for :adapt do |routing|
    routing.intent('GreetIntent')
      .required('greet')
      #.optional('another_entity')
      .route_to('base', 'hello')
end

Example above defines new intent GreetIntent, with one required entity. We can also define optional entities which does not need to occur in the utterance. Last step of defining is setting the routing. By specifying route_to('base', 'hello') we define that matched intent should be routed to Skill::BaseController into action hello.

Routing can't be defined outside the scope of the skill as it is automatically nested into skill namespace.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/adapt-charyf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the CharyfAdaptProcessor project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.