{"id":2832,"date":"2022-06-12T09:29:15","date_gmt":"2022-06-12T03:59:15","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2832"},"modified":"2022-06-12T09:29:15","modified_gmt":"2022-06-12T03:59:15","slug":"definite-clause-grammars-in-lisp-part-4","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/","title":{"rendered":"Definite Clause Grammars in Lisp &#8211; Part 4"},"content":{"rendered":"<p>In a series of <a href=\"https:\/\/www.rangakrish.com\/index.php\/2017\/06\/23\/definite-clause-grammars-in-lisp-part-3\/\" target=\"_blank\" rel=\"noopener\"><em><strong>articles<\/strong><\/em><\/a>\u00a0written earlier, I had shown how it is possible to model <em><strong>Definite Clause Grammars<\/strong><\/em> (<em><strong>DCG<\/strong><\/em>) in <em><strong>LispWorks Lisp (Enterprise Edition)<\/strong><\/em>. We use <em><strong>defgrammar<\/strong><\/em>\u00a0in <em><strong>Common Prolog<\/strong><\/em> (available as part of <a href=\"http:\/\/www.lispworks.com\/products\/knowledgeworks.html\" target=\"_blank\" rel=\"noopener\"><em><strong>KnowledgeWorks<\/strong><\/em><\/a> package) to define our grammar rules.<\/p>\n<p>Here is a toy English grammar represented using <em><strong>defgrammar<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2833\" aria-describedby=\"caption-attachment-2833\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2833\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/defgrammar-version\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg\" data-orig-size=\"927,547\" 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;1654940651&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=\"DCG Using Defgrammar\" data-image-description=\"&lt;p&gt;DCG Using Defgrammar&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;DCG Using Defgrammar&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg\" class=\"wp-image-2833\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg?resize=600%2C354&#038;ssl=1\" alt=\"DCG Using Defgrammar\" width=\"600\" height=\"354\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg?resize=300%2C177&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg?resize=768%2C453&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version.jpg?w=927&amp;ssl=1 927w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2833\" class=\"wp-caption-text\"><strong>DCG Using Defgrammar<\/strong><\/figcaption><\/figure>\n<p>This corresponds to the following <em><strong>Prolog DCG<\/strong><\/em> grammar:<\/p>\n<figure id=\"attachment_2834\" aria-describedby=\"caption-attachment-2834\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2834\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/prolog-version\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg\" data-orig-size=\"799,276\" 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;1654940175&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=\"Corresponding Prolog DCG\" data-image-description=\"&lt;p&gt;Corresponding Prolog DCG&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Corresponding Prolog DCG&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg\" class=\"wp-image-2834\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg?resize=600%2C207&#038;ssl=1\" alt=\"Corresponding Prolog DCG\" width=\"600\" height=\"207\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg?resize=300%2C104&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg?resize=768%2C265&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version.jpg?w=799&amp;ssl=1 799w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2834\" class=\"wp-caption-text\"><strong>Corresponding Prolog DCG<\/strong><\/figcaption><\/figure>\n<p>You will notice that the <em><strong>Prolog<\/strong><\/em> syntax is less verbose and hence more expressive than the <em><strong>defgrammar<\/strong><\/em>\u00a0version (y<span class=\"Apple-converted-space\">ou can ignore the minor difference in the naming of non-terminal names).<\/span><\/p>\n<p>We need not lose heart because <em><strong>Lisp<\/strong><\/em> is a <em><strong>&#8220;programmable programming language&#8221;<\/strong><\/em>, and we can improve the existing syntax to suite our preference!<\/p>\n<p>Here is the <em><strong>improved<\/strong><\/em>\u00a0version of the same <em><strong>defgrammar<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2835\" aria-describedby=\"caption-attachment-2835\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2835\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/simplified-version\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg\" data-orig-size=\"341,401\" 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;1655017402&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=\"Simplified Defgrammar\" data-image-description=\"&lt;p&gt;Simplified Defgrammar&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Simplified Defgrammar&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg\" class=\"wp-image-2835\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg?resize=300%2C353&#038;ssl=1\" alt=\"Simplified Defgrammar\" width=\"300\" height=\"353\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg?resize=255%2C300&amp;ssl=1 255w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/simplified-version.jpg?w=341&amp;ssl=1 341w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-2835\" class=\"wp-caption-text\"><strong>Simplified Defgrammar<\/strong><\/figcaption><\/figure>\n<p>If you look at the grammar carefully, you will notice that it does not\u00a0<em><strong>explicitly<\/strong><\/em>\u00a0build the\u00a0<em><strong>parse tree<\/strong><\/em>, whereas the other two versions do! The tree building happens inside the generated <em><strong>defgrammar<\/strong><\/em>\u00a0code.<\/p>\n<p>So, what is the <em><strong>trick<\/strong><\/em>? The trick is that we write suitable <em><strong>macros<\/strong><\/em>\u00a0to convert our simpler syntax to the corresponding <em><strong>defgrammar<\/strong><\/em>\u00a0version:<\/p>\n<figure id=\"attachment_2837\" aria-describedby=\"caption-attachment-2837\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2837\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/code-20\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg\" data-orig-size=\"783,852\" 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;1654956224&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 Core Macros\" data-image-description=\"&lt;p&gt;The Core Macros&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Core Macros&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg\" class=\"wp-image-2837\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg?resize=600%2C653&#038;ssl=1\" alt=\"The Core Macros\" width=\"600\" height=\"653\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg?resize=276%2C300&amp;ssl=1 276w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg?resize=768%2C836&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/code.jpg?w=783&amp;ssl=1 783w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2837\" class=\"wp-caption-text\"><strong>The Core Macros<\/strong><\/figcaption><\/figure>\n<p>The above shows the core logic involved in the syntax transformation. The full source code is available <a href=\"http:\/\/www.rangakrish.com\/downloads\/Simple Defgrammar.lisp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>.<\/p>\n<p>Let us now check the grammar with some sample sentence fragments:<\/p>\n<figure id=\"attachment_2838\" aria-describedby=\"caption-attachment-2838\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2838\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/session-9\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg\" data-orig-size=\"1031,464\" 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;1654955941&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=\"Sample Session\" data-image-description=\"&lt;p&gt;Sample Session&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Session&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session-1024x461.jpg\" class=\"wp-image-2838\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?resize=600%2C270&#038;ssl=1\" alt=\"Sample Session\" width=\"600\" height=\"270\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?resize=300%2C135&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?resize=1024%2C461&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?resize=768%2C346&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/session.jpg?w=1031&amp;ssl=1 1031w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2838\" class=\"wp-caption-text\"><strong>Sample Session<\/strong><\/figcaption><\/figure>\n<p>Here is a sample session in <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus Prolog 4.7.0<\/strong><\/em><\/a> for the <em><strong>Prolog<\/strong> <\/em>DCG:<\/p>\n<figure id=\"attachment_2839\" aria-describedby=\"caption-attachment-2839\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2839\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/prolog-version2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg\" data-orig-size=\"710,216\" 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;1655018194&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=\"Sample Session &amp;#8211; Prolog\" data-image-description=\"&lt;p&gt;Sample Session &amp;#8211; Prolog&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Session &amp;#8211; Prolog&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg\" class=\"wp-image-2839\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg?resize=550%2C167&#038;ssl=1\" alt=\"Sample Session - Prolog\" width=\"550\" height=\"167\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg?resize=300%2C91&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/Prolog-version2.jpg?w=710&amp;ssl=1 710w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2839\" class=\"wp-caption-text\"><strong>Sample Session &#8211; Prolog<\/strong><\/figcaption><\/figure>\n<p>You can see that the outputs match.<\/p>\n<p>Here comes an important question: If I have to implement an <em><strong>NLP<\/strong><\/em> parser in <em><strong>DCG<\/strong><\/em>, is it better to do this in <em><strong>Prolog<\/strong><\/em> directly, or use <em><strong>defgrammar<\/strong><\/em> (perhaps using the tricks shown here) in <em><strong>Lisp<\/strong><\/em>?<\/p>\n<p>I guess the answer is not straightforward. If you are a <em><strong>Lisp<\/strong><\/em> programmer (using <em><strong>LispWorks<\/strong><\/em>) and you are not comfortable with <em><strong>Prolog<\/strong><\/em>, then <em><strong>defgrammar<\/strong><\/em> is probably the natural approach. The other advantage is that you can easily integrate this with other <em><strong>Lisp<\/strong><\/em> code, if needed. In my case, I would prefer using <em><strong>Prolog<\/strong><\/em> directly (especially <em><strong>Sicstus Prolog<\/strong><\/em>) since I can get better performance on large grammars.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>This article concludes the series on using <em><strong>DCG<\/strong><\/em> in <em><strong>Lisp<\/strong><\/em>. Hope you find this series useful.<\/p>\n<p>The <em><strong>Lisp<\/strong><\/em> source is available <a href=\"http:\/\/www.rangakrish.com\/downloads\/Simple Defgrammar.lisp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>\u00a0.<\/p>\n<p>Have a nice weekend!<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a series of articles\u00a0written earlier, I had shown how it is possible to model Definite Clause Grammars (DCG) in LispWorks Lisp (Enterprise Edition). We use defgrammar\u00a0in Common Prolog (available as part of KnowledgeWorks package) to define our grammar rules. Here is a toy English grammar represented using defgrammar: This corresponds to the following Prolog [&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_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},"jetpack_post_was_ever_published":false},"categories":[18,107,17,147],"tags":[100,101,19,148],"class_list":["post-2832","post","type-post","status-publish","format-standard","hentry","category-lisp","category-natural-language-processing","category-programming","category-prolog","tag-dcg","tag-definite-clause-grammar","tag-lisp","tag-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-JG","jetpack-related-posts":[{"id":534,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/05\/22\/definite-clause-grammars-dcg-in-lisp\/","url_meta":{"origin":2832,"position":0},"title":"Definite Clause Grammars (DCG) in Lisp","author":"admin","date":"May 22, 2017","format":false,"excerpt":"Definite Clause Grammars (DCG) are an elegant formalism for specifying context free grammars, and part of their popularity is due to their support in the Prolog language. Most books on Natural Language processing usually include a brief coverage of DCGs, even though Natural languages are not context-free. Because of the\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"DCG Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/05\/DCG-Grammar.png?resize=525%2C300 1.5x"},"classes":[]},{"id":541,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/06\/04\/definite-clause-grammars-in-lisp-part-2\/","url_meta":{"origin":2832,"position":1},"title":"Definite Clause Grammars in Lisp &#8211; Part 2","author":"admin","date":"June 4, 2017","format":false,"excerpt":"In the last post, I showed how we can implement DCGs in LispWorks using the KnowledgeWorks package. The grammar discussed in that post did not take into account subject\/predicate number agreement. This is one of the basic constraints in English grammar. Today I will show how easy it is to\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Prolog Grammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/06\/Prolog-Grammar.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":548,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/06\/23\/definite-clause-grammars-in-lisp-part-3\/","url_meta":{"origin":2832,"position":2},"title":"Definite Clause Grammars in Lisp &#8211; Part 3","author":"admin","date":"June 23, 2017","format":false,"excerpt":"In today's post, let us see how we can enhance the grammar representation discussed so far to include both Number constraint and Parse Tree. Fortunately, this turns out to be quite straightforward. Just as we do in Prolog, we need to include additional parameters, as needed, to each grammar rule.\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"POS Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/06\/POS-Function.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/06\/POS-Function.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/06\/POS-Function.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1659,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/04\/generating-poetry-in-prolog\/","url_meta":{"origin":2832,"position":3},"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":1817,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/12\/08\/using-definite-clause-grammars-dcg-for-information-extraction\/","url_meta":{"origin":2832,"position":4},"title":"Using Definite Clause Grammars (DCG) for Information Extraction","author":"admin","date":"December 8, 2019","format":false,"excerpt":"In the previous article, I showed how we can use ATNs for extracting key information from natural language text. I also pointed out in that article that Definite Clause Grammars (DCG) are a more compact formalism for doing this. That will be the focus of today's article. For a nice\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":"Processing the Text","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.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":2832,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2832","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=2832"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2832\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}