Search Mailing List Archives
[protege-discussion] beanshell scripting in protege
Jonathan Carter
jonathan.carter at e-asolutions.com
Thu Nov 13 02:52:02 PST 2008
Hi Jason.
Comments in-line
Regards
Jonathan
__________________________________________
Jonathan Carter - Head of Technical Architecture
Enterprise Architecture Solutions Ltd
__________________________________________
Assess your EA maturity at:
www.enterprise-architecture.com/EAvaluator
__________________________________________
On 12 Nov 2008, at 21:16, Jason Sachs wrote:
> Hmmm, I am trying to figure out where to get info on beanshell
> bindings for protege. I'm vaguely familiar with Java & can figure
> the pure-language stuff out from appropriate references. But I'm
> stuck trying to figure out:
>
> 1) how I load an external script (so i don't have to type in the
> damn thing again over and over... it would be Real Nice to be able
> to put frequently-used scripts in a combo box or something so
> they're easy to select in a few clicks)
Save your script to a simple text file.
Use the command: execfile("<path to your script file>") at the prompt
and it will load the file and run the script. Works a treat. Check out
Olivier's wiki pages for how to use this.
Note that Unix shell style command history is available (cursor up),
too.
This approach works well for me and you can execfile() other files
from within a script file. So, you can build libraries of frequently
used functions.
>
> 2) how do I import an external class if I write one
Again, see Olivier's wiki pages. However the basic principle is to use
the from <package> import <class> commands.
I have found what I think is a bug in the BeanScripting stuff - not
the Script Tab, which means that the sys.path.append() commands to
update the classpath don't seem to work on Windows for some reason.
Works a treat on my OSX machine.
You need this if you want to import classes that are not in the core
Protege class library. The root directory for specifying the classpath
to add is the Protege root directory. However, as I said, I couldn't
get this to work properly on Windows.
>
> 3) which variables are already exposed (I found a webpage that
> refers to "kb" and "kb.getNamedCls()")
All you need is kb and the things that are documented on the Script
Tab wiki pages. From kb you can get to everything. I have scripts that
manipulate the Instances, the Clses, the Project itself (e.g. script
an Archive) and the Forms.
>
> 4) anything else that's simple but non-obvious that wouldn't be in
> the Protege Java class hierarchy (which i can't find at the moment,
> i found it earlier... argh....)
Depends what you want to do. As I say with some experimentation - and
the interactive script tab is good for this - I have managed to script
updates to everything in my project. The source of all information is
the Java API Javadoc and when it's not clear what the classes/methods
will do, I find that the source code for Protege is very helpful.
Let me know what things you need some help with - I may have already
done something similar.
>
>
> p.s. a request: Javascript/Rhino is in the list of languages in the
> Apache BSF page (http://jakarta.apache.org/bsf/index.html); it would
> be nice to add it to the Protege scripting tab.
Again, check out the wiki for the Protege Script Tab. It describes the
process of adding your own script language. Haven't tried it but
having looked at the source code for the Tab, it should be pretty
straight-forward, provided that that BSF version supports the language .
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20081113/8105d4fa/attachment.html>
More information about the protege-discussion
mailing list