Class: SiriProxy::Interpret
- Inherits:
-
Object
- Object
- SiriProxy::Interpret
- Defined in:
- lib/siriproxy/interpret_siri.rb
Overview
The idea behind this class is that you can call the different methods to get different interpretations of a Siri object. For instance, you can “unknown_intent” and it will check to see if an object is a “Common#unknownIntent” response and call the provided processor method with the appropriate info. processor method signatures are provided in comments above each method.
each method will return “nil” if the object is not the valid type. If it is, it will return the result of the processor.
Class Method Summary collapse
-
.speech_recognized(object) ⇒ Object
Checks if the object is Guzzoni responding that it recognized speech.
-
.unknown_intent(object, connection, processor) ⇒ Object
Checks if the object is Guzzoni responding that it can’t determine the intent of the query processor(object, connection, unknown_text).
Class Method Details
.speech_recognized(object) ⇒ Object
Checks if the object is Guzzoni responding that it recognized speech. Sends “best interpretation” phrase to processor processor(object, connection, phrase)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/siriproxy/interpret_siri.rb', line 32 def speech_recognized(object) return nil if object == nil return nil if (!(object["class"] == "SpeechRecognized") rescue true) phrase = "" object["properties"]["recognition"]["properties"]["phrases"].map { |phraseObj| phraseObj["properties"]["interpretations"].first["properties"]["tokens"].map { |token| tokenProps = token["properties"] phrase = phrase[0..-2] if tokenProps["removeSpaceBefore"] and phrase[-1] == " " phrase << tokenProps["text"] phrase << " " if !tokenProps["removeSpaceAfter"] } } phrase.strip end |
.unknown_intent(object, connection, processor) ⇒ Object
Checks if the object is Guzzoni responding that it can’t determine the intent of the query processor(object, connection, unknown_text)
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/siriproxy/interpret_siri.rb', line 18 def unknown_intent(object, connection, processor) return false if object == nil return false if (!(object["properties"]["views"][0]["properties"]["dialogIdentifier"] == "Common#unknownIntent") rescue true) searchUtterance = object["properties"]["views"][1]["properties"]["commands"][0]["properties"]["commands"][0]["properties"]["utterance"] searchText = searchUtterance.split("^")[3] return processor.call(object, connection, searchText) return false end |