{"id":1677,"date":"2019-08-18T09:29:28","date_gmt":"2019-08-18T03:59:28","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1677"},"modified":"2019-08-18T10:28:59","modified_gmt":"2019-08-18T04:58:59","slug":"using-berkeley-db-with-sicstus-prolog","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/","title":{"rendered":"Using Berkeley DB with Sicstus Prolog"},"content":{"rendered":"<p>One of the nice features of <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus Prolog<\/strong><\/em><\/a>\u00a0is the support for storing <em><strong>Terms<\/strong><\/em>\u00a0externally in a <a href=\"https:\/\/www.oracle.com\/in\/database\/technologies\/related\/berkeleydb.html\" target=\"_blank\" rel=\"noopener\"><em><strong>Berkeley DB<\/strong><\/em><\/a>\u00a0database. Since we can control how the terms are indexed in the database, it is possible to store and retrieve a large amount of<em><strong> Terms\u00a0<\/strong><\/em>(the limit is <em><strong>2^32-1<\/strong><\/em>) fairly efficiently. This can be useful when we work in a memory-constrained environment. The interface to <em><strong>Berkeley DB<\/strong><\/em> is provided by the library <em><strong>&#8220;bdb&#8221;.<\/strong><\/em><\/p>\n<p>As a matter of interest, the <em><strong>Prolog<\/strong><\/em> version of my <a href=\"https:\/\/www.rangakrish.com\/index.php\/2018\/02\/11\/onomatopoeia-palindrome-and-semordnilap\/\" target=\"_blank\" rel=\"noopener\"><em><strong>&#8220;iLexicon&#8221;<\/strong><\/em><\/a> words database currently contains <em><strong>2,453,333<\/strong><\/em> facts (close to <em><strong>2.5 million<\/strong><\/em>) and <em><strong>Sicstus Prolog<\/strong><\/em> loads this entire data in <em><strong>4 seconds<\/strong><\/em> flat! Of course, I have 32 GB RAM on my machine and that can explain the good performance. Therefore, as of now I have not felt the need to use <em><strong>Berkeley DB<\/strong><\/em> as the backend, but who knows, it might come in handy later on.<\/p>\n<p>In today&#8217;s article, I want to explore the <em><strong>BDB<\/strong><\/em> library. For more details, you may want to consult the <em><strong>Sicstus Prolog<\/strong><\/em> <a href=\"https:\/\/sicstus.sics.se\/sicstus\/docs\/latest4\/pdf\/sicstus.pdf\" target=\"_blank\" rel=\"noopener\"><em><strong>manual<\/strong><\/em><\/a>.<\/p>\n<blockquote><p><span style=\"color: #0000ff;\"><strong>My Prolog environment: Sicstus Prolog 4.5.1, 64 bit Windows edition.<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span><\/span><\/p><\/blockquote>\n<p>It is important to note that the current version of <em><strong>Sicstus Prolog<\/strong><\/em> only supports <a href=\"https:\/\/www.oracle.com\/technetwork\/database\/database-technologies\/berkeleydb\/downloads\/index-082944.html\" target=\"_blank\" rel=\"noopener\"><em><strong>Berkeley DB version 6.2.38<\/strong><\/em><\/a>. So I had to download this version and install on my <em><strong>Windows<\/strong><\/em> machine in order to use the <em><strong>BDB<\/strong><\/em> library.<\/p>\n<h3>Creating a new database<\/h3>\n<p>To create a new database, we have to give it a <em><strong>&#8220;name&#8221;<\/strong><\/em> and also mention the various <em><strong>&#8220;functors&#8221;<\/strong><\/em> and their respective\u00a0<em><strong>indexing<\/strong><\/em> specifications. Additionally, the DB must be opened in <em><strong>&#8220;update&#8221;<\/strong><\/em> mode. In this case, the <em><strong>BDB<\/strong><\/em> engine creates a directory with the same name in the current working directory. In my example, instead of storing one fact at a time, I am going to read facts from an existing <em><strong>Prolog<\/strong><\/em> file and store them in the database.<\/p>\n<p>Here are the facts (stored in the file <em><strong>&#8220;remedies.pro&#8221;<\/strong><\/em>):<\/p>\n<figure id=\"attachment_1680\" aria-describedby=\"caption-attachment-1680\" style=\"width: 601px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"1680\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/sample-data\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg\" data-orig-size=\"601,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;1566072210&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 Facts about Homeo Remedies\" data-image-description=\"&lt;p&gt;Sample Facts about Homeo Remedies&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Sample Facts about Homeo Remedies&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg\" class=\"size-full wp-image-1680\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg?resize=601%2C254&#038;ssl=1\" alt=\"Sample Facts about Homeo Remedies\" width=\"601\" height=\"254\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg?w=601&amp;ssl=1 601w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/sample-data.jpg?resize=300%2C127&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><figcaption id=\"caption-attachment-1680\" class=\"wp-caption-text\"><strong>Sample Facts about Homeo Remedies<\/strong><\/figcaption><\/figure>\n<p>Here is the code to create a new <em><strong>Berkeley DB<\/strong><\/em> and populate it with the facts from the given file:<\/p>\n<figure id=\"attachment_1681\" aria-describedby=\"caption-attachment-1681\" style=\"width: 628px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1681\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/create-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg\" data-orig-size=\"628,317\" 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;1566065691&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=\"Code to Create the DB\" data-image-description=\"&lt;p&gt;Code to Create the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Create the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg\" class=\"size-full wp-image-1681\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg?resize=628%2C317&#038;ssl=1\" alt=\"Code to Create the DB\" width=\"628\" height=\"317\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg?w=628&amp;ssl=1 628w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db.jpg?resize=300%2C151&amp;ssl=1 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><figcaption id=\"caption-attachment-1681\" class=\"wp-caption-text\"><strong>Code to Create the DB<\/strong><\/figcaption><\/figure>\n<p>As the code above shows, after the database is created and populated with sample data, it is closed immediately.<\/p>\n<p>The above predicate is executed in <em><strong>Sicstus Prolog<\/strong><\/em> IDE thus:<\/p>\n<figure id=\"attachment_1682\" aria-describedby=\"caption-attachment-1682\" style=\"width: 568px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1682\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/create-db2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg\" data-orig-size=\"568,95\" 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;1566066458&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=\"Creating the DB\" data-image-description=\"&lt;p&gt;Creating the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Creating the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg\" class=\"size-full wp-image-1682\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg?resize=568%2C95&#038;ssl=1\" alt=\"Creating the DB\" width=\"568\" height=\"95\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg?w=568&amp;ssl=1 568w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/create-db2.jpg?resize=300%2C50&amp;ssl=1 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/a><figcaption id=\"caption-attachment-1682\" class=\"wp-caption-text\"><strong>Creating the DB<\/strong><\/figcaption><\/figure>\n<p>If you look at the third argument, you can see the indexing specification of the various functors. The <em><strong>&#8220;+&#8221;<\/strong><\/em> denotes that the corresponding argument is to be indexed. In the case of <em><strong>&#8220;abbrev&#8221;<\/strong><\/em> functor, we have separately indexed both the arguments and there is also an un-indexed version. The latter is required if we decide to retrieve all matches of <em><strong>&#8220;abbrev&#8221;<\/strong><\/em> without specifying the arguments (i.e., non-ground, e.g. <em><strong>abbrev(X, Y)<\/strong><\/em> ).<\/p>\n<h3>Updating the database<\/h3>\n<p>When we update an existing database, for example, by adding a new fact, the database must be opened in <em><strong>&#8216;<\/strong><strong>update&#8217;<\/strong><\/em> mode and more importantly, we have to again supply the same predicate specification we gave at the time of creating. The latter looks like an avoidable repetition, but it is needed.<\/p>\n<p>Here is the code to update:<\/p>\n<figure id=\"attachment_1686\" aria-describedby=\"caption-attachment-1686\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1686\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/update-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg\" data-orig-size=\"660,193\" 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;1566065727&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=\"Code to Update\" data-image-description=\"&lt;p&gt;Code to Update&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Update&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg\" class=\"size-full wp-image-1686\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg?resize=660%2C193&#038;ssl=1\" alt=\"Code to Update\" width=\"660\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg?w=660&amp;ssl=1 660w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db.jpg?resize=300%2C88&amp;ssl=1 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-1686\" class=\"wp-caption-text\"><strong>Code to Update<\/strong><\/figcaption><\/figure>\n<p>It is executed as follows:<\/p>\n<figure id=\"attachment_1687\" aria-describedby=\"caption-attachment-1687\" style=\"width: 634px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1687\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/update-db2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg\" data-orig-size=\"634,70\" 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;1566066496&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=\"Executing Update in the IDE\" data-image-description=\"&lt;p&gt;Executing Update in the IDE&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Executing Update in the IDE&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg\" class=\"size-full wp-image-1687\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg?resize=634%2C70&#038;ssl=1\" alt=\"Executing Update in the IDE\" width=\"634\" height=\"70\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg?w=634&amp;ssl=1 634w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/update-db2.jpg?resize=300%2C33&amp;ssl=1 300w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/a><figcaption id=\"caption-attachment-1687\" class=\"wp-caption-text\"><strong>Executing Update in the IDE<\/strong><\/figcaption><\/figure>\n<p>This adds a new fact <span style=\"color: #0000ff;\"><em><strong>abbrev(&#8216;acon.&#8217;, &#8216;aconitum napellus&#8217;)<\/strong><\/em><\/span> into the DB. As in the earlier case, this operation closes the DB after update. This is not optimal if we want to add many facts to the DB at the same time, but it is easy to extend the code to handle that case.<\/p>\n<h3>Opening in &#8216;read&#8217; mode<\/h3>\n<p>If we do not need to add or delete entries from the DB, we can safely open it in <em><strong>&#8216;read&#8217;<\/strong><\/em> mode. In practice, after opening the DB, we might perform several operations before closing it at the end. In such a situation, it is a good idea to <em><strong>assert<\/strong><\/em> the DB handle in the current working memory so that it is available for subsequent operations. Here is the code to illustrate this:<\/p>\n<figure id=\"attachment_1689\" aria-describedby=\"caption-attachment-1689\" style=\"width: 601px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1689\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/open-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg\" data-orig-size=\"601,106\" 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;1566065756&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=\"Opening in &amp;#8216;read&amp;#8217; Mode\" data-image-description=\"&lt;p&gt;Opening in &amp;#8216;read&amp;#8217; Mode&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Opening in &amp;#8216;read&amp;#8217; Mode&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg\" class=\"size-full wp-image-1689\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg?resize=601%2C106&#038;ssl=1\" alt=\"Opening in 'read' Mode\" width=\"601\" height=\"106\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg?w=601&amp;ssl=1 601w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/open-db.jpg?resize=300%2C53&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><figcaption id=\"caption-attachment-1689\" class=\"wp-caption-text\"><strong>Opening in &#8216;read&#8217; Mode<\/strong><\/figcaption><\/figure>\n<p>The above predicate uses the <em><strong>functor &#8216;dbinfo&#8217;<\/strong><\/em> to remember the current DB name and its handle. You can also see that I am not passing the original indexing specification here; it is not needed in <em><strong>&#8216;read&#8217;<\/strong><\/em> mode.<\/p>\n<h3>Fetching one or more facts<\/h3>\n<p>Once the DB is open for reading, we can retrieve matching terms based on unification. Here is a simple predicate for doing that:<\/p>\n<figure id=\"attachment_1691\" aria-describedby=\"caption-attachment-1691\" style=\"width: 582px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1691\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/retrieve-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg\" data-orig-size=\"582,148\" 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;1566065829&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=\"Retrieving Facts\" data-image-description=\"&lt;p&gt;Retrieving Facts&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Retrieving Facts&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg\" class=\"size-full wp-image-1691\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg?resize=582%2C148&#038;ssl=1\" alt=\"Retrieving Facts\" width=\"582\" height=\"148\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg?w=582&amp;ssl=1 582w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/retrieve-db.jpg?resize=300%2C76&amp;ssl=1 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/a><figcaption id=\"caption-attachment-1691\" class=\"wp-caption-text\"><strong>Retrieving Facts<\/strong><\/figcaption><\/figure>\n<p>We can use this predicate in our remedies database to look for all abbreviations:<\/p>\n<figure id=\"attachment_1692\" aria-describedby=\"caption-attachment-1692\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1692\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/get-1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg\" data-orig-size=\"350,125\" 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;1566049468&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=\"get-1\" data-image-description=\"&lt;p&gt;Fetching Terms&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fetching Terms&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg\" class=\"size-full wp-image-1692\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg?resize=350%2C125&#038;ssl=1\" alt=\"Fetching Terms\" width=\"350\" height=\"125\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg?w=350&amp;ssl=1 350w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-1.jpg?resize=300%2C107&amp;ssl=1 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-1692\" class=\"wp-caption-text\"><strong>Fetching Terms<\/strong><\/figcaption><\/figure>\n<p>Notice how the predicate can backtrack to return multiple bindings for<em><strong> X<\/strong><\/em> and <em><strong>Y<\/strong><\/em>. This is made possible by the indexing specification <em><strong>&#8220;abbrev(-,-)&#8221;<\/strong><\/em>. Let us see what happens when we try this with the <em><strong>&#8220;group&#8221; functor:<\/strong><\/em><\/p>\n<figure id=\"attachment_1693\" aria-describedby=\"caption-attachment-1693\" style=\"width: 621px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1693\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/get-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg\" data-orig-size=\"621,60\" 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;1566049616&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=\"Index Specification Mismatch\" data-image-description=\"&lt;p&gt;Index Specification Mismatch&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Index Specification Mismatch&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg\" class=\"size-full wp-image-1693\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg?resize=621%2C60&#038;ssl=1\" alt=\"Index Specification Mismatch\" width=\"621\" height=\"60\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg?w=621&amp;ssl=1 621w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-2.jpg?resize=300%2C29&amp;ssl=1 300w\" sizes=\"(max-width: 621px) 100vw, 621px\" \/><\/a><figcaption id=\"caption-attachment-1693\" class=\"wp-caption-text\"><strong>Index Specification Mismatch<\/strong><\/figcaption><\/figure>\n<p>If you recall, the index specification in this case is <em><strong>&#8220;group(+,-)&#8221;<\/strong><\/em>, which says that the first argument must be grounded because it is used for indexing. Since we supplied a <em><strong>variable<\/strong><\/em> as the first argument, the fetch operation could not succeed.<\/p>\n<p>The following, however, works:<\/p>\n<figure id=\"attachment_1694\" aria-describedby=\"caption-attachment-1694\" style=\"width: 457px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1694\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/get-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg\" data-orig-size=\"457,101\" 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;1566050826&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=\"Satisfying Index Specification\" data-image-description=\"&lt;p&gt;Satisfying Index Specification&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Satisfying Index Specification&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg\" class=\"size-full wp-image-1694\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg?resize=457%2C101&#038;ssl=1\" alt=\"Satisfying Index Specification\" width=\"457\" height=\"101\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg?w=457&amp;ssl=1 457w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/get-3.jpg?resize=300%2C66&amp;ssl=1 300w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/a><figcaption id=\"caption-attachment-1694\" class=\"wp-caption-text\"><strong>Satisfying Index Specification<\/strong><\/figcaption><\/figure>\n<h3>Iterating over all facts<\/h3>\n<p>Instead of fetching specific terms, we can also iterate over all (or select) items in the DB.<\/p>\n<figure id=\"attachment_1695\" aria-describedby=\"caption-attachment-1695\" style=\"width: 597px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1695\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/iterate-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg\" data-orig-size=\"597,341\" 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;1566117274&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=\"Iterating Over the DB\" data-image-description=\"&lt;p&gt;Iterating Over the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Iterating Over the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg\" class=\"size-full wp-image-1695\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?resize=597%2C341&#038;ssl=1\" alt=\"Iterating Over the DB\" width=\"597\" height=\"341\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?w=597&amp;ssl=1 597w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?resize=300%2C171&amp;ssl=1 300w\" sizes=\"(max-width: 597px) 100vw, 597px\" \/><\/a><figcaption id=\"caption-attachment-1695\" class=\"wp-caption-text\"><strong>Iterating Over the DB<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>&#8216;traverse_db&#8217;<\/strong><\/em> predicate takes the DB name and another <em><strong>&#8216;Action&#8217;<\/strong> <\/em>predicate (which must take a single argument) and applies the &#8216;<em><strong>Action&#8217;<\/strong><\/em> on each item in the DB. The traversal <em>order is not guaranteed<\/em>.<\/p>\n<p>Here is a use case:<\/p>\n<figure id=\"attachment_1697\" aria-describedby=\"caption-attachment-1697\" style=\"width: 539px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1697\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/iterate-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg\" data-orig-size=\"539,163\" 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;1566118515&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=\"Iterating Over the DB\" data-image-description=\"&lt;p&gt;Iterating Over the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Iterating Over the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg\" class=\"size-full wp-image-1697\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg?resize=539%2C163&#038;ssl=1\" alt=\"Iterating Over the DB\" width=\"539\" height=\"163\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg?w=539&amp;ssl=1 539w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-1.jpg?resize=300%2C91&amp;ssl=1 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/a><figcaption id=\"caption-attachment-1697\" class=\"wp-caption-text\"><strong>Example: Iterating Over the DB<\/strong><\/figcaption><\/figure>\n<h3>Closing the DB<\/h3>\n<p>Once all database operations are complete, it is necessary to close the DB. Here is a predicate that does that:<\/p>\n<figure id=\"attachment_1698\" aria-describedby=\"caption-attachment-1698\" style=\"width: 469px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1698\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/close-db\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg\" data-orig-size=\"469,105\" 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;1566065786&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=\"Closing the DB\" data-image-description=\"&lt;p&gt;Closing the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Closing the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg\" class=\"size-full wp-image-1698\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg?resize=469%2C105&#038;ssl=1\" alt=\"Closing the DB\" width=\"469\" height=\"105\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg?w=469&amp;ssl=1 469w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/close-db.jpg?resize=300%2C67&amp;ssl=1 300w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/a><figcaption id=\"caption-attachment-1698\" class=\"wp-caption-text\"><strong>Closing the DB<\/strong><\/figcaption><\/figure>\n<p>It uses the supplied DB name to look up the corresponding handle and then uses that handle to close the DB. In the process, it removes information about the current DB from the working memory.<\/p>\n<h3>Exporting and Importing<\/h3>\n<p>The contents of a <em><strong>Berkeley DB<\/strong><\/em> can be exported to a text file. The predicate <em><strong>&#8220;db_export&#8221;<\/strong><\/em> does this. The exported file contains extra meta information about the database and is in <em><strong>Prolog<\/strong><\/em> format. This file can be <em><strong>&#8220;imported&#8221;<\/strong><\/em>, if needed, using the predicate <em><strong>&#8220;db_import&#8221;<\/strong><\/em>.<\/p>\n<p>One aspect of the database I have ignored is the <em><strong>&#8220;Environment&#8221;<\/strong><\/em>. This is optional and is only needed if <em><strong>multiple processes<\/strong><\/em> wish to share access to the same database. I urge you to go through the manual if you are interested to learn more about this.<\/p>\n<p>As you would have observed, using the <em><strong>BDB library<\/strong><\/em> to access an external <em><strong>Berkeley DB<\/strong><\/em> is quite intuitive in <em><strong>Sicstus Prolog.<\/strong><\/em> As hinted earlier, this feature will come in handy when working with a large fact base in a memory-limited environment.<\/p>\n<p>You can download my <em><strong>Prolog<\/strong><\/em> file <a href=\"http:\/\/www.rangakrish.com\/downloads\/BDBExplorer.pro\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. The sample data is in this <a href=\"http:\/\/www.rangakrish.com\/downloads\/remedies.pro\" target=\"_blank\" rel=\"noopener\"><em><strong>file<\/strong><\/em><\/a>.<\/p>\n<p>Have a nice weekend!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the nice features of Sicstus Prolog\u00a0is the support for storing Terms\u00a0externally in a Berkeley DB\u00a0database. Since we can control how the terms are indexed in the database, it is possible to store and retrieve a large amount of Terms\u00a0(the limit is 2^32-1) fairly efficiently. This can be useful when we work in a [&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":[17,147],"tags":[214,151],"class_list":["post-1677","post","type-post","status-publish","format-standard","hentry","category-programming","category-prolog","tag-berkeley-db","tag-sicstus-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-r3","jetpack-related-posts":[{"id":2553,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/","url_meta":{"origin":1677,"position":0},"title":"Using Sicstus Prolog with LMDB","author":"admin","date":"October 3, 2021","format":false,"excerpt":"In an earlier article, I showed how Sicstus Prolog allows us to use Berkeley DB for storage and retrieval of terms using the file system. Interestingly, the latest release of Sicstus Prolog, version 4.7.0, deprecates the Berekely DB library, while recommending an alternative implementation based on Lightning Memory-Mapped Database Manager\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Facts About Homeopathic Remedies","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies-300x116.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1025,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/19\/sicstus-prolog-building-a-windows-executable\/","url_meta":{"origin":1677,"position":1},"title":"Sicstus Prolog &#8211; Building a Windows Executable","author":"admin","date":"August 19, 2018","format":false,"excerpt":"In my previous post, I showed how to build a C-based Windows DLL to execute Prolog predicates in the Sicstus Prolog\u00a0engine. Today, I want to show how to build an executable (on Windows) from a C\/C++ program that uses Sicstus prolog engine. The process is quite simple. In order to\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":"Creating WordNet Prolog Image","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Creating-image.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1004,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/05\/sicstus-prolog-building-a-windows-dll\/","url_meta":{"origin":1677,"position":2},"title":"Sicstus Prolog &#8211; Building a Windows DLL","author":"admin","date":"August 5, 2018","format":false,"excerpt":"Last week I upgraded to the latest version (4.4.1) of Sicstus Prolog\u00a0for Windows.\u00a0Since the Prolog engine can be embedded (royalty free) in other applications, it is useful to understand how to create a DLL (on Windows) for this purpose. In today's article, I would like to outline this process in\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Creating Prolog Program Image","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/08\/Saving-Prolog-Image.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1770,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/11\/10\/calling-c-methods-from-sicstus-prolog-through-com-interface\/","url_meta":{"origin":1677,"position":3},"title":"Calling C# Methods from Sicstus Prolog through COM Interface","author":"admin","date":"November 10, 2019","format":false,"excerpt":"Recently\u00a0I needed to make use of a C# library (which I had implemented a few years ago) from Sicstus Prolog. Calling C\/C++ functions from Sicstus Prolog is fairly well documented. When it comes to C#\/.NET, the official documentation recommends the PrologBeans library. After going through the documentation, I felt that\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Prolog Client Code","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/11\/Prolog-Code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3260,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/11\/26\/generating-polynomials-in-prolog\/","url_meta":{"origin":1677,"position":4},"title":"Generating Polynomials in Prolog","author":"admin","date":"November 26, 2023","format":false,"excerpt":"Polynomial is an important topic in High School maths curriculum. There are many online courses that explain the topic in great details with lots of examples and sample exercises. Wouldn\u2019t it be interesting if we can generate polynomials of given degree programmatically? It turns out that this is not such\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Generating Polynomials - Main Clauses","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/11\/Code1-300x163.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/11\/Code1-300x163.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/11\/Code1-300x163.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":1677,"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\/1677","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=1677"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1677\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}