Implementing iLexicon using LiteDB

Written by on March 28, 2021 in Natural Language Processing, Programming, Prolog with 0 Comments

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.  

LiteDB is a NoSQL database for .NET. I wrote about it a few weeks ago. Since that time, I have been working on implementing ILexicon using LiteDB as the back-end. That is almost complete. The primary reason for moving iLexicon to LiteDB is that I can now access the lexicon from both Lisp and Prolog through the respective COM/Automation modules.

In today’s article, I will show the primary COM Server interface and how it is used from Sicstus Prolog. iLexicon is quite feature-rich and it is difficult to demonstrate its capabilities in a single article. You may want to see my other posts related to this.

Here is the COM Server layer, written in C#.

COM Server

COM Server

The above exposes two functions:

  • hasPOS(Word, POS) checks if the given word has the indicated POS (remember, a word can have many parts of speech)
  • hasLemma(Word, Lemma) checks if the given word has the indicated Lemma

The second functionality is often used when implementing an ATN-based (semantic) parser for English.

Here is the Prolog code that interfaces with the lexicon:

The Prolog Interface

The Prolog Interface

I think the mapping is self-explanatory.

The following commands show how this can be used:

Sample Commands

Sample Commands

To take this further, here is a toy grammar for English written in Definite Clause Grammar (DCG) notation:

A Toy English Grammar

A Toy English Grammar

The has_pos predicate is used to check the part-of-speech of the in-coming word. Here are some example sentences parsed using the grammar (I am skipping tokenization, structure building, etc.):

Parsing Using the Grammar

Parsing Using the Grammar

I used Visual Studio 2019 Release 16.9.2 for building the 64-bit COM server. In an earlier article, I have explained how to build the COM server in C#.

Have a nice weekend! 

Tags: , , , , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top