Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ Renamed to use American spelling – James is slightly irked, but agr…

…ees it's for the common good.
  • Loading branch information...
commit 73a8e9725c008c2e4eb507e2d8419aec36010aa7 1 parent ee30082
@floere authored
Showing with 237 additions and 530 deletions.
  1. +20 −20 README.textile
  2. +5 −5 examples/README.textile
  3. +3 −3 examples/{bad_jokes_dialogue.rb → bad_jokes_dialog.rb}
  4. +3 −3 examples/{itunes_dialogue.rb → itunes_dialog.rb}
  5. +3 −3 examples/{magic_eight_ball_dialogue.rb → magic_eight_ball_dialog.rb}
  6. +3 −3 examples/{time_dialogue.rb → time_dialog.rb}
  7. +5 −5 examples/twitter_dialogue.rb
  8. +9 −7 examples/weather_dialogue.rb
  9. +1 −1  experiments/phonebook/phonebook_dialogue.rb
  10. +4 −4 history.textile
  11. +2 −2 james.gemspec
  12. +4 −4 lib/james.rb
  13. +1 −1  lib/james/builtin/README
  14. +0 −48 lib/james/builtin/core_dialogue.rb
  15. +9 −9 lib/james/controller.rb
  16. +0 −34 lib/james/dialogue_api.rb
  17. +0 −53 lib/james/dialogue_internals.rb
  18. +0 −58 lib/james/dialogues.rb
  19. +1 −1  lib/james/inputs/base.rb
  20. +1 −1  lib/james/state_api.rb
  21. +1 −1  lib/james/visitor.rb
  22. +3 −3 lib/james/visitors.rb
  23. +1 −1  old/README
  24. +1 −1  old/config/sentences.yml
  25. +1 −1  old/dialogue.rb
  26. +6 −6 old/dialogue_extension.rb
  27. +16 −16 old/dialogue_frontend.rb
  28. +5 −5 old/dialogue_plugin.rb
  29. +1 −1  old/dialogues/joke/README
  30. +1 −1  old/dialogues/joke/init.rb
  31. +2 −2 old/dialogues/joke/lib/joke_dialogue.rb
  32. +1 −1  old/dialogues/phonebook/init.rb
  33. +3 −3 old/dialogues/phonebook/lib/phonebook_dialogue.rb
  34. +32 −32 old/dialogues/phonebook/test/test_phonebook.rb
  35. +1 −1  old/dialogues/quote/README
  36. +1 −1  old/dialogues/quote/init.rb
  37. +2 −2 old/dialogues/quote/lib/quote_dialogue.rb
  38. +1 −1  old/dialogues/sbb/init.rb
  39. +3 −3 old/dialogues/sbb/lib/sbb_dialogue.rb
  40. +19 −19 old/dialogues/sbb/test/test_sbb.rb
  41. +1 −1  old/dialogues/time/README
  42. +1 −1  old/dialogues/time/init.rb
  43. +2 −2 old/dialogues/time/lib/time_dialogue.rb
  44. +7 −7 old/initializer.rb
  45. +10 −10 old/main_dialogue.rb
  46. +2 −2 old/quote_dialugue.rb
  47. +24 −24 old/test/test_dialogue.rb
  48. +2 −2 old/time_dialogue.rb
  49. +3 −3 spec/aux/james/cli_spec.rb
  50. +10 −10 spec/integration/test_dialogue_spec.rb
  51. +0 −102 spec/lib/james/dialogue_spec.rb
View
40 README.textile
@@ -1,6 +1,6 @@
h1. James
-A voice controlled electronic butler
+A voice controlled electronic butler.
h2. Requirements
@@ -13,7 +13,7 @@ h2. Installation
h2. Basics
-James consists of dialog(ue)s that are modeled as state machines. You navigate through these dialog(ue)s by talking to James.
+James consists of dialogs that are modeled as state machines. You navigate through these dialogs by talking to James.
He will then take action (looking up timetables, checking the weather etc.) and inform you. Or maybe just tell a joke.
@@ -21,11 +21,11 @@ h2. Examples
All examples can be found in "/examples":http://github.com/floere/james/tree/master/examples.
-Create a file called @time_dialogue.rb@ (or @time_dialog.rb@, James doesn't mind Americans ;) ):
+Create a file called @time_dialog.rb@:
-<pre><code>class TimeDialogue
+<pre><code>class TimeDialog
- include James::Dialogue
+ include James::Dialog
hear 'what time is it?' => :time
state :time do
@@ -40,7 +40,7 @@ This says that if James hears (@hear@) @"What time is it?"@ that it should enter
If he then hears "What time is it?" again, it will return to state @:time@.
-When he enters (@into@), James executes the block in the dialogue's context. Whatever is returned from the block, James will say out lout. Everything else he will just think. (So it's like Sinatra in rendering, just that James renders audio)
+When he enters (@into@), James executes the block in the dialog's context. Whatever is returned from the block, James will say out lout. Everything else he will just think. (So it's like Sinatra in rendering, just that James renders audio)
Here, he will just say the current time when entering the @:time@ state.
@@ -51,33 +51,33 @@ Running it is easy. Either use
<pre><code>require 'rubygems'
require 'james'
-# Your dialogue goes here.
+# Your dialog goes here.
James.listen</code></pre>
in your script, and call it by using
-<pre><code>ruby time_dialogue.rb</code></pre>
+<pre><code>ruby time_dialog.rb</code></pre>
Or else, in the terminal, just call
<pre><code>$ james</code></pre>
-and it will include all dialogues (files called @_dialog{ue,}.rb@) in this directory and subdirectories. E.g. @joke_dialog.rb@, @newsfeed_dialogue.rb@, or @social_media/tweets_dialog.rb@.
+and it will include all dialogs (files called @_dialog{ue,}.rb@, the @ue@ is for the brits and aussies :) ) in this directory and subdirectories. E.g. @joke_dialog.rb@, @newsfeed_dialog.rb@, or @social_media/tweets_dialog.rb@.
-You can select dialogues using their first file name part
+You can select dialogs using their first file name part
<pre><code>$ james time joke twitter</code></pre>
-and it will include the time dialogue, the joke dialogue, and the twitter dialogue.
+and it will include the time dialog, the joke dialog, and the twitter dialog.
Note: The @james@ executable looks for files called and includes them.
h3. Short Version
-There is a short, anonymous dialogue version, using @James.dialogue@ aka @James.dialog@.
+There is a short, anonymous dialog version, using @James.dialog@.
-<pre><code>James.dialogue do
+<pre><code>James.dialog do
hear 'what time is it?' => :time
state :time do
@@ -93,9 +93,9 @@ Or there is an extended version, using initialize to set up some important stuff
<pre><code>require 'james'
-class TwitterDialogue
+class TwitterDialog
- include James::Dialogue
+ include James::Dialog
def initialize
@client = Twitter.new 'user', 'password'
@@ -123,7 +123,7 @@ end</code></pre>
h2. Contributions
Contributions are in the "/examples":http://github.com/floere/james/tree/master/examples folder.
-Sending dialogue gists is appreciated. Thanks!
+Sending dialog gists is appreciated. Thanks!
h2. Running the specs
@@ -131,15 +131,15 @@ h2. Running the specs
h2. Roadmap
-* Make James (e.g. voice, core dialogue) configurable.
-* Add more useful dialogues made by YOU :)
+* Make James (e.g. voice, core dialog) configurable.
+* Add more useful dialogs made by YOU :)
h2. Ideas
# Put it on a Mac Mini, attach a few microphones, distribute in the house.
-# Create a few useful dialogues, like a train timetable, or similar.
+# Create a few useful dialogs, like a train timetable, or similar.
# Sit on your sofa, and talk to James out loud.
-# Send us your dialogues :)
+# Send us your dialogs :)
h2. MIT License
View
10 examples/README.textile
@@ -8,11 +8,11 @@ They should always be of the form:
# require 'james'
require File.expand_path '../../lib/james', __FILE__
- class ItunesDialogue
+ class ItunesDialog
- include James::Dialogue
+ include James::Dialog
- # You dialogue definitions go here.
+ # You dialog definitions go here.
end
@@ -28,9 +28,9 @@ One example is the following simple one:
# require 'james'
require File.expand_path '../../lib/james', __FILE__
- class ItunesDialogue
+ class ItunesDialog
- include James::Dialogue
+ include James::Dialog
def initialize
# Usually though it's a good idea to set it up in the actions:
View
6 examples/bad_jokes_dialogue.rb → examples/bad_jokes_dialog.rb
@@ -4,7 +4,7 @@
# require 'james'
require File.expand_path '../../lib/james', __FILE__
-# Time dialogue by Florian Hanke.
+# Time dialog by Florian Hanke.
#
# This is a very simple James example.
#
@@ -13,9 +13,9 @@
#
# Improve the jokes ;)
#
-class JokeDialogue
+class JokeDialog
- include James::Dialogue
+ include James::Dialog
hear 'Tell me a joke' => :joke
View
6 examples/itunes_dialogue.rb → examples/itunes_dialog.rb
@@ -4,7 +4,7 @@
# require 'james'
require File.expand_path '../../lib/james', __FILE__
-# iTunes dialogue by Florian Hanke.
+# iTunes dialog by Florian Hanke.
#
# This is a very simple James example.
#
@@ -13,9 +13,9 @@
#
# How could you enhance it to answer "What date is it?" ?
#
-class ItunesDialogue
+class ItunesDialog
- include James::Dialogue
+ include James::Dialog
hear 'Open iTunes and play' => :itunes
state :itunes do
View
6 examples/magic_eight_ball_dialogue.rb → examples/magic_eight_ball_dialog.rb
@@ -4,16 +4,16 @@
# require 'james'
require File.expand_path '../../lib/james', __FILE__
-# Time dialogue by Florian Hanke.
+# Time dialog by Florian Hanke.
#
# This is a very simple James example.
#
# It has only one state, :shake, and a single
# entry/hook phrase, "Shake the eight ball"
#
-class MagicEightBallDialogue
+class MagicEightBallDialog
- include James::Dialogue
+ include James::Dialog
attr_reader :states
View
6 examples/time_dialogue.rb → examples/time_dialog.rb
@@ -4,7 +4,7 @@
# require 'james'
require File.expand_path '../../lib/james', __FILE__
-# Time dialogue by Florian Hanke.
+# Time dialog by Florian Hanke.
#
# This is a very simple James example.
#
@@ -13,9 +13,9 @@
#
# How could you enhance it to answer "What date is it?" ?
#
-class TimeDialogue
+class TimeDialog
- include James::Dialogue
+ include James::Dialog
hear 'What time is it?' => :time
state :time do
View
10 examples/twitter_dialogue.rb
@@ -1,4 +1,4 @@
-# Note: This dialogue does not work yet due to a bug in MacRuby.
+# Note: This dialog does not work yet due to a bug in MacRuby.
#
require 'twitter'
@@ -8,13 +8,13 @@
# require 'james'
require File.expand_path '../../lib/james', __FILE__
-# Twitter dialogue by Florian Hanke.
+# Twitter dialog by Florian Hanke.
#
# This is a bit more complex example providing a self.configure method.
#
-class TwitterDialogue
+class TwitterDialog
- include James::Dialogue
+ include James::Dialog
def self.configure from
@@ -37,6 +37,6 @@ def self.configure from
# This could be somewhere else of course.
#
-TwitterDialogue.configure 'hanke'
+TwitterDialog.configure 'hanke'
James.listen
View
16 examples/weather_dialogue.rb
@@ -7,23 +7,23 @@
require 'rubygems'
require 'barometer'
-# Weather dialogue by Florian Hanke.
+# Weather dialog by Florian Hanke.
#
# This is a very simple James example.
#
# Note: Currently it just a stub.
#
-# Note 2: We need to enable Dialogue passing to James.listen
-# to make dialogues configurable a la WeatherDialogue.for("Paris").
+# Note 2: We need to enable Dialog passing to James.use
+# to make dialogs configurable a la WeatherDialog.for("Paris").
#
-class WeatherDialogue
+class WeatherDialog
- include James::Dialogue
+ include James::Dialog
- def initialize
+ def initialize location
Barometer.config = { 1 => [:yahoo, :google], 2 => :wunderground }
- @barometer = Barometer.new "Melbourne"
+ @barometer = Barometer.new location
end
hear 'How is the weather?' => :weather
@@ -33,4 +33,6 @@ def initialize
end
+James.use WeatherDialog.new('Melbourne')
+
James.listen
View
2  experiments/phonebook/phonebook_dialogue.rb
@@ -6,7 +6,7 @@
#
require File.expand_path '../phonebook', __FILE__
-class PhonebookDialogue < DialogueExtension
+class PhonebookDialog < DialogExtension
NUMBER_MAPPING = {
'nil' => 0,
View
8 history.textile
@@ -1,6 +1,6 @@
h2. Version 0.0.12
-* hanke: @hear 'Stay in same state' => ->(){ "This block will now be instance eval'd in the context of the Dialogue" }@
+* hanke: @hear 'Stay in same state' => ->(){ "This block will now be instance eval'd in the context of the Dialog" }@
h2. Version 0.0.11
@@ -8,7 +8,7 @@ h2. Version 0.0.11
h2. Version 0.0.8 - 0.0.10
-* hanke: Reordered dialogue options such that the most important ones, currently, are on top.
+* hanke: Reordered dialog options such that the most important ones, currently, are on top.
h2. Version 0.0.7
@@ -16,8 +16,8 @@ h2. Version 0.0.7
h2. Version 0.0.6
-* hanke: Dialogues implemented.
-* hanke: Dialogues are hooked up to a central control dialogue.
+* hanke: Dialogs implemented.
+* hanke: Dialogs are hooked up to a central control dialog.
h2. Version 0.0.1-0.0.5
View
4 james.gemspec
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
s.homepage = 'http://floere.github.com/james'
- s.description = 'Modular Electronic Butler. Using a simple dialogue system where you can easily add more dialogues.'
- s.summary = 'James: Modular Electronic Butler with modular Dialogues.'
+ s.description = 'Modular Electronic Butler. Using a simple dialog system where you can easily add more dialogs.'
+ s.summary = 'James: Modular Electronic Butler with modular Dialogs.'
s.files = Dir["lib/**/*.rb", "aux/**/*.rb"]
s.test_files = Dir["spec/**/*_spec.rb"]
View
8 lib/james.rb
@@ -8,10 +8,10 @@ module James; end
require File.expand_path '../james/visitor', __FILE__
require File.expand_path '../james/visitors', __FILE__
-require File.expand_path '../james/dialogue_api', __FILE__
-require File.expand_path '../james/dialogue_internals', __FILE__
+require File.expand_path '../james/dialog_api', __FILE__
+require File.expand_path '../james/dialog_internals', __FILE__
-require File.expand_path '../james/dialogues', __FILE__
+require File.expand_path '../james/dialogs', __FILE__
require File.expand_path '../james/inputs/base', __FILE__
require File.expand_path '../james/inputs/audio', __FILE__
@@ -20,7 +20,7 @@ module James; end
require File.expand_path '../james/outputs/audio', __FILE__
require File.expand_path '../james/outputs/terminal', __FILE__
-require File.expand_path '../james/builtin/core_dialogue', __FILE__
+require File.expand_path '../james/builtin/core_dialog', __FILE__
require File.expand_path '../james/controller', __FILE__
View
2  lib/james/builtin/README
@@ -1 +1 @@
-This folder contains predefined dialogues.
+This folder contains predefined dialogs.
View
48 lib/james/builtin/core_dialogue.rb
@@ -1,48 +0,0 @@
-# This is the core dialogue every dialogue will be hooking into.
-#
-# Eventually, the design should be such that everyone can use
-# the design and core dialogue they like best.
-#
-# But to get going, this suffices for now.
-#
-class CoreDialogue
-
- include James::Dialogue
-
- # The alert state.
- # When James is in this state, he should be
- # open for user dialogues.
- #
- state :awake do
- # If James is awake, he offers more dialogues
- # on this state, if there are any hooked into this state.
- #
- chainable
-
- hear "Thank you, James." => :awake,
- 'I need some time alone, James.' => :away,
- "Good night, James." => :exit
- into { "Sir?" }
- end
-
- # The away state. James does not listen to any
- # user dialogue hooks, but only for his name
- # or the good night, i.e. exit phrase.
- #
- state :away do
- hear 'James?' => :awake,
- "Good night, James." => :exit
- into { "Of course, Sir!" }
- end
-
- # This is not a real state. It just exists to Kernel.exit
- # James when he enters this state.
- #
- state :exit do
- into do
- puts "James: Exits through a side door."
- Kernel.exit
- end
- end
-
-end
View
18 lib/james/controller.rb
@@ -6,12 +6,12 @@ class Controller
attr_reader :visitor
- # This puts together the core dialogue and the user
+ # This puts together the core dialog and the user
# ones that are hooked into it.
#
def initialize
- user_visitor = initialize_dialogues.visitor
- system_visitor = Visitor.new CoreDialogue.new.state_for(:awake)
+ user_visitor = initialize_dialogs.visitor
+ system_visitor = Visitor.new CoreDialog.new.state_for(:awake)
@visitor = Visitors.new system_visitor, user_visitor
end
@@ -31,12 +31,12 @@ def load_voices
end
# Initialize and "parse" the
- # dialogues.
+ # dialogs.
#
- def initialize_dialogues
- dialogues = Dialogues.new
- dialogues.resolve
- dialogues
+ def initialize_dialogs
+ dialogs = Dialogs.new
+ dialogs.resolve
+ dialogs
end
# Start recognizing words.
#
@@ -50,7 +50,7 @@ def start_output
@output = Outputs::Audio.new
end
- # Callback method from dialogue.
+ # Callback method from dialog.
#
def say text
@output.say text
View
34 lib/james/dialogue_api.rb
@@ -1,34 +0,0 @@
-module James
-
- # A dialog(ue) can be instantiated in two ways:
- #
- # James.dialogue do
- # # Your dialogue.
- # #
- # end
- #
- # class MyDialogue
- # include James::Dialogue
- #
- # # Your dialogue.
- # #
- # end
- #
- module Dialogue; end
-
- # We don't care about the spelling.
- #
- Dialog = Dialogue
-
- class << self
-
- def dialogue &block
- dialogue = Class.new { include James::Dialogue }
- dialogue.class_eval &block
- dialogue
- end
- alias dialog dialogue
-
- end
-
-end
View
53 lib/james/dialogue_internals.rb
@@ -1,53 +0,0 @@
-module James
-
- # A dialogue is just a container object
- # for defining states and executing methods.
- #
- module Dialogue
-
- def self.included into
- into.extend ClassMethods
- Dialogues << into unless into == CoreDialogue # TODO Dirty as hell.
- end
-
- #
- #
- def state_for name
- self.class.state_for name, self
- end
-
- module ClassMethods
-
- # Defines the entry sentences.
- #
- def hear definition
- define_method :entries do
- definition
- end
- end
-
- # Defines a state with transitions.
- #
- # state :name do
- # # state properties (hear, into, exit) go here.
- # end
- #
- attr_reader :states
- def state name, &block
- @states ||= {}
- @states[name] ||= block if block_given?
- end
- def state_for name, instance
- # Lazily wrap.
- #
- if states[name].respond_to?(:call)
- states[name] = State.new(name, instance, &states[name])
- end
- states[name]
- end
-
- end
-
- end
-
-end
View
58 lib/james/dialogues.rb
@@ -1,58 +0,0 @@
-module James
-
- # Registers all dialogues and connects their states.
- #
- class Dialogues
-
- attr_reader :initial, :dialogues
-
- def initialize
- @initial = State.new :__initial_plugin_state__, nil
- @dialogues = self.class.dialogues.map &:new
- end
-
- class << self
-
- attr_reader :dialogues
-
- def << dialogue
- @dialogues ||= []
- @dialogues << dialogue
- end
-
- end
-
- # Generate the graph for the dialogues.
- #
- # Hooks up the entry phrases of all dialogues
- # into the main dialogue.
- #
- # It raises if the hook phrase of a dialogue
- # is already used.
- #
- def resolve
- # Hook dialogues into initial state.
- #
- resolved_entries = {}
- dialogues.each do |dialogue|
- dialogue.entries.each do |(phrases, state)|
- resolved_entries[phrases] = state.respond_to?(:phrases) ? state : dialogue.state_for(state)
- end
- end
-
- # Hook all user dialogues into the initial state.
- #
- initial.hear resolved_entries
- end
-
- # Get the visitor.
- #
- # Initialized on the initial state.
- #
- def visitor
- @visitor ||= Visitor.new initial
- end
-
- end
-
-end
View
2  lib/james/inputs/base.rb
@@ -13,7 +13,7 @@ def initialize controller
# Call this method if you heard something in the subclass.
#
def heard command
- # Call dialogue.
+ # Call dialog.
#
controller.hear command
end
View
2  lib/james/state_api.rb
@@ -1,6 +1,6 @@
module James
- # A state is defined in a dialogue.
+ # A state is defined in a dialog.
#
# It has a name with which it can be targeted.
#
View
2  lib/james/visitor.rb
@@ -72,7 +72,7 @@ def hears? phrase
def expects
current.phrases
end
- # Does the current state allow penetration into another dialogue?
+ # Does the current state allow penetration into another dialog?
#
def chainable?
current.chainable?
View
6 lib/james/visitors.rb
@@ -1,7 +1,7 @@
module James
# The visitors class has a number of visitors, whose
- # dialogues are visited in order of preference.
+ # dialogs are visited in order of preference.
#
# Why?
# Discussions have multiple points where they can be.
@@ -39,13 +39,13 @@ def hear phrase, &block
end
end
- # Enter enters the first dialogue.
+ # Enter enters the first dialog.
#
def enter
visitors.first.enter
end
- # Simply returns the sum of what phrases all dialogues expect.
+ # Simply returns the sum of what phrases all dialogs expect.
#
# Stops as soon as a visitor is not in a chainable state anymore.
#
View
2  old/README
@@ -1 +1 @@
-Dialogues are externally configurable
+Dialogs are externally configurable
View
2  old/config/sentences.yml
@@ -2,7 +2,7 @@
# commands are denoted with an exclamation mark
# it is not possible to use multiple command words
sleep!: sleep
-return from dialogue!: thank you
+return from dialog!: thank you
# when james ... he says one of ...
wakes up:
- yes?
View
2  old/dialogue.rb
@@ -1,4 +1,4 @@
-class Dialogue
+class Dialog
# choose one reply randomly from the given replies
def random_reply(replies)
View
12 old/dialogue_extension.rb
@@ -1,13 +1,13 @@
# require 'cocoa'
# TODO make ['HB','berne','geneva'] => :from possible using the splat operator
-# add ability to chain dialogues a la chain_dialogue :state, <dialogue_name>
+# add ability to chain dialogs a la chain_dialog :state, <dialog_name>
-# superclass for dialogue modules
-# dialogues move along the moves
+# superclass for dialog modules
+# dialogs move along the moves
# if a state is entered, enter_#{state_name} is called
# if a state is exited, exit_#{state_name} is called
-class DialogueExtension < Dialogue
+class DialogExtension < Dialog
attr_reader :state
@@ -55,14 +55,14 @@ def next_state(phrase)
self.class.moves[@state][phrase] if self.class.moves[@state]
end
- # returns the possible states of this dialogue
+ # returns the possible states of this dialog
def self.possible_states
self.moves.keys
end
# metaprog
- # hook words - these define when this dialogue is entered
+ # hook words - these define when this dialog is entered
# adds a hooks method
# TODO get hooks from yaml file
def self.hook_words(*hooks)
View
32 old/dialogue_frontend.rb
@@ -1,23 +1,23 @@
require 'osx/cocoa'
-require 'main_dialogue'
+require 'main_dialog'
-# TODO move some stuff in the dialogue
+# TODO move some stuff in the dialog
# TODO extract cocoa connection
# TODO implement callback
# debug
USE_TEXTUAL_INTERFACE = false
-class DialogueFrontend
+class DialogFrontend
- attr_reader :dialogue
+ attr_reader :dialog
def initialize
# load voices
load_voices
- # get a dialogue
- @dialogue = MainDialogue.new(self)
+ # get a dialog
+ @dialog = MainDialog.new(self)
# get and configure a recognizer interface
start_recognizer
@@ -32,23 +32,23 @@ def initialize
# callback method from the speech interface
def speechRecognizer_didRecognizeCommand( sender, command )
command = command.to_s
- # call the dialogue system
- @dialogue.hear(command)
+ # call the dialog system
+ @dialog.hear(command)
# set actual commands
- self.commands = @dialogue.expects
+ self.commands = @dialog.expects
end
- # callback method from dialogue
+ # callback method from dialog
def say(text)
@synthesizer.startSpeakingString(text)
end
- # callback from dialogue
+ # callback from dialog
def male
self.voice = @male_voice
end
- # callback from dialogue
+ # callback from dialog
def female
self.voice = @female_voice
end
@@ -72,7 +72,7 @@ def start_recognizer
@recognizer.setBlocksOtherRecognizers(true)
@recognizer.setListensInForegroundOnly(false)
@recognizer.setDelegate(self)
- self.commands = @dialogue.expects
+ self.commands = @dialog.expects
@recognizer.startListening
end
@@ -92,17 +92,17 @@ def load_voices
end
-controller = DialogueFrontend.new
+controller = DialogFrontend.new
# code to use a textual interface
while USE_TEXTUAL_INTERFACE
exit_words = ['quit','exit']
- puts "'#{exit_words.join("' or '")}' to quit. Expects: #{controller.dialogue.expects.join(', ')}"
+ puts "'#{exit_words.join("' or '")}' to quit. Expects: #{controller.dialog.expects.join(', ')}"
input = gets.chomp
if exit_words.include?(input)
break
end
- controller.dialogue.hear(input)
+ controller.dialog.hear(input)
end
OSX::NSApplication.sharedApplication.run
View
10 old/dialogue_plugin.rb
@@ -1,10 +1,10 @@
require 'rubycocoa'
-# superclass for dialogue modules
-# dialogues move along the moves
+# superclass for dialog modules
+# dialogs move along the moves
# if a state is entered, enter_#{state_name} is called
# if a state is exited, exit_#{state_name} is called
-class DialoguePlugin
+class DialogPlugin
# automatically adds a hook phrase
# meaning: adds a move from :awake to this hook word
@@ -18,7 +18,7 @@ def initialize
}
end
- # returns the possible states of this dialogue
+ # returns the possible states of this dialog
def possible_states
@moves.keys
end
@@ -49,7 +49,7 @@ def say(text)
# TODO blah
end
- # hook words - these define when this dialogue is entered
+ # hook words - these define when this dialog is entered
def hook_words(names = nil)
names.each do |name|
# TODO
View
2  old/dialogues/joke/README
@@ -1,2 +1,2 @@
TODO: load the jokes from somewhere
-With this dialogue part, james can tell jokes!
+With this dialog part, james can tell jokes!
View
2  old/dialogues/joke/init.rb
@@ -1 +1 @@
-require 'joke_dialogue'
+require 'joke_dialog'
View
4 old/dialogues/joke/lib/joke_dialogue.rb
@@ -1,7 +1,7 @@
-require 'dialogue_extension'
+require 'dialog_extension'
# little parody on
-class JokeDialogue < DialogueExtension
+class JokeDialog < DialogExtension
initial_state :joke
hook_words 'tell me a funny thing', 'tell me a joke'
View
2  old/dialogues/phonebook/init.rb
@@ -1 +1 @@
-require 'phonebook_dialogue'
+require 'phonebook_dialog'
View
6 old/dialogues/phonebook/lib/phonebook_dialogue.rb
@@ -1,9 +1,9 @@
# TODO remove
-require File.dirname(__FILE__) + '/../../../dialogue_extension'
-# require 'dialogue_extension'
+require File.dirname(__FILE__) + '/../../../dialog_extension'
+# require 'dialog_extension'
require 'phonebook'
-class PhonebookDialogue < DialogueExtension
+class PhonebookDialog < DialogExtension
# this class again tells me that I absolutely need a mapping!!!
NUMBER_MAPPING = {
View
64 old/dialogues/phonebook/test/test_phonebook.rb
@@ -3,8 +3,8 @@
require 'rubygems'
require 'phonebook'
# TODO remove
-require File.dirname(__FILE__) + '/../../../dialogue_extension'
-require 'phonebook_dialogue'
+require File.dirname(__FILE__) + '/../../../dialog_extension'
+require 'phonebook_dialog'
class TestPhonebook < Test::Unit::TestCase
# not really an automated test - still need human visual processing
@@ -12,42 +12,42 @@ class TestPhonebook < Test::Unit::TestCase
# puts Phonebook.find('0443643532').inspect
# end
- def test_phonebook_dialogue
- dialogue = PhonebookDialogue.new
+ def test_phonebook_dialog
+ dialog = PhonebookDialog.new
- assert_equal(:entry, dialogue.state)
- assert_equal(:phonebook, dialogue.next_state('phonebook'))
- dialogue.hear('phonebook')
- assert_equal(:phonebook, dialogue.state)
- assert_equal(:number, dialogue.next_state('name and address'))
- dialogue.hear('name and address')
+ assert_equal(:entry, dialog.state)
+ assert_equal(:phonebook, dialog.next_state('phonebook'))
+ dialog.hear('phonebook')
+ assert_equal(:phonebook, dialog.state)
+ assert_equal(:number, dialog.next_state('name and address'))
+ dialog.hear('name and address')
- assert_equal(:number, dialogue.next_state('zero'))
- dialogue.hear('zero')
- assert_equal(:number, dialogue.next_state('four'))
- dialogue.hear('four')
- assert_equal(:number, dialogue.next_state('four'))
- dialogue.hear('four')
+ assert_equal(:number, dialog.next_state('zero'))
+ dialog.hear('zero')
+ assert_equal(:number, dialog.next_state('four'))
+ dialog.hear('four')
+ assert_equal(:number, dialog.next_state('four'))
+ dialog.hear('four')
- assert_equal(:number, dialogue.next_state('three'))
- dialogue.hear('three')
- assert_equal(:number, dialogue.next_state('six'))
- dialogue.hear('six')
- assert_equal(:number, dialogue.next_state('four'))
- dialogue.hear('four')
+ assert_equal(:number, dialog.next_state('three'))
+ dialog.hear('three')
+ assert_equal(:number, dialog.next_state('six'))
+ dialog.hear('six')
+ assert_equal(:number, dialog.next_state('four'))
+ dialog.hear('four')
- assert_equal(:number, dialogue.next_state('three'))
- dialogue.hear('three')
- assert_equal(:number, dialogue.next_state('five'))
- dialogue.hear('five')
+ assert_equal(:number, dialog.next_state('three'))
+ dialog.hear('three')
+ assert_equal(:number, dialog.next_state('five'))
+ dialog.hear('five')
- assert_equal(:number, dialogue.next_state('three'))
- dialogue.hear('three')
- assert_equal(:number, dialogue.next_state('two'))
- dialogue.hear('two')
+ assert_equal(:number, dialog.next_state('three'))
+ dialog.hear('three')
+ assert_equal(:number, dialog.next_state('two'))
+ dialog.hear('two')
- assert_equal(:result, dialogue.next_state("that's it"))
- dialogue.hear("that's it")
+ assert_equal(:result, dialog.next_state("that's it"))
+ dialog.hear("that's it")
end
end
View
2  old/dialogues/quote/README
@@ -1 +1 @@
-With this dialogue part (and an internet connection), james can tell witty quotes of the day.
+With this dialog part (and an internet connection), james can tell witty quotes of the day.
View
2  old/dialogues/quote/init.rb
@@ -1 +1 @@
-require 'quote_dialogue'
+require 'quote_dialog'
View
4 old/dialogues/quote/lib/quote_dialogue.rb
@@ -1,7 +1,7 @@
-require 'dialogue_extension'
+require 'dialog_extension'
require 'quote_of_the_day'
-class QuoteDialogue < DialogueExtension
+class QuoteDialog < DialogExtension
initial_state :quote
hook_words 'quote of the day', 'quote'
View
2  old/dialogues/sbb/init.rb
@@ -1 +1 @@
-require 'sbb_dialogue'
+require 'sbb_dialog'
View
6 old/dialogues/sbb/lib/sbb_dialogue.rb
@@ -1,9 +1,9 @@
-require 'dialogue_extension'
+require 'dialog_extension'
require 'sbb'
# uses the sbb class to gather sbb information
-# can be used in the dialogue class as a delegate
-class SbbDialogue < DialogueExtension
+# can be used in the dialog class as a delegate
+class SbbDialog < DialogExtension
HERE = 'bints'
CITIES = ['berne','geneva','HB','basel','solothurn']
View
38 old/dialogues/sbb/test/test_sbb.rb
@@ -2,15 +2,15 @@
require '../../../test/test_helper'
require '../../../test/dummy_frontend'
require 'sbb'
-require 'main_dialogue'
-require 'sbb_dialogue'
+require 'main_dialog'
+require 'sbb_dialog'
class TestSbb < Test::Unit::TestCase
- attr_reader :dialogue
+ attr_reader :dialog
def setup
- @dialogue = MainDialogue.new(DummyFrontend.new)
+ @dialog = MainDialog.new(DummyFrontend.new)
end
# not really an automated test - still need human visual processing
@@ -20,21 +20,21 @@ def test_sbb
# TODO fix
def test_sbb_next_train
- dialogue.extend_with(SbbDialogue.new)
- dialogue.hear('james')
+ dialog.extend_with(SbbDialog.new)
+ dialog.hear('james')
- assert_equal(:awake, dialogue.state)
- assert_equal(:from, dialogue.next_state('train'))
- dialogue.hear('train')
- assert_equal(:from, dialogue.state)
- dialogue.hear('basel')
- assert_equal(:to, dialogue.state)
- assert_equal(:result, dialogue.next_state('next train'))
- dialogue.hear('next train')
- assert_equal(:result, dialogue.state)
- dialogue.hear('go back')
- assert_equal(:awake, dialogue.state)
- dialogue.hear('sleep')
- assert_equal(:sleeping, dialogue.state)
+ assert_equal(:awake, dialog.state)
+ assert_equal(:from, dialog.next_state('train'))
+ dialog.hear('train')
+ assert_equal(:from, dialog.state)
+ dialog.hear('basel')
+ assert_equal(:to, dialog.state)
+ assert_equal(:result, dialog.next_state('next train'))
+ dialog.hear('next train')
+ assert_equal(:result, dialog.state)
+ dialog.hear('go back')
+ assert_equal(:awake, dialog.state)
+ dialog.hear('sleep')
+ assert_equal(:sleeping, dialog.state)
end
end
View
2  old/dialogues/time/README
@@ -1 +1 @@
-With this dialogue part, james can tell the actual time.
+With this dialog part, james can tell the actual time.
View
2  old/dialogues/time/init.rb
@@ -1 +1 @@
-require 'time_dialogue'
+require 'time_dialog'
View
4 old/dialogues/time/lib/time_dialogue.rb
@@ -1,6 +1,6 @@
-require 'dialogue_extension'
+require 'dialog_extension'
-class TimeDialogue < DialogueExtension
+class TimeDialog < DialogExtension
initial_state :time
hook_words "what's the time?"
View
14 old/initializer.rb
@@ -6,15 +6,15 @@
JAMES_ROOT = File.join(File.dirname(__FILE__), '.')
end
-# add each dialogue lib subdir to the load path
-Dir['dialogues/**'].each do | dialogue_dir |
- dialogue_init_path = dialogue_dir + '/init.rb'
- dialogue_load_path = dialogue_dir + '/lib'
- # add dialogue lib to load_path
+# add each dialog lib subdir to the load path
+Dir['dialogs/**'].each do | dialog_dir |
+ dialog_init_path = dialog_dir + '/init.rb'
+ dialog_load_path = dialog_dir + '/lib'
+ # add dialog lib to load_path
# TODO unshift?
- $: << dialogue_load_path
+ $: << dialog_load_path
# eval init.rb
- eval(IO.read(dialogue_init_path), binding, dialogue_init_path)
+ eval(IO.read(dialog_init_path), binding, dialog_init_path)
end
# borrowed from rails
View
20 old/main_dialogue.rb
@@ -1,11 +1,11 @@
require 'osx/cocoa'
-require 'dialogue'
+require 'dialog'
require 'initializer'
# has exactly two states, sleeping and awake
# from the awake state, extensions can be plugged in to be delegated to them
-class MainDialogue < Dialogue
+class MainDialog < Dialog
attr_accessor :state
@@ -30,7 +30,7 @@ def initialize(frontend)
},
:awake => {
@sentences['sleep!'] => :sleeping,
- @sentences['return from dialogue!'] => :awake
+ @sentences['return from dialog!'] => :awake
}
}
end
@@ -137,7 +137,7 @@ def hear(phrase)
end
# if the phrase cannot be handled, say so and return to awake
- # this only occurs in badly formed dialogues
+ # this only occurs in badly formed dialogs
say("I don't know what you mean.")
exit_extension
end
@@ -210,18 +210,18 @@ def exit_awake(phrase)
private
def configure_extensions
- # which dialogue extension it is in right now
+ # which dialog extension it is in right now
@extension = nil
# actual packs
@extensions = []
- Dir['dialogues/**'].each do | dialogue_dir |
- dialogue_dir.match('(.*)(\/)(.*)')
- dialogue_file = $3 + '_dialogue'
- extend_with dialogue_file.camelize.constantize.new
+ Dir['dialogs/**'].each do | dialog_dir |
+ dialog_dir.match('(.*)(\/)(.*)')
+ dialog_file = $3 + '_dialog'
+ extend_with dialog_file.camelize.constantize.new
end
end
- # extend the main dialogue
+ # extend the main dialog
# later added extension methods will not override old phrases
def extend_with(extension)
# reset extension
View
4 old/quote_dialugue.rb
@@ -1,7 +1,7 @@
require 'quote_of_the_day'
-class QuoteDialogue
- include James::Dialogue
+class QuoteDialog
+ include James::Dialog
entry 'quote of the day', 'quote' => :quote
state :quote, ['random', 'next', 'last', 'repeat'] => :quote
View
48 old/test/test_dialogue.rb
@@ -1,20 +1,20 @@
require 'test_helper'
-require '../main_dialogue'
+require '../main_dialog'
require 'dummy_frontend'
require 'yaml'
# TODO require all files inside the extensions subdirectory
-Dir['dialogues/**/lib/**_dialogue.rb'].each do | dialogue_file |
- dialogue_file.to_s.match(/(.*)(\.)/)
+Dir['dialogs/**/lib/**_dialog.rb'].each do | dialog_file |
+ dialog_file.to_s.match(/(.*)(\.)/)
require $1
end
-class TestDialogue < Test::Unit::TestCase
+class TestDialog < Test::Unit::TestCase
- attr_reader :dialogue
+ attr_reader :dialog
def setup
- @dialogue = MainDialogue.new(DummyFrontend.new)
+ @dialog = MainDialog.new(DummyFrontend.new)
end
def test_dummy_frontend
@@ -26,33 +26,33 @@ def test_dummy_frontend
end
def test_sleeping_awake
- assert_equal(:sleeping, dialogue.state)
- assert_equal(:awake, dialogue.next_state('james'))
- dialogue.hear('james')
- assert_equal(:awake, dialogue.state)
+ assert_equal(:sleeping, dialog.state)
+ assert_equal(:awake, dialog.next_state('james'))
+ dialog.hear('james')
+ assert_equal(:awake, dialog.state)
end
def test_awake_sleeping
- dialogue.hear('james')
- assert_equal(:awake, dialogue.state)
+ dialog.hear('james')
+ assert_equal(:awake, dialog.state)
- assert_equal(:sleeping, dialogue.next_state('sleep'))
+ assert_equal(:sleeping, dialog.next_state('sleep'))
- dialogue.hear('sleep')
- assert_equal(:sleeping, dialogue.state)
- dialogue.hear('james')
- assert_equal(:awake, dialogue.state)
+ dialog.hear('sleep')
+ assert_equal(:sleeping, dialog.state)
+ dialog.hear('james')
+ assert_equal(:awake, dialog.state)
end
# the following test is dependent on the config file's content
def test_expects_phrases
- assert_equal(['jamie','james'], dialogue.expects)
- dialogue.hear('james')
- dialogue.hear('sleep')
- assert_equal(['jamie','james'], dialogue.expects)
- dialogue.hear('jamie')
- dialogue.hear('sleep')
- assert_equal(['jamie','james'], dialogue.expects)
+ assert_equal(['jamie','james'], dialog.expects)
+ dialog.hear('james')
+ dialog.hear('sleep')
+ assert_equal(['jamie','james'], dialog.expects)
+ dialog.hear('jamie')
+ dialog.hear('sleep')
+ assert_equal(['jamie','james'], dialog.expects)
end
end
View
4 old/time_dialogue.rb
@@ -1,7 +1,7 @@
require File.expand_path '../../lib/james', __FILE__
-class TimeDialogue
- include James::Dialogue
+class TimeDialog
+ include James::Dialog
hear 'What time is it?' => :time
state :time do
View
6 spec/aux/james/cli_spec.rb
@@ -5,14 +5,14 @@
describe James::CLI do
before(:each) do
- Dir.stub! :[] => ['test_dialogue.rb', 'test_dialog.rb', 'test/test_dialogue.rb']
+ Dir.stub! :[] => ['test_dialog.rb', 'test_dialog.rb', 'test/test_dialog.rb']
end
let(:cli) { James::CLI.new }
- describe 'find_dialogues' do
+ describe 'find_dialogs' do
it 'returns the right ones' do
- cli.find_dialogues.should == ['test_dialogue.rb', 'test_dialog.rb', 'test/test_dialogue.rb']
+ cli.find_dialogs.should == ['test_dialog.rb', 'test_dialog.rb', 'test/test_dialog.rb']
end
end
View
20 spec/integration/test_dialogue_spec.rb
@@ -2,10 +2,10 @@
#
require File.expand_path '../../../lib/james', __FILE__
-describe 'TestDialogue' do
+describe 'TestDialog' do
context 'unit' do
- let(:dialogue) do
+ let(:dialog) do
Class.new do
include James::Dialog
@@ -23,7 +23,7 @@
end
let(:visitor) do
- James::Visitor.new dialogue.state_for(:first)
+ James::Visitor.new dialog.state_for(:first)
end
describe "integration" do
@@ -40,8 +40,8 @@
end
# context 'integration' do
- # let(:dialogue) do
- # dialogue = Class.new do
+ # let(:dialog) do
+ # dialog = Class.new do
# include James::Dialog
#
# hear ['test1', 'test2'] => :first
@@ -54,13 +54,13 @@
# end.new
# end
# it 'works correctly' do
- # dialogue.state.name.should == :awake
- # dialogue.hear 'sleep'
- # dialogue.state.name.should == :sleeping
+ # dialog.state.name.should == :awake
+ # dialog.hear 'sleep'
+ # dialog.state.name.should == :sleeping
# end
# it 'delegates correctly' do
- # dialogue.state.name.should == :awake
- # dialogue.hear 'test1'
+ # dialog.state.name.should == :awake
+ # dialog.hear 'test1'
# end
# end
View
102 spec/lib/james/dialogue_spec.rb
@@ -1,102 +0,0 @@
-# encoding: utf-8
-#
-require File.expand_path '../../../../lib/james/state_api', __FILE__
-require File.expand_path '../../../../lib/james/dialogue_api', __FILE__
-require File.expand_path '../../../../lib/james/dialogue_internals', __FILE__
-require File.expand_path '../../../../lib/james/builtin/core_dialogue', __FILE__
-require File.expand_path '../../../../lib/james/dialogues', __FILE__
-
-describe James::Dialogue do
-
- it 'can haz merkin spellink' do
- James::Dialogue.should == James::Dialog
- end
-
- context 'units' do
- let(:dialogue) do
- James.dialogue do
-
- hear 'something' => :first
-
- state :first do
- hear 'something else' => :second
- into {}
- exit {}
- end
-
- state :second do
- hear 'yet something else' => :first
- into {}
- exit {}
- end
-
- end
- end
- describe 'state_for' do
- it 'delegates to the class, adding itself' do
- new_dialogue = dialogue.new
- dialogue.should_receive(:state_for).once.with :some_name, new_dialogue
-
- new_dialogue.state_for :some_name
- end
- it 'returns nil on not found' do
- dialogue.new.state_for(:nonexistent).should == nil
- end
- end
- end
-
- describe 'hear with lambda' do
- let(:dialogue) do
- class Test
- include James::Dialogue
-
- def initialize
- @bla = 'some bla'
- end
-
- state :test do
- hear 'bla' => ->(){ @bla }
- end
- end
- Test.new
- end
- it "is instance eval'd" do
- test_state = dialogue.state_for :test
- test_state.hear 'bla' do |result|
- result.should == 'some bla'
- end
- end
- end
-
- describe 'initialization' do
- it 'can be included' do
- expect do
- class Test
- include James::Dialogue
-
- hear 'something' => :some_state
- end
- end.to_not raise_error
- end
-
- it 'can be defined' do
- expect do
- James.dialogue do
-
- hear 'something' => :some_state
-
- end
- end.to_not raise_error
- end
- it 'can haz merkin spellink' do
- expect do
- James.dialog do
-
- hear 'something' => :some_state
-
- end
- end.to_not raise_error
- end
- end
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.