Обновление Diamond и мы построим вам свой собственный приложение для Android или iOS
Self, AIML, and scripting : Evaluation flow, declaring new :response sentences and miscelany

RE: Evaluation flow, declaring new :response sentences and miscelany

по aazxcqwe опубликовано Jan 24 2015, 15:12

Great, this is working. I hate to reply to an excellent response with more questions, but that's excitement that it's getting closer.

I'm still working this script out, but I've turned off all the Learning opitons and I'm still getting "I don't know .. " even after I've assigned an :unknown case to an inquiry response (see script). I thought I had seen the use of :unknown before, and would like to use it to catch any unknown words.

Also, although your web-IDE and debugger are quite impressive, I do keep running into confusing responses of "I don't know.." with scripts that have passed the debugging, but have some erronious line. As soon as I remove these lines, the script processes the correct responses. In the script below I remove "not" from the "if not (:question, #null).." block to get it past that, but it must be throwing an internal error. Confusing when debugging whether using unknown word, unparseable sentence or internal error. I suppose this is in the debugging info, but a return of 'error' would be very helpful, at least in my case.

Your script does work nearly to what I'd like, but one structural comment I have continues to present itself. I believe I was trying to use Do and If operations before the Equation to simplify the code. For example in your script, if there is a verb present it goes to subjectVerbState to process the second noun. This is fine except you've had to add all the other cases that followed before into that state. A bit non-concise, but it makes for double duty when troubleshooting or changing case statements, because the scripter has to change items in both places.
This could be greatly simplified and probably useful for other situations, if I could add an assign statement along with the goto statement (in fact, the latter would often be unnecessary). For example in your script, instead of having the nearly duplicate subjectVerbState, you could have "case :verb do(assign #true to :verbfound)" and "case :noun do(assign #true to :noun1found)" and then "case :noun do(if not (:noun1, #null) then do(assign :noun2 to :noun)". (I may have those assign parameters backwards, but the order for assign is counter-intuitive and grammatically backwards, at least in English). I hope you can see this would greatly eliminate the need for redundancy in slightly different states. And furthermore, those variable definition could be used elsewhere, though I see you accomplish that by checking if those variables are null.



Finally, I introduced a :case for the sentence starting with a :question word, and followed your structure for checking if :question was #null, but it kept coming back false even with no question word was present (I also tried switching it to "?" to avoid double meanings with :verb). It seems like it treating this variable different that :noun, :verb and :adjective and returning values stored in the knowledgebase, but that is just my best guess.

Here is some of my code, it's not working yet for several reasons, but you can see what I'm talking about. I'm also trying to code to ask for definition of unknown words, or filling in missing verbs or adjectives, with the very next user response (commented line). I've borrowed lines from the WrongAnswer script, but I don't have it working yet. Currently, "case :question" seems to be identifying random words as :question. EDIT: I have the unknown check moving forward, but the :anything used to move to the sentenceState is catching the verb "is" - explaining the hard definition of is, but again with added Case abilities explained above, this could be avoided. Very close though.. and I think I can implement that same explanation example using If statements.

// This script looks for a subject and predicate of a sentence. State:SimpleLanguage { case :input goto State:questionState for each #word of :sentence; :input { set #input to :sentence; set #speaker to :speaker; set #conversation to :conversation; set #target to :target;} :sentence {set #instantiation to #sentence;} State:questionState { case "cancel" return; case :question goto State:sentenceState; case :anything goto State:sentenceState; State:sentenceState { case :noun goto State:subjectState; case :unknown goto State:subjectState; case :anything goto State:sentenceState; :noun {set #meaning to :subject;} :subject {set #instantiation to #thing;} State:subjectState { case :not goto State:subjectState; case :verb goto State:subjectVerbState; case :adjective goto State:subjectState; case :noun2 goto State:subjectState; case :unknown goto State:subjectState; case :question-mark goto State:sentenceState; case :anything goto State:subjectState; :not {set #meaning to #not;} :verb {set #instantiation to #action;} :adjective {set #instantiation to #description;} :noun2 {set #meaning to :object;} :object {set #instantiation to #thing;} Quotient:1.00:Equation:response; Equation:response { if (:unknown, #null) then (do (return Formula:"What is {:unknown}?")); if not (:question, #null) then (do ( if (is :noun related to :adjective by :verb, #true) then (return "yes, true"), if (:verb, #null) then (return (all :verb from :noun)), if (:adjective, #null) then (return (all :adjective from :noun)), if (:noun2, #null) then (return (all :noun2 from :noun)) else (return "no verbs, adjectives or descriptions found") )); if (:noun, #null) then (do ( return Formula:"What is the subject? (use ! in front for emphasis)", assign :correction to (get #input from (get #input from :conversation at last 1)), associate :subject to :correction by #response, return )); if (:verb, #null) and (:adjective, #null) and (:noun2, #null) then (return Formula:"{:question} is {:anything}?"); if (:verb, #null) then (assign :verb to #is); if (:adjective, #null) and (:noun2, #null) then (do ( assign :value to (get :verb from :noun), if (:value, #null) then (return Formula:"What does {:subject} {:verb}?") else (return Formula:"{:subject} {:verb} {:value}") )); if (:adjective, #null) then (assign :adjective to :noun2); if (is :noun related to :adjective by :verb, #true) then (return "yes, that's true"); if (:not, #null) then (do ( associate :noun to :adjective by :verb, return Formula:"I understand, {:subject} {:verb} {:adjective}" )) else (do ( dissociate :noun to :adjective by :verb, return Formula:"I understand, {:subject} does not {:verb} {:adjective}" ));} State:subjectVerbState {case :not goto State:subjectVerbState; case :adjective goto State:subjectVerbState; case :noun2 goto State:subjectVerbState; case :? goto State:subjectVerbState; case :anything goto State:subjectVerbState; Quotient:1.00:Equation:response;} } } } }
// This script looks for a subject and predicate of a sentence. State:SimpleLanguage { case :input goto State:questionState for each #word of :sentence; :input { set #input to :sentence; set #speaker to :speaker; set #conversation to :conversation; set #target to :target; } :sentence { set #instantiation to #sentence; } State:questionState { case "cancel" template "cancelled"; case :question goto State:sentenceState; case :anything goto State:sentenceState; :question { set #instantiation to #question; } State:sentenceState { case :noun goto State:subjectState; case :anything goto State:sentenceState; :noun { set #meaning to :subject; } :subject { set #instantiation to #thing; } State:subjectState { do (assign #verb to "is"); case :not goto State:subjectState; case :verb goto State:subjectVerbState; case :adjective goto State:subjectState; case :noun2 goto State:subjectState; case :question_mark goto State:sentenceState; case :anything goto State:subjectState; :not { set #meaning to #not; } :verb { set #meaning to #action; } :adjective { set #instantiation to #description; } :noun2 { set #meaning to :object; } :object { set #instantiation to #thing; } Quotient:1.00:Equation:response; Equation:response { assign :response to (new #sentence); append (sentence ( "question:", :question, "noun:", :noun, "not:", :not, "verb:", :verb, "adjective:", :adjective, "anything:", :anything )) to #word of :response; if not (is :anything related to #thing, #unknown) then (do (return Formula:"0 What is {:anything}?")); if (:question, "what") then (do ( if (is :noun related to :adjective by :verb, #true) then (return "yes, true"), if (:verb, #null) then (return (all :verb from :noun)), if (:adjective, #null) then (return (all :adjective from :noun)), if (:noun2, #null) then (return (all :noun2 from :noun)) else (return "no verbs, adjectives or descriptions found") )); if (:subject, #null) then (do ( return Formula:"What is the subject? (use ! in front for emphasis)", assign :correction to (get #input from (get #input from :conversation at last 1)), associate :subject to :correction by #response, return )); if (:verb, #null) and (:adjective, #null) and (:noun2, #null) then (return Formula:"1 what is {:anything}? {:response}"); if (:verb, #null) then (assign :verb to #is); if (:adjective, #null) and (:noun2, #null) then (do ( assign :value to (get :verb from :noun), if (:value, #null) then (return Formula:"What does {:subject} {:verb}?") else (return Formula:"2 {:subject} {:verb} {:value}") )); if (:adjective, #null) then (assign :adjective to :noun2); if (is :noun related to :adjective by :verb, #true) then (return "yes, that's true"); if (:not, #null) then (do ( associate :noun to :adjective by :verb, return Formula:"I understand, {:subject} {:verb} {:adjective}" )) else (do ( dissociate :noun to :adjective by :verb, return Formula:"I understand, {:subject} does not {:verb} {:adjective}" )); } State:subjectVerbState { case :not goto State:subjectVerbState; case :adjective goto State:subjectVerbState; case :noun2 goto State:subjectVerbState; case :_ goto State:subjectVerbState; case :anything goto State:subjectVerbState; Quotient:1.00:Equation:response; } } } } }


Идентификатор: 717726
Опубликовано: Jan 24 2015, 15:12
Обновлено: Jan 25 2015, 17:28
Ответы: 0
Вид: 1856, сегодня: 1, неделю: 1, месяц: 4
0 0 0.0/5