• ghost065.pl Mentifex Strong AI Perl6 Killer App treats Unicode as quasi

    From mentificium@gmail.com@21:1/5 to All on Sat Feb 6 17:55:22 2016
    #!/usr/bin/perl
    use strict; # PERL by Example (2015) p. 77
    use warnings; # PERL by Example (2015) p. 85
    # use feature 'say'; # PERL by Example (2015) p. 73
    # ghost065.pl being coded on Sat.06.FEB.2016 or later.
    our $. = 0; # 2016jan14: line counter variable; PbyX 299
    our $_ = " "; # 2016jan10: hidden variable; P_by_Ex p. 301
    our $act = 0; # 2016jan16: quasi-neuronal activation-level
    our $actbase = 0; # 2016jan23: AudRecog discrimination activation base
    our $age = 0; # 2015apr26: Temporary age for loop-counting.
    our $aud = " "; # 2016jan28: explicit package from @ear array
    our $audbase = 0; # 2016jan27: recall-vector for VerbGen()
    our $audbeg = 0; # 2016jan17: auditory-beginning tag for start of word.
    our $audnew = 0; # 2016jan17: holds onset-tag while rest of word comes in. our $audpsi = 0; # 2016jan17: concept number of word in @aud array
    our $audrec = 0; # 2016jan23: auditory recognition concept-number
    our $audrv = 0; # 2015may13: auditory recall-vector for speech()
    our $audrun = 1; # 2016jan26: counter of loops through AudRecog()
    our $audult = 0; # 2016jan17: ultimate-tag for end of word-engram
    our $bias = 0; # 2015jun04: EnParser; NewConcept: expected POS
    our $char = " "; # 2016jan12: For use with getc in FileInput()
    # our $cns = 32; # 2015apr26: size of central nervous system
    our $cns = 48; # 2016jan23: size of central nervous system
    our $coda = 0; # 2016jan16: "tail" or time of word-end.
    our $dba = 0; # 2016jan16: doing-business-as noun-case or verb-person our $defcon = 5; # 2016jan21: defense condition
    our $engram = " ";
    our $eot = 0; # 2016feb01: end-of-transmission for end of input
    our $hlc = "en"; # 2016jan22: human-language code; 1=en; 2=de; 3=ru.
    our $lex = " "; # 2016jan16: Explicit package for showing $en array.
    our $jux = 0; # 2016jan20: jux(taposed) concept in @psy array.
    our $kbr = 0; # 2016jan28: knowledge-base-row# splits @psy array.
    our $krt = 0; # 2015may10: knowledge representation time
    our $len = 0; # 2016jan27: length, for avoiding input non-words
    our $lftell = 0; # 2016jan18: linefeed-tell for final word in line
    our $mfn = 0; # 2016jan16: masculine-feminine-neuter gender flag.
    our $midway = 0; # 2016jan23: limit for searching backwards in memory
    our $monopsi = 0; # 2016jan27: For use in AudRecog() module
    our $morphpsi = 0; # 2016jan27: "for audRecog recognition of morphemes"
    our $msg = " "; # 2015may01: $msg is for "message" of input.
    our $num = 0; # 2016jan16: number-flag for grammatical number.
    our $node = 0; # 2016jan27: "split" @psy array row into nodes
    our $nxr = " "; # 2016jan26: for AudRecog dealing with next memory row
    our $nxt = 0; # 2016feb03: number incremented for each new concept
    our $oldpsi = 0; # 2016jan30: used in OldConcept to de-globalize "psi"
    our $onset = 0; # 2016jan16: onset-tag for use as recall-vector.
    our $pho = ""; # $pho is for a "phoneme" or character of input.
    our $pos = "5"; # 2016jan20: part-of-speech for @psy conceptual array.
    our $pov = 35; # 2015jun04: point-of-view: #35 internal; *42 external
    our $prc = 0; # 2016jan26: provisional recognition in AudRecog()
    our $pre = 0; # 2016jan20: pre(vious) associated @psy concept.
    our $psi = 1; # 2016jan19: variable for elements of @psy array
    our $psibase = 0; # 2016jan27: "winning psibase with winning actbase"
    our $recnum = 0; # 2016jan27: "recognized number of a recognized word"
    our $rv = 0; # 2016jan22: recall-vector for auditory memory.
    our $seq = 0; # 2016jan20: subSEQuent @psy concept in an idea.
    our $spt = 0; # 2016jan23: blank space time before start of a word
    our $stemgap = 0; # 2016jan27: "for avoiding false audRecog stems"
    our $sublen = 0; # 2016jan27: "length of audRecog subpsi word-stem"
    our $subpsi = 0; # 2016jan27: "for AudRecog of sub-component wordstems"
    our $t = 0; # 2015may02: Lifetime experiential time "$t"
    our $t2s = 0; # 2015apr26: auditory text-to-speech index
    our $tkb = 0; # 2016jan20: time-in-knowledge-base of an idea.
    our $tult = 0; # 2016jan18: t penultimate, or time-minus-one
    our @ear = " "; # 2016jan28: new name for auditory memory array.
    our @psy = " "; # 2016jan19: conceptual array renamed as @psy
    sub AudBuffer; # 2016jan15 PbEx5e p. 351: Forward declaration.
    sub AudInput; # 2015apr25 PbEx5e p. 351: Forward declaration.
    sub AudMem; # 2015apr25 PbEx5e p. 351: Forward declaration.
    sub AudRecog; # 2016jan23 auditory recognition module.
    sub DeThink; # 2016jan24: Selected dynamically by $hlc flag.
    sub emotion; # 2015apr25 PbEx5e p. 351: Forward declaration.
    sub EnThink; # 2016jan24: Selected dynamically by $hlc flag.
    sub EnVocab; # 2015jun01 PbEx5e p. 351: Forward declaration.
    sub FileInput; # 2016jan10 PbEx5e p. 351: Forward declaration.
    sub InStantiate; # 2016jan19 PbEx5e p. 351: Forward declaration.
    sub KbLoad; # 2016jan22 PbEx5e p. 351: Forward declaration.
    sub MindBoot; # 2016jan23 PbEx5e p. 351: Forward declaration.
    sub motorium; # 2015apr25 PbEx5e p. 351: Forward declaration.
    sub NewConcept; # 2015may28 PbEx5e p. 351: Forward declaration.
    sub OldConcept; # 2016jan14 PbEx5e p. 351: Forward declaration.
    sub RuThink; # 2016jan24: Selected dynamically by $hlc flag.
    sub sensorium; # 2015apr24 PbEx5e p. 351: Forward declaration.
    sub TabulaRasa; # 2016jan25: Called from MainLoop as in MindForth
    sub VisRecog; # 2015apr26 PbEx5e p. 351: Forward declaration.
    sub volition; # 2015apr24 PbEx5e p. 351: Forward declaration.

    # TabulaRasa: { # 2015may28: Establish size and emptiness of CNS.
    sub TabulaRasa() { # 2016jan25: Establish size and emptiness of CNS.
    print "Size of AI memory is $cns \n"; # 2015apr26
    my $trc = 0; # 2015apr2015 $trc is "tabula rasa counter".
    until ($trc == $cns) { # 2015apr26 PbEx5e p. 193 "Loops".
    $psy[$trc] = "0,0,0,0,0,0,0,0,0,0,0,0"; # 2016jan21 merge @psy and @en
    $ear[$trc] = " ,0,0"; # 2016jan28: initialize three columns.
    $trc++; # 2015apr26: Increment tabula-rasa-counter $trc.
    } # End of loop filling auditory memory with blank engrams.
    }; # End of TabulaRasa "clean slate" sequence.


    sub AudDamp() { # 2016feb03: "deactivate auditory engrams"
    for (my $i=$midway; $i<$cns; $i++) { # 2016feb03:
    my @aud=split(',',$ear[$i]); # 2016feb03: Examine the @ear array.
    $ear[$i] = "$aud[0],0,$aud[2]"; # 2016feb03: Reset act to zero.
    } # 2016feb03: end of forwards sweep through auditory memory.
    } # 2016feb03: End of AudDamp(0; return to input module.


    sub KbLoad() { # 2016jan23: load MindBoot knowledge-base bootstrap.
    print "KbLoad stores MindBoot knowledge-base, t= $t. \n"; # 2016jan23
    $psy[$t] = "$psi,$act,$hlc,$pos,$jux,$pre,$tkb,$seq,$num,$mfn,$dba,$rv";
    } # 2016jan23: End of KbLoad; return to MindBoot knowledge bootstrap.


    sub AudBuffer() { # http://code.google.com/p/mindforth/wiki/AudBuffer
    # print "AudBuffer has been called. \n"; # 2016jan15
    } # End of AudBuffer; return to AudInput or FileInput or VerbGen.


    # 2015jun01 Requirements of EnVocab English vocabulary mind-module:
    # EnVocab shall create nodes of lexical memory with associative tags.
    # EnVocab shall only _control_ English words and not _hold_ English words.
    sub EnVocab() { # http://mind.sourceforge.net/envocab.html
    $act = 8; # 2016jan16: Test with typical activation $act
    $num = 1; # 2016jan16: Test with typical number = 1.
    $mfn = 3; # 2016jan16: Test with mfn=3 neutral gender.
    $dba = 1; # 2016jan16: Test with dba=1 for subject or first person.
    $rv = $audnew; #2016jan17: $audnew is from FileInput().
    $audnew = 0; # 2016jan18: Reset $audnew after transferring value.
    $tult = $t - 1; # 2016jan18: penultimate time
    print " EnVocab: Stores rv ", $rv, " at tult = ", "$tult\n"; #2016jan18
    $psy[$tult] = "$psi,$act,$hlc,$pos,$jux,$pre,$tkb,$seq,$num,$mfn,$dba,$rv";
    } # http://code.google.com/p/mindforth/wiki/EnVocab


    sub InStantiate() { # http://mind.sourceforge.net/instiate.html
    print "\nInStantiate() has been called by EnParser().\n"; # 2016jan19
    print " InSt: psi=$psi,act=$act,hlc=$hlc,pos=$pos,"; # 2016jan21: flags
    print "jux=$jux,pre=$pre,tkb=$tkb,seq=$seq,"; # 2016jan21: @psy flag-panel
    print "num=$num,mfn=$mfn,dba=$dba,rv=$rv\n"; # 2016jan21: @psy flag-panel
    print " InSt: Storing psi $psi flag-panel at time = $tult \n"; #2016jan20
    $psy[$tult] = "$psi,$act,$hlc,$pos,$jux,$pre,$tkb,$seq,$num,$mfn,$dba,$rv";
    } # http://code.google.com/p/mindforth/wiki/InStantiate


    # 2015jun04 Requirements of EnParser English Parser module:
    # EnParser shall at first assume that a new word is a noun.
    # EnParser shall call InStantiate to complete the parsing process.
    sub EnParser() { # http://mind.sourceforge.net/parser.html
    $bias = 5; # 2015jun04: Expect a noun until overruled.
    print " EnParser has been called by NewConcept \n"; # 2016jan14
    InStantiate(); # 2016jan19: for creating @psi concept-nodes
    } # http://code.google.com/p/mindforth/wiki/EnParser


    sub OldConcept() { # http://mind.sourceforge.net/oldcept.html
    print "\nOldConcept() called by an input module.\n"; # 2016jan30
    print "OldConcept storing oldpsi $oldpsi t $t -1 \n"; # 2016jan30
    my @kbr=split(',',$psy[$t-1]); # 2016jan30: expose ALL the values;
    $psy[$t-1]="$oldpsi,0,$hlc,$pos,$jux,$pre,$tkb,$seq,$num,$mfn,$dba,$rv";
    $oldpsi = 0; # 2016jan30: reset for safety.
    } # http://code.google.com/p/mindforth/wiki/OldConcept


    # 2015may28 Requirements of NewConcept mind-module:
    # NewConcept shall create a concept in @psy for each new word encountered.
    # A flag-panel shall lodge associative tags with each new @psy concept.
    sub NewConcept() { # http://mind.sourceforge.net/newcept.html
    print "NewConcept: nxt= $nxt len= $len \n"; # 2016feb03:
    $psi = $nxt; # 2016jan22: For xfer to InStantiate().
    print " NewC hlc=$hlc calls EnVocab for psi $psi len $len \n"; # 2016jan30
    if ($len > 0) { # 2016jan30: Only if word has a positive length.
    EnVocab(); # 2015jun01: To create an English vocabulary node.
    } # 2016jan30: end of test to avoid spurious concepts of zero length.
    # if ($hlc eq "de") { # 2016jan22: test for governing human-language-code
    # DeParser(); # 2016jan22: In preparation to call InStantiate().
    # } # 2016jan22: end of test for German human-language-code.
    if ($hlc eq "en") { # 2016jan22: test for governing human-language-code
    EnParser(); # 2015jun04: In preparation to call InStantiate().
    } # 2016jan22: end of test for English human-language-code
    # if ($hlc eq "ru") { # 2016jan22: test for governing human-language-code
    # RuParser(); # 2016jan22: In preparation to call InStantiate().
    # } # 2016jan22: end of test for Russian human-language-code.
    print "NewConcept-late: nxt= $nxt len= $len \n"; # 2016feb03:
    if ($len > 0) { # 2016jan30: do not count spurious new concepts
    $nxt++; # 2016jan22: Increment for each new human word/concept.
    print "NewConcept increments nxt counter to $nxt \n"; # 2016feb02 TEST
    } # 2016jan30: end of test for new concepts with positive length.
    $audpsi = 0; # 2016feb03: reset to prevent carry-overs.
    } # 2016jan30: from NewConcept() return to AudInput() or FileInput().


    # The visual recognition module in the Perlmind for robots
    # when fully implemented will serve the purpose of letting
    # AI Minds dynamically describe what they see in real time
    # instead of fetching knowledge from the AI knowledge base.
    sub VisRecog() { # http://www.openhub.net/p/opencv-perl
    # 2016jan22: NOTHING = default answer for "What do you see?"
    } # http://code.google.com/p/mindforth/wiki/VisRecog


    sub AudRecog() { # http://code.google.com/p/mindforth/wiki/AudRecog
    $audrec = 0; # 2016jan23: prevent carry-over of previous value.
    $psi = 0; # 2016jan23: prevent carry-over of previous value.
    $act = 8; # 2016jan30: as in Mindforth, start with a hefty value.
    $actbase = 0; # 2016jan23: prevent carry-over of previous value.
    for (my $i=$midway; $i<$spt; $i++) { # 2016jfeb03: Seek no-act initial pho
    my @aud=split(',',$ear[$i]); # 2016jan28: @ear is new array-name
    if ($pho eq $aud[0]) { # 2016jan29: If incoming pho matches stored aud0;
    if ($aud[1]==0) { # 2016jan28: if matching engram has no activation;
    my @prv=split(',',$ear[$i-1]); # 2016feb3: "explicit package name"
    if ($prv[0] !~ /[A-Z]/) { # 2016feb3: "if beg=1 on matching no-act aud engram"
    if ($audrun < 2) { # 2016jan27: "if comparing start of a word"
    my @nxr=split(',',$ear[($i+1)]); # 2016jan28: for next-in-line char
    if ($nxr[0] =~ /[A-Z]/) { # 2016jan27: pattern binding operator
    $ear[$i+1] = "$nxr[0],8,$nxr[2]"; # 2016feb3: "activate N-I-L character"
    $audrec = 0; # 2016jan27: from MindForth AI
    } # 2016jan27: "end of test for continuation of beg-aud"
    my @aud=split(',',$ear[($i)]); # 2016jan31: for current char
    if ($aud[2] > 0) { # 2016jan31: if concept number present
    $monopsi = $aud[2]; # 2016feb06: hold onto potential monopsi
    } # 2016feb06: end of test for potential monopsi ultimate-tag
    } # 2016jan27: Mindforth "end of test for audrun=1 start of word"
    } # 2016jan24: "end of test for a beg(inning) non-active aud0"
    } # 2016jan27: "end of test for matching aud0 with no activation"
    my @aud=split(',',$ear[$i]); # 2016jan28: Using new names.
    if ($aud[1] > 0) { # 2016jan28: "If matching aud0 has activation"
    $audrec = 0; # 2016jan27: "Zero out any previous audrec."
    my @nxr=split(',',$ear[($i+1)]); # 2016jan27: for next-in-line char
    if ($nxr[0] =~ /[A-Z]/) { # 2016jan27: pattern binding operator
    $act = ($act + 2); # 2016jan27: Increment $act for discrimination.
    $audrec = 0; # 2016jan27: "because match-up is not complete"
    $ear[$i+1] = "$nxr[0],$act,$nxr[2]"; # "Increment for discrimination."
    } # 2016jan27: "end of test for active-match aud0 continuation"
    @nxr=split(',',$ear[($i+1)]); # 2016jan28: for next-in-line char
    if ($nxr[0] !~ /[A-Z]/) { # 2016jan27: If ctu=0 indicates end of word
    if ($len == 2) { # 2016jan27: "If len(gth) is only two characters."
    my @aud=split(',',$ear[$i]); # Expose values of @ear row #i
    if ($aud[1] > 7) { # 2016jan28: "testing for eight (8)"
    $psibase = $aud[2]; # 2016jan28 MindForth: "Assume a match."
    } # 2016jan27 MindForth: "End of test for act=8 or positive."
    } # 2016jan27 MindForth: "End of test for two-letter words."
    } # 2016jan27 MindForth: "End of test in AudRecog for end of word."
    my @aud=split(',',$ear[$i]); # Expose values of @ear row #i
    if ($aud[1] > 8) { # 2016jan28: "If activation higher than initial"
    $actbase = 8; # 2016jan27 Mindforth: "Since act is > 8 anyway;"
    my @nxr=split(',',$ear[($i+1)]); # 2016jan27: for next-in-line char
    if ($nxr[0] !~ /[A-Z]/) { # 2016jan27: If matching word-engram ends
    if ($aud[1] > $actbase) { # 2016feb03: "Testing for high act."
    $audrec = $aud[2]; # 2016jan28: "Fetch the potential tag"
    $subpsi = $aud[2]; # 2016jan28: "Seize a potential stem."
    $sublen = $len; # 2016jan27: "Hold length of word-stem."
    $psibase = $aud[2]; # 2016jan28: "Hold onto winner."
    my @kbr=split(',',$psy[$i]); # 2016jan28
    $recnum = $kbr[8]; # 2016jan28: recognized grammatical number
    if ($kbr[10] > 0) { # 2016jan28: if there is a $dba value
    $dba = $kbr[10]; # 2016jan28: for verb-recognition, etc.
    } # 2016jan27: "end of test for dba"
    $actbase = $aud[1]; # 2016jan28: "Winner is new actbase."
    } else { # 2016jan27: "End of test for act higher than actbase."
    $audrec = 0; # 2016jan27: no word has been recognized
    } # 2016jan27: End of else-clause
    } # 2016jan27: "End of test for final char that has a psi-tag."
    } # 2016jan27: "End of test for engram-activation above eight."
    } # 2016jan27: "End of test for matching aud0 with activation."
    } # 2016jan27: "End of test for a character matching 'pho'."
    } # 2016feb03: End of forwards search through auditory memory.
    $audrun++; # 2016jan27: audrun is only a counter, not a factor.
    $act = 0; # 2016jan27:
    $actbase = 0; # 2016jan27:
    if ($psibase > 0) { $audrec = $psibase } # 2016jan27:
    if ($psibase > 0) { print " AUDR: psibase to audrec \n" } # 2016feb06
    if ($audrec == 0) { # 2016feb06: correction, to what MindForth does here.
    if ($monopsi > 0) { # 2016jan27:
    if ($len < 2) { # 2016jan27:
    $audrec = $monopsi; # 2016jan27: recognize one-letter word.
    } # 2016jan27: end of test for word-length less than two
    } # 2016jan27: end of test for presence of a found monopsi
    } # 2016jan27: end of test for a found auditory recognition.
    if ($audrec == 0 && $prc > 0) { # 2016jan27
    $audrec = $prc; # 2016jan27: from Dushka RuAi; prov. recog;
    } # 2016jan27
    if ($audrec == 0) { # 2016jan27:
    $audrec = $morphpsi; # 2016jan27:
    if ($sublen > 0) { # 2016jan27:
    $stemgap = ($len - $sublen); # 2016jan27
    } # 2016jan27:
    if ($stemgap < 0) { $stemgap = 0 } # 2016jan27
    if ($stemgap > 1) { $subpsi = 0 } # 2016jan27
    if ($stemgap > 1) { $morphpsi = 0 } # 2016jan27
    if ($stemgap > 1) { $audrec = 0 } # 2016jan27
    } # 2016jan27:
    $psibase = 0; # 2016jan27
    $subpsi = 0; # 2016jan27
    if ($audrec > 0) { # 2016jan27
    if ($stemgap > 2) { # 2016jan27
    $audrec = 0; # 2016jan27
    } # 2016jan27
    } # 2016jan27
    $audpsi = $audrec; # 2016jan27
    $audrec = 0; # 2016jan27: temporary safety precaution after xfer.
    $stemgap = 0; # 2016jan27: safety measure
    } # End of AudRecog(); return to AudMem(); 2016jan26


    sub AudMem() { # http://code.google.com/p/mindforth/wiki/AudMem
    if ($pho =~ /[A-Z]/) { # 2016jan30: Only try to recognize pho(nemes)
    AudRecog(); # 2016jan23: Recognize old words $char by $char.
    } # 2016jan30: End of test for a letter of the alphabet.
    if ($audpsi == 0) { # 2016feb05: if no news from AudRecog() early in the word
    $ear[$t] = "$pho,$act,0"; # 2016feb05: no ultimate-tag
    } # 2016feb05: end of test for storing pre-audpsi pho(nemes)
    if ($len > 0) { # 2016feb05: assign tags to words, not empty rows
    my @aud=split(',',$ear[($t)]); # 2016feb05: look at current row
    if ($aud[0] !~ /[A-Z]/) { # 2016feb05: if aud0 is not a letter
    if ($audpsi == 0) { # 2016feb05: if word unrecognized, nxt new concept
    my @prv=split(',',$ear[($t-1)]); # 2016feb05: assuming post-word blank
    $ear[$t-1] = "$prv[0],$prv[1],$nxt"; # 2016feb05: retroactive audpsi
    } # 2016feb05: end of test to declare new concept for lack of old.
    } # 2016feb05: end of check to see if space is reached after a word.
    } # 2016feb05: end of test for a positive word-length
    if ($audpsi > 0) { # 2016feb05: if there is an audpsi
    $ear[$t] = "$pho,$act,0"; # 2016feb05: at first store no audpsi
    my @aud=split(',',$ear[($t)]); # 2016feb05: look at current row
    if ($aud[0] !~ /[A-Z]/) { # 2016feb05: if aud0 is not a letter
    my @prv=split(',',$ear[($t-1)]); # 2016feb05: assuming post-word blank
    $ear[$t-1] = "$prv[0],$prv[1],$audpsi"; # 2016feb05: retroactive audpsi
    } # 2016feb06: end of waiting until just after a word to identify it.
    } # 2016feb05: end of test for an audpsi from AudRecog()
    if ($pho =~ /[A-Z]/) { # 2016feb03: If a $char is being stored...
    $coda++ ; # 2016jan16: Increment word-coda with each stored $char.
    } # 2016jan16: End of test for a non-empty $char
    $coda = ($coda - 1); # 2016jan16: lower #coda by one unit.
    if ($pho !~ /[A-Z]/) { # 2016feb03
    $ear[$t] = "$pho,0,0"; # 2016jan28: initialize @ear panel-flags.
    } # 2016jan23: Establish end of word.
    } # http://mind.sourceforge.net/audstm.html


    sub AudInput() { # 2015apr25
    $spt = $t; # 2016jan28: as in FileInput() module.
    # my $_ = " "; # 2016jan28: as in FileInput() module; PbEx p. 301
    $_ = " "; # 2016FEB03: PERL by Example (2015), p. 301
    print "\nInput words, or Q for quit, then press RETURN: \n"; # 2016jan29
    $msg = <STDIN>; # 2015may01: PERL by Example (2015), p. 50
    print "Changing to uppercase. You entered: \n"; # 2016jan29: for left margin.
    $msg = uc $msg; # 2016jan29: from Perl Black Book, p. 341.
    print "\nHuman: $msg \n"; # 2016jan29: newline is now _outside_ $msg.
    my $reversed = reverse $msg; # 2016jan29: PbyEx p. 125
    if ($reversed =~ /[Q]/) { die "\aTERMINATE: Q for quit. \n"; } # 2016jan29
    do { # 2016feb02: outer loop receives input of an entire sentence.
    do { # 2016feb02: inner loop treats each word character by character.
    $pho = chop($reversed); # 2016jan29 returns chopped character as $pho.
    print "\n$pho"; # 2016feb03: show pho-string amid diagnostic messages
    if ($pho eq "\n") { $eot = 1 } # 2016feb01: for escape from outer loop.
    $t++; # 2016jan16: Increment time "t" here instead of AudMem()
    if ( $pho =~ /[A-Z]/) { # 2016jan29: pattern binding operator
    print " pho $pho is an alphabetic letter \n"; # 2016jan29
    $len++; # 2016jan31: increment length as per MindForth
    print " AudInput: increasing len(gth) to $len \n"; # 2016jan31
    if ($len == 1) { $rv = $t } # 2016jan30: set recall-vector.
    AudMem(); # 2016jan29: Calling memory-insertion subroutine
    } else { # 2016jan30:
    $pho = " "; # 2016jan30: Send blank space...
    AudMem(); # 2016jan30: ...as a message that word has ended
    } # 2016feb02: end of else-clause for sending a blank space
    } until $pho eq " "; # 2016jan30: Store whole word until $pho is empty.
    AudDamp(); # 2016feb03: TEST; REMOVE
    $monopsi = 0; # 2016feb06: zero out to prevent carry-over
    if ($audpsi > 0) { # 2016jan30: would be from AudRecog()
    $oldpsi = $audpsi; # 2016jan30: JSAI: for conformance with MindForth
    $audpsi = 0; # 2016feb04: zero out to prevent carry-over
    $prc = 0; # 2016feb06: as is done in the JavaScript AiMind.html
    print " AudInput() calls OldConcept() for oldpsi $oldpsi \n"; # 2016feb04
    OldConcept() } # 2016jan30: code-bloc from FileInput()
    else { # 2016jan30: Expanding for diagnostic message.
    if ($len > 0) { # 2016jan31: if input word one char or longer
    print "AudInput-else calls NewConcept nxt $nxt len= $len \n"; # 2016jan30
    NewConcept(); # 2016jan30: if not old concept, then new concept
    } # 2016jan31: end of test for postive length before NewConcept().
    $len = 0; # 2016jan30: Reset so next word must accumulate length.
    } ; # 2016jan30: as in MindForth AudInput module.
    $audpsi = 0; # 2016jan30: reset for safety
    $len = 0; # 2016jan31: when pho=0 length reverts to zero.
    $audrun = 1; # 2016feb06: for multiple calls to AudMem().
    } until $eot == 1; # 2016feb01: a condition set within inner loop.
    $eot = 0; # 2016feb02: Reset to zero for the sake of whole sentneces.
    print "Ghost: (AI does not yet think) \n"; # 2016feb04: as if Transcript
    $audpsi = 0; # 2016jan30: reset for safety
    } # http://mind.sourceforge.net/audition.html


    sub FileInput() { #2016jan10
    $spt = $t; # 2016jan23: from MindForth AudInput
    my $_ = " "; # 2016jan10: PERL by Example (2015), p. 301
    print "PerlAI will try to open and read input.txt file \n"; # 2016jan28
    # open (my $fh, "<", "input.txt") or die "Can't open: $!\n"; #2016jan14
    open (my $fh, "<", "input.txt") or AudInput(); # 2016jan28
    # print "Switching to human input because file not found... \n";
    # AudInput() } # 2016jan28: Human user must communicate by keyboard.
    # 2016jan28: end of measures to take if input.txt file not found.
    while (defined($char=getc $fh)) { # 2016jan12 P_B_Book p. 569
    $char = uc $char; # 2016jan26: from Perl Black Book, p. 341.
    AudBuffer(); #2016jan15: to manipulate inflections in OutBuffer()
    if ($char eq " ") { # 2016jan18: i.e., at the end of a word
    $onset = $audnew; # 2016jan18 set only at start of each word
    print "\nFileInput for audnew $audnew calling NewConcept \n"; # 2016jan18
    NewConcept(); # 2016jan17 test
    print "\n"; #2016jan18: new-line for diagnostic clarity
    }; # 2016jan13 Stop at end of word.
    $rv = $t; # 2016jan16: Capture auditory onset as recall-vector.
    $coda = $t; # 2016jan16: base-value before AudMem() increments
    if ($char ne " ") { # 2016jan14: Avoid storing blank characters.
    if ($audnew == 0) {$audnew = $t}; # 2016jan17 Set only once.
    print "F-Input calls AudMem for char $char audrun $audrun \n"; # 2016jan26
    $coda++ ; # 2016jan16: Increment word-coda with each stored $char.
    } # 2016jan14: End of test for a non-blank character.
    $t++; # 2016jan16: Increment time "t" here instead of AudMem()
    if ( $char =~ /[A-Z]/) { # 2016jan27: pattern binding operator
    print " char $char is an alphabetic letter \n"; # 2016jan27:
    $len++; # 2016jan27: increment length as per MindForth
    print " FileInput: increasing len(gth) to $len \n"; # 2016jan31
    AudMem(); # 2016jan27: Calling memory-insertion subroutine
    } else { # 2016jan27:
    print " char $char is not a letter \n" # 2016jan27:
    } # 2016jan27: Perl by Example, p. 222 (binding operator)
    } # 2016jan12 P_B_Book p. 569
    $audnew = 0; # 2016jan24: Reset $audnew for sake of next word.
    close ($fh); #2016jan10: P_by_Ex p. 301
    if ($audpsi > 0) { # 2016jan17: would be from AudRecog()
    print " FileInput() calls OldConcept() \n"; # 2016jan28
    OldConcept() } # 2016jan17:
    else { # 2016jan18: Expanding for diagnostic message.
    print "FileInput-else calling NewConcept"; # 2016jan18
    NewConcept()
    } ; # 2016jan17: as in MindForth AudInput module.
    $audrun = 1; # 2016jan26: for multiple calls to AudMem().
    } # http://mind.sourceforge.net/audition.html


    sub sensorium() { # http://mind.sourceforge.net/perl.html
    AudInput(); # 2015apr25: Calling the sense of audition.
    # FileInput(); # 2016jan10: Inputting from file, not keyboard.
    # GusRecog(); # http://mind.sourceforge.net/gusrecog.html
    # OlfRecog(); # http://mind.sourceforge.net/olfrecog.html
    # TacRecog(); # http://mind.sourceforge.net/tacrecog.html
    # VisRecog(); # 2015apr26: Opportunity to add vision.
    } # http://mind.sourceforge.net/sesorium.html


    # MindBoot: { # 2016jan23 Bootstrap prior to learning new words.
    sub MindBoot() { # 2016jan23 Bootstrap prior to learning new words.
    $t = 0; # 2015apr26: bootstrap stretches over time "$t".
    print "MindBoot is loading the knowledge base... \n"; #2016jan23
    $t = 0; $ear[$t] = " ,0,0"; # 2016jan27: Initialize row properly.
    $t = 1; $ear[$t] = "E,0,0"; # 2016jan28
    $t = 2; $ear[$t] = "R,0,0"; # 2016jan28
    $t = 3; $ear[$t] = "R,0,0"; # 2016jan28
    $t = 4; $ear[$t] = "O,0,0"; # 2016jan28
    $t = 5; $ear[$t] = "R,0,586"; # 2016jan28
    $psi=586; $hlc="en"; $pos=5; $num=1; $mfn=3; $rv=1; KbLoad(); # 2016jan22
    $t = 6; $ear[$t] = " ,0,0"; # 2016jan28: Initialize row properly.
    $t = 7; $ear[$t] = "A,0,101"; # 2016jan28
    $psi=101; $hlc="en"; $pos=1; $num=1; $mfn=0; $rv=7; KbLoad(); # 2016jan22
    $t = 9; $ear[$t] = "A,0,0"; # 2016jan28
    $t = 10; $ear[$t] = "L,0,0"; # 2016jan28
    $t = 11; $ear[$t] = "L,0,123"; # 2016jan28
    $psi=123; $hlc="en"; $pos=1; $num=0; $mfn=0; $rv=9; KbLoad(); # 2016jan23
    $t = 13; $ear[$t] = "B,0,0"; # 2016jan28 TEMPORARY
    $t = 14; $ear[$t] = "O,0,0"; # 2016jan28 TEMPORARY
    $t = 15; $ear[$t] = "Y,0,589"; # 2016jan28
    $psi=589; $hlc="en"; $pos=5; $num=1; $mfn=1; $rv=13; KbLoad(); # 2016jan24
    $t = 16; # 2016jan31: Leave a gap of one space in memory.
    $nxt = 900; # 2016jan22: Value based on MindForth AI.
    }; # http://mind.sourceforge.net/enboot.html


    # 2015may28 Requirements of Speech mind-module:
    # Speech module shall output a single word starting at given @aud point.
    # Outputted word shall be fed internally into the ReEntry module.
    # Inflected nouns and verbs shall be spoken from NounGen or VerbGen.
    sub speech() {
    if ($age > $cns) { die "TERMINATING: memory full \n"; } # 2016jan28
    my $detour;
    $t2s = $audrv; # Start from the auditory recall-vector $audrv
    print "\npho act audpsi spoken from auditory memory. \n"; # columns
    do { # PERL by Example (2015), p. 194: do/until Loops
    @main::engram = (); # 2015may15
    @main::engram = $ear[$t2s]; # 2016jan28: @ear is new array-name.
    $detour = reverse @main::engram;
    print chop($detour); # 2015may15
    $t2s++ ; # Increment time-to-speech to advance thru memory.
    my @aud=split(',',$ear[$t2s]); # 2016jan28: expose @ear values
    if ($aud[0] eq " ") { # 2016jan28: if no character is found
    print "\nSpeech: blank space found at $t2s\n"; # 2015may15
    $audrv = $t2s; # 2015may13: Prepare for next word in memory.
    return; # 2015may13: Exit at end of a word
    }; # 2015may13: End of if-clause
    } until $t2s eq $cns; # Show the whole array of AI Mind memory.
    } # http://mind.sourceforge.net/speech.html


    sub EnThink() { # Start showing output as if generated by thinking.
    print "\nEnThink: Calling speech() \n"; # Display new-line before "Think: "
    speech(); # Calling the speech() module as if to say a thought
    } # http://mind.sourceforge.net/think.html


    MainLoop: { # 2016jan25: for inclusion of TabulaRasa() & MindBoot()
    TabulaRasa(); # 2016jan25: one-time call as in MindForth AI.
    MindBoot(); # 2016jan25: one-time call as in MindForth AI.
    while ($t < $cns) { # 2015may02: Until CNS memory is full.
    $age = $age + 1; # 2015apr26
    print "\nMain loop cycle ", $age, " \n"; # 2015may02
    sensorium(); # PERL by Example p. 350: () empty parameter list
    if ($hlc eq "en") { # 2016jan24: check human-language-code $hlc
    EnThink(); # 2016jan24: Chosen over German DeThink, Russian RuThink
    } # 2016jan24: End of test to select a human language to think in.
    if ($age eq 999) { die "Perlmind dies when time = $t \n" }; # 2015may02
    # if ($t > 30) { # 2015may10: Wait until near the time limit of 32.
    if ($t > 47) { # 2016jan30: Wait until near the CNS-size time limit
    print "\nMainLoop shows psy array and ear array.\n"; # 2016jan28
    print "time psi act hlc pos jux pre tkb seq "; # 2016jan21
    print "num mfn dba rv pho act audpsi \n"; # 2016jan21
    # AudDamp(); # 2016feb03: TEST; REMOVE
    do { # 2016jan28: Show @ear array line-by-line.
    print "t=$krt. psi=$psy[$krt], "; # 2016jan21: No need to split @psy?
    print " aud= $ear[$krt], \n"; # 2016jan28: No need to split @psy?
    $krt++; # 2016jan30: increment $krt knowledge representation time.
    } while ($krt < 48); # 2016jan28: show @ear array at all time-points
    }; # 2015may10: outer braces of if-clause
    } # http://code.google.com/p/mindforth/wiki/MainLoop
    } # 2016jan25: End of MainLoop as an entity.

    our $birth = localtime($^T); #2015apr26: PERL Black Book p. 444
    print "End of ghost065.pl running since $birth\n"; #2016jan22

    # http://perl6.org main resource for Strong AI Perl6 Killer App.
    # http://irclog.perlgeek.de/perl6/2016-02-06 Internet Relay Chat
    # http://ai.neocities.org/perlmind.txt rename as ghost065.pl etc.

    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)