New CWM extension

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

New CWM extension

Hi, I have built a little cwm extension that creates built-ins on the fly.

When a URI like <python://mymodule#myfunction> is found in a rule,
it imports the module and uses the function as a built-in.


     :c :input ("All these worlds are yours except europa") .

     {?x :input (?y).
         ?z1b <python://#unicode.upper> (?y) .
         ?z2 <python://#unicode.rsplit> ( ?z1b " " 2 ) .
         ?x :output ?z2.
     }. --think --data teste.n3

      @prefix : <#> .

     :c     :input  (
         "All these worlds are yours except europa" );
          :output  (
         "EUROPA" ) .

The equivalent python code would be y.upper.rsplit(" ", 2)

Another example, a little more useful, would be to put a custom function
in a file, like
and use that function as a built-in:

     import subprocess
     def callExt(arglist):


     @prefix teste: <python://teste#>.
     :d :input ().
     {?x :input ().
         ?z1 teste:callExt (("ls" "-l" "../")) .
         ?x :output ?z1.
     }. --think --data teste.n3

      @prefix : <#> .

     :d     :input ();
          :output """total 16
drwxrwxr-x  2 atila.alr atila.alr  4096 Mai  9 08:52 CVS
drwxrwxr-x 26 atila.alr atila.alr 12288 Mai 17 17:54 swap
""" .

To "install" the extension, it should suffice to put in the folder.
Then, to use it, call like you would call cwm.
Internally, all the extension does is to monkeypatch an internal
function (so it understand "python://" URI)
and then pass the ball to cwm.

Sure, the idea of call any function is not very
production-security-friendly, but it may come handy in a controlled

The code is at

If anyone like it, let me know.