Powerloom API

View: New views
10 Messages — Rating Filter:   Alert me  

Powerloom API

by Magnus Malm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello

I am looking into the API of PowerLoom, and I was just wondering if there's some examples of how to use it? Especially the s-* functions. How to create/delete concepts, objects, relations, etc. If there's no such examples available, perhaps someone could post one or two quick and simple ones to the mailinglist?

I'd appreciate any help.

Kind regards,
--
Magnus Malm
_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Thomas Russ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Oct 30, 2007, at 7:14 AM, Magnus Malm wrote:

> Hello
>
> I am looking into the API of PowerLoom, and I was just wondering if  
> there's some examples of how to use it? Especially the s-*  
> functions. How to create/delete concepts, objects, relations, etc.  
> If there's no such examples available, perhaps someone could post  
> one or two quick and simple ones to the mailinglist?

You didn't specify which language you were planning to use.

There is an example file for Java, which is on the documentation page  
of our web site:

   <http://www.isi.edu/isd/LOOM/PowerLoom/documentation/ 
PowerLoomExample.java>


_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Rera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thomas Russ ha scritto:

> On Oct 30, 2007, at 7:14 AM, Magnus Malm wrote:
>
>  
>> Hello
>>
>> I am looking into the API of PowerLoom, and I was just wondering if  
>> there's some examples of how to use it? Especially the s-*  
>> functions. How to create/delete concepts, objects, relations, etc.  
>> If there's no such examples available, perhaps someone could post  
>> one or two quick and simple ones to the mailinglist?
>>    
>
> You didn't specify which language you were planning to use.
>
>  
I need to use C++ for my thesis on home automation
> There is an example file for Java, which is on the documentation page  
> of our web site:
>
>    <http://www.isi.edu/isd/LOOM/PowerLoom/documentation/ 
> PowerLoomExample.java>
>
>
>  
The manual hasn't any documentation on C++ API. There are some examples?
_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Magnus Malm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2007/10/30, Thomas Russ <tar@...>:

You didn't specify which language you were planning to use.

I am using Common Lisp.

There is an example file for Java, which is on the documentation page
of our web site:

   <http://www.isi.edu/isd/LOOM/PowerLoom/documentation/
PowerLoomExample.java>

Hmm, the PowerLoom website seems to be down. I can ping the server but when I try to browse it, nothing happens. No response at all, it just sits there trying to connect... Anyone else who's having the same problem?
 
Regards,
--
Magnus Malm
_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Thomas Russ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Oct 31, 2007, at 3:04 AM, Andrea Poli wrote:

> Thomas Russ ha scritto:
>> On Oct 30, 2007, at 7:14 AM, Magnus Malm wrote:
>>
>>
>>> Hello
>>>
>>> I am looking into the API of PowerLoom, and I was just wondering if
>>> there's some examples of how to use it? Especially the s-*
>>> functions. How to create/delete concepts, objects, relations, etc.
>>> If there's no such examples available, perhaps someone could post
>>> one or two quick and simple ones to the mailinglist?
>>>
>>
>> You didn't specify which language you were planning to use.
>>
>>
> I need to use C++ for my thesis on home automation
>> There is an example file for Java, which is on the documentation page
>> of our web site:
>>
>>    <http://www.isi.edu/isd/LOOM/PowerLoom/documentation/
>> PowerLoomExample.java>
>>
>>
>>
> The manual hasn't any documentation on C++ API. There are some  
> examples?

We don't really have any specific C++ examples, since we haven't  
programmed directly using that language.  When we use the C++ version  
of PowerLoom, we have always done that through the Stella programming  
language and had the resulting C++ code generated for us.

What you can do, however, is use the command "cpptrans" in the  
PowerLoom listener to translate and print Stella constructs in their C
++ form.  That will allow you to see how constructs from the  
reference manual will look.  There are also analogous commands for  
java "jptrans" and lisp "ptrans".  The name is short for "print  
translation".

For example:

PL-USER |= (cpptrans (pli/get-concept "RELATION" null null))

pli::getConcept("RELATION", NULL, NULL)

PL-USER |= (cpptrans (pli/s-retrieve "all (concept ?y" null null))

pli::sRetrieve("all (concept ?y", NULL, NULL)

The main difference between the C++ examples and the Java code is  
that C++ uses namespaces corresponding to the PowerLoom modules, in  
contrast to Java and Lisp which uses their native packages.  For  
lisp, the pli functions are in the PLI package.  All others are in  
the STELLA package.

The other difference in C++ compared to Java, is that objects are  
referred to using pointers.

PL-USER |= (cpptrans (let ((c (pli/get-concept "CONCEPT" null null))
                            (it (pli/get-concept-instances c null  
null)))
                        (print it)))

{ LogicObject* c = pli::getConcept("CONCEPT", NULL, NULL);
   pli::PlIterator* it = pli::getConceptInstances(c, NULL, NULL);

   std::cout << it;
}

The naming convention transformations for C++ are the same as Java,  
except that the "*" character is translated to "o" instead of "$".





_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Rera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thomas Russ wrote:
On Oct 31, 2007, at 3:04 AM, Andrea Poli wrote:

> Thomas Russ ha scritto:
>> On Oct 30, 2007, at 7:14 AM, Magnus Malm wrote:
>>
>>
>>> Hello
>>>
>>> I am looking into the API of PowerLoom, and I was just wondering if
>>> there's some examples of how to use it? Especially the s-*
>>> functions. How to create/delete concepts, objects, relations, etc.
>>> If there's no such examples available, perhaps someone could post
>>> one or two quick and simple ones to the mailinglist?
>>>
>>
>> You didn't specify which language you were planning to use.
>>
>>
> I need to use C++ for my thesis on home automation
>> There is an example file for Java, which is on the documentation page
>> of our web site:
>>
>>    <http://www.isi.edu/isd/LOOM/PowerLoom/documentation/
>> PowerLoomExample.java>
>>
>>
>>
> The manual hasn't any documentation on C++ API. There are some  
> examples?

We don't really have any specific C++ examples, since we haven't  
programmed directly using that language.  When we use the C++ version  
of PowerLoom, we have always done that through the Stella programming  
language and had the resulting C++ code generated for us.

What you can do, however, is use the command "cpptrans" in the  
PowerLoom listener to translate and print Stella constructs in their C
++ form.  That will allow you to see how constructs from the  
reference manual will look.  There are also analogous commands for  
java "jptrans" and lisp "ptrans".  The name is short for "print  
translation".

For example:

PL-USER |= (cpptrans (pli/get-concept "RELATION" null null))

pli::getConcept("RELATION", NULL, NULL)

PL-USER |= (cpptrans (pli/s-retrieve "all (concept ?y" null null))

pli::sRetrieve("all (concept ?y", NULL, NULL)

The main difference between the C++ examples and the Java code is  
that C++ uses namespaces corresponding to the PowerLoom modules, in  
contrast to Java and Lisp which uses their native packages.  For  
lisp, the pli functions are in the PLI package.  All others are in  
the STELLA package.

The other difference in C++ compared to Java, is that objects are  
referred to using pointers.

PL-USER |= (cpptrans (let ((c (pli/get-concept "CONCEPT" null null))
                            (it (pli/get-concept-instances c null  
null)))
                        (print it)))

{ LogicObject* c = pli::getConcept("CONCEPT", NULL, NULL);
   pli::PlIterator* it = pli::getConceptInstances(c, NULL, NULL);

   std::cout << it;
}

The naming convention transformations for C++ are the same as Java,  
except that the "*" character is translated to "o" instead of "$".





_______________________________________________
powerloom-forum mailing list
powerloom-forum@isi.edu
http://mailman.isi.edu/mailman/listinfo/powerloom-forum
Be patient with me, I'm an absolute beginners in programming (with C++).
What I need to load in my own code to use PowerLoom C++ functions?
Which files have I to include?
Thanks

Re: Powerloom API

by Thomas Russ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Dec 10, 2007, at 6:43 AM, Rera wrote:

> Be patient with me, I'm an absolute beginners in programming (with C
> ++).
> What I need to load in my own code to use PowerLoom C++ functions?
> Which files have I to include?

Well, if you are an absolute beginner with C++, then I would  
recommend that you use the Java version of PowerLoom and do your  
programming in Java.  The interfacing methods and general programming  
will be a lot easier.

The PowerLoom developers do not develop directly in C++.  When we use  
C++, we do it through the use of our Stella language instead, so that  
makes things a bit tricky to describe the method manually, since I  
don't actually do anything that way.

A basic outline would be that you will need to make sure that you  
have the proper pathways set up for include files as well as  
libraries.  Note also that PowerLoom depends on use of the Boehm GC  
code for C++ (included with the Stella component).  For some idea of  
what those would need to look like, you can examine the Makefile that  
comes in the PowerLoom distribution.  It is quite complicated, but if  
you want to do your development in C++ you will need to be able to  
understand things along that line.  Since we don't actually develop  
using the C++ translation of our code, we don't have any instructions  
on how to set up an IDE to work with the code.

Some of the flags and settings are OS-specific.  Look for them in the  
Makefile.  As a starter, you can run make in the native/cpp/powerloom  
directory and examine the form of the compiler calls.  You will need  
to mimic that when creating the code that you will want to run.

Sorry I can't be of more help, but we just don't have instructions  
for what you want to do.

That's why I suggest going with Java.  The setup is much simpler with  
only the need to include the PowerLoom.jar file in the classpath.



_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Hans Chalupsky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrea,

to be able to call PowerLoom and STELLA functions in your code,
include the file powerloom-system.hh which will include all other
necessary files (the file lives in powerloom/native/cpp/powerloom/).
Use -Ipowerloom/native/cpp in your C++ compilation (adjust the path to
your installation directory) so that it will find all the include files.

Then there are two ways to interface your C++ code with PowerLoom:

(1) Have PowerLoom be the main application shell and add your own
extensions to it.  To do that you'd have to edit main.c in
powerloom/native/cpp/powerloom/ to include/call your code and edit the
Makefile in the same directory to link with your extension
files/libraries.

(2) Treat PowerLoom as a library and link it with your C++
application.  To do that first build the C++ version of PowerLoom (see
the manual - basically type `make' in the
powerloom/native/cpp/powerloom directory) which will build the various
PowerLoom libraries such as stella.so, logic.so, etc.  Then link your
C++ application with the libraries built (look at the final link step
when `make'ing PowerLoom which will show you which of these libraries
you'll need to link with your application; use the switch
-Lpowerloom/native/cpp/lib to tell the compiler where all the
libraries live).

Hope that does the trick.  All of this assumes a Unix-based
environment such as Linux or MinGW/Cygwin under Windows.

Hans

>>>>> Thomas Russ <tar@...> writes:

> On Dec 10, 2007, at 6:43 AM, Rera wrote:

>> Be patient with me, I'm an absolute beginners in programming (with C
>> ++).
>> What I need to load in my own code to use PowerLoom C++ functions?
>> Which files have I to include?

> Well, if you are an absolute beginner with C++, then I would  
> recommend that you use the Java version of PowerLoom and do your  
> programming in Java.  The interfacing methods and general programming  
> will be a lot easier.

> The PowerLoom developers do not develop directly in C++.  When we use  
> C++, we do it through the use of our Stella language instead, so that  
> makes things a bit tricky to describe the method manually, since I  
> don't actually do anything that way.

> A basic outline would be that you will need to make sure that you  
> have the proper pathways set up for include files as well as  
> libraries.  Note also that PowerLoom depends on use of the Boehm GC  
> code for C++ (included with the Stella component).  For some idea of  
> what those would need to look like, you can examine the Makefile that  
> comes in the PowerLoom distribution.  It is quite complicated, but if  
> you want to do your development in C++ you will need to be able to  
> understand things along that line.  Since we don't actually develop  
> using the C++ translation of our code, we don't have any instructions  
> on how to set up an IDE to work with the code.

> Some of the flags and settings are OS-specific.  Look for them in the  
> Makefile.  As a starter, you can run make in the native/cpp/powerloom  
> directory and examine the form of the compiler calls.  You will need  
> to mimic that when creating the code that you will want to run.

> Sorry I can't be of more help, but we just don't have instructions  
> for what you want to do.

> That's why I suggest going with Java.  The setup is much simpler with  
> only the need to include the PowerLoom.jar file in the classpath.



> _______________________________________________
> powerloom-forum mailing list
> powerloom-forum@...
> http://mailman.isi.edu/mailman/listinfo/powerloom-forum
_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum

Re: Powerloom API

by Rera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hans Chalupsky wrote:
Andrea,

to be able to call PowerLoom and STELLA functions in your code,
include the file powerloom-system.hh which will include all other
necessary files (the file lives in powerloom/native/cpp/powerloom/).
Use -Ipowerloom/native/cpp in your C++ compilation (adjust the path to
your installation directory) so that it will find all the include files.

Then there are two ways to interface your C++ code with PowerLoom:

(1) Have PowerLoom be the main application shell and add your own
extensions to it.  To do that you'd have to edit main.c in
powerloom/native/cpp/powerloom/ to include/call your code and edit the
Makefile in the same directory to link with your extension
files/libraries.

(2) Treat PowerLoom as a library and link it with your C++
application.  To do that first build the C++ version of PowerLoom (see
the manual - basically type `make' in the
powerloom/native/cpp/powerloom directory) which will build the various
PowerLoom libraries such as stella.so, logic.so, etc.  Then link your
C++ application with the libraries built (look at the final link step
when `make'ing PowerLoom which will show you which of these libraries
you'll need to link with your application; use the switch
-Lpowerloom/native/cpp/lib to tell the compiler where all the
libraries live).

Hope that does the trick.  All of this assumes a Unix-based
environment such as Linux or MinGW/Cygwin under Windows.

Hans
Thanks very much. You have been really useful to me.
I had already seen that powerloom-system.hh includes other files including other files etc.
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?

Re: Powerloom API

by Thomas Russ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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 ;
}



_______________________________________________
powerloom-forum mailing list
powerloom-forum@...
http://mailman.isi.edu/mailman/listinfo/powerloom-forum
LightInTheBox - Buy quality products at wholesale price