SlideShare a Scribd company logo
1 of 37
Download to read offline
Translating
human language
 with computer
    grammar
German — English
__DATA__
Mein Name ist Andreas.
__DATA__
Mein Name ist Andreas. My name is Andrew.
my %dictionary = (
  Mein    => 'My',
  Name    => 'name',
  ist     => 'is',
  Andreas => 'Andrew',
);
my %dictionary = (
  Mein    => 'My',
  Name    => 'name',
  ist     => 'is',
  Andreas => 'Andrew',
);


$text =~ s{(w+)}{$dictionary{$1}}ge;
sub Mein    {return quot;My $_[0]quot;;    }
sub Name    {return quot;name $_[0]quot;;  }
sub ist     {return quot;is $_[0]quot;;    }
sub Andreas {return quot;Andrew $_[0]quot;;}
sub Mein    {return quot;My $_[0]quot;;    }
sub Name    {return quot;name $_[0]quot;;  }
sub ist     {return quot;is $_[0]quot;;    }
sub Andreas {return quot;Andrew $_[0]quot;;}


say eval $text;
sub translate {
  given ($_[0]) {
    when ('Der')      {return 'the'   }
    when ('Mein')     {return 'my'    }
    when ('Sein')     {return 'his'   }
    when ('Name')     {return 'name'  }
    when ('ist')      {return 'is'    }
    when ('Andreas')  {return 'Andrew'}
 }
}
Grammar
forefer

Grammar
sentence  : word(s) fullstop eofile
sentence  : word(s) fullstop eofile



word      : /w+/



fullstop  : '.' 



eofile    : /^Z/
sentence  : word(s) fullstop eofile



word      : /w+/ {
            print ::translate($item[1])
     }
fullstop  : '.' 



eofile    : /^Z/
my $text = <DATA>;


$parser = 
    new Parse::RecDescent ($grammar);


$parser‐>sentence($text);
sentence  : statement     eofile               
statement : subject verb object fullstop
subject   : adjective noun             
          | article noun                   
          | noun                       
object    : noun
noun      : 'Name'
           | 'Andreas'
adjective : 'Mein'
          | 'Sein'
verb      : 'ist'
article   : 'Die'
          | 'Der'
          | 'Das'
fullstop  : '.'
eofile    : /^Z/
Mein Name ist Andreas.
Sein Name ist Andreas.
Name ist Andreas.
Der Name ist Andreas.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas.
Name ist Andreas.
Der Name ist Andreas.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas. His name is Andrew.
Name ist Andreas.
Der Name ist Andreas.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas. His name is Andrew.
Name ist Andreas.      Name is Andrew.
Der Name ist Andreas.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas. His name is Andrew.
Name ist Andreas.      Name is Andrew.
Der Name ist Andreas.  The name is Andrew.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas. His name is Andrew.
Name ist Andreas.      Name is Andrew.
Der Name ist Andreas.  The name is Andrew.



Ich heiße Andreas.
Mein Name ist Andreas. My name is Andrew.
Sein Name ist Andreas. His name is Andrew.
Name ist Andreas.      Name is Andrew.
Der Name ist Andreas.  The name is Andrew.



Ich heiße Andreas.     I am called Andrew.
Perl 5
Perl 6
Ruby
         Parrot
Python
PHP
Java
C++
Perl 5
Perl 5
                  Perl 6
Perl 6
                  Ruby
Ruby
         Parrot   Python
Python
                  PHP
PHP
                  Java
Java
                  C++
C++
Mein Name ist Andreas.


$VAR1 = {
          'object'     => 'Andreas',
          'person'     => 3,
          'subject'    => 'Name',
          'possession' => 'Mein',
          'action'     => 'be'
        };
Ich heiße Andreas.


$VAR1 = {
          'subject'    => 'Andreas',
          'object'     => 'Andreas',
          'person'     => 1,
          'action'     => 'name'
        };
say ucfirst (

 
 ($::grammar{possession}
        ? translate($::grammar{possession}) . ' '
        : ''
     )
    . translate($::grammar{subject}) . ' ' 
    . conjugation(
         $::grammar{action},
         $::grammar{person}
       ) . ' '
     . translate($::grammar{object}) . '.' 
);
Mein Name ist Andreas.
Ich heiße Andreas.
Mein Name ist Andreas. My name is Andrew.
Ich heiße Andreas.
Mein Name ist Andreas. My name is Andrew.
Ich heiße Andreas.     I am Andrew.
640
pages!
__END__


Andrew Shitov

http://andy.sh

More Related Content

Viewers also liked

Calendariodereflexao
CalendariodereflexaoCalendariodereflexao
Calendariodereflexaoilnanetto
 
Trol
TrolTrol
TrolASB0
 
Bedeutung von Location-based Services wächst
Bedeutung von Location-based Services wächstBedeutung von Location-based Services wächst
Bedeutung von Location-based Services wächstTWT
 
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...Blog Forum Gdańsk
 
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012NPOサポートセンター
 
Mirage 03 www.mitsubishibekasi.com
Mirage 03 www.mitsubishibekasi.comMirage 03 www.mitsubishibekasi.com
Mirage 03 www.mitsubishibekasi.commitsubishibekasi
 
Tab multiplicar
Tab multiplicarTab multiplicar
Tab multiplicarAnita Ruiz
 
Diagrama arbol asociacion poblaciones sem 3
Diagrama arbol asociacion poblaciones sem 3Diagrama arbol asociacion poblaciones sem 3
Diagrama arbol asociacion poblaciones sem 3Silvia Delgado L
 
Proyecto pibes
Proyecto pibesProyecto pibes
Proyecto pibeskontenidos
 

Viewers also liked (20)

Ewrt 1 c class 23
Ewrt 1 c class 23Ewrt 1 c class 23
Ewrt 1 c class 23
 
Calendariodereflexao
CalendariodereflexaoCalendariodereflexao
Calendariodereflexao
 
09-Egovernment
09-Egovernment09-Egovernment
09-Egovernment
 
Trol
TrolTrol
Trol
 
Bedeutung von Location-based Services wächst
Bedeutung von Location-based Services wächstBedeutung von Location-based Services wächst
Bedeutung von Location-based Services wächst
 
Cuencas Hidrograficas
Cuencas HidrograficasCuencas Hidrograficas
Cuencas Hidrograficas
 
Preguntas
PreguntasPreguntas
Preguntas
 
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...
Blog Forum Gdańsk 2012 | Przetwarzać czy tworzyć? Konstruowanie treści w medi...
 
Ro 1237 metbac2014
Ro 1237 metbac2014Ro 1237 metbac2014
Ro 1237 metbac2014
 
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012
Nonprofit marketing program 2012 presentation07 blastbeat #npomap2012
 
2
22
2
 
Mirage 03 www.mitsubishibekasi.com
Mirage 03 www.mitsubishibekasi.comMirage 03 www.mitsubishibekasi.com
Mirage 03 www.mitsubishibekasi.com
 
Tab multiplicar
Tab multiplicarTab multiplicar
Tab multiplicar
 
Diagrama arbol asociacion poblaciones sem 3
Diagrama arbol asociacion poblaciones sem 3Diagrama arbol asociacion poblaciones sem 3
Diagrama arbol asociacion poblaciones sem 3
 
Proyecto pibes
Proyecto pibesProyecto pibes
Proyecto pibes
 
4
44
4
 
9
99
9
 
Scannen0012
Scannen0012Scannen0012
Scannen0012
 
Strauss
StraussStrauss
Strauss
 
Awesome
AwesomeAwesome
Awesome
 

More from Andrew Shitov

Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6Andrew Shitov
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Andrew Shitov
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Andrew Shitov
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingAndrew Shitov
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story ofAndrew Shitov
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовAndrew Shitov
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массивAndrew Shitov
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14Andrew Shitov
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14Andrew Shitov
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty itAndrew Shitov
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an arrayAndrew Shitov
 

More from Andrew Shitov (20)

Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6
 
AllPerlBooks.com
AllPerlBooks.comAllPerlBooks.com
AllPerlBooks.com
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
YAPC::Europe 2013
YAPC::Europe 2013YAPC::Europe 2013
YAPC::Europe 2013
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистов
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массив
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty it
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an array
 
Perl 5.10 и 5.12
Perl 5.10 и 5.12Perl 5.10 и 5.12
Perl 5.10 и 5.12
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Translating human language with computer grammar