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 (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

The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
Andrew 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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Translating human language with computer grammar