{"id":2483,"date":"2021-07-18T10:24:43","date_gmt":"2021-07-18T04:54:43","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2483"},"modified":"2021-07-18T10:24:43","modified_gmt":"2021-07-18T04:54:43","slug":"sentence-negation","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/","title":{"rendered":"Sentence Negation"},"content":{"rendered":"<p>In the <a href=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/\" target=\"_blank\" rel=\"noopener\"><em><strong>last article<\/strong><\/em><\/a>, I talked about determining sentence types automatically. Another interesting task is to generate the <em><strong>&#8220;negation&#8221;<\/strong><\/em> of a given sentence.<\/p>\n<blockquote><p>Example-1:<\/p>\n<p style=\"padding-left: 40px;\">Sentence =&gt; &#8220;My teacher lives nearby&#8221;<\/p>\n<p style=\"padding-left: 40px;\">Negation =&gt; &#8220;My teacher does not live nearby&#8221;<\/p>\n<p>Example-2:<\/p>\n<p style=\"padding-left: 40px;\">Sentence =&gt; &#8220;She did not like that speech&#8221;<\/p>\n<p style=\"padding-left: 40px;\">Negation =&gt; &#8220;She liked that speech&#8221;<\/p>\n<\/blockquote>\n<p>I have implemented this idea using <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em> and a <em><strong>DCG<\/strong><\/em>-based parser for English Grammar in <em><strong>Sicstus Prolog<\/strong><\/em>.<\/p>\n<p>The parser first parses the given sentence and emits a <em><strong>&#8220;parse tree&#8221;<\/strong><\/em>. The sentence <em><strong>Negator<\/strong><\/em> then manipulates the parse tree and derives the negation of the given sentence.<\/p>\n<p>For example, the sentence <em><strong>&#8220;Jack teaches at Harvard&#8221;<\/strong><\/em> results in the following parse tree:<\/p>\n<figure id=\"attachment_2484\" aria-describedby=\"caption-attachment-2484\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2484\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/parsetree\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg\" data-orig-size=\"1022,82\" 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;1626518848&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=\"Parse Tree\" data-image-description=\"&lt;p&gt;Parse Tree&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Parse Tree&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg\" class=\"wp-image-2484\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg?resize=600%2C48&#038;ssl=1\" alt=\"Parse Tree\" width=\"600\" height=\"48\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg?resize=300%2C24&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg?resize=768%2C62&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree.jpg?w=1022&amp;ssl=1 1022w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-2484\" class=\"wp-caption-text\"><strong>Parse Tree<\/strong><\/figcaption><\/figure>\n<p>It can be visualized as follows:<\/p>\n<figure id=\"attachment_2485\" aria-describedby=\"caption-attachment-2485\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2485\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/parsetree2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg\" data-orig-size=\"1067,930\" 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;1626520571&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=\"Visualizing Parse Tree\" data-image-description=\"&lt;p&gt;Visualizing Parse Tree&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Visualizing Parse Tree&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2-1024x893.jpg\" class=\"wp-image-2485\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?resize=500%2C436&#038;ssl=1\" alt=\"Visualizing Parse Tree\" width=\"500\" height=\"436\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?resize=300%2C261&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?resize=1024%2C893&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?resize=768%2C669&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree2.jpg?w=1067&amp;ssl=1 1067w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2485\" class=\"wp-caption-text\"><strong>Visualizing Parse Tree<\/strong><\/figcaption><\/figure>\n<p>The sentence <em><strong>Negator<\/strong><\/em> applies various rules and patterns to detect the appropriate <em><strong>Verb<\/strong><\/em> and handle its negation.<\/p>\n<p>The top-level logic can be expressed thus:<\/p>\n<figure id=\"attachment_2486\" aria-describedby=\"caption-attachment-2486\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2486\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/code_toplevel\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg\" data-orig-size=\"770,412\" 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;1626531640&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=\"Top-Level Logic\" data-image-description=\"&lt;p&gt;Top-Level Logic&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Top-Level Logic&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg\" class=\"wp-image-2486\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg?resize=500%2C268&#038;ssl=1\" alt=\"Top-Level Logic\" width=\"500\" height=\"268\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg?resize=300%2C161&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg?resize=768%2C411&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_toplevel.jpg?w=770&amp;ssl=1 770w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2486\" class=\"wp-caption-text\"><strong>Top-Level Logic<\/strong><\/figcaption><\/figure>\n<p>The actual negation depends on the sentence type, for example is it<span class=\"Apple-converted-space\">\u00a0 <\/span><em><strong>&#8220;declarative&#8221;<\/strong><\/em> or <em><strong>&#8220;imperative&#8221;,<\/strong><\/em> and so on.<\/p>\n<p>A part of the core patterns that apply to <em><strong>&#8220;declarative&#8221;<\/strong><\/em> sentences is shown here:<\/p>\n<figure id=\"attachment_2487\" aria-describedby=\"caption-attachment-2487\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2487\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/code_decl\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg\" data-orig-size=\"931,898\" 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;1626531684&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=\"Handling Declarative Sentence\" data-image-description=\"&lt;p&gt;Handling Declarative Sentence&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Handling Declarative Sentence&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg\" class=\"wp-image-2487\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg?resize=500%2C482&#038;ssl=1\" alt=\"Handling Declarative Sentence\" width=\"500\" height=\"482\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg?resize=300%2C289&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg?resize=768%2C741&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_decl.jpg?w=931&amp;ssl=1 931w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2487\" class=\"wp-caption-text\"><strong>Handling Declarative Sentence<\/strong><\/figcaption><\/figure>\n<p>Similarly, <em><strong>&#8220;imperative&#8221;<\/strong><\/em> sentences are handled this way:<\/p>\n<figure id=\"attachment_2488\" aria-describedby=\"caption-attachment-2488\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2488\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/code_imp\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg\" data-orig-size=\"898,307\" 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;1626531569&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=\"Handling Imperative Sentence\" data-image-description=\"&lt;p&gt;Handling Imperative Sentence&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Handling Imperative Sentence&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg\" class=\"wp-image-2488\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg?resize=500%2C171&#038;ssl=1\" alt=\"Handling Imperative Sentence\" width=\"500\" height=\"171\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg?resize=300%2C103&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg?resize=768%2C263&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code_imp.jpg?w=898&amp;ssl=1 898w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2488\" class=\"wp-caption-text\"><strong>Handling Imperative Sentence<\/strong><\/figcaption><\/figure>\n<p>Here I have shown just a few of the possible patterns.<\/p>\n<p>Let us look at some actual outputs. First, some declarative sentences:<\/p>\n<figure id=\"attachment_2489\" aria-describedby=\"caption-attachment-2489\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2489\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/session1-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg\" data-orig-size=\"788,371\" 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;1626531110&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=\"Example Output\" data-image-description=\"&lt;p&gt;Example Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Example Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg\" class=\"wp-image-2489\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg?resize=500%2C235&#038;ssl=1\" alt=\"Example Output\" width=\"500\" height=\"235\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg?resize=300%2C141&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg?resize=768%2C362&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session1.jpg?w=788&amp;ssl=1 788w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2489\" class=\"wp-caption-text\"><strong>Example Output<\/strong><\/figcaption><\/figure>\n<p>What about sentences that contain negation?<\/p>\n<figure id=\"attachment_2490\" aria-describedby=\"caption-attachment-2490\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2490\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/session2-4\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg\" data-orig-size=\"659,254\" 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;1626531196&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=\"Handling Negative Sentences\" data-image-description=\"&lt;p&gt;Handling Negative Sentences&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Handling Negative Sentences&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg\" class=\"wp-image-2490\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg?resize=500%2C193&#038;ssl=1\" alt=\"Handling Negative Sentences\" width=\"500\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg?resize=300%2C116&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session2.jpg?w=659&amp;ssl=1 659w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2490\" class=\"wp-caption-text\"><em><strong>Handling Negative Sentences<\/strong><\/em><\/figcaption><\/figure>\n<p>Here are some examples of imperative sentences:<\/p>\n<figure id=\"attachment_2491\" aria-describedby=\"caption-attachment-2491\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2491\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/session3-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg\" data-orig-size=\"594,196\" 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;1626531327&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=\"Imperative Sentences\" data-image-description=\"&lt;p&gt;Imperative Sentences&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Imperative Sentences&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg\" class=\"wp-image-2491\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg?resize=500%2C165&#038;ssl=1\" alt=\"Imperative Sentences\" width=\"500\" height=\"165\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg?resize=300%2C99&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/Session3.jpg?w=594&amp;ssl=1 594w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2491\" class=\"wp-caption-text\"><strong>Imperative Sentences<\/strong><\/figcaption><\/figure>\n<p>Once we parse a sentence and obtain its <em><strong>&#8220;syntactic structure&#8221;<\/strong><\/em>, it is possible to analyze and manipulate the structure to suit our requirements.<\/p>\n<p>Have a great weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the last article, I talked about determining sentence types automatically. Another interesting task is to generate the &#8220;negation&#8221; of a given sentence. Example-1: Sentence =&gt; &#8220;My teacher lives nearby&#8221; Negation =&gt; &#8220;My teacher does not live nearby&#8221; Example-2: Sentence =&gt; &#8220;She did not like that speech&#8221; Negation =&gt; &#8220;She liked that speech&#8221; I have [&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":[101,287,151],"class_list":["post-2483","post","type-post","status-publish","format-standard","hentry","category-natural-language-processing","category-programming","category-prolog","tag-definite-clause-grammar","tag-sentence-negation","tag-sicstus-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-E3","jetpack-related-posts":[{"id":1843,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/12\/22\/distributed-computing-with-linda\/","url_meta":{"origin":2483,"position":0},"title":"Distributed Computing with Linda","author":"admin","date":"December 22, 2019","format":false,"excerpt":"Linda, originally proposed by Nicholas Carriero and David Gelernter, is a model of process communication using a small set of well-defined primitives, operating on a tuple space.\u00a0 Interestingly, Sicstus Prolog\u00a0comes with a library that implements Linda (both Server and Client).\u00a0 I played with it a little bit and really enjoyed\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"The Simple Client","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Simple-client-source.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":541,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/06\/04\/definite-clause-grammars-in-lisp-part-2\/","url_meta":{"origin":2483,"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":2832,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/06\/12\/definite-clause-grammars-in-lisp-part-4\/","url_meta":{"origin":2483,"position":2},"title":"Definite Clause Grammars in Lisp &#8211; Part 4","author":"admin","date":"June 12, 2022","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"DCG Using Defgrammar","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version-300x177.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version-300x177.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/06\/defgrammar-version-300x177.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2467,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/","url_meta":{"origin":2483,"position":3},"title":"Identifying Sentence Types Automatically","author":"admin","date":"July 4, 2021","format":false,"excerpt":"Sentences in English can be classified into the following common types: - Simple sentence (\"I am drinking coffee\") - Compound sentence (\"He came home with his school friend and they had an enjoyable evening\") - Complex sentence (\"Whenever my dog barks, I give him some biscuit\") - Imperative sentence (\"Please\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":"Top-level Predicates","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code-300x233.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1285,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/12\/09\/parsing-text-with-meaningclouds-text-analytics-api\/","url_meta":{"origin":2483,"position":4},"title":"Parsing Text with MeaningCloud&#8217;s Text Analytics API","author":"admin","date":"December 9, 2018","format":false,"excerpt":"There is wide-spread interest in Natural Language Processing (NLP) today, and there are several API services available to cater to this demand. See this article for a fairly detailed list of services. All of them support multiple languages, including English. Today, I am going to share my experience in working\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Get Words Function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/12\/Get-words.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":534,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/05\/22\/definite-clause-grammars-dcg-in-lisp\/","url_meta":{"origin":2483,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2483","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=2483"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2483\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}