[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

mind0057.pl Strong AI Perl6 Killer App needs porting into Lisp

mentificium

2/2/2016 2:14:00 AM

#!/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
# mind0057.pl being coded on Mon.01.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; # 2016jan22: next-word replacement for EnBoot "nen"
our $oldpsi = 0; # 2016jan30: used in OldConcept to de-globalize "psi"
our $onset = 0; # 2016jan16: onset-tag for use as recall-vector.
our $penult = 0; # 2016jan17: penultimate for going back one unit.
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 $tpo = 0; # 2016jan26: time-plus-one for AudRecog() next $char
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 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...
# 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/en...
$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/wi...


sub InStantiate() { # http://mind.sourceforge.net/ins...
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/I...


# 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/p...
$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/wik...


sub OldConcept() { # http://mind.sourceforge.net/ol...
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/...


# 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/ne...
$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.
if ($len > 0) { # 2016jan30: do not count spurious new concepts
$nxt++; # 2016jan22: Increment for each new human word/concept.
} # 2016jan30: wnd of test for new concepts with positive length.
} # 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/o...
# 2016jan22: NOTHING = default answer for "What do you see?"
} # http://code.google.com/p/mindforth/wik...


sub AudRecog() { # http://code.google.com/p/mindforth/wik...
print " AudR pho= $pho spt= $spt penult= $penult audrun= $audrun\n"; # 2016jan26
$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++) { # 2016jan25: searching forwards
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;
print " AudR: MATCH pho $pho i= $i penult= $penult audrun= $audrun\n"; # 2016jan26
if ($penult eq "0") { # 2016jan27: "if beg=1 on matching no-act aud engram"
print " MATCH OF BEG(INNING) ZERO-ACT aud0 \n"; # 2016jan25
if ($audrun < 2) { # 2016jan27: "if comparing start of a word"
$tpo = $i + 1; # 2016jan26: creating time-plus-one $tpo
print " AudR: tpo= $tpo prc= $prc monopsi= $monopsi \n"; # 2016jan31
my @nxr=split(',',$ear[($i+1)]); # 2016jan28: for next-in-line char
if ($nxr[0] =~ /[A-Z]/) { # 2016jan27: pattern binding operator
$aud[$i+1] = "$nxr[0], 8, $nxr[2]"; # "activate N-I-L character"
print "AUDRECOG MODULE: 1 past i $i activating pho $pho \n"; #2016jan30 TEST
$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
$prc = "$aud[2]"; # 2016jan31: provisional recognition
print " AudR: ear# $i prc = $prc \n"; # 2016jan31
} else { # 2016jan27: end of test for provisional recog.
if ($len == 1) { # 2016jan27: length from input module
$monopsi = $prc; # 2016jan27: for a single-character word
print " AudR: setting monopsi $monopsi \n"; # 2016jan27
} # 2016jan27: end of test for single-character length
} # 2016jan27: end of length-test to detect a monopsi
} # 2016jan27: Mindforth "end of test for audrun=1 start of word"
$penult = 1; # 2016jan30: zero only at start of a word-engram
print " 0-ACT MATCH audrun= $audrun penult= $penult \n"; # 2016jan30
} # 2016jan24: "end of test for a beg(inning) non-active aud0"
} # 2016jan27: "end of test for matching aud0 with no activation"
print " AudR: i= row# $i audrun= $audrun aud2= $aud[2]\n"; # 2016jan31 test;
$audrec = $aud[2]; # 2016jan30: because len>2 TEST; REMOVE
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] > $audbase) { # 2016jan28: "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."
print " AUDRECOG: actbase $actbase audrec $audrec \n"; #2016jan30 TEST
$audrec = 0; # 2016jan27: no word has been recognized
if ($monopsi > 0) { # 2016jan27
$audrec = $monopsi; # 2016jan27: recognizing one-letter word
$monopsi = 0; # 2016jan27: reset for safety after transfer.
} # 2016jan27: end of test for a word of only one letter.
} # 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'."
} # 2016jan23: End of backwards 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:
print " AudRecog MODULE: psibase $psibase audrec $audrec \n"; #2016jan31 test
if ($audrec > 0) { # 2016jan27:
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:
$morphpsi = $subpsi; # 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/w...
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.
print " AudM t $t of pho $pho audpsi $audpsi or nxt $nxt len= $len \n"; #2016jan31
if ($audpsi == 0) { # 2016jan31: if no news from AudRecog()
$ear[$t] = "$pho, $act, $nxt"; # 2016jan31: provisional $nxt
} else { # 2016jan31: if there is indeed an audpsi value...
print " AudMem: nxt= $nxt but storing audpsi $audpsi \n"; # 2016jan31
$ear[$t] = "$pho, $act, $audpsi"; # 2016jan31: recognized word
} # 2016jan31: end of test
if ($len > 1) { # 2016jan31: chance to change audpsi retroactively?
print " AudMem: wordlength $len is longer than 1 char \n"; # 2016jan31
if ($audpsi == 0) { # 2016jan31: if no audpsi yet
$ear[$t] = "$pho, $act, $nxt"; # 2016jan31: provisional $nxt
} # 2016jan31:
print " AudMem: ear at t $t = $ear[$t] \n"; # 2016jan31 TEST
} # 2016jan31:
if ($len > 1) { # 2016jan31: chance to change audpsi retroactively
if ($audpsi == 0) { # 2016jan31: presence of $audpsi does not matter
print " AudMem: ear at t-1 = $ear[$t-1] \n"; # 2016jan31 TEST
my @nxr=split(',',$ear[($t-1)]); # 2016jan31: for last memory slot
if ($nxr[0] ne " ") { # 2016jan31: erase tag only after a letter
print " AudMem at t-1 erases tag $nxr[2] of $nxr[0] \n"; # 2016jan31
$ear[$t-1] = "$nxr[0], $nxr[1], 0"; # 2016jan31: erase $nxt
} else { # 2016jan31: if not yet an audpsi
my @nxr=split(',',$ear[($t-1)]); # 2016jan31: for last memory slot
$ear[$t-1] = "$nxr[0], $nxr[1], 0"; # 2016jan31: insert tag
} # 2016jan31: end of else-clause
print " AudMem: ear at t $t = $ear[$t] \n"; # 2016jan31 TEST
} # 2016jan31: end of test for an audpsi...
} # 2016jan31: end of test for a word long enough for retroactivity
if ($pho eq " " && $audpsi == 0) { # 2016jan30:
my @nxr=split(',',$ear[($t-1)]); # 2016jan30: for last memory slot
if ($nxr[0] =~ /[A-Z]/) { # 2016jan30: if previous engram is char
print " AudMem: audpsi= $audpsi storing nxt $nxt \n"; # 2016jan31
$ear[$t-1] = "$nxr[0], $nxr[1], $nxt"; # 2016jan30: new concept
} # 2016jan30: end of test only for spaces after alphabetical letter
} # 2016jan30: end of retroactive insertion of $nxt new-concept.
if ($pho ne " ") { # 2016jan16: 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 eq " ") { # 2016jan27
$spt = $t; # 2016jan27
$ear[$t] = "$pho, 0, 0"; # 2016jan28: initialize @ear panel-flags.
} # 2016jan23: Establish end of word.
print " AudMem: audrec'd audpsi = $audpsi prc= $prc monopsi= $monopsi\n"; #2016jan31
} # http://mind.sourceforge.net/a...


sub AudInput() { # 2015apr25
$spt = $t; # 2016jan28: as in FileInput() module.
my $_ = " "; # 2016jan28: as in FileInput() module; PbEx 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 { # 2016feb01: aiming for input of a whole sentence
do { # PERL by Example (2015), p. 194: do/until Loops
$pho = chop($reversed); # 2016jan29 returns chopped character as $pho.
print "$pho"; # 2016feb01: 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(); # 2016han30: ...as a message that word has ended
} # 2016jan30: End of else-clause.
# else { # 2016jan29:
} until $pho eq " "; # 2016jan30: Store whole word until $pho is empty.
$len = 0; # 2016jan31: when pho=0 length reverts to zero.
} until $eot == 1; # 2016feb01: a condition set within inner loop.
print "Robot: (AI does not yet think) \n"; # 2016jan29: as if Transcript
if ($audpsi > 0) { # 2016jan30: would be from AudRecog()
$oldpsi = $audpsi; # 2016jan30: JSAI: for conformance with MindForth
print " AudInput() calls OldConcept() \n"; # 2016jan30
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
} # http://mind.sourceforge.net/aud...


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/aud...


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


# 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/e...


# 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/s...


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/...


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
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/wik...
} # 2016jan25: End of MainLoop as an entity.

our $birth = localtime($^T); #2015apr26: PERL Black Book p. 444
print "End of mind0057.pl running since $birth\n"; #2016jan22
print "The AI may need input.txt file in the same directory.\n";
print "input.txt Line 1: boys play games Line 2: john is boy\n";

# http:/... main resource for Strong AI Perl6 Killer App.
# http://irclog.perlgeek.de/perl6/... Internet Relay Chat
# http://ai.neocities.org/pe... rename as mind0057.pl etc.
# http://ai.neocities.org/P6A... -- Perl6 AI User Manual
# http://ai.neocities.org... -- Perl Mind Programming Journal
# http://www.amazon.com/dp/... shows how the P6AI will think.
# http://www.nlg-wiki.org/systems/...
# http://www.nasa.gov/planet...

# 2015apr23 First upload of code while learning Perl.
# 2015apr24 sensorium() gets input; think() shows input.
# 2015apr24 think() shows engrams fetched from @aud array.
# 2015apr25 Saving mind0011.pl as stable; coding mind0012.pl
# 2015apr25 AudMem() stores AudInput() data in @aud array.
# 2015apr26 EnBoot: uses time $t instead of recall-vector $rv.
# 2015apr26 TabulaRasa: will both fill and reserve CNS memory.
# 2015may01 AudMem() stores and Think() displays whole words.
# 2015may02 Prototype Perlmind dies when CNS memory fills up.
# 2015may10 @aud array stores words with associative flag-panel.
# 2015may13 speech() module shows engrams until any blank space.
# 2015may15 speech() displays single words retrieved from @aud.
# 2015may16 Requirements for speech() module prepended as comments.
# 2015may17 Perl "split" function separates retrieval of aud-panel.
# 2015may18 Using if/else construct to print @aud array contents.
# 2015may28 Introducing rudimentary NewConcept called from AudInput.
# 2015jun01 EnVocab module stubbed in for control of English vocabulary.
# 2015jun04 EnParser() English Parser module stubbed in.
# 2016jan10 FileInput() replaces AudInput() to read input.txt file.
# 2016jan11 WHILE loop in FileInput() calls NewConcept() and AudMem().
# 2016jan12 FileInput() uses getc to send single characters to AudMem(0).
# 2016jan13 uses "return" to exit from FileInput() at end of first word.
# https://groups.google.c...!topic/comp.programming/_F4PTlvJy_8
# 2016jan14 FileInput() calls AudMem() to store multiple input.txt words.
# https://groups.google.c...!topic/comp.sys.super/XcaLu5p1_gU
# 2016jan15 stubs in AudBuffer(); resets module sequence as in MindForth.
# https://groups.google.c...!topic/comp.lang.forth/nzEsANtlBGk
# 2016jan18 EnVocab() and AudMem() use flag-panels simpler than MindForth.
# https://groups.google.c...!topic/sci.cognitive/sAGrJEg_wew
# 2016jan19 renames @psi as @psy array to avoid psi-variable conflict.
# 2016jan20 InStantiate() stores psi, act, pos, jux, pre, tkb, and seq.
# 2016jan21 merges @en English lexical array into @psy conceptual array.
# 2016jan22 stubs in KbLoad() and fleshes out start of EnBoot() sequence.
# 2016jan23 mind0043.pl stubs in AudRecog() but MindBoot() is too small.
# 2016jan24 mind0044 splits Think() into DeThink, EnThink and RuThink.
# 2016jan25 mind0045.pl has MainLoop call TabulaRasa() and MindBoot().
# 2016jan26 mind0046.pl uses "uc" function to convert input to uppercase.
# 2016jan27 mind0049.pl completes the undebugged coding of AudRecog().
# 2016jan28 mind0050.pl changes names; calls AudInput if file not found.
# 2016jan28 mind0051.pl begins update of AudInput on par with FileInput.
# 2016jan29 mind0052.pl feeds input $pho into AudMem() and AudRecog().
# 2016jan30 mind0053.pl recognizes and sends input word to OldConcept().
# 2016jan30 mind0054.pl has AudMem() store recognized or new concept.
# 2016jan31 mind0055.pl has AudRecog() recognize one-character words.
# 2016feb01 mind0056.pl detects end of auditory input but is messy.
# 2016feb01 mind0057.pl uses $eot for AudInput() to input a sentence.