Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Slot Widgets

228 views

Published on

For four years in the late 1990's and early 2000's I worked at Stanford University’s Section on Medical Informatics doing research in Artificial Intelligence. I was one of the primary architects on the Protege project (an open-sourced knowledge representation system) and spent quite a bit of time thinking about how to represent knowledge, the logical structure of knowledge, how to define constraints on information, and how to classify algorithms (a.k.a. “problem-solving methods”).

This talk, from 2001, describes the "slot widget" architecture that enabled other knowledge representation labs around the world to extend Protege.

Published in: Data & Analytics
  • Be the first to comment

  • Be the first to like this

Slot Widgets

  1. 1. 1 The Awesome Power of (Slot) Widgets Unleashed William Grosso Stanford Medical Informatics Stanford University
  2. 2. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Warning
  3. 3. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting The Protege Bootstrap • Protege is built around the idea of “Doing KA to do KA” • Traditionally, this involves three steps – First, acquire an ontology of conceptual definitions – Then, acquire user-interface information (“Forms layout information”) – And then, acquire instances of the concepts
  4. 4. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting The Idea of a Form • Central to this is an analogy: – Class is to Instance as – Blank Form is to Filled-Out Form
  5. 5. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting
  6. 6. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting
  7. 7. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting
  8. 8. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting What is a Widget • A widget is a piece of code that faithfully translates and renders a small portion of the knowledge base – Idea: if you take a small enough piece of the knowledge-base, the user doesn’t need to think about the logical details • A “Form” is nothing more than a set of widgets, laid out as a single conceptual entity
  9. 9. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting
  10. 10. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Why Do This ? • Separate out structure of knowledge (meta-knowledge) from actual knowledge • Use the meta-knowledge to improve knowledge acquisition – Make it easier to acquire information – Make it harder to make mistakes • Use the meta-knowledge to improve knowledge-base maintenance – Make it easier to know what’s in the KB
  11. 11. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting What do you do with a Widget • In the forms layout panel, users choose the widgets that will be in the form – Widgets must know when they are suitable for a particular class and slot • In the instance panel, users use widgets to view, and edit, instances – Widgets need to display values, allow the user to edit values, and communicate the results back to Protege
  12. 12. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Widgets are Software Components • The set of available widgets can be extended at any time – You can write a widget and add it to your existing installation of Protege • The Project contains the widget information – Which widgets are available – Which forms have what widgets – Any customizations that have been done
  13. 13. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting The Widget is Not in Control ! • Protege is a Container Framework – It places and removes widgets on the screen – It is responsible for persistence and for updating the knowledge base – It is responsible for keeping the knowledge- base consistent • Widgets should only respond to user interface events – Local events, in a limited fashion
  14. 14. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Widget Tasks • Suitability Checking • Configuration • Rendering Values • Editing Values
  15. 15. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Widget Lifecycle • Initial Construction • Initialization • One of either – Configuration (and saving configuration information) – SetValues loop • Framework calls setValues, widget renders and allows editing of values
  16. 16. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting The Structure of a Widget
  17. 17. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting SliderWidget: A Worked Example • Idea: Textfields are a simple, intuitive, and precise way to enter numbers – Great for floating point numbers – Not so good for “An integer between 1 and 100” • Want a graphical way to represent small ranges of integers
  18. 18. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting SuitabilityChecking • Done in a static method on the java class public static boolean isSuitable(Cls cls, Slot slot, Facet facet){ if ((null==cls) || (null==slot)) { return false; } // does the slot point to integers if (cls.getTemplateSlotValueType(slot) != ValueType.INTEGER) { return false; } // is the slot single valued if (cls.getTemplateSlotAllowsMultipleValues(slot)) { return false; } if (null==cls.getTemplateSlotMaximumValue(slot)) { return false; } if (null==cls.getTemplateSlotMinimumValue(slot)){ return false; } //looks like we're suitable return true; }
  19. 19. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting What’s Configurable on a Slider? • Not Much (this is an example) ! – Whether or not to display ticks – How often to display them
  20. 20. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting We Store this in SliderProperties package edu.stanford.smi.protegex.sliderwidget; import edu.stanford.smi.protege.model.*; import edu.stanford.smi.protege.widget.*; import edu.stanford.smi.protege.util.*; import java.util.*; import edu.stanford.smi.protege.event.*; public class SliderProperties extends Observable { private final String displayTicksKey = ":SliderWidget:Display-Ticks"; private final String tickIncrementKey = ":SliderWidget:Tick-Increment"; private Boolean _displayTicks; private Integer _tickIncrement; private PropertyList _properties; private Cls _cls; private Slot _slot; private ListensToClass _classChangeListener; public SliderProperties(PropertyList properties, Cls cls, Slot slot) { _properties = properties; _cls = cls; _slot = slot; _classChangeListener= new ListensToClass(); _cls.addClsListener(_classChangeListener); restore(); } Protege object that the framework stores for the widget Class and slot where the widget is being used
  21. 21. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Slider Properties handles Persistence public void dispose() { _classChangeListener = null; } public void save() { _properties.setBoolean(displayTicksKey,_displayTicks); _properties.setInteger(tickIncrementKey,_tickIncrement); broadcast(); } public void restore() { _displayTicks = _properties.getBoolean(displayTicksKey); _tickIncrement = _properties.getInteger(tickIncrementKey); // default values if (null==_displayTicks) { _displayTicks = new Boolean(true); } if (null==_tickIncrement) { _tickIncrement = new Integer(1); } } All the widget (or the state object) does is store state into the PropertyList (and read information from it). The Framework handles the actual storage and retrieval of properties.
  22. 22. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting ClsListener ? private class ListensToClass implements ClsListener { public void directInstanceCreated(ClsEvent event){} public void directInstanceDeleted(ClsEvent event) {} public void directSubclassAdded(ClsEvent event){} public void directSubclassRemoved(ClsEvent event){} public void directSuperclassAdded(ClsEvent event){} public void directSuperclassRemoved(ClsEvent event){} public void templateFacetAdded(ClsEvent event){} public void templateFacetRemoved(ClsEvent event){} public void templateSlotAdded(ClsEvent event){} public void templateSlotValueChanged(ClsEvent event){} public void templateFacetValueChanged(ClsEvent event) { broadcast(); } public void templateSlotRemoved(ClsEvent event) { if ((event.getSlot()).equals(_slot)) { _cls.removeClsListener(_classChangeListener); } } } }
  23. 23. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting How Configuration Works • The framework creates and initializes the widget – As part of this, it gives the widget a property list • The framework calls the widget’s createWidgetConfigurationPanel() method – It gets a Component – The user interacts with the component • The framework stores the property list
  24. 24. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting SliderWidget’s Configuration package edu.stanford.smi.protegex.sliderwidget; import edu.stanford.smi.protege.widget.*; import edu.stanford.smi.protege.model.*; import edu.stanford.smi.protege.ui.*; import edu.stanford.smi.protege.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; import javax.swing.*; public class MainConfigurationPanel extends JPanel implements Validatable { SliderProperties _properties; private JTextField _minimum; private JTextField _maximum; private JTextField _tickIncrement; private JCheckBox _displayTicks; private Box _internalBox; public MainConfigurationPanel(SliderWidget widget) { super(new BorderLayout()); _properties = widget.getProperties(); _internalBox = new Box(BoxLayout.Y_AXIS); createTickIncrementTextField(); createDisplayTicksCheckBox(); add(_internalBox, BorderLayout.CENTER); }
  25. 25. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Configuration involves Components public void saveContents() { _properties.save(); } public boolean validateContents() { if (_properties.isDisplayTicks()) { return (null!=getTextFieldAsInteger()); } return true; } private void createTickIncrementTextField() { _tickIncrement = constructLabeledTextField("Tick Increment"); (_tickIncrement.getDocument()).addDocumentListener(new TickIncrementListener()); setTickIncrementField(); } private void createDisplayTicksCheckBox() { _displayTicks = new JCheckBox("Display Ticks"); _displayTicks.addActionListener(new DisplayTicksListener()); LabeledComponent surroundingBox = new LabeledComponent("", _displayTicks); _internalBox.add(surroundingBox); _internalBox.createVerticalStrut(4); setDisplayChecksCheckBox(); }
  26. 26. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting The Widget Must Handle Events private class TickIncrementListener extends DocumentChangedListener{ public void stateChanged(ChangeEvent e) { Integer newValue = getTextFieldAsInteger(); if (null!=newValue) { _properties.setTickIncrement(newValue); } } } private class DisplayTicksListener implements ActionListener { public void actionPerformed(ActionEvent e) { _properties.setDisplayTicks(_displayTicks.isSelected()); } } }
  27. 27. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting How KA Works • As with Configuration, the Widget will be initialized with a Class, a Slot, and a PropertyList • Over time, however, the widget will be repeatedly placed on screen – Each time, it will have setInstance and setValues called • Specifying the instance being viewed and the values of of the slot
  28. 28. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting SliderWidget’s Initializeprivate SliderProperties _properties; private JSlider _slider; private JTextField _textField; private ListensToSlider _sliderChangeListener; public void initialize() { // initialize is called after the constructor has been called and AbstractWidget // is fully configured. This means that the methods defined in AbstractWidget will // all return the appropriate objects. Slot slot = getSlot(); setPreferredRows(1); setPreferredColumns(1); _properties = new SliderProperties(getPropertyList(), getCls(), slot); _slider = new JSlider(); _textField = new JTextField(); _textField.setEditable(false); _textField.setColumns(3); /* create some grid bag constraints objects (code omitted) */ JPanel contentPanel = new JPanel(new GridBagLayout()); contentPanel.add(_slider, sliderConstraints); contentPanel.add(_textField, textfieldConstraints); LabeledComponent actualUI = new LabeledComponent(getLabel(),contentPanel); add(actualUI); setUIFromProperties(); if (isRuntime()) { addListeners(); } }
  29. 29. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Most of the Time • Most Widgets inherit from AbstractWidget – AbstractWidget is a convenience class provided by Protege • Widgets that do so need to implement the initialize() methods in order to be configured properly
  30. 30. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Editing the Knowledge-Base • Initialize() is entirely a user-interface setup method • There are 4 methods involved in editing the knowledge base – setInstance, setValues. Called by the Framework at the start of editing – getValues. Called by the framework to get the new values when editing is done – valueChanged. A convenience method in AbstractWidget
  31. 31. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting SliderWidget’s implementations public void setValues(java.util.Collection values) { if ((null==values) || (0==values.size())) { return; } Iterator i = values.iterator(); Object value = i.next(); _slider.setValue(((Integer) value).intValue()); return; } public Collection getValues() { ArrayList returnValue = new ArrayList(); returnValue.add(new Integer(_slider.getValue())); return returnValue; }
  32. 32. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting private class ListensToSlider implements ChangeListener { public void stateChanged(ChangeEvent e) { _textField.setText(String.valueOf(_slider.getValue())); if (false==_slider.getValueIsAdjusting()){ valueChanged(); } } } Editing happens in response to user actions • Changes happen as per the standard Java GUI model – _slider sends out a change event – SliderWidget gets the event, and calls valueChanged()
  33. 33. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Key Points • Framework handles most details – Storage, placement, configuration • Widget is, more or less, a special-purpose event handler – No guarantees about lifetime or a continuous existence – Should never initiate action or perform extensive computations
  34. 34. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting A Subtle Point • A widget implements the isSuitable method • SliderWidget checked – Slot had integer value type – Slot was single-valued – That minimum and maximum facet values were set • Many many other things can be checked – Complex widgets frequently come with their own ontologies (and ontological assumptions)
  35. 35. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Widget Scale • This talk has been about slot widgets – Widgets used to view, edit, and acquire values at a single slot • SliderWidget is emphatically a small-scale (local) widget • Widgets can display large sections of the knowledge base
  36. 36. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Non-Local Slot Widgets • Still slot widgets • But much larger scale-- – They make more assumptions – They pull in larger amounts of data from the KB • ContainsWidget navigates the KB and pulls in lots of data – Needs to know when lots of things have changed (SliderWidget simply needs to know when a local value has changed)
  37. 37. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting Tabs • Something new under the sun-- large scale widgetry • Key Motivation: Aid in navigation and in viewing large-scale structure of kb – Slot widget: a knowledge base is a logical theory which needs to be faithfully represented – Tab widget: a knowledge base is an incredibly detailed web site, which needs to be navigated
  38. 38. Knowledge ModelsWilliam Grosso Fourth International ProtegeUsers Group Meeting HPKB Tab • New types of kb validation now possible: completeness (whereas slotwidgets are really only about correctness) • HPKBTab is very much domain specific. – But there’s a fruitful domain here

×