Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-discussion] getSlotWidget(slot)

Tania Tudorache tudorache at stanford.edu
Fri Oct 5 18:02:57 PDT 2007


I can tell you how to do it, if you won't tell anybody about it :)

Short story: Protege stores all the forms information in an internal 
knowledge base (the pprj file is a pins file, actually) and you can 
directly access the internal project knowledge base. The following code 
will print out for each class its customized slot widgets and the name 
of the java class of the slot widgets.

Please do not modify anything directly in the pprj file, because Protege 
will get confused. It is better to use the existing APIs, if you want to 
modify the forms.

Enjoy :)
Tania


     private static final String SLOT_PROPERTY_LIST = "property_list";
     private static final String SLOT_CUSTOMIZED_INSTANCE_WIDGETS = 
"customized_instance_widgets";   
       
    private void test95() {       
        Project prj = kb.getProject();
       
        KnowledgeBase internalKB = prj.getInternalProjectKnowledgeBase();
       
        Slot propertyListSlot = internalKB.getSlot(SLOT_PROPERTY_LIST);
        Slot customizedWidgetsSlot = 
internalKB.getSlot(SLOT_CUSTOMIZED_INSTANCE_WIDGETS);
       
        Instance prjInstance = prj.getProjectInstance();
        Collection<Instance> customizedWidegts = 
prjInstance.getOwnSlotValues(customizedWidgetsSlot);
       
        for (Instance widgetInstance : customizedWidegts) {           
            WidgetDescriptor d = WidgetDescriptor.create(widgetInstance);
            String clsName = d.getName();
            System.out.println(clsName + " has customized widgets: ");
            if (d != null) {
                if 
(d.getWidgetClassName().equals(FormWidget.class.getName())) {
                    Collection<Instance> pl = 
widgetInstance.getOwnSlotValues(propertyListSlot);
                    if (pl != null) {
                        for (Instance propertyListInst : pl) {
                            PropertyList propertyList = new 
PropertyList(propertyListInst);
                            Collection<WidgetDescriptor> 
widgetDescriptors = propertyList.getLiveWidgetDescriptors();
                            for (WidgetDescriptor wd : widgetDescriptors) {
                                String slotName = wd.getName();
                                String widgetJavaClassName = 
wd.getWidgetClassName();
                               
                                System.out.println("\t" + slotName + "   
--->   " + widgetJavaClassName);
                               
                            }                           
                        }
                    }
                }
            }
        }
       
    }


Neil Douglas Matatall wrote:
> Dear List,
>
> Short Version of my question:
>
>   is there a way to call getSlotWidget(slot) without creating a 
> ClsWidget?  Even better would be slot.getSlotWidget().  Is there a 
> way to do this?
>
>
> Long Version:
>
> I have written a SlotPlugin and I'm trying to find a way to find all 
> slots that use that plugin during one of the hooks in my 
> ProjectPlugin.  So far the only way I have accomplished this is with 
> the strategy from 
> http://protegewiki.stanford.edu/index.php/Working_with_the_graph_widget
>
>          Project p = slot.getProject();
>          p.getKnowledgeBase().getSlots();
>          if (this.cachedSlots.containsKey(slot.getName())) {
>              return true;
>          }
>
>          ClsWidget valueType = p.createRuntimeClsWidget(instance);
>          SlotWidget slotWidget = valueType.getSlotWidget(slot);
>          if ("MyPluginField".equals(slotWidget.getName())) {
>              this.cachedSlots.put(slot.getName(), slot);
>              return true;
>          }
>
>          return false;
>
>
> This does work, but the problem is that I'm iterating over every 
> single instance in my ontology, creating a runtime ClsWidget each 
> time.  This either takes too long or causes an OutOfMemory exception 
> and is just a bad idea in general.
>
> Ideally, I want to just get all the slots and determine which ones 
> use my SlotWidget without needing to construct a runtime widget (i.e. 
> using the slot only).  That way I can interate over the Clses, 
> determine if the Cls contains one of the slots in question, and then 
> perform individual operations on the SlotValues if necessary.  This 
> way, the chances of taking a noticeable performance hit / running out 
> of memory would be pretty low.
>
>
>
> Thanks in advance,
> Neil Matatall
>
> _______________________________________________
> 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 
>
>   




More information about the protege-discussion mailing list