Re: [Flora-development] XSB and Flora-2 wrappers for .NET and Python
Brought to you by:
kifer
From: Markus S. <msc...@fo...> - 2007-01-18 00:30:16
|
Dear Michael, I'll try to coordinate with Goncalo (seems he run into the same problem I did). BTW. here's my code: http://arka.foi.hr/~mschatten/xsb/XSB.NET.v.0.01.zip I didn't try the code with Mono just on MSVS.NET but if Gonzalo and me are able to coordinate I'll surely try to make it work with Mono. Regarding the Python interface here some basic ideas on how to use Logic Programming concepts in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303057 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360698 My idea is to extend these recipes with F-logic and OO (e.g. use Python objects as facts, Python objects with some logical variables as their attributes for queries and rule heads and bodies). Python has very nice fetaures which let you query the internal structure of an object. In this manner its straight forward to map Python objects to F-molecules and use them in the Flora-2 engine. I've written a paper about this concept (for now only in croatian). As soon as I finish this inteface I'll probably publish it on some conference. For example lets say we have a python class like: class example: def __init__( self, a=1, b=[1,2,3] ): self.a = a self.b = b def some_func( self ): print "Hello from example" to create an instance we use: ex = example() now the power of Python lies in: >>> dir(ex) ['__doc__', '__init__', '__module__', 'a', 'b', 'some_func'] >>> ex.__dict__ {'a': 1, 'b': [1, 2, 3]} >>> So we can query the internal structure of the 'ex' object. An algorithm I allmost finished tries to translate Python objects into F-molecules. Basicly I want it to be ex:example[ a->1, b:list->[1,2,3] ]. for now since I'm not 100% clear with the idea of using the object's methods at all or not. I was thinking of using boolean methods as descibed in the manual to have a reference in Flora-2 that a method for a given object exists, but I'm still not sure if it would be of any use. To go further with the concept if we have an object like described before and use logical variables like described in the recipes then we can do the following: X = Variable() qu = example( X, [1, 2, 3] ) so we would have a mapping to a F-molecule like qu:example[ a->X, b:list->[1, 2, 3] ] Now by using the concept of rules as described in the recipe we could say: qu << [ ex, [X, 2, 3] ] No real sense in the rule but I hope you understand the Idea. This could then be translated to Flora-2 like: qu:example[ a->X, b:list->[1, 2, 3] ] :- ex:example[ a->1, b:list->[1, 2, 3], [X, 2, 3]. So you could basicly use the Flora-2 engine to store data objects from Python applications and then using the concept of rules and logic variables query this objects. I also tought of making the data consisent using ZODB which allows easily to store Python objects. There's also an idea to make it network ready (e.g. to make it possible to run as a knowledge base server which any python program can use over the network using Python NetWork Spaces). But this is still a little idea in my head ;-) As soon as I have a little bit more usable version of the Python interface I'll let you know. If you have any comments, suggestions, critiques etc. they are very wellcome since I'm not 100% sure that I'm doing thigs right ;-) Best regards -- Markus Schatten, dipl. inf. e-mail: mar...@fo... http://www.tiaktiv.hr On Wed, 17 Jan 2007, Michael Kifer wrote: > > Hi Markus, > > It looks very promising. I think it is best if you could coordinate > with Goncalo on the xsb.dll wrapper. >> From what he described, it looks like he is using the same model as the > Interprolog's Java interface, which is very convenient. > > Regarding Python, it all looks very interesting. I would like to see a more > detailed description of how rules can be used from within > Python. Unfortunately, I am Python-illiterate right now, but would like to > learn. > > You probably know that we now have a high-level interface from Java to > Flora where one can create Java proxy objects for Flora objects and then > manipulate them from within Java through get/set style methods. > This is far from seamless, so I would like to learn more on your design. > > Does your code work with Linux through Mono? > > > best regards > --michael > > >> Dear Michael >> >> I'm fully dedicated to OpenSource and have allready added LGPL headers to= >> >> my source, so thats no problem. The wrapper is a .NET class library which= >> >> exports allmost all functions which are exported in xsb.dll (xsb_query,=20 >> xsb_init, is_functor etc.). I have also included some examples for using=20 >> the wrapper in VB.NET, C#.NET (using a simple Prolog program and a simple >> >> Flora-2 knowledge base). So it's just an export of the functions provided >> >> in xsb.dll (and since Flora-2 uses=20 >> asserta(library_directory('C:\Flora2\dir')). and [flora2].=20 >> bootrstrap_flora. I used xsb_command_string and xsb_query_string to load >> Flora-2). So far for the .NET wrapper. The Python wrapper I'm now working >> >> on should make it more intuitive for Python programmers to use Flora-2 as >> >> a knowledge base engine (e.g. translation of Python objects directly into >> Flora-2 F-molecules, using of queries and rules inside Python etc.) If you >> want to take a look at the code be it for the .NET wrapper or for the >> Python interface (done so far) just tell me where to send it :-) >> >> Best regards >> >> -- >> Markus Schatten, dipl. inf. >> e-mail: mar...@fo... >> http://www.tiaktiv.hr >> >> >> On Tue, 16 Jan 2007, Michael Kifer wrote: >> >>> >>> Dear Markus, >>> Thank you very much for the contribution. >>> To be included in either XSB or Flora-2, your files have to be released >>> under LGPL. >>> >>> I didn't quite understand what the wrapper around xsb.dll does. >>> Is it exporting things like xsb_query to .NET languages >>> (in this case it should be really part of XSB)? >>> >>> Or is it an object-oriented interface, which can talk to Flora-2 directly= >> ? >>> You alluded to this in connection with the Python wrapper, which is very >>> interesting. >>> >>> >>> =09regards >>> =09 --michael >>> >>>> Dear sirs, >>>> >>>> my name is Markus Schatten, I'm an assistant on the Faculty of Organizat= >> ion >>>> and Informatics in Vara=C5=BEdin, Croatia in Databases and Formal Metho= >> ds. One of >>>> my professors (dr.sc. Mirko =C4?ubrilo) asked me to develop a XSB and F= >> lora-2 >>>> dll-wrapper for MS Visual Studio.NET, which I have developed using the >>>> C-binding of XSB. I'm not a .NET professional so there are probably some= >> bugs >>>> in the solution, but it works fine, and since I'm not sure if I will hav= >> e >>>> time to develop it further I'd like to contribute it to your projects, o= >> f >>>> course if there is interest in such a contribution. >>>> I've created a C# class which wraps around the xsb.dll and makes allmost= >> all >>>> functions exported in the dll available to all other .NET languages. I'v= >> e >>>> also implemented two methods for converting prolog terms to strings and >>>> printing of terms (allmost direct translation of printpterm in cmain2.c)= >> =2E >>>> Since my primary programming language is Python I also created a wrapper= >> for >>>> Python (using SWIG http://www.swig.org) which could be used to wrap XSB = >> and >>>> Flora-2 to all the other scripting languages supported by SWIG. The Pyth= >> on >>>> wrapper is not fully implemented by now since I'd like to make the inter= >> face >>>> more intuitive to Python programmers and will probably try to combine th= >> e >>>> power of Flora-2 and ZODB (http://www.zope.org/Products/ZODB3.3). >>>> So if there's any interest I'll be very happy if I can contribute to you= >> r >>>> projects. >>>> >>>> Best regards >>>> >>>> -- >>>> Markus Schatten, dipl. inf. >>>> Faculty of Organization and Informatics >>>> Vara=C5=BEdin, Croatia >>>> e-mail: mar...@fo... >>>> http://www.foi.hr >>>> >>>> ------------------------------------------------------------------------= >> - >>>> Take Surveys. Earn Cash. Influence the Future of IT >>>> Join SourceForge.net's Techsay panel and you'll get the chance to share = >> your >>>> opinions on IT & business topics through brief surveys - and earn cash >>>> http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID= >> =3DDEVDEV >>>> _______________________________________________ >>>> Flora-development mailing list >>>> Flo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/flora-development > |