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-owl] Any one got working examples of protégé-owl api programmer's guide

Seung-Hwan Kang sk33mail at yahoo.com
Wed May 21 19:32:38 PDT 2008


There are two examples from http://protege.stanford.edu/plugins/owl/api/guide.html.  The second example is not working? I have been trying to fix the source codes but I have not been successful yet.

Anyone has a working version of 'Protégé User Interface Programming' example. It seems like lots of Java classes and methods are depreciated.

public static void main(String[] args) throws Exception {

        String uri = "http://www.owl-ontologies.com/travel.owl";
        OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
        OWLNamedClass destinationClass = owlModel.getOWLNamedClass("Destination");

        ListPanel listPanel = new ListPanel(destinationClass);
        JFrame frame = new JFrame("Simple List Example");
        Container cont = frame.getContentPane();
        cont.setLayout(new BorderLayout());
        cont.add(BorderLayout.CENTER, listPanel);

        frame.setBounds(100, 100, 300, 300);
        frame.setVisible(true);
    }


//

    private static class ListPanel extends JPanel implements Disposable {
        private OWLNamedClass destinationClass;
        private JList list;
        private DefaultListModel listModel;

        private ModelListener modelListener = new ModelAdapter() {
            public void individualCreated(RDFResource resource) {
                if (resource.hasRDFType(destinationClass, true)) {
                    handleDestinationAdded(resource);
                }
            }
        };

        private OWLModel owlModel;

        ListPanel(OWLNamedClass activityClass) {
            this.destinationClass = activityClass;
            this.owlModel = activityClass.getOWLModel();

            owlModel.addModelListener(modelListener);

            listModel = new DefaultListModel();
            for (Iterator it = activityClass.getInstances(true).iterator(); it.hasNext();) {
                OWLIndividual individual = (OWLIndividual) it.next();
                listModel.addElement(individual);
            }
            list = new JList(listModel);

            // Make sure list entries show up nicely with icons
            list.setCellRenderer(new ResourceRenderer());

            // Wrap the list together with a button bar
            OWLLabeledComponent lc = new OWLLabeledComponent("Destinations", new JScrollPane(list));
            lc.addHeaderButton(new AbstractAction("Add Destination...", 
                    OWLIcons.getAddIcon(OWLIcons.RDF_INDIVIDUAL)) {
                public void actionPerformed(ActionEvent e) {
                    addDestination();
                }
            });

            // Add everything into the JPanel
            setLayout(new BorderLayout());
            add(BorderLayout.CENTER, lc);
        }

        private void addDestination() {

// pickOWLNamedClass is depreciated. 
// Deprecated. use ProtegeUI.getSelectionDialogFactory()...
// but it does NOT work too.??
            OWLNamedClass newType = OWLUI.pickOWLNamedClass(owlModel,
                    Collections.singleton(destinationClass), "Select type of new Destination");
            if (newType != null) {
                String name = JOptionPane.showInputDialog(
                        "Enter name of new " + newType.getBrowserText());
                if (name != null) {
                    newType.createOWLIndividual(name);
                }
            }
        }

        public void dispose() {
            owlModel.removeModelListener(modelListener);
        }

        private void handleDestinationAdded(RDFResource destination) {
            listModel.addElement(destination);
            list.setSelectedValue(destination, true);
        }
    }



      Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/mail



More information about the protege-owl mailing list