mind0032.pl Strong AI Perl6 Killer App

23 views
Skip to first unread message

menti...@gmail.com

unread,
Jan 13, 2016, 8:50:06 AM1/13/16
to
#!/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
# mind0032.pl being coded on Wed.13.JAN.2016 or later.
our $_ = " "; # 2016jan10: hidden variable; P_by_Ex p. 301
our $act = 8; # 2015may10: quasi-neuronal activation-level
our $age = 0; # 2015apr26 Temporary age for loop-counting.
our $audpsi = 586; # 2015may13: concept number of word "ERROR"
our $audrv = 0; # 2015may13: auditory recall-vector for speech()
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 $engram = " ";
our $krt = 0; # 2015may10: knowledge representation time
our $msg = " "; # 2015may01: $msg is for "message" of input.
our $nen = 0; # 2015may15: English lexical concept number
our $panel = " "; # 2015may17: explicit package from @panel array
our $pho = ""; # $pho is for a "phoneme" or character of input.
our $pov = 35; # 2015jun04: point-of-view: #35 internal; *42 external
our $t = 0; # 2015may02: Lifetime experiential time "$t"
our $t2s = 0; # 2015apr26: auditory text-to-speech index
our @aud = " "; # 2015may02: auditory memory array
our @en = " "; # 2015apr25: English lexical array
our @psi = " "; # 2015apr25: psi conceptual array
sub AudInput; # 2015apr25 PbEx5e p. 351: Forward declaration.
sub AudMem; # 2015apr25 PbEx5e p. 351: Forward declaration.
sub emotion; # 2015apr25 PbEx5e p. 351: Forward declaration.
sub EnVocab; # 2015jun01 PbEx5e p. 351: Forward declaration.
sub FileInput; # 2016jan10 PbEx5e p. 351: Forward declaration.
sub motorium; # 2015apr25 PbEx5e p. 351: Forward declaration.
sub NewConcept; # 2015may28 PbEx5e p. 351: Forward declaration.
sub sensorium; # 2015apr24 PbEx5e p. 351: Forward declaration.
sub think; # 2015apr24 PbEx5e p. 351: Forward declaration.
sub VisRecog; # 2015apr26 PbEx5e p. 351: Forward declaration.
sub volition; # 2015apr24 PbEx5e p. 351: Forward declaration.

TabulaRasa: { # 2015may28: 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".
$psi[$trc] = 0; # 2015may28: Fill conceptual @psi with zeroes.
$en[$trc] = 0; # 2015may28: Fill lexical @en with zeroes.
$aud[$trc] = " "; # 2015may18: Fill CNS with space-32's.
$trc++; # 015apr26: Increment tabula-rasa-counter $trc.
} # End of loop filling auditory memory with blank engrams.
}; # End of TabulaRasa "clean slate" sequence.

EnBoot: { # 2015apr24 Bootstrap prior to learning new words.
$t = 0; # 2015apr26: bootstrap stretches over time "$t".
print "English bootstrap is loading... \n"; #2015apr24
$t = 0; $aud[$t] = " "; # 2015may13: blank to detect "beg(ining)".
$t = 1; $aud[$t] = "E, $act, $audpsi"; # 2015may13: flag-panel
$t = 2; $aud[$t] = "R, $act, $audpsi"; # 2015may13: flag-panel
$t = 3; $aud[$t] = "R, $act, $audpsi"; # 2015may13: flag-panel
$t = 4; $aud[$t] = "O, $act, $audpsi"; # 2015may13: flag-panel
$t = 5; $aud[$t] = "R, $act, $audpsi"; # 2015may13: flag-panel
$t = 6; $aud[$t] = " "; # 2015may18: blank to signify end of word.
$t = 7; # 2015may13: Time for storage of next word.
$audpsi++; # 2015may28: increment for any new concept.
$nen = 901; # 2015jun01: Value based on MindForth AI.
}; # http://mind.sourceforge.net/enboot.html

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
think(); # PERL by Example p. 350: () empty parameter list
if ($age eq 999) { die "Perlmind dies when time = $t \n" }; # 2015may02
if ($t > 30) { # 2015may10: Wait until near the time limit of 32.
print "Now showing psi-concept, English and auditory arrays \n"; # 2015jun01
do { # 2015may10: Show @aud array line-by-line.
my @panel=split(',',$aud[$krt]); # 2015may18 PbEx p. 115
if ($panel[0] ne " ") {print "t=$krt. psi=$psi[$krt], "}
if ($panel[0] ne " ") {print "nen=$en[$krt], "}
if ($panel[0] ne " ") {print "aud=$panel[0] $panel[1], $panel[2]\n"}
else {print "t=$krt. \n"}; # 2015may18 PbEx 185: if/else construct
$krt++; # increment $krt
} while ($krt < 31); # show @aud array at all time-points
}; # 2015may10: outer braces of if-clause
} # http://code.google.com/p/mindforth/wiki/MainLoop

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

sub AudInput() { #2015apr25
print "Enter a word of input, then press RETURN: "; # 2015may02
$msg = <STDIN>; # 2015may01: PERL by Example (2015), p. 50
print "AudInput: You entered the word: $msg"; # 2015may02
NewConcept(); # 2015may28: Create a concept in the @psi array.
AudMem(); # 2015jun01: Calling memory-insertion subroutine
} # http://mind.sourceforge.net/audition.html

sub FileInput() { #2016jan10
my $_ = " "; # 2016jan10: PERL by Example (2015), p. 301
print "PerlAI will open and read input.txt file \n"; # 2016jan10
open (my $fh, "<", "input.txt"); # 2016jan10: P_by_Ex p. 298
while (defined($char=getc $fh)) { # 2016jan12 P_B_Book p. 569
print $char; # 2016jan12 Perl_Black_Book p. 569
if ($char eq " ") { return }; # 2016jan13 Stop at end of word.
NewConcept(); # 2016jan13: Assign an @psi new concept number.
AudMem(); # 2016jan12: Calling memory-insertion subroutine
} # 2016jan12 P_B_Book p. 569
close ($fh); #2016jan10: P_by_Ex p. 301
} # http://mind.sourceforge.net/audition.html

sub AudMem() { # http://code.google.com/p/mindforth/wiki/AudMem
# chop($msg); # 2015may02: Remove new-line from end of word.
# my $reversed = reverse $msg; # 2015may02: PERL by Example (2015), p. 125
# print "Input word reversed is: $reversed"; # PERL by Example (2015), p. 125
# do { # 2015may01
# $pho = chop($reversed); # 2015may01
$pho = $char; # 2016jan12: $char comes from FileInput() getc
print "\nAudMem: Storing ", $pho, " at time = ", "$t"; #2015may02
$audpsi = $nen; # 2015jun01: Store new words with new concept numbers.
$aud[$t] = "$pho, $act, $audpsi"; # 2015may18: neuronal flag-panel
$t++ ; # 2015may01 Increment to advance thru memory.
# } until $pho eq ""; # 2015may01: Store the whole word.
# $t++ ; # 2015may02: Add one more time point for a blank engram.
print "\n"; # 2015may02: Show a new-line gap on-screen.
} # http://mind.sourceforge.net/audstm.html

# 2015may28 Requirements of NewConcept mind-module:
# NewConcept shall create a concept in @psi for each new word encountered.
# A flag-panel shall lodge associative tags with each new @psi concept.
sub NewConcept() { # http://mind.sourceforge.net/newcept.html
$audpsi++; # 2015may28: increment for each new concept.
$nen++; # 2015jun01: Increment for each new English word/concept.
$psi[$t] = "$nen"; # 2015jun01: Assign the newest concept number.
EnVocab(); # 2015jun01: To create an English vocabulary node.
EnParser(); # 2015jun04: In preparation to call InStantiate().
} # http://code.google.com/p/mindforth/wiki/NewConcept

# 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
$en[$t] = "$nen"; # 2015jun01: Concept number of new English word.
} # http://code.google.com/p/mindforth/wiki/EnVocab

# 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 "\nEnParser has been called by NewConcept \n"; # 2016jan10
} # http://code.google.com/p/mindforth/wiki/EnParser

sub think() { # Start showing output as if generated by thinking.
print "\nThink: 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

# 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() {
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 = $aud[$t2s]; # 2015may15
$detour = reverse @main::engram;
print chop($detour); # 2015may15
$t2s++ ; # Increment time-to-speech to advance thru memory.
if ($aud[$t2s] eq " ") { # 2015may13: No longer using Forth "ctu".
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

our $birth = localtime($^T); #2015apr26: PERL Black Book p. 444
print "End of mind.pl AI running since $birth\n"; #2016jan10
print "The AI requires an input.txt file in the same directory.\n";
print "input.txt line 1: boys play games line 2: john is boy\n";
# 2015apr26: Claim your bragging rights for oldest living AI Mind.

# http://perl6.org main resource for Strong AI Perl6 Killer App.
# http://irclog.perlgeek.de/perl6/2016-01-13 Internet Relay Chat
# http://ai.neocities.org/perlmind.txt rename as mind0032.pl etc.
# http://ai.neocities.org/P6AI_man.html -- Perl6 AI User Manual
# http://ai.neocities.org/PMPJ.html -- Perl Mind Programming Journal
# http://www.cpan.org/authors/id/M/ME/MENTIFEX/mind.txt
# 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.
Reply all
Reply to author
Forward
0 new messages