How to Manage Electronic Library Databases with Intellexer API

Continued from page 1

Beside e-libraries, this solution is often used by help desk and enterprise document/knowledge management systems.

To function correctly, the system should have a special database with an array of ready answers to possible questions made by users. This database must be relevant to the company/university that integrates this tool, and to the sphere the enterprise works in, which often creates a need for an in-house solution with an open API.

If you want to integrate this QAS into your e-library here’s a C++ example:

#include < iostream >
#include < Indexer.h >
#include < IndexManager.h >
#include < QPCore.h >
#include < LPXml.h >
#include < LRCore.h >

using std::cout;
using std::cerr;

using namespace NsSemSDK;

int main(int argc, char* argv[])
{
        try
        {
                char szDBPath[] = "../../LDB";    //path to ldb
                char szPluginsPath[] = "../../LPlugins";    //path to plugins
                char szProvider[] = "FBIndexDriver";        //path to data provider
                char szQuery[] = "What does the present invention relate to?"; //question
                int nAnswerCount = 0;

                // provide path to license file
                SetQPLicensePath("../../ISDK_License.xml");
                SetLPXMLLicensePath("../../ISDK_License.xml");
               
                // necessary to use indexer for creating database
                SetIndexerLicensePath("../../ISDK_License.xml");
                SetLanguageRecognizerLicensePath("../../ISDK_License.xml");

                // Create search index       
                // See IndexerSample-CPP sample for details       
                CInterfacePtr pIndex((IIndexManager *)CreateProvider("FBIndexDriver", "CreateIndexManager"));
                pIndex->Open("../Data/QAS/Index.FDB");
                pIndex->Clear();
                CInterfacePtr pDB(LoadIndexerDB(szDBPath, szPluginsPath));
                CInterfacePtr pIndexer(CreateIndexer(*pDB));
                const char* arDocs[] =
                {
                         "../Data/QAS/4,194,484.htm",
                         "../Data/QAS/6,812,981.htm",
                         "../Data/QAS/6,816,711.htm"
                };
                for (int i = 0; i < 3; ++i)
                {
                         CInterfacePtr piDoc;
                         pIndexer->Process(arDocs[i], &piDoc);
                         pIndex->AddDocument(piDoc.Get());
                }
                pIndex->Close();

                // ****** Search in index database *******

                pIndex->Open("../Data/QAS/Index.FDB");

                //Create  query processor database
                CInterfacePtr pQASLDB(CreateQueryLDB());
              
                //Create query processor interface
                CInterfacePtr pQAS(CreateQueryProcessor());
                IQueryResult* pResult = NULL;
               
                //Load query processor database
                pQASLDB->Setup(szDBPath, pDB->GetLPDB());
               
                //Initialize query processor with IQueryLDB* and IIndexDataProvider*
                pQAS->Setup(pQASLDB.Get(), pIndex.Get());
               
                //Process query
                pResult = pQAS->Process(szQuery);
                if (pResult != NULL)
                {
                        //Get answer count
                         nAnswerCount = pResult->GetAnswerCount();
                         //Get and print answers
                         for (int i = 0; i < nAnswerCount; i++)
                         {
                                  const IQueryAnswer* pAnswer = pResult->GetAnswer(i);
                                  int nAnswerSize = 0;
                                  const char* szAnswer = NULL;

                                  //Print relevance
                                  cout << pAnswer->GetRelevance() << "\t";
                                  //Get sentence info by id
                                  CInterfacePtr pSentInfoSet;
                                  const ISentenceInfo* pSentInfo;
                                  int nSentID = pAnswer->GetSentenceID();
                                  pIndex->GetSentencesInfo(1, &nSentID, &pSentInfoSet);
                                  pSentInfoSet->Reset();
                                  if (pSentInfoSet->Next(&pSentInfo))
                                  {
                                           cout << pSentInfo->GetPath() << "\t\t" << pSentInfo->GetText() << "\n\n";
                                  }
                         }
                }
                pIndex->Close();
        }
        catch (const CSemBaseException& x)
        {
                // Handle exceptions.
                cerr << x.what();
        }
        return 0;
}

4) Comparator is another semantic solution that can help manage e-library content. It allows finding similar and recommended books in the database and defining their similarity degree.

Using C/C++ and C# language it’s possible to add Intellexer Comparator to the needed system:

#include <iostream>
#include <Indexer.h>
#include <IndexManager.h>
#include <Comparator.h>
#include <ComparatorInt.h>
#include <LPXml.h>
#include <LRCore.h>

using std::cout;
using std::cerr;

using namespace NsSemSDK;

int main()
{
        try
        {
                // provide path to license file
                SetComparatorLicensePath("../../ISDK_License.xml");
                SetLPXMLLicensePath("../../ISDK_License.xml");
                SetLanguageRecognizerLicensePath("../../ISDK_License.xml");
               
                // Load indexer database that is required to create an instance of comparator.
                // It may be shared among several instances of comparator and indexer.
                CInterfacePtr<IIndexerDB> pDB(LoadIndexerDB("../../LDB", "../../LPlugins"));
               
                // Create comparator instance.
                CInterfacePtr<IComparator> pComparator(CreateComparator(*pDB));

                // Open document index using FireBird DB provider (FBIndexDriver).
                CInterfacePtr<IIndexManager> pIndex((IIndexManager *)CreateProvider("FBIndexDriver", "CreateIndexManager"));
                pIndex->Open("../Data/Indexer/Index.FDB");

                if (pIndex->GetDocumentCount() == 0) {
                         cout << "Please fill index with IndexerSample before using ComparatorSample";
                         return 0;
                }

                // Find similar documents in index.
                CInterfacePtr<IFindSimilarResults>
                pResults(pComparator->FindSimilar("../Data/Comparator/Test.htm", *pIndex));

                // Print search results.
                if (pResults != NULL)
                {
                         for (int i = 0, nCount = pResults->GetResultCount(); i < nCount; ++i)
                         {
                                  const FIND_SIMILAR_RESULT& result(pResults->GetResult(i));
                                  CInterfacePtr<IEnumDocumentInfo> pEnumDocumentsInfo;
                                  pIndex->GetDocumentsInfo(1, &result.nID, &pEnumDocumentsInfo);
                                  pEnumDocumentsInfo->Reset();
                                  const IDocumentInfo *pDocumentInfo;
                                  if (pEnumDocumentsInfo->Next(&pDocumentInfo))
                                  {
                                           cout << "Similarity between ../Data/Comparator/Test.htm and "
                                           << pDocumentInfo->GetPath() << " is " << (100 * result.dSimilarity) << "%\n";
                                  }
                         }
                }
        }
        catch (const CSemBaseException& x)
        {
                // Handle exceptions.
                cerr << x.what() << "\n";
        }
        return 0;
}

Thus, the above-mentioned tools can help information professionals manage the development and delivery of new e-library services  or improve the accuracy of their existing information management systems.

 

Comments (0)