{"id":2553,"date":"2021-10-03T09:15:45","date_gmt":"2021-10-03T03:45:45","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2553"},"modified":"2021-10-03T09:15:45","modified_gmt":"2021-10-03T03:45:45","slug":"using-sicstus-prolog-with-lmdb","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/","title":{"rendered":"Using Sicstus Prolog with LMDB"},"content":{"rendered":"<p>In an <a href=\"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/\" target=\"_blank\" rel=\"noopener\"><em><strong>earlier article<\/strong><\/em><\/a>, I showed how <a href=\"https:\/\/sicstus.sics.se\" target=\"_blank\" rel=\"noopener\"><em><strong>Sicstus Prolog<\/strong><\/em><\/a> allows us to use <a href=\"https:\/\/www.oracle.com\/in\/database\/technologies\/related\/berkeleydb.html\" target=\"_blank\" rel=\"noopener\"><em><strong>Berkeley DB<\/strong><\/em><\/a> for storage and retrieval of terms using the file system. Interestingly, the latest release of <em><strong>Sicstus Prolo<\/strong><strong>g<\/strong><\/em>, version 4.7.0, deprecates the <em><strong>Berekely DB<\/strong><\/em> library, while recommending an alternative implementation based on <a href=\"http:\/\/www.lmdb.tech\/doc\/\" target=\"_blank\" rel=\"noopener\"><em><strong>Lightning Memory-Mapped Database Manager (LMDB<\/strong><strong>)<\/strong><\/em><\/a>. The library interfaces are quite similar, so it is easy to port from <em><strong>BDB<\/strong><\/em> to <em><strong>LMDB<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>For this article, I am going to use the same <em><strong>Homeopathic Remedies<\/strong><\/em> example that I used in the earlier article. The file <em><strong>&#8220;remedies.pl&#8221;<\/strong><\/em> contains simple facts about a few homeopathic remedies:<\/p>\n<figure id=\"attachment_2554\" aria-describedby=\"caption-attachment-2554\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2554\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/remedies\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg\" data-orig-size=\"901,348\" 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;1633246733&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=\"Facts About Homeopathic Remedies\" data-image-description=\"&lt;p&gt;Facts About Homeopathic Remedies&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Facts About Homeopathic Remedies&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg\" class=\"wp-image-2554\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg?resize=500%2C193&#038;ssl=1\" alt=\"Facts About Homeopathic Remedies\" width=\"500\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg?resize=300%2C116&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg?resize=768%2C297&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/remedies.jpg?w=901&amp;ssl=1 901w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2554\" class=\"wp-caption-text\"><strong>Facts About Homeopathic Remedies<\/strong><\/figcaption><\/figure>\n<p>Here is the code to create a new database, given an input <em><strong>Prolog<\/strong><\/em> file and corresponding <em><strong>Index<\/strong><\/em> specification:<\/p>\n<figure id=\"attachment_2555\" aria-describedby=\"caption-attachment-2555\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2555\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-create\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg\" data-orig-size=\"948,498\" 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;1633246693&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 New Database\" data-image-description=\"&lt;p&gt;Code to Create New Database&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Create New Database&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg\" class=\"wp-image-2555\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg?resize=500%2C263&#038;ssl=1\" alt=\"Code to Create New Database\" width=\"500\" height=\"263\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg?resize=300%2C158&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg?resize=768%2C403&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-create.jpg?w=948&amp;ssl=1 948w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2555\" class=\"wp-caption-text\"><strong>Code to Create New Database<\/strong><\/figcaption><\/figure>\n<p>As you might notice, one difference from the <em><strong>BDB<\/strong><\/em> library is the need to call <em><strong>&#8220;lmdb_create&#8221;<\/strong><\/em> explicitly.<\/p>\n<p>Here is how we can create the actual <em><strong>DB<\/strong><\/em> in <em><strong>Sicstus Prolog&#8217;s IDE<\/strong><\/em>:<\/p>\n<figure id=\"attachment_2556\" aria-describedby=\"caption-attachment-2556\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2556\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/createdb\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg\" data-orig-size=\"777,214\" 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;1633185126&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=\"Create the Database\" data-image-description=\"&lt;p&gt;Create the Database&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Create the Database&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg\" class=\"wp-image-2556\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg?resize=500%2C138&#038;ssl=1\" alt=\"Create the Database\" width=\"500\" height=\"138\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg?resize=300%2C83&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg?resize=768%2C212&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/createdb.jpg?w=777&amp;ssl=1 777w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2556\" class=\"wp-caption-text\"><strong>Create the Database<\/strong><\/figcaption><\/figure>\n<p>What if we wish to add some facts after creating the database? Here is the code that facilitates updates:<\/p>\n<figure id=\"attachment_2557\" aria-describedby=\"caption-attachment-2557\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2557\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-update\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg\" data-orig-size=\"1019,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;1633247316&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 the Database\" data-image-description=\"&lt;p&gt;Code to Update the Database&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Update the Database&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg\" class=\"wp-image-2557\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg?resize=500%2C151&#038;ssl=1\" alt=\"Code to Update the Database\" width=\"500\" height=\"151\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg?resize=300%2C90&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg?resize=768%2C231&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-update.jpg?w=1019&amp;ssl=1 1019w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2557\" class=\"wp-caption-text\"><strong>Code to Update the Database<\/strong><\/figcaption><\/figure>\n<p>Using it is straightforward:<\/p>\n<figure id=\"attachment_2558\" aria-describedby=\"caption-attachment-2558\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2558\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/update\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg\" data-orig-size=\"800,79\" 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;1633185195&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=\"Adding New Facts\" data-image-description=\"&lt;p&gt;Adding New Facts&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Adding New Facts&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg\" class=\"wp-image-2558\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg?resize=500%2C49&#038;ssl=1\" alt=\"Adding New Facts\" width=\"500\" height=\"49\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg?resize=300%2C30&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg?resize=768%2C76&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/update.jpg?w=800&amp;ssl=1 800w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2558\" class=\"wp-caption-text\"><strong>Adding New Fact<\/strong><\/figcaption><\/figure>\n<p>The new fact to insert is passed as the second argument.<\/p>\n<p>A majority of the times, we would want to open the database, perform some operations, and then close the database. The code for opening and closing are given below:<\/p>\n<figure id=\"attachment_2559\" aria-describedby=\"caption-attachment-2559\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2559\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-openclose\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg\" data-orig-size=\"933,314\" 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;1633247539&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=\"Cde to Open and Close the DB\" data-image-description=\"&lt;p&gt;Cde to Open and Close the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Cde to Open and Close the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg\" class=\"wp-image-2559\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg?resize=500%2C168&#038;ssl=1\" alt=\"Cde to Open and Close the DB\" width=\"500\" height=\"168\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg?resize=300%2C101&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg?resize=768%2C258&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-openclose.jpg?w=933&amp;ssl=1 933w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2559\" class=\"wp-caption-text\"><strong>Code to Open and Close the DB<\/strong><\/figcaption><\/figure>\n<p>One useful functionality is to retrieve all terms that match a template:<\/p>\n<figure id=\"attachment_2560\" aria-describedby=\"caption-attachment-2560\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2560\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-getall\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg\" data-orig-size=\"1146,97\" 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;1633247799&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 Fetch Terms from the DB\" data-image-description=\"&lt;p&gt;Code to Fetch Terms from the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Fetch Terms from the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall-1024x87.jpg\" class=\"wp-image-2560\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?resize=500%2C42&#038;ssl=1\" alt=\"Code to Fetch Terms from the DB\" width=\"500\" height=\"42\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?resize=300%2C25&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?resize=1024%2C87&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?resize=768%2C65&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-getall.jpg?w=1146&amp;ssl=1 1146w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2560\" class=\"wp-caption-text\"><strong>Code to Fetch Terms from the DB<\/strong><\/figcaption><\/figure>\n<p>Obviously, this feature is useful only when we are expecting a <em><strong>&#8220;manageable&#8221;<\/strong><\/em> number of terms as result. In general, it is a good idea to be able to perform some <em><strong>&#8220;operation&#8221;<\/strong><\/em> on <em><strong>&#8220;matching&#8221;<\/strong><\/em> facts in the database.<\/p>\n<figure id=\"attachment_2561\" aria-describedby=\"caption-attachment-2561\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2561\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-traverse\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg\" data-orig-size=\"981,470\" 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;1633248004&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 Traverse the DB\" data-image-description=\"&lt;p&gt;Code to Traverse the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Traverse the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg\" class=\"wp-image-2561\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg?resize=500%2C240&#038;ssl=1\" alt=\"Code to Traverse the DB\" width=\"500\" height=\"240\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg?resize=300%2C144&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg?resize=768%2C368&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-traverse.jpg?w=981&amp;ssl=1 981w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2561\" class=\"wp-caption-text\"><strong>Code to Traverse the DB<\/strong><\/figcaption><\/figure>\n<p>Let us put the above ideas to work.<\/p>\n<p>Since we know that our toy <em><strong>DB<\/strong><\/em> contains very few facts, let us retrieve all of them in one go:<\/p>\n<figure id=\"attachment_2562\" aria-describedby=\"caption-attachment-2562\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2562\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/get1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg\" data-orig-size=\"1051,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;1633185349&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=\"Fetch All Terms from the DB\" data-image-description=\"&lt;p&gt;Fetch All Terms from the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fetch All Terms from the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1-1024x191.jpg\" class=\"wp-image-2562\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?resize=500%2C93&#038;ssl=1\" alt=\"Fetch All Terms from the DB\" width=\"500\" height=\"93\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?resize=300%2C56&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?resize=1024%2C191&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?resize=768%2C143&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get1.jpg?w=1051&amp;ssl=1 1051w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2562\" class=\"wp-caption-text\"><strong>Fetch All Terms from the DB<\/strong><\/figcaption><\/figure>\n<p>This time, let us fetch terms that correspond to <em><strong>&#8220;abbrev&#8221;<\/strong><\/em>:<\/p>\n<div class=\"mceTemp\"><\/div>\n<figure id=\"attachment_2565\" aria-describedby=\"caption-attachment-2565\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2565\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/get2-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg\" data-orig-size=\"1055,98\" 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;1633185429&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=\"Fetch Matching Terms\" data-image-description=\"&lt;p&gt;Fetch Matching Terms&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Fetch Matching Terms&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1-1024x95.jpg\" class=\"wp-image-2565\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?resize=500%2C46&#038;ssl=1\" alt=\"Fetch Matching Terms\" width=\"500\" height=\"46\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?resize=300%2C28&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?resize=1024%2C95&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?resize=768%2C71&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/get2-1.jpg?w=1055&amp;ssl=1 1055w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2565\" class=\"wp-caption-text\"><strong>Fetch Matching Terms<\/strong><\/figcaption><\/figure>\n<p>This also works as expected.<\/p>\n<p>To illustrate the use of <em><strong>&#8220;traversal&#8221;<\/strong><\/em>, let us define a predicate to <em><strong>print<\/strong><\/em> any given term:<\/p>\n<figure id=\"attachment_2577\" aria-describedby=\"caption-attachment-2577\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2577\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-print-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg\" data-orig-size=\"670,129\" 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;1633252291&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 Print Any Term\" data-image-description=\"&lt;p&gt;Code to Print Any Term&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Print Any Term&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg\" class=\"size-medium wp-image-2577\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg?resize=300%2C58&#038;ssl=1\" alt=\"Code to Print Any Term\" width=\"300\" height=\"58\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg?resize=300%2C58&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-print-1.jpg?w=670&amp;ssl=1 670w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-2577\" class=\"wp-caption-text\"><strong>Code to Print Any Term<\/strong><\/figcaption><\/figure>\n<p>First, let us visit all the <em><strong>&#8220;abbrev&#8221;<\/strong><\/em> terms and print them:<\/p>\n<figure id=\"attachment_2567\" aria-describedby=\"caption-attachment-2567\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2567\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/trav1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg\" data-orig-size=\"678,114\" 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;1633185478&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=\"Traversal &amp;#8211; 1\" data-image-description=\"&lt;p&gt;Traversal &amp;#8211; 1&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Traversal &amp;#8211; 1&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg\" class=\"wp-image-2567\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg?resize=500%2C84&#038;ssl=1\" alt=\"Traversal - 1\" width=\"500\" height=\"84\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg?resize=300%2C50&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg?resize=675%2C114&amp;ssl=1 675w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav1.jpg?w=678&amp;ssl=1 678w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2567\" class=\"wp-caption-text\"><strong>Traversal &#8211; 1<\/strong><\/figcaption><\/figure>\n<p>Great. Now traverse all terms in the database:<\/p>\n<figure id=\"attachment_2568\" aria-describedby=\"caption-attachment-2568\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2568\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/trav2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg\" data-orig-size=\"797,231\" 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;1633185520&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=\"Traversal &amp;#8211; 2\" data-image-description=\"&lt;p&gt;Traversal &amp;#8211; 2&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Traversal &amp;#8211; 2&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg\" class=\"wp-image-2568\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg?resize=500%2C145&#038;ssl=1\" alt=\"Traversal - 2\" width=\"500\" height=\"145\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg?resize=300%2C87&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg?resize=768%2C223&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/trav2.jpg?w=797&amp;ssl=1 797w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2568\" class=\"wp-caption-text\"><strong>Traversal &#8211; 2<\/strong><\/figcaption><\/figure>\n<p>Everything seems to work as expected.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>One additional useful feature is the ability to <em><strong>export<\/strong><\/em> the contents of the database to a text file. Here is the code:<\/p>\n<figure id=\"attachment_2569\" aria-describedby=\"caption-attachment-2569\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2569\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/code-export\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg\" data-orig-size=\"867,131\" 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;1633249540&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 Export the DB\" data-image-description=\"&lt;p&gt;Code to Export the DB&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Code to Export the DB&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg\" class=\"wp-image-2569\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export-300x45.jpg?resize=500%2C76&#038;ssl=1\" alt=\"Code to Export the DB\" width=\"500\" height=\"76\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg?resize=300%2C45&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg?resize=768%2C116&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/code-export.jpg?w=867&amp;ssl=1 867w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2569\" class=\"wp-caption-text\"><strong>Code to Export the DB<\/strong><\/figcaption><\/figure>\n<p>We can now export our toy database thus:<\/p>\n<figure id=\"attachment_2570\" aria-describedby=\"caption-attachment-2570\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2570\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/export\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg\" data-orig-size=\"549,57\" 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;1633185605&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=\"Exporting Our Database\" data-image-description=\"&lt;p&gt;Exporting Our Database&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Exporting Our Database&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg\" class=\"wp-image-2570\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg?resize=500%2C52&#038;ssl=1\" alt=\"Exporting Our Database\" width=\"500\" height=\"52\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg?resize=300%2C31&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/export.jpg?w=549&amp;ssl=1 549w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2570\" class=\"wp-caption-text\"><strong>Exporting Our Database<\/strong><\/figcaption><\/figure>\n<p>Here is the resulting text file:<\/p>\n<figure id=\"attachment_2571\" aria-describedby=\"caption-attachment-2571\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2571\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/exported\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg\" data-orig-size=\"1211,629\" 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;1633249761&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=\"Exported Data\" data-image-description=\"&lt;p&gt;Exported Data&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Exported Data&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported-1024x532.jpg\" class=\"wp-image-2571\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?resize=500%2C260&#038;ssl=1\" alt=\"Exported Data\" width=\"500\" height=\"260\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?resize=300%2C156&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?resize=1024%2C532&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?resize=768%2C399&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/exported.jpg?w=1211&amp;ssl=1 1211w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2571\" class=\"wp-caption-text\"><strong>Exported Data<\/strong><\/figcaption><\/figure>\n<p>This text file can be <em><strong>&#8220;imported&#8221;<\/strong><\/em> into another database if needed. That part is quite easy to implement and I am not detailing the code here.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Finally, we have to close the database:<\/p>\n<figure id=\"attachment_2572\" aria-describedby=\"caption-attachment-2572\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/close.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2572\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/10\/03\/using-sicstus-prolog-with-lmdb\/close\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/close.jpg\" data-orig-size=\"329,58\" 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;1633185692&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\/2021\/10\/close.jpg\" class=\"size-medium wp-image-2572\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/close.jpg?resize=300%2C53&#038;ssl=1\" alt=\"Closing the DB\" width=\"300\" height=\"53\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/close.jpg?resize=300%2C53&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/10\/close.jpg?w=329&amp;ssl=1 329w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-2572\" class=\"wp-caption-text\"><strong>Closing the DB<\/strong><\/figcaption><\/figure>\n<p>Well, that is it! Using the new <em><strong>LMDB<\/strong><\/em> library poses no surprises.<\/p>\n<p>Here is the <a href=\"http:\/\/www.rangakrish.com\/downloads\/LMDBExplorer.zip\" target=\"_blank\" rel=\"noopener\"><strong><em>ZIP file<\/em><\/strong><\/a>\u00a0that contains the source, sample data and the exported text file.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 (LMDB). The library interfaces are [&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,296,295,151],"class_list":["post-2553","post","type-post","status-publish","format-standard","hentry","category-programming","category-prolog","tag-berkeley-db","tag-lightning-memory-mapped-database-manager","tag-lmdb","tag-sicstus-prolog"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Fb","jetpack-related-posts":[{"id":1677,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/08\/18\/using-berkeley-db-with-sicstus-prolog\/","url_meta":{"origin":2553,"position":0},"title":"Using Berkeley DB with Sicstus Prolog","author":"admin","date":"August 18, 2019","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Iterating Over the DB","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/08\/iterate-db.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1025,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/08\/19\/sicstus-prolog-building-a-windows-executable\/","url_meta":{"origin":2553,"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":2553,"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":2553,"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":2366,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/03\/28\/implementing-ilexicon-using-litedb\/","url_meta":{"origin":2553,"position":4},"title":"Implementing iLexicon using LiteDB","author":"admin","date":"March 28, 2021","format":false,"excerpt":"iLexicon is an \"intelligent\" dictionary that can be used to build Natural Language applications. I have two implementations, one in Lisp and another in Prolog. Both implementations are memory-based, in order to speed up performance. I have written several articles referencing it, for example see this. \u00a0 LiteDB is a\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Sample Commands","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/03\/Session1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3260,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/11\/26\/generating-polynomials-in-prolog\/","url_meta":{"origin":2553,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2553","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=2553"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2553\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}