{"id":1711,"date":"2019-09-01T08:55:07","date_gmt":"2019-09-01T03:25:07","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1711"},"modified":"2019-09-01T08:55:07","modified_gmt":"2019-09-01T03:25:07","slug":"poetry-in-prolog-part-2","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/","title":{"rendered":"Poetry in Prolog: Part-2"},"content":{"rendered":"<p>In an <a href=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/04\/generating-poetry-in-prolog\/\" target=\"_blank\" rel=\"noopener\"><em><strong>earlier post<\/strong><\/em><\/a>, I showed how <em><strong>Prolog<\/strong><\/em> can be used to generate poetry, making use of my <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em>. I want to continue the discussion today by giving another example, this time based on the theme of sounds emitted by various animals and birds.<\/p>\n<p>As hinted in my previous articles, <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em> stands for <em><strong>&#8220;Intelligent Lexicon&#8221;<\/strong><\/em>. It is a fairly large repository (presently containing around 2.5 million entries) of English words and their related information. In this\u00a0<a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/02\/11\/onomatopoeia-palindrome-and-semordnilap\/\" target=\"_blank\" rel=\"noopener\"><em><strong>article<\/strong><\/em><\/a>, I showed how <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em> can help us in identifying interesting word patterns. That example was based on the <em><strong>Lisp<\/strong><\/em> implementation of <em><strong>iLexicon<\/strong><\/em>; subsequently I have also ported it to <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus prolog<\/strong><\/em><\/a>.<\/p>\n<p>In today&#8217;s article, I will walk you through a <em><strong>DCG (Definite Clause Grammar)<\/strong><\/em> that generates a poem referencing various sounds of animals and birds. In order to do this, it taps into the knowledgebase contained in <em><strong>iLexicon<\/strong><\/em> about various species (animals, birds, fish, insects, etc.) and the names of sounds emitted by them. For example,<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<ul>\n<li><span style=\"color: #0000ff;\">a &#8220;frog&#8221; &#8220;croaks&#8221;<\/span><\/li>\n<li><span style=\"color: #0000ff;\">a &#8220;donkey&#8221; &#8220;brays&#8221;<\/span><\/li>\n<li><span style=\"color: #0000ff;\">a &#8220;kangaroo&#8221; &#8220;chortles&#8221;<\/span><\/li>\n<li><span style=\"color: #0000ff;\">etc.<\/span><\/li>\n<\/ul>\n<p>The <em><strong>DCG<\/strong><\/em> attempts to build a poem by stringing together a few of these <em><strong>&lt;entity, sound&gt;<\/strong><\/em> combinations. Just to make the poem interesting, it optionally defines a starting <em><strong>catchphrase<\/strong><\/em> and an ending <em><strong>catchphrase<\/strong><\/em>.<\/p>\n<p>The following shows the setup and the <em><strong>DCG<\/strong><\/em>:<\/p>\n<figure id=\"attachment_1712\" aria-describedby=\"caption-attachment-1712\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"1712\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/code-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg\" data-orig-size=\"961,840\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567243038&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"The DCG Grammar\" data-image-description=\"&lt;p&gt;The DCG Grammar&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The DCG Grammar&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg\" class=\"wp-image-1712\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=650%2C568&#038;ssl=1\" alt=\"The DCG Grammar\" width=\"650\" height=\"568\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?w=961&amp;ssl=1 961w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=300%2C262&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code.jpg?resize=768%2C671&amp;ssl=1 768w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1712\" class=\"wp-caption-text\"><strong>The DCG Grammar<\/strong><\/figcaption><\/figure>\n<p>The generation logic is embodied in the following code (same as the one in the <a href=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/04\/generating-poetry-in-prolog\/\" target=\"_blank\" rel=\"noopener\"><em><strong>earlier article<\/strong><\/em><\/a>).<\/p>\n<figure id=\"attachment_1713\" aria-describedby=\"caption-attachment-1713\" style=\"width: 659px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1713\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/code-2-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg\" data-orig-size=\"659,570\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567243122&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Generation Logic\" data-image-description=\"&lt;p&gt;Generation Logic&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Generation Logic&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg\" class=\"size-full wp-image-1713\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg?resize=659%2C570&#038;ssl=1\" alt=\"Generation Logic\" width=\"659\" height=\"570\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg?w=659&amp;ssl=1 659w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/code-2.jpg?resize=300%2C259&amp;ssl=1 300w\" sizes=\"(max-width: 659px) 100vw, 659px\" \/><\/a><figcaption id=\"caption-attachment-1713\" class=\"wp-caption-text\"><strong>Generation Logic<\/strong><\/figcaption><\/figure>\n<p>As the first example, let us generate a few lines using only <em><strong>animal<\/strong><\/em> sounds:<\/p>\n<figure id=\"attachment_1714\" aria-describedby=\"caption-attachment-1714\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1714\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/animals\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg\" data-orig-size=\"662,155\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242478&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Poem with Animal Sounds\" data-image-description=\"&lt;p&gt;Poem with Animal Sounds&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Poem with Animal Sounds&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg\" class=\"wp-image-1714\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg?resize=650%2C152&#038;ssl=1\" alt=\"Poem with Animal Sounds\" width=\"650\" height=\"152\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg?w=662&amp;ssl=1 662w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals.jpg?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1714\" class=\"wp-caption-text\"><strong>Poem with Animal Sounds<\/strong><\/figcaption><\/figure>\n<p>While generating each line, an animal is selected at random from the KB and its corresponding sound is paired. In case an animal sound has multiple names, one of those is again selected at random.<\/p>\n<p>I did not bother to indent the lines to make the presentation attractive. Also, the <em><strong>&#8220;Yes&#8221;<\/strong><\/em> at the end is the value printed by the <em><strong>Prolog<\/strong><\/em> interpreter to indicate whether the predicate succeeded or failed; it is not part of the poem.<\/p>\n<p>What happens if we run the generator again? The result is likely to be different because of the randomness:<\/p>\n<figure id=\"attachment_1715\" aria-describedby=\"caption-attachment-1715\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1715\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/animals-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg\" data-orig-size=\"663,155\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242592&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Another Run\" data-image-description=\"&lt;p&gt;Another Run&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Run&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg\" class=\"wp-image-1715\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg?resize=650%2C152&#038;ssl=1\" alt=\"Another Run\" width=\"650\" height=\"152\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg?w=663&amp;ssl=1 663w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/animals-2.jpg?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1715\" class=\"wp-caption-text\"><strong>Another Run<\/strong><\/figcaption><\/figure>\n<p>Of course, we retain the first and last line without any change.<\/p>\n<p>For our second example, let us focus on birds:<\/p>\n<figure id=\"attachment_1716\" aria-describedby=\"caption-attachment-1716\" style=\"width: 599px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1716\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/birds\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg\" data-orig-size=\"599,156\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242706&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Poem with Bird Sounds\" data-image-description=\"&lt;p&gt;Poem with Bird Sounds&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Poem with Bird Sounds&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg\" class=\"size-full wp-image-1716\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg?resize=599%2C156&#038;ssl=1\" alt=\"Poem with Bird Sounds\" width=\"599\" height=\"156\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg?w=599&amp;ssl=1 599w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds.jpg?resize=300%2C78&amp;ssl=1 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/a><figcaption id=\"caption-attachment-1716\" class=\"wp-caption-text\"><strong>Poem with Bird Sounds<\/strong><\/figcaption><\/figure>\n<p>Here is another run:<\/p>\n<figure id=\"attachment_1717\" aria-describedby=\"caption-attachment-1717\" style=\"width: 603px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1717\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/birds-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg\" data-orig-size=\"603,156\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242760&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Another Poem\" data-image-description=\"&lt;p&gt;Another Poem&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Another Poem&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg\" class=\"size-full wp-image-1717\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg?resize=603%2C156&#038;ssl=1\" alt=\"Another Poem\" width=\"603\" height=\"156\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg?w=603&amp;ssl=1 603w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/birds-2.jpg?resize=300%2C78&amp;ssl=1 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><figcaption id=\"caption-attachment-1717\" class=\"wp-caption-text\"><strong>Another Poem<\/strong><\/figcaption><\/figure>\n<p><span style=\"font-size: 16px;\">Note again that the two results are different.\u00a0<\/span><\/p>\n<p>For the last example, let us choose between animal and bird randomly!<\/p>\n<figure id=\"attachment_1718\" aria-describedby=\"caption-attachment-1718\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1718\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/random\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg\" data-orig-size=\"667,156\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242847&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Animal and Bird Combination\" data-image-description=\"&lt;p&gt;Animal and Bird Combination&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Animal and Bird Combination&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg\" class=\"wp-image-1718\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg?resize=650%2C152&#038;ssl=1\" alt=\"Animal and Bird Combination\" width=\"650\" height=\"152\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg?w=667&amp;ssl=1 667w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random.jpg?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1718\" class=\"wp-caption-text\"><strong>Animal and Bird Combination<\/strong><\/figcaption><\/figure>\n<p>Let us try again:<\/p>\n<figure id=\"attachment_1719\" aria-describedby=\"caption-attachment-1719\" style=\"width: 667px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1719\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/01\/poetry-in-prolog-part-2\/random-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg\" data-orig-size=\"667,155\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1567242916&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"One More Random Example\" data-image-description=\"&lt;p&gt;One More Random Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;One More Random Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg\" class=\"size-full wp-image-1719\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg?resize=667%2C155&#038;ssl=1\" alt=\"One More Random Example\" width=\"667\" height=\"155\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg?w=667&amp;ssl=1 667w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/random-2.jpg?resize=300%2C70&amp;ssl=1 300w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/a><figcaption id=\"caption-attachment-1719\" class=\"wp-caption-text\"><strong>One More Random Example<\/strong><\/figcaption><\/figure>\n<p>Notice how the <em><strong>DCG<\/strong><\/em> rule <em><strong>&#8220;random_sound&#8221; \u00a0<\/strong><\/em>chooses between <em><strong>&#8220;animal_sound&#8221;<\/strong><\/em> and <em><strong>&#8220;bird_sound&#8221;<\/strong><\/em>.<\/p>\n<p>That was simple, wasn&#8217;t it? What makes this possible is the extensive information available in <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em> coupled with the succinct generation formalism of <em><strong>DCG<\/strong><\/em> in <em><strong>Prolog<\/strong><\/em>.<\/p>\n<p>Hope you liked this article. I will continue to share more interesting ideas in future articles. Have a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an earlier post, I showed how Prolog can be used to generate poetry, making use of my &#8220;iLexicon&#8221;. I want to continue the discussion today by giving another example, this time based on the theme of sounds emitted by various animals and birds. As hinted in my previous articles, &#8220;iLexicon&#8221; stands for &#8220;Intelligent Lexicon&#8221;. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[107,17,147],"tags":[130,173,148],"class_list":["post-1711","post","type-post","status-publish","format-standard","hentry","category-natural-language-processing","category-programming","category-prolog","tag-ilexicon","tag-poetry-generation","tag-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-rB","jetpack-related-posts":[{"id":1659,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/04\/generating-poetry-in-prolog\/","url_meta":{"origin":1711,"position":0},"title":"Generating Poetry in Prolog","author":"admin","date":"August 4, 2019","format":false,"excerpt":"In an earlier article, I showed how we can generate poetry (with limitations, of course!) using my iLangGen framework. That implementation (in Lisp) made use of iLexicon, a large dictionary of English words, which I have been building over the years. I subsequently ported iLexicon to Prolog and it now\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Generation Logic","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/Code3.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2366,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/03\/28\/implementing-ilexicon-using-litedb\/","url_meta":{"origin":1711,"position":1},"title":"Implementing iLexicon using LiteDB","author":"admin","date":"March 28, 2021","format":false,"excerpt":"iLexicon is an \"intelligent\" dictionary that can be used to build Natural Language applications. I have two implementations, one in Lisp and another in Prolog. Both implementations are memory-based, in order to speed up performance. I have written several articles referencing it, for example see this. \u00a0 LiteDB is a\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Sample Commands","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/03\/Session1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1757,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/10\/13\/conjugating-phrasal-verbs\/","url_meta":{"origin":1711,"position":2},"title":"Conjugating Phrasal Verbs","author":"admin","date":"October 13, 2019","format":false,"excerpt":"In the last article, I showed how to generate verb conjugations in the \"iLexicon\" system. Today, let us see how this idea can be extended to English \"phrasal verbs\". According to Wikipedia: \"a phrasal verb is a phrase such as turn down or ran into which combines two or three\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Conjugation of \"Turn on\"","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/10\/Example3.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1727,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/15\/exploring-word-patterns\/","url_meta":{"origin":1711,"position":3},"title":"Exploring Word Patterns","author":"admin","date":"September 15, 2019","format":false,"excerpt":"Working with word patterns can be an exciting (and challenging) creative activity. Such patterns come into picture while playing word games, solving word puzzles or even writing poetry. It is precisely to facilitate such tasks that I am building my \"iLexicon\" system.\u00a0 One popular word game goes like this: The\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Prolog Predicates for Word Pair Generation","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/Code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/Code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/Code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1889,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/02\/16\/automatically-converting-active-voice-to-passive-voice-and-vice-versa\/","url_meta":{"origin":1711,"position":4},"title":"Automatically Converting Active Voice to Passive Voice and Vice Versa","author":"admin","date":"February 16, 2020","format":false,"excerpt":"The iLexicon system can handle active\/passive voice conversion of fairly complex English sentences. I gave examples of the underlying verb conjugation mechanism in this article\u00a0and this one. Today, I am going to give examples of the conversion of complete sentences. Here is an example of active to passive voice conversion:\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"The Core Conversion Logic","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/02\/Code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/02\/Code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/02\/Code.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/02\/Code.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1741,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/09\/29\/generating-verb-conjugations\/","url_meta":{"origin":1711,"position":5},"title":"Generating Verb Conjugations","author":"admin","date":"September 29, 2019","format":false,"excerpt":"We have been taught in school that English language has different \u201ctense\u201d forms. To help you quickly recollect, I am listing them in the table below (the verb 'sleep' is used as example): No. Tense Form Example Sentence (3rd Person Singular Pronoun) 1 Simple Present She sleeps 2 Simple Past\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Full Conjugation - Example3","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/09\/example3.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=1711"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1711\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}