Re: Powerloom API

Thomas Russ <[email protected]> Tue, 11 Dec 2007 15:32:40 -0800
Newsgroups gmane.comp.ai.powerloom
Message-ID <[email protected]>
On Dec 11, 2007, at 2:38 PM, Rera wrote:
>
> Now I'm trying to understand which functions correspond to basic  
> PowerLom
> commands like defconcept, defrelation etc. I think they're all in
> logic-inn.hh, aren't they?


The most convenient way to use PowerLoom from a program is to use the  
PowerLoom API functions.  They are described (abstractly) in the  
manual.  In C++ they are in the pli:: namespace, using names similar  
to the Java names (which you can find in the manual).

Generally the simplest interface methods are those that start with  
"s" ("S-") in the manual, since they take string arguments instead of  
requiring you to construct and use PowerLoom or Stella objects.   
Although you can create concepts and relations using those API  
functions, in most cases you will find it more convenient to create  
the PowerLoom KB using a text editor to make a PowerLoom file  
containing the (defconcept ...), (defrelation ...)  (assert ...)  
forms and then load that before using the code.

Then you can use the PLI functions to make assertions and ask queries  
(with 5-valued truth value answers) and retrieve matching tuples from  
the knowledge base.

Some examples of what that might look like are the following.  They  
assume that you are using stella:: as the default namespace.

pli::load("pl:kbs;business.plm", NULL)

TruthValue* tv = pli::sAsk("(company megasoft)", "BUSINESS", NULL);
boolean answer = pli::isTrue(tv);

pli::PlIterator* tuples = pli::sRetrieve("all (and (company ?c)  
(company-name ?c ?name))", "BUSINESS", NULL);


Module* module = pli::getModule("BUSINESS", NULL);
pli::PlIterator* tuples = pli::sRetrieve("all (and (company ?c)  
(company-name ?c ?name))", "BUSINESS", NULL);
Object* item = NULL;
for (item, tuples; tuples->nextP(); ) {
    item = tuples->value;
    std::cout << pli::getNthValue(item, 0, module, NULL) <<  
pli::getNthString(item, 1, module, NULL) << std::endl ;
}