{"id":2467,"date":"2021-07-04T20:19:47","date_gmt":"2021-07-04T14:49:47","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2467"},"modified":"2021-07-04T20:25:59","modified_gmt":"2021-07-04T14:55:59","slug":"identifying-sentence-types-automatically","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/","title":{"rendered":"Identifying Sentence Types Automatically"},"content":{"rendered":"<p>Sentences in <em><strong>English<\/strong><\/em> can be classified into the following common types:<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>Simple sentence<\/strong><\/em> (&#8220;I am drinking coffee&#8221;)<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>Compound sentence<\/strong><\/em> (&#8220;He came home with his school friend and they had an enjoyable evening&#8221;)<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>Complex sentence<\/strong><\/em> (&#8220;Whenever my dog barks, I give him some biscuit&#8221;)<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>Imperative sentence<\/strong><\/em> (&#8220;Please keep quiet&#8221;)<\/p>\n<p style=\"padding-left: 40px;\">&#8211; <em><strong>Interrogative sentence<\/strong><\/em> (&#8220;Where did I park my car?&#8221;)<\/p>\n<p>As you can see from the example sentences, there is a distinct grammatical structure for each of the above types. The question now is, how easy is it to identify the type, given a sentence? I guess it is not too hard (note that I am not saying it is easy!) for humans to identify the type. But my interest is in identifying the type programmatically.<\/p>\n<p>Before I get into the details, I would like to make a reference to an article I wrote over a year ago &#8211; <a href=\"https:\/\/www.rangakrish.com\/index.php\/2020\/02\/16\/automatically-converting-active-voice-to-passive-voice-and-vice-versa\/\" target=\"_blank\" rel=\"noopener\"><em><strong>&#8220;Automatically Converting Active Voice to Passive Voice and Vice Versa&#8221;<\/strong><\/em><\/a>. That and the idea that I am discussing today both use traditional parsing (defining the grammar and parsing using <em><strong>DCG<\/strong><\/em>) technique. I am not using any <em><strong>Machine Learning<\/strong><\/em> algorithms in my implementation. I like this approach because I can learn so much in the process. Helping me here is <em><strong>&#8220;iLexicon&#8221;<\/strong><\/em>, a fairly comprehensive lexicon I have built over the years. It provides the parser with<span class=\"Apple-converted-space\">\u00a0<\/span><em><strong>Part of speech<\/strong><\/em> information as well as the other constraints required for detecting valid <em><strong>English<\/strong><\/em> sentences.<\/p>\n<p>The top-level logic is contained in the following predicates:<\/p>\n<figure id=\"attachment_2468\" aria-describedby=\"caption-attachment-2468\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2468\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/code-16\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg\" data-orig-size=\"915,712\" 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;1625236460&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 Predicates\" data-image-description=\"&lt;p&gt;Top-level Predicates&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Top-level Predicates&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg\" class=\"wp-image-2468\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg?resize=500%2C389&#038;ssl=1\" alt=\"Top-level Predicates\" width=\"500\" height=\"389\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg?resize=300%2C233&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg?resize=768%2C598&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code.jpg?w=915&amp;ssl=1 915w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2468\" class=\"wp-caption-text\"><strong>Top-level Predicates<\/strong><\/figcaption><\/figure>\n<p>The predicate <em><strong>&#8220;sentence_type(Sentence)&#8221;<\/strong><\/em> takes a sentence as input and prints the type of the sentence. To make the idea even more interesting, I am allowing the possibility of detecting the type of sentence fragments as well. This is handled by the predicate <em><strong>&#8220;sentence_part(SentencePart)&#8221;<\/strong><\/em>. This will be clear when you see some examples later.<\/p>\n<p>The finer details of mapping a valid parsed syntactic structure into the corresponding type is handled by a few auxiliary predicates:<\/p>\n<figure id=\"attachment_2469\" aria-describedby=\"caption-attachment-2469\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2469\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/code2-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg\" data-orig-size=\"896,839\" 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;1625236509&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=\"Helper Predicates\" data-image-description=\"&lt;p&gt;Helper Predicates&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Helper Predicates&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg\" class=\"wp-image-2469\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg?resize=500%2C468&#038;ssl=1\" alt=\"Helper Predicates\" width=\"500\" height=\"468\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg?resize=300%2C281&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg?resize=768%2C719&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/code2.jpg?w=896&amp;ssl=1 896w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2469\" class=\"wp-caption-text\"><strong>Helper Predicates<\/strong><\/figcaption><\/figure>\n<p>The extreme case of a <strong><em>&#8220;sentence fragment&#8221;<\/em><\/strong> being just a single word is also taken into account. In this case, the predicate will print its possible <em><strong>parts of speech<\/strong><\/em>.<\/p>\n<p>You can see from the above listing, what sentence types, sentence fragments and parts of speech are supported.<\/p>\n<p>Let us take a look at some actual outputs. The first is categorization of complete sentences.<\/p>\n<figure id=\"attachment_2470\" aria-describedby=\"caption-attachment-2470\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2470\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/sentence\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg\" data-orig-size=\"1033,309\" 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;1625237096&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=\"Categorizing Complete Sentences\" data-image-description=\"&lt;p&gt;Categorizing Complete Sentences&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Categorizing Complete Sentences&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence-1024x306.jpg\" class=\"wp-image-2470\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?resize=550%2C165&#038;ssl=1\" alt=\"Categorizing Complete Sentences\" width=\"550\" height=\"165\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?resize=300%2C90&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?resize=1024%2C306&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?resize=768%2C230&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/sentence.jpg?w=1033&amp;ssl=1 1033w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2470\" class=\"wp-caption-text\"><strong>Categorizing Complete Sentences<\/strong><\/figcaption><\/figure>\n<p>Although both <em><strong>&#8220;compound&#8221;<\/strong><\/em> and <em><strong>&#8220;complex&#8221;<\/strong><\/em> sentences contain more than one verb, a <em><strong>compound sentence<\/strong><\/em> may be thought of as having <em><strong>two independent sentences\/clauses<\/strong><\/em>, whereas a <em><strong>complex sentence<\/strong><\/em> has a <em><strong>main clause<\/strong><\/em> and a <em><strong>dependent clause<\/strong><\/em>. The program has correctly identified the types. What is missing in the above is <em><strong>&#8220;Interrogative&#8221;<\/strong><\/em> type. The following shows that the program is able to detect different interrogative sentences:<\/p>\n<figure id=\"attachment_2471\" aria-describedby=\"caption-attachment-2471\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2471\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/interrogative\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg\" data-orig-size=\"718,255\" 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;1625236584&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=\"Detecting Interrogative Sentences\" data-image-description=\"&lt;p&gt;Detecting Interrogative Sentences&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Detecting Interrogative Sentences&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg\" class=\"wp-image-2471\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg?resize=500%2C178&#038;ssl=1\" alt=\"Detecting Interrogative Sentences\" width=\"500\" height=\"178\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg?resize=300%2C107&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg?resize=675%2C240&amp;ssl=1 675w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/interrogative.jpg?w=718&amp;ssl=1 718w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2471\" class=\"wp-caption-text\"><strong>Detecting Interrogative Sentences<\/strong><\/figcaption><\/figure>\n<p>Note that not all interrogations involve <em><strong>&#8220;WH&#8221;<\/strong><\/em> type (see my earlier article on <a href=\"https:\/\/www.rangakrish.com\/index.php\/2021\/05\/23\/the-structure-of-wh-questions\/\" target=\"_blank\" rel=\"noopener\"><em><strong>WH-Questions<\/strong><\/em><\/a>). An interrogative sentence can start with words such as <em><strong>&#8220;Can&#8221;, &#8220;Are&#8221;, &#8220;May&#8221;, &#8220;Would&#8221;<\/strong><\/em>, etc. I am not showing the other cases, for want of space.<\/p>\n<p>The next set of examples pertain to sentence <em><strong>fragments<\/strong><\/em>: <em><strong>phrases<\/strong><\/em> and <em><strong>clauses<\/strong><\/em>.<\/p>\n<figure id=\"attachment_2472\" aria-describedby=\"caption-attachment-2472\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2472\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/phrase\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg\" data-orig-size=\"926,410\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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=\"Phrases\/Clauses\" data-image-description=\"&lt;p&gt;Phrases\/Clauses&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Phrases\/Clauses&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg\" class=\"wp-image-2472\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?resize=550%2C244&#038;ssl=1\" alt=\"Phrases\/Clauses\" width=\"550\" height=\"244\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?resize=300%2C133&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?resize=768%2C340&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?resize=680%2C300&amp;ssl=1 680w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/phrase.jpg?w=926&amp;ssl=1 926w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2472\" class=\"wp-caption-text\"><strong>Phrases\/Clauses<\/strong><\/figcaption><\/figure>\n<p>What about <em><strong>single words<\/strong><\/em>? The program can handle that as well:<\/p>\n<figure id=\"attachment_2474\" aria-describedby=\"caption-attachment-2474\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2474\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/04\/identifying-sentence-types-automatically\/pos\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg\" data-orig-size=\"676,138\" 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;1625236735&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 Single Words\" data-image-description=\"&lt;p&gt;Handling Single Words&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Handling Single Words&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg\" class=\"wp-image-2474\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg?resize=500%2C102&#038;ssl=1\" alt=\"Handling Single Words\" width=\"500\" height=\"102\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg?resize=300%2C61&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/POS.jpg?w=676&amp;ssl=1 676w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2474\" class=\"wp-caption-text\"><strong>Handling Single Words<\/strong><\/figcaption><\/figure>\n<p>I know I still have to account for more complex sentence structures (it is fairly good as it is) and it is thus an on-going project. The project uses <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus Prolog 4.6.0<\/strong><\/em><\/a> and runs on Windows 10 (64-bit).<\/p>\n<p>I hope to share more such experiments in the near future.<\/p>\n<p>Have a nice weekend and a great week ahead!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sentences in English can be classified into the following common types: &#8211; Simple sentence (&#8220;I am drinking coffee&#8221;) &#8211; Compound sentence (&#8220;He came home with his school friend and they had an enjoyable evening&#8221;) &#8211; Complex sentence (&#8220;Whenever my dog barks, I give him some biscuit&#8221;) &#8211; Imperative sentence (&#8220;Please keep quiet&#8221;) &#8211; Interrogative sentence [&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_feature_clip_id":0,"_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":[107,17,147],"tags":[286,203,148],"class_list":["post-2467","post","type-post","status-publish","format-standard","hentry","category-natural-language-processing","category-programming","category-prolog","tag-definte-clause-grammar","tag-english-grammar","tag-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-DN","jetpack-related-posts":[{"id":2483,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/07\/18\/sentence-negation\/","url_meta":{"origin":2467,"position":0},"title":"Sentence Negation","author":"admin","date":"July 18, 2021","format":false,"excerpt":"In the last article, I talked about determining sentence types automatically. Another interesting task is to generate the \"negation\" of a given sentence. Example-1: Sentence => \"My teacher lives nearby\" Negation => \"My teacher does not live nearby\" Example-2: Sentence => \"She did not like that speech\" Negation => \"She\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":"Parse Tree","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree-300x24.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree-300x24.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/07\/parsetree-300x24.jpg?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":2467,"position":1},"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":1889,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/02\/16\/automatically-converting-active-voice-to-passive-voice-and-vice-versa\/","url_meta":{"origin":2467,"position":2},"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":1817,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/12\/08\/using-definite-clause-grammars-dcg-for-information-extraction\/","url_meta":{"origin":2467,"position":3},"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":541,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/06\/04\/definite-clause-grammars-in-lisp-part-2\/","url_meta":{"origin":2467,"position":4},"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":1792,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/11\/23\/using-augmented-transition-networks-atn-for-information-extraction\/","url_meta":{"origin":2467,"position":5},"title":"Using Augmented Transition Networks (ATN) for Information Extraction","author":"admin","date":"November 23, 2019","format":false,"excerpt":"After Wood\u2019s paper [1], Augmented Transition Networks\u00a0(ATN) became popular in the 1970s, for parsing text. An ATN is a generalized transition network with two major enhancements: Support for recursive transitions, including jumping to other ATNs Performing arbitrary actions when edges are traversed Remembering state through the use of registers See\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"ATN for Modality","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/modality.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/modality.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/modality.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2467","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=2467"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2467\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}