Protégé Script Console (Python) question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Protégé Script Console (Python) question

Roman Bischoff-2
Hi

(this time with correct "subject:" ...)

After a long Protégé abstinence, I'm again using it (version 3.1 Build 214).
I need to tweak an old ontology. Therefore I want to use the Script Console
with Python code. Basicallly I want to add some information (like ID,
creation date, export_flag, ISO language code) to each instance, so that
this information is exported through XMLtab as well.

I'd like to do sth. like this:

for mycls in kb.getCls("ExampleClass").getDirectSubclasses():
    for spa in mycls.getDirectInstances():
        "depending on the content of field 'description', the slot value
iso_lang_code should be set ( e.g., to 'deu' ")


-->How can I list the slots of a given instance?
-->How can I set the slot value of a given instance and slot?

I've quickly checked the old JOT tutorial and presentation and
ProtegeScriptTabRepositoryPython Wiki page, but couldn't find a list of the
available functions. Do I need to consult the Protégé Java API doc?


Furthermore, my "Script Console" (Python) hangs from time to time. Is this
normal?

Regards,

Roman

-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html

Reply | Threaded
Open this post in threaded view
|

Re: Protégé Script Console (Python) question

Olivier Dameron

On Wed, 7 Jun 2006 23:04:13 +0200, "Roman Bischoff"
<[hidden email]> wrote:

> for mycls in kb.getCls("ExampleClass").getDirectSubclasses():
>     for spa in mycls.getDirectInstances():
>         "depending on the content of field 'description', the slot
> value iso_lang_code should be set ( e.g., to 'deu' ")

(maybe off-topic)
The code above only retrieves the direct instances of the direct
subclasses of ExampleClass. Therefore, instances of the subclasses of a
subclass of ExampleClass are not found. You should probably use the
getSubclasses() method. But then fortunately, the method getInstances()
retrieves all the direct and indirect instances of a class, so you
may not even need to bother with getSubclasses() (if i got you right):

for currentInstance in kb.getCls("ExampleClass").getInstances():
    # do whatever you like with currentInstance

> -->How can I list the slots of a given instance?

check out the methods of the Instance interface

> -->How can I set the slot value of a given instance and slot?

addOwnSlotValue(...) or setOwnSlotValue(...)

> I've quickly checked the old JOT tutorial and presentation and
> ProtegeScriptTabRepositoryPython Wiki page, but couldn't find a list
> of the available functions. Do I need to consult the Protégé Java API
> doc?

Yes, the script console doesn't provide ontology-manipulations by
itself. All it does is providing on-the-fly access to the protégé API.

> Furthermore, my "Script Console" (Python) hangs from time to time. Is
> this normal?

Definitely not :-)
You may experience some delay when you launch Protégé from a
new directory and when the system needs to create the cache directory
where it stores informations about the available python modules.

Or is it freezing completely ?

I hope this helps,
Olivier
-------------------------------------------------------------------------
To unsubscribe go to http://protege.stanford.edu/community/subscribe.html