From: <lor...@us...> - 2008-03-26 20:11:58
|
Revision: 728 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=728&view=rev Author: lorenz_b Date: 2008-03-26 13:11:12 -0700 (Wed, 26 Mar 2008) Log Message: ----------- Wizard for ORE Added Paths: ----------- trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/LeftPanel.java trunk/src/dl-learner/org/dllearner/tools/ore/Main.java trunk/src/dl-learner/org/dllearner/tools/ore/ORE_alt.java trunk/src/dl-learner/org/dllearner/tools/ore/Wizard.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardController.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardModel.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardPanelDescriptor.java trunk/src/dl-learner/org/dllearner/tools/ore/WizardPanelNotFoundException.java trunk/src/dl-learner/org/dllearner/tools/ore/father.owl Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java Added: trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanel.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,101 @@ +package org.dllearner.tools.ore; + +import java.awt.BorderLayout; +import java.awt.Color; + +import javax.swing.DefaultListModel; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.event.ListSelectionListener; + +public class ConceptPanel extends JPanel{ + + + + private javax.swing.JList conceptList; + + private JPanel contentPanel; + + private DefaultListModel model; + private BlinkLabel blink; + + public ConceptPanel() { + + super(); + model = new DefaultListModel(); + blink = new BlinkLabel(); + blink.setText("Loading Concepts"); + contentPanel = getContentPanel(); + setLayout(new java.awt.BorderLayout()); + add(contentPanel,BorderLayout.CENTER); + add(blink, BorderLayout.SOUTH); + } + + private JPanel getContentPanel() { + + JPanel contentPanel1 = new JPanel(); + JScrollPane scroll = new JScrollPane(); + + + conceptList = new JList(model); + scroll.setSize(100,100); + scroll.setViewportView(conceptList); + + contentPanel1.add(scroll); + + + + return contentPanel1; + } + + public DefaultListModel getModel(){ + return model; + } + + public void setModel(DefaultListModel dm){ + conceptList.setModel(dm); + } + + public void addSelectionListener(ListSelectionListener l){ + conceptList.addListSelectionListener(l); + } + + public JList getList(){ + return conceptList; + } + + public BlinkLabel getBlinkLabel(){ + return blink; + } + + class BlinkLabel extends JLabel implements Runnable{ + private boolean blinking = false; + + public void start(){ + blinking = true; + new Thread(this).start(); + } + public void stop(){ + blinking = false; + setText("Done! Select Concept and press 'Next'"); + } + public void run(){ + while(blinking){ + setForeground(Color.red); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + return; + } + setForeground(Color.black); + } + } + } + + + + + +} \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ConceptPanelDescriptor.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,60 @@ +package org.dllearner.tools.ore; + +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + + + + +public class ConceptPanelDescriptor extends WizardPanelDescriptor implements ListSelectionListener{ + + public static final String IDENTIFIER = "CONCEPT_CHOOSE_PANEL"; + + ConceptPanel panel3; + + public ConceptPanelDescriptor() { + + panel3 = new ConceptPanel(); + panel3.addSelectionListener(this); + + setPanelDescriptorIdentifier(IDENTIFIER); + setPanelComponent(panel3); + + } + + public Object getNextPanelDescriptor() { + return LearningPanelDescriptor.IDENTIFIER; + } + + public Object getBackPanelDescriptor() { + return KnowledgeSourcePanelDescriptor.IDENTIFIER; + } + + public void aboutToDisplayPanel() { + setNextButtonAccordingToConceptSelected(); + } + + + @Override + public void valueChanged(ListSelectionEvent e) { + setNextButtonAccordingToConceptSelected(); + if (!e.getValueIsAdjusting()) + getWizardModel().getOre().setConcept(panel3.getList().getSelectedValue().toString()); + + } + + private void setNextButtonAccordingToConceptSelected() { + + if (panel3.getList().getSelectedValue()!= null){ + getWizard().setNextFinishButtonEnabled(true); + }else{ + getWizard().setNextFinishButtonEnabled(false); + } + + } + + + + + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanel.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,109 @@ +package org.dllearner.tools.ore; + + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.UIManager; + + +public class IntroductionPanel extends JPanel { + + private JTextArea instructionsField; + private JScrollPane jScrollPane1; + + + + private JLabel welcomeTitle; + private JPanel contentPanel; + + + + public IntroductionPanel() { + + + + + + contentPanel = getContentPanel(); + + + + + setLayout(new java.awt.BorderLayout()); + + + + //add(leftPanel, BorderLayout.WEST); + + JPanel secondaryPanel = new JPanel(); + secondaryPanel.add(contentPanel, BorderLayout.NORTH); + add(contentPanel, BorderLayout.CENTER); + } + + + private JPanel getContentPanel() { + + JPanel contentPanel1 = new JPanel(); + JPanel jPanel1 = new JPanel(); + + jScrollPane1 = new JScrollPane(); + instructionsField = new JTextArea(); + + + //setLayout(new GridBagLayout()); + setBorder(BorderFactory.createEmptyBorder(12, 6, 12, 12)); + jScrollPane1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + jScrollPane1.setViewportBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + instructionsField.setBackground(UIManager.getDefaults().getColor("control")); + instructionsField.setColumns(20); + instructionsField.setEditable(false); + instructionsField.setLineWrap(true); + instructionsField.setRows(5); + instructionsField.setFont(new Font("Serif",Font.PLAIN,14)); + instructionsField.setText("This is an test of a wizard dialog, which allows a knowledge engineer to select " + + "a concept of an ontology which should be (re)learned. \n\nOn " + + "the next page, choose a JAR file that contains some components. It will find any " + + "JavaBeans listed in the manifest, and also let you add classes from the JAR file. " + + "When the resulting NetBeans plug-in is installed in NetBeans, the components you " + + "selected will be on the Component Palette, and can be dragged and dropped onto Swing " + + "forms. The library display name you enter is also the name that will be used for the " + + "category in the component palette where your components will appear."); + instructionsField.setWrapStyleWord(true); + jScrollPane1.setViewportView(instructionsField); + + + + + + welcomeTitle = new JLabel(); + welcomeTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0, 0, 0))); + + + + contentPanel1.setLayout(new java.awt.BorderLayout()); + + welcomeTitle.setFont(new java.awt.Font("MS Sans Serif", Font.BOLD, 14)); + welcomeTitle.setText("Welcome to the DL-Learner ORE-Tool!"); + contentPanel1.add(welcomeTitle, java.awt.BorderLayout.NORTH); + + jPanel1.setLayout(new java.awt.GridLayout(0, 1,0,0)); + + //jPanel1.add(blankSpace); + + + jPanel1.add(jScrollPane1); + + contentPanel1.add(jPanel1, java.awt.BorderLayout.CENTER); + + return contentPanel1; + + } + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanelDescriptor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/IntroductionPanelDescriptor.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,23 @@ +package org.dllearner.tools.ore; + + + +public class IntroductionPanelDescriptor extends WizardPanelDescriptor { + + public static final String IDENTIFIER = "INTRODUCTION_PANEL"; + + public IntroductionPanelDescriptor() { + super(IDENTIFIER, new IntroductionPanel()); + } + + public Object getNextPanelDescriptor() { + return KnowledgeSourcePanelDescriptor.IDENTIFIER; + } + + public Object getBackPanelDescriptor() { + return null; + } + + + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanel.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,127 @@ +package org.dllearner.tools.ore; + +import java.awt.BorderLayout; +import java.awt.event.ActionListener; +import java.io.File; + +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.event.DocumentListener; +import javax.swing.filechooser.FileFilter; + +public class KnowledgeSourcePanel extends JPanel{ + + + private javax.swing.JTextField fileURL; + private javax.swing.JButton browseButton; + + private JPanel contentPanel; + private LeftPanel leftPanel; + private JLabel message; + + public KnowledgeSourcePanel() { + +// super(); + leftPanel = new LeftPanel(1); + contentPanel = getContentPanel(); + + setLayout(new java.awt.BorderLayout()); + + //add(leftPanel,BorderLayout.WEST); + add(contentPanel,BorderLayout.CENTER); + + } + + private JPanel getContentPanel() { + + JPanel contentPanel1 = new JPanel(); + + message = new JLabel(); + message.setText("enter or browse OWL file"); + fileURL = new javax.swing.JTextField(40); + + browseButton = new javax.swing.JButton("browse"); + + contentPanel1.setLayout(new BorderLayout()); + + JPanel panel = new JPanel(); + panel.add(fileURL); + panel.add(browseButton); + + contentPanel1.add(panel,BorderLayout.CENTER); + contentPanel1.add(message,BorderLayout.SOUTH); + + + + return contentPanel1; + } + + public void addListeners(ActionListener l, DocumentListener d) { + browseButton.addActionListener(l); + fileURL.addActionListener(l); + fileURL.getDocument().addDocumentListener(d); + } + + + + public void openFileChooser(){ + JFileChooser filechooser = new JFileChooser(); + + filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + String choosenPath = fileURL.getText(); + if(!choosenPath.equals("") && (new File(choosenPath)).exists()) + filechooser.setCurrentDirectory(new File(fileURL.getText())); + + filechooser.addChoosableFileFilter(new FileFilter() { + public boolean accept(File f) { + if (f.isDirectory()) return true; + return f.getName().toLowerCase().endsWith(".owl"); + } + public String getDescription () { return "OWLs"; } + }); + int status = filechooser.showOpenDialog( null ); + + if ( status == JFileChooser.APPROVE_OPTION ){ + String strURL = filechooser.getSelectedFile().getAbsolutePath(); + fileURL.setText(strURL); + + + + }else{ + System.out.println( "Auswahl abgebrochen" ); + } + } + + public boolean isExistingOWLFile(){ + if(!fileURL.getText().equals("") && !getOWLFile().exists()){ + + message.setText(fileURL.getText()+" does not exist"); + return false; + } + if(!fileURL.getText().equals("") && (getOWLFile().isDirectory() || (getOWLFile().isFile() && !getOWLFile().getPath().endsWith(".owl")))){ + System.err.println(getOWLFile().getPath()); + message.setText(fileURL.getText()+" is not a OWL file"); + return false; + } + if(fileURL.getText().equals("")){ + message.setText("enter or browse OWL file"); + return false; + } + if(getOWLFile().exists() && getOWLFile().getPath().endsWith(".owl")){ + message.setText(""); + return true; + } + return true; + + + + } + + public File getOWLFile() { + return new File(fileURL.getText()); + } + + + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/KnowledgeSourcePanelDescriptor.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,119 @@ +package org.dllearner.tools.ore; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Set; + +import javax.swing.SwingWorker; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.dllearner.core.owl.NamedClass; + + +public class KnowledgeSourcePanelDescriptor extends WizardPanelDescriptor implements ActionListener, DocumentListener{ + + public static final String IDENTIFIER = "KNOWLEDGESOURCE_CHOOSE_PANEL"; + + KnowledgeSourcePanel panel2; + + public KnowledgeSourcePanelDescriptor() { + + panel2 = new KnowledgeSourcePanel(); + + panel2.addListeners(this, this); + + setPanelDescriptorIdentifier(IDENTIFIER); + setPanelComponent(panel2); + + } + + public Object getNextPanelDescriptor() { + return ConceptPanelDescriptor.IDENTIFIER; + } + + public Object getBackPanelDescriptor() { + return IntroductionPanelDescriptor.IDENTIFIER; + } + + + public void aboutToDisplayPanel() { + setNextButtonAccordingToExistingOWLFile(); + } + + public void actionPerformed(ActionEvent e) { + String cmd = e.getActionCommand(); + if(cmd.equals("browse")){ + panel2.openFileChooser(); + } + + setNextButtonAccordingToExistingOWLFile(); + } + + + + + private void setNextButtonAccordingToExistingOWLFile() { + + if (panel2.isExistingOWLFile()){ + getWizardModel().getOre().setKnowledgeSource(panel2.getOWLFile()); + getWizard().setNextFinishButtonEnabled(true); +// new ConceptRetriever().execute(); +// System.err.println("test"); + } + + + + + + else + getWizard().setNextFinishButtonEnabled(false); + + } + + + @Override + public void changedUpdate(DocumentEvent e) { + setNextButtonAccordingToExistingOWLFile(); + + } + + @Override + public void insertUpdate(DocumentEvent e) { + setNextButtonAccordingToExistingOWLFile(); + + } + + @Override + public void removeUpdate(DocumentEvent e) { + setNextButtonAccordingToExistingOWLFile(); + + } + class ConceptRetriever extends SwingWorker<Set<NamedClass>, NamedClass> + { + @Override + public Set<NamedClass> doInBackground() + { + getWizardModel().getOre().detectReasoner(); + Set<NamedClass> ind = getWizardModel().getOre().getReasoningService().getAtomicConcepts(); + ConceptPanelDescriptor nextPanel = (ConceptPanelDescriptor)getWizardModel().getPanelHashMap().get(getNextPanelDescriptor()); + nextPanel.panel3.getModel().clear(); + + for (NamedClass cl : ind){ + publish(cl); + nextPanel.panel3.getModel().addElement(cl); + System.out.println(cl.toString()); + } + return ind; + } + + + + + } + + + + + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanel.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,73 @@ +package org.dllearner.tools.ore; + +import java.awt.BorderLayout; +import java.awt.event.ActionListener; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +public class LearningPanel extends JPanel{ + + + + private javax.swing.JList conceptList; + + private JPanel contentPanel; + + private DefaultListModel model; + private JLabel result; + private JButton run; + + public LearningPanel() { + + super(); + model = new DefaultListModel(); + result = new JLabel(); + run = new JButton("Run"); + contentPanel = getContentPanel(); + setLayout(new java.awt.BorderLayout()); + add(run,BorderLayout.EAST); + add(contentPanel,BorderLayout.CENTER); + add(result, BorderLayout.SOUTH); + } + + private JPanel getContentPanel() { + + JPanel contentPanel1 = new JPanel(); + JScrollPane scroll = new JScrollPane(); + + + conceptList = new JList(model); + scroll.setSize(100,100); + scroll.setViewportView(conceptList); + + contentPanel1.add(scroll); + + + + return contentPanel1; + } + + public void addButtonListener(ActionListener a){ + run.addActionListener(a); + } + + public void setResult(String resultStr){ + result.setText(resultStr); + } + + + + + +} + + + + + + Added: trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,82 @@ +package org.dllearner.tools.ore; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.concurrent.ExecutionException; + +import javax.swing.SwingWorker; + +import org.dllearner.core.owl.Description; + + + + +public class LearningPanelDescriptor extends WizardPanelDescriptor implements ActionListener{ + + public static final String IDENTIFIER = "LEARNING_PANEL"; + + LearningPanel panel4; + + public LearningPanelDescriptor() { + + panel4 = new LearningPanel(); + panel4.addButtonListener(this); + + setPanelDescriptorIdentifier(IDENTIFIER); + setPanelComponent(panel4); + + } + + public Object getNextPanelDescriptor() { + return LearningPanelDescriptor.IDENTIFIER; + } + + public Object getBackPanelDescriptor() { + return ConceptPanelDescriptor.IDENTIFIER; + } + + + public void displayingPanel(){ + + } + + class Result extends SwingWorker<Description, Void> + { + @Override + public Description doInBackground() + { + getWizardModel().getOre().start(); + Description result = getWizardModel().getOre().getLearningResult(); + + + return result; + } + + public void done(){ + Description result=null; + try { + result = get(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExecutionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + panel4.setResult(result.toString()); + } + + + + } + + + + + + + @Override + public void actionPerformed(ActionEvent arg0) { + new Result().execute(); + + }} Added: trunk/src/dl-learner/org/dllearner/tools/ore/LeftPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/LeftPanel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/LeftPanel.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,59 @@ +package org.dllearner.tools.ore; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; + +import javax.swing.JLabel; +import javax.swing.JPanel; + +public class LeftPanel extends JPanel{ + + private JLabel[] jLabel; + + public LeftPanel(int i){ + + jLabel = new JLabel[5]; + setBackground(new java.awt.Color(255, 255, 255)); + JPanel panel2 = new JPanel(); + panel2.setBackground(new java.awt.Color(255, 255, 255)); + panel2.setLayout(new GridLayout(5,1,0,10)); + jLabel[0] = new JLabel("1. Introduction"); + jLabel[1] = new JLabel("2. Knowledge Source"); + jLabel[2] = new JLabel("3. Concept"); + jLabel[3] = new JLabel("4. Examples"); + jLabel[4] = new JLabel("5. Learning"); + + jLabel[i].setFont(jLabel[i].getFont().deriveFont(Font.BOLD)); + + for(JLabel current : jLabel) + panel2.add(current); + setLayout(new BorderLayout()); + setPreferredSize(new Dimension(140,500)); + add(panel2, BorderLayout.NORTH); + + } + + public void set(int i){ + removeAll(); + + setBackground(new java.awt.Color(255, 255, 255)); + JPanel panel2 = new JPanel(); + panel2.setBackground(new java.awt.Color(255, 255, 255)); + panel2.setLayout(new GridLayout(5,1,0,10)); + jLabel[0] = new JLabel("1. Introduction"); + jLabel[1] = new JLabel("2. Knowledge Source"); + jLabel[2] = new JLabel("3. Concept"); + jLabel[3] = new JLabel("4. Examples"); + jLabel[4] = new JLabel("5. Learning"); + + jLabel[i].setFont(jLabel[i].getFont().deriveFont(Font.BOLD)); + + for(JLabel current : jLabel) + panel2.add(current); + setLayout(new BorderLayout()); + add(panel2, BorderLayout.NORTH); + } + +} Added: trunk/src/dl-learner/org/dllearner/tools/ore/Main.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/Main.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/Main.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,54 @@ +package org.dllearner.tools.ore; + +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + + + +public class Main { + + public static void main(String[] args) { + try { + UIManager.setLookAndFeel( + UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (UnsupportedLookAndFeelException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Wizard wizard = new Wizard(); + wizard.getDialog().setTitle("DL-Learner ORE-Tool"); + wizard.getDialog().setSize(700, 400); + + WizardPanelDescriptor descriptor1 = new IntroductionPanelDescriptor(); + wizard.registerWizardPanel(IntroductionPanelDescriptor.IDENTIFIER, descriptor1); + + WizardPanelDescriptor descriptor2 = new KnowledgeSourcePanelDescriptor(); + wizard.registerWizardPanel(KnowledgeSourcePanelDescriptor.IDENTIFIER, descriptor2); + + WizardPanelDescriptor descriptor3 = new ConceptPanelDescriptor(); + wizard.registerWizardPanel(ConceptPanelDescriptor.IDENTIFIER, descriptor3); + + WizardPanelDescriptor descriptor4 = new LearningPanelDescriptor(); + wizard.registerWizardPanel(LearningPanelDescriptor.IDENTIFIER, descriptor4); + + wizard.setCurrentPanel(IntroductionPanelDescriptor.IDENTIFIER); + + int ret = wizard.showModalDialog(); + + System.out.println("Dialog return code is (0=Finish,1=Cancel,2=Error): " + ret); + + + System.exit(0); + + } + +} Deleted: trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-03-26 15:49:00 UTC (rev 727) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java 2008-03-26 20:11:12 UTC (rev 728) @@ -1,610 +0,0 @@ -/** - * Copyright (C) 2007-2008, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.tools.ore; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.dllearner.algorithms.BruteForceLearner; -import org.dllearner.algorithms.RandomGuesser; -import org.dllearner.algorithms.gp.GP; -import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; -import org.dllearner.algorithms.refinement.ROLearner; -import org.dllearner.cli.ConfFileOption; -import org.dllearner.core.Component; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.ReasonerComponent; -import org.dllearner.core.ReasoningService; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.DoubleConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; -import org.dllearner.core.config.StringSetConfigOption; -import org.dllearner.core.config.StringTupleListConfigOption; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.kb.KBFile; -import org.dllearner.kb.OWLFile; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.learningproblems.PosNegDefinitionLP; -import org.dllearner.parser.ConfParser; -import org.dllearner.parser.KBParser; -import org.dllearner.parser.ParseException; -import org.dllearner.parser.TokenMgrError; -import org.dllearner.reasoning.DIGReasoner; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.reasoning.FastRetrievalReasoner; -import org.dllearner.reasoning.OWLAPIReasoner; -import org.dllearner.utilities.ConceptComparator; -import org.dllearner.utilities.Datastructures; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.StringTuple; - -/** - * Start class for the ontology repair and enrichment tool. - * - * @author Lorenz Buehmann. - * - */ -public class ORE { - - private static Logger logger = Logger.getRootLogger(); - - private static LearningAlgorithm la; - private ReasoningService rs; - - /** - * Entry point for CLI interface. - * - * @param args - */ - public static void main(String[] args) throws ComponentInitException { - - File file = new File(args[args.length - 1]); - - // create logger (a simple logger which outputs - // its messages to the console) - SimpleLayout layout = new SimpleLayout(); - ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.setLevel(Level.DEBUG); - - ORE ore = null; - ore = new ORE(file); - ore.start(); - } - - /** - * Initialise all components based on conf file. - * - * @param file - * Conf file to read. - * @throws ComponentInitException - */ - public ORE(File file) throws ComponentInitException { - String baseDir = file.getParentFile().getPath(); - - // create component manager instance - String message = "starting component manager ... "; - long cmStartTime = System.nanoTime(); - ComponentManager cm = ComponentManager.getInstance(); - long cmTime = System.nanoTime() - cmStartTime; - message += "OK (" + Helper.prettyPrintNanoSeconds(cmTime) + ")"; - logger.info(message); - - // create a mapping between components and prefixes in the conf file - Map<Class<? extends Component>, String> componentPrefixMapping = createComponentPrefixMapping(); - - // parse conf file - ConfParser parser = ConfParser.parseFile(file); - - // step 1: detect knowledge sources - Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); - Map<URL, Class<? extends KnowledgeSource>> importedFiles = getImportedFiles( - parser, baseDir); - for (Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles - .entrySet()) { - KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); - // apply URL entry (this assumes that every knowledge source has a - // configuration option "url"), so this may need to be changed in - // the - // future - cm.applyConfigEntry(ks, "url", entry.getKey().toString()); - - sources.add(ks); - configureComponent(cm, ks, componentPrefixMapping, parser); - initComponent(cm, ks); - } - - // step 2: detect used reasoner - ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); - ReasonerComponent reasoner = cm.reasoner( - getReasonerClass(reasonerOption), sources); - configureComponent(cm, reasoner, componentPrefixMapping, parser); - initComponent(cm, reasoner); - rs = cm.reasoningService(reasoner); - - } - - public void start() { - processOREMode(rs); - - } - - /** - * creates a mapping from components to option prefix strings - */ - public static Map<Class<? extends Component>, String> createComponentPrefixMapping() { - Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); - // knowledge sources - componentPrefixMapping.put(SparqlKnowledgeSource.class, "sparql"); - // reasoners - componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); - componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); - // learning problems - configured via + and - flags for examples - componentPrefixMapping.put(PosNegDefinitionLP.class, - "posNegDefinitionLP"); - // learning algorithms - componentPrefixMapping.put(ROLearner.class, "refinement"); - componentPrefixMapping.put(ExampleBasedROLComponent.class, - "refexamples"); - componentPrefixMapping.put(GP.class, "gp"); - return componentPrefixMapping; - } - - /** - * convenience method basically every prefix (e.g. "refinement" in - * "refinement.horizontalExpFactor) corresponds to a specific component - - * this way the CLI will automatically support any configuration options - * supported by the component - */ - public static void configureComponent(ComponentManager cm, - Component component, - Map<Class<? extends Component>, String> componentPrefixMapping, - ConfParser parser) { - String prefix = componentPrefixMapping.get(component.getClass()); - if (prefix != null) - configureComponent(cm, component, parser - .getConfOptionsByPrefix(prefix)); - } - - // convenience method - see above method - private static void configureComponent(ComponentManager cm, - Component component, List<ConfFileOption> options) { - if (options != null) - for (ConfFileOption option : options) - applyConfFileOption(cm, component, option); - } - - // applies an option to a component - checks whether the option and its - // value is valid - private static void applyConfFileOption(ComponentManager cm, - Component component, ConfFileOption option) { - // the name of the option is suboption-part (the first part refers - // to its component) - String optionName = option.getSubOption(); - - ConfigOption<?> configOption = cm.getConfigOption(component.getClass(), - optionName); - // check whether such an option exists - if (configOption != null) { - - // catch all invalid config options - try { - - // perform compatibility checks - if (configOption instanceof StringConfigOption - && option.isStringOption()) { - - ConfigEntry<String> entry = new ConfigEntry<String>( - (StringConfigOption) configOption, option - .getStringValue()); - cm.applyConfigEntry(component, entry); - - } else if (configOption instanceof IntegerConfigOption - && option.isIntegerOption()) { - - ConfigEntry<Integer> entry = new ConfigEntry<Integer>( - (IntegerConfigOption) configOption, option - .getIntValue()); - cm.applyConfigEntry(component, entry); - - } else if (configOption instanceof DoubleConfigOption - && (option.isIntegerOption() || option.isDoubleOption())) { - - double value; - if (option.isIntegerOption()) - value = option.getIntValue(); - else - value = option.getDoubleValue(); - - ConfigEntry<Double> entry = new ConfigEntry<Double>( - (DoubleConfigOption) configOption, value); - cm.applyConfigEntry(component, entry); - - } else if (configOption instanceof BooleanConfigOption - && option.isStringOption()) { - - ConfigEntry<Boolean> entry = new ConfigEntry<Boolean>( - (BooleanConfigOption) configOption, Datastructures - .strToBool(option.getStringValue())); - cm.applyConfigEntry(component, entry); - - } else if (configOption instanceof StringSetConfigOption - && option.isSetOption()) { - - ConfigEntry<Set<String>> entry = new ConfigEntry<Set<String>>( - (StringSetConfigOption) configOption, option - .getSetValues()); - cm.applyConfigEntry(component, entry); - - } else if (configOption instanceof StringTupleListConfigOption - && option.isListOption()) { - - ConfigEntry<List<StringTuple>> entry = new ConfigEntry<List<StringTuple>>( - (StringTupleListConfigOption) configOption, option - .getListTuples()); - cm.applyConfigEntry(component, entry); - - } else { - handleError("The type of conf file entry \"" - + option.getFullName() - + "\" is not correct: value \"" + option.getValue() - + "\" not valid for option type \"" - + configOption.getClass().getName() + "\"."); - } - - } catch (InvalidConfigOptionValueException e) { - e.printStackTrace(); - System.exit(0); - } - - } else - handleError("Unknow option " + option + "."); - } - - /** - * detects all imported files and their format - */ - public static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles( - ConfParser parser, String baseDir) { - List<List<String>> imports = parser.getFunctionCalls().get("import"); - Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); - - if (imports != null) { - for (List<String> arguments : imports) { - // step 1: detect URL - URL url = null; - try { - String fileString = arguments.get(0); - if (fileString.startsWith("http:")) { - url = new URL(fileString); - } else { - File f = new File(baseDir, arguments.get(0)); - url = f.toURI().toURL(); - } - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - // step 2: detect format - Class<? extends KnowledgeSource> ksClass; - if (arguments.size() == 1) { - String filename = url.getPath(); - String ending = filename.substring(filename - .lastIndexOf(".") + 1); - - if (ending.equals("rdf") || ending.equals("owl")) - ksClass = OWLFile.class; - else if (ending.equals("nt")) - ksClass = OWLFile.class; - else if (ending.equals("kb")) - ksClass = KBFile.class; - else { - System.err.println("Warning: no format given for " - + arguments.get(0) - + " and could not detect it. Chosing RDF/XML."); - ksClass = OWLFile.class; - } - - importedFiles.put(url, ksClass); - } else { - String formatString = arguments.get(1); - - if (formatString.equals("RDF/XML")) - ksClass = OWLFile.class; - else if (formatString.equals("KB")) - ksClass = KBFile.class; - else if (formatString.equals("SPARQL")) - ksClass = SparqlKnowledgeSource.class; - else if (formatString.equals("NT")) - ksClass = OWLFile.class; - else { - throw new RuntimeException( - "Unsupported knowledge source format " - + formatString + ". Exiting."); - } - - importedFiles.put(url, ksClass); - } - } - } - - return importedFiles; - } - - private static void initComponent(ComponentManager cm, Component component) - throws ComponentInitException { - String startMessage = "initialising component \"" - + cm.getComponentName(component.getClass()) + "\" ... "; - long initStartTime = System.nanoTime(); - component.init(); - // standard messsage is just "OK" but can be more detailed for certain - // components - String message = "OK"; - if (component instanceof KBFile) - message = ((KBFile) component).getURL().toString() + " read"; - else if (component instanceof DIGReasoner) { - DIGReasoner reasoner = (DIGReasoner) component; - message = "using " + reasoner.getIdentifier() - + " connected via DIG 1.1 at " - + reasoner.getReasonerURL().toString(); - } - - long initTime = System.nanoTime() - initStartTime; - logger.info(startMessage + message + " (" - + Helper.prettyPrintNanoSeconds(initTime, false, false) + ")"); - } - - private static void processOREMode(ReasoningService rs) { - System.err.println("Concepts :" + rs.getAtomicConcepts()); - - System.out.println("Individuals " + rs.getIndividuals()); - System.out - .println("Entering ORE mode. Enter a existing concept for learning(new) or q to quit"); - - String conceptStr = ""; - do { - //Step 1: choose existing concept which should be (new) learned - System.out.print("enter concept: "); - // read input string - BufferedReader input = new BufferedReader(new InputStreamReader( - System.in)); - - try { - conceptStr = input.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - - if (!conceptStr.equals("q")) { - - // parse concept - Description concept = null; - boolean parsedCorrectly = true; - - try { - concept = KBParser.parseConcept(conceptStr); - - } catch (ParseException e1) { - e1.printStackTrace(); - System.err - .println("The concept you entered could not be parsed. Please try again."); - parsedCorrectly = false; - } catch (TokenMgrError e) { - e.printStackTrace(); - System.err - .println("An error occured during parsing. Please enter a syntactically valid concept."); - parsedCorrectly = false; - } - - if (parsedCorrectly) { - - // compute atomic concepts used in concept - SortedSet<NamedClass> occurringConcepts = new TreeSet<NamedClass>( - new ConceptComparator()); - occurringConcepts.addAll(Helper.getAtomicConcepts(concept)); - - // substract existing concepts from detected - // concepts -> the resulting set should be - // empty, otherwise print a warning (the DIG reasoner - // will just treat them as concepts about which it - // has no knowledge - this makes it hard to - // detect typos - // (note that removeAll currently gives a different - // result here, because the comparator of the argument - // is used) - for (NamedClass ac : rs.getAtomicConcepts()) - occurringConcepts.remove(ac); - - boolean nonExistingConstructs = false; - if (occurringConcepts.size() != 0) { - System.out - .println("You used non-existing atomic concepts or roles. Please correct your query."); - if (occurringConcepts.size() > 0) - - System.out.println("non-existing concepts: " - + occurringConcepts); - - nonExistingConstructs = true; - } - - if (!nonExistingConstructs) { - - // Step 2_1: choose all individuals of the concept as positive examples - SortedSet<Individual> posExamples = null; - posExamples = rs.retrieval(concept); - posExamples.removeAll(posExamples); - posExamples.add(new Individual( - "http://example.com/father#stefan")); - posExamples.add(new Individual( - "http://example.com/father#markus")); - posExamples.add(new Individual( - "http://example.com/father#martin")); - - //Step 2_2: subtract positive examples from all individuals of the ontology - //->negative examples of the concepts - SortedSet<Individual> negExamples = null; - negExamples = rs.getIndividuals(); - for (Individual rem_pos : posExamples) - negExamples.remove(rem_pos); - System.out.println("+" + posExamples); - System.out.println("-" + negExamples); - - //Step 3: Start learning-algorithm - - // step 3_1: set learning problem - ComponentManager cm = ComponentManager.getInstance(); - - PosNegDefinitionLP lp = new PosNegDefinitionLP(rs, - posExamples, negExamples); - - try { - initComponent(cm, lp); - } catch (ComponentInitException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - // step 3_2: set learning algorithm - - la = new ROLearner(lp, rs); - - try { - initComponent(cm, la); - } catch (ComponentInitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Thread laThread = new Thread() - { - @Override - public void run(){ - la.start(); - } - }; - laThread.start(); - - - System.out.println(la.getBestSolutions(5)); - - //Step 4: Knowledge Engineer chooses one of the suggestions - - //Step 5: Enrichment - - //Step 6: Repair:-check which individuals cause inconsistency - // -problem solving - - } - } - } - - } while (!conceptStr.equals("q")); - - } - - /** - * error handling over the logger - * - * @param message - * is a string and you message for problem - */ - public static void handleError(String message) { - logger.error(message); - System.exit(0); - } - - public ReasoningService getReasoningService() { - return rs; - } - - // edit by Tilo Hielscher - - /** - * Set Reasoner class. Define here all possible reasoners. - * - * @param reasonerOption - * from config file - * @return reasonerClass reasoner class - */ - public static Class<? extends ReasonerComponent> getReasonerClass( - ConfFileOption reasonerOption) { - Class<? extends ReasonerComponent> reasonerClass = null; - if (reasonerOption == null - || reasonerOption.getStringValue().equals("dig")) - reasonerClass = DIGReasoner.class; - else if (reasonerOption.getStringValue().equals("owlAPI")) - reasonerClass = OWLAPIReasoner.class; - else if (reasonerOption.getStringValue().equals("fastRetrieval")) - reasonerClass = FastRetrievalReasoner.class; - else if (reasonerOption.getStringValue().equals("fastInstanceChecker")) - reasonerClass = FastInstanceChecker.class; - else { - handleError("Unknown value " + reasonerOption.getStringValue() - + " for option \"reasoner\"."); - } - return reasonerClass; - } - - public static Class<? extends LearningAlgorithm> getLearningAlgorithm( - ConfFileOption algorithmOption) { - Class<? extends LearningAlgorithm> laClass = null; - if (algorithmOption == null - || algorithmOption.getStringValue().equals("refinement")) - laClass = ROLearner.class; - else if (algorithmOption.getStringValue().equals("refexamples")) - laClass = ExampleBasedROLComponent.class; - else if (algorithmOption.getStringValue().equals("gp")) - laClass = GP.class; - else if (algorithmOption.getStringValue().equals("bruteForce")) - laClass = BruteForceLearner.class; - else if (algorithmOption.getStringValue().equals("randomGuesser")) - laClass = RandomGuesser.class; - else - handleError("Unknown value in " + algorithmOption); - - return laClass; - } - -} Copied: trunk/src/dl-learner/org/dllearner/tools/ore/ORE_alt.java (from rev 721, trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/ore/ORE_alt.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/tools/ore/ORE_alt.java 2008-03-26 20:11:12 UTC (rev 728) @@ -0,0 +1,619 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.tools.ore; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithms.BruteForceLearner; +import org.dllearner.algorithms.RandomGuesser; +import org.dllearner.algorithms.gp.GP; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.cli.ConfFileOption; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.DoubleConfigOption; +import org.dllearner.core.config.IntegerConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; +import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.config.StringTupleListConfigOption; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.KBFile; +import org.dllearner.kb.OWLFile; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.learningproblems.PosNegDefinitionLP; +import org.dllearner.parser.ConfParser; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.parser.TokenMgrError; +import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.FastRetrievalReasoner; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.utilities.ConceptComparator; +import org.dllearner.utilities.Datastructures; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.StringTuple; + +/** + * Start class for the ontology repair and enrichment tool. + * + * @author Lorenz Buehmann. + * + */ +public class ORE_alt { + + private static Logger logger = Logger.getRootLogger(); + + private static LearningAlgorithm la; + private ReasoningService rs; + private KnowledgeSource ks; + + /** + * Entry point for CLI interface. + * + * @param args + */ + public static void main(String[] args) throws ComponentInitException { + + File file = new File(args[args.length - 1]); + + // create logger (a simple logger which outputs + // its messages to the console) + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.DEBUG); + + ORE_alt ore = null; + ore = new ORE_alt(file); + ore.start(); + } + + public ORE_alt(){ + + } + + public void setKnowledgeSource(File file){ + + } + + /** + * Initialise all components based on conf file. + * + * @param file + * Conf file to read. + * @throws ComponentInitException + */ + public ORE_alt(File file) throws ComponentInitException { + String baseDir = file.getParentFile().getPath(); + + // create component manager instance + String message = "starting component manager ... "; + long cmStartTime = System.nanoTime(); + ComponentManager cm = ComponentManager.getInstance(); + long cmTime = System.nanoTime() - cmStartTime; + message += "OK (" + Helper.prettyPrintNanoSeconds(cmTime) + ")"; + logger.info(message); + + // create a mapping between components and prefixes in the conf file + Map<Class<? extends Component>, String> componentPrefixMapping = createComponentPrefixMapping(); + + // parse conf file + ConfParser parser = ConfParser.parseFile(file); + + // step 1: detect knowledge sources + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); + Map<URL, Class<? extends KnowledgeSource>> importedFiles = getImportedFiles( + parser, baseDir); + for (Map.Entry<URL, Class<? extends KnowledgeSource>> entry : importedFiles + .entrySet()) { + KnowledgeSource ks = cm.knowledgeSource(entry.getValue()); + // apply URL entry (this assumes that every knowledge source has a + // configuration option "url"), so this may need to be changed in + // the + // future + cm.applyConfigEntry(ks, "url", entry.getKey().toString()); + + sources.add(ks); + configureComponent(cm, ks, componentPrefixMapping, parser); + initComponent(cm, ks); + } + + // step 2: detect used reasoner + ConfFileOption reasonerOption = parser.getConfOptionsByName("reasoner"); + ReasonerComponent reasoner = cm.reasoner( + getReasonerClass(reasonerOption), sources); + configureComponent(cm, reasoner, componentPrefixMapping, parser); + initComponent(cm, reasoner); + rs = cm.reasoningService(reasoner); + + } + + public void start() { + processOREMode(rs); + + } + + /** + * creates a mapping from components to option prefix strings + */ + public static Map<Class<? extends Component>, String> createComponentPrefixMapping() { + Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); + // knowledge sources + componentPrefixMapping.put(SparqlKnowledgeSource.class, "sparql"); + // reasoners + componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); + componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); + // learning problems - configured via + and - flags for examples + componentPrefixMapping.put(PosNegDefinitionLP.class, + "posNegDefinitionLP"); + // learning algorithms + componentPrefixMapping.put(ROLearner.class, "refinement"); + componentPrefixMapping.put(ExampleBasedROLComponent.class, + "refexamples"); + componentPrefixMapping.put(GP.class, "gp"); + return componentPrefixMapping; + } + + /** + * convenience method basically every prefix (e.g. "refinement" in + * "refinement.horizontalExpFactor) corresponds to a specific component - + * this way the CLI will automatically support any configuration options + * supported by the component + */ + public static void configureComponent(ComponentManager cm, + Component component, + Map<Class<? extends Component>, String> componentPrefixMapping, + ConfParser parser) { + String prefix = componentPrefixMapping.get(component.getClass()); + if (prefix != null) + configureComponent(cm, component, parser + .getConfOptionsByPrefix(prefix)); + } + + // convenience method - see above method + private static void configureComponent(ComponentManager cm, + Component component, List<ConfFileOption> options) { + if (options != null) + for (ConfFileOption option : options) + applyConfFileOption(cm, component, option); + } + + // applies an option to a component - checks whether the option and its + // value is valid + private static void applyConfFileOption(ComponentManager cm, + Component component, ConfFileOption option) { + // the name of the option is suboption-part (the first part refers + // to its component) + String optionName = option.getSubOption(); + + ConfigOption<?> configOption = cm.getConfigOption(component.getClass(), + optionName); + // check whether such an option exists + if (configOption != null) { + + // catch all invalid config options + try { + + // perform compatibility checks + if (configOption instanceof StringConfigOption + && option.isStringOption()) { + + ConfigEntry<String> entry = new ConfigEntry<String>( + (StringConfigOption) configOption, option + .getStringValue()); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof IntegerConfigOption + && option.isIntegerOption()) { + + ConfigEntry<Integer> entry = new ConfigEntry<Integer>( + (IntegerConfigOption) configOption, option + .getIntValue()); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof DoubleConfigOption + && (option.isIntegerOption() || option.isDoubleOption())) { + + double value; + if (option.isIntegerOption()) + value = option.getIntValue(); + else + value = option.getDoubleValue(); + + ConfigEntry<Double> entry = new ConfigEntry<Double>( + (DoubleConfigOption) configOption, value); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof BooleanConfigOption + && option.isStringOption()) { + + ConfigEntry<Boolean> entry = new ConfigEntry<Boolean>( + (BooleanConfigOption) configOption, Datastructures + .strToBool(option.getStringValue())); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof StringSetConfigOption + && option.isSetOption()) { + + ConfigEntry<Set<String>> entry = new ConfigEntry<Set<String>>( + (StringSetConfigOption) configOption, option + .getSetValues()); + cm.applyConfigEntry(component, entry); + + } else if (configOption instanceof StringTupleListConfigOption + && option.isListOption()) { + + ConfigEntry<List<StringTuple>> entry = new ConfigEntry<List<StringTuple>>( + (StringTupleListConfigOption) configOption, option + .getListTuples()); + cm.applyConfigEntry(component, entry); + + } else { + handleError("The type of conf file entry \"" + + option.getFullName() + + "\" is not correct: value \"" + option.getValue() + + "\" not valid for option type \"" + + configOption.getClass().getName() + "\"."); + } + + } catch (InvalidConfigOptionValueException e) { + e.printStackTrace(); + System.exit(0); + } + + } else + handleError("Unknow option " + option + "."); + } + + /** + * detects all imported files and their format + */ + public static Map<URL, Class<? extends KnowledgeSource>> getImportedFiles( + ConfParser parser, String baseDir) { + List<List<String>> imports = parser.getFunctionCalls().get("import"); + Map<URL, Class<? extends KnowledgeSource>> importedFiles = new HashMap<URL, Class<? extends KnowledgeSource>>(); + + if (imports != null) { + for (List<String> arguments : imports) { + // step 1: detect URL + URL url = null; + try { + String fileString = arguments.get(0); + if (fileString.startsWith("http:")) { + url = new URL(fileString); + } else { + File f = new File(baseDir, arguments.get(0)); + url = f.toURI().toURL(); + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } + + // step 2: detect format + Class<? extends KnowledgeSource> ksClass; + if (arguments.size() == 1) { + String filename = url.getPath(); + String ending = filename.substring(filename + .lastIndexOf(".") + 1); + + if (ending.equals("rdf") || ending.equals("owl")) + ksClass = OWLFile.class; + else if (ending.equals("nt")) + ksClass = OWLFile.class; + else if (ending.equals("kb")) + ksClass = KBFile.class; + else { + System.err.println("Warning: no format given for " + + arguments.get(0) + + " and could not detect it. Chosing RDF/XML."); + ksClass = OWLFile.class; + } + + importedFiles.put(url, ksClass); + } else { + String formatString = arguments.get(1); + + if (formatString.equals("RDF/XML")) + ksClass = OWLFile.class; + else if (formatString.equals("KB")) + ksClass = KBFile.class; + else if (formatString.equals("SPARQL")) + ksClass = SparqlKnowledgeSource.class; + else if (formatString.equals("NT")) + ksClass = OWLFile.class; + else { + throw new RuntimeException( + "Unsupported knowledge source format " + + formatString + ". Exiting."); + } + + importedFiles.put(url, ksClass); + } + } + } + + return importedFiles; + } + + private static void initComponent(ComponentManager cm, Component component) + throws ComponentInitException { + String startMessage = "initialising component \"" + + cm.getComponentName(component.getClass()) + "\" ... "; + long initStartTime = System.nanoTime(); + component.init(); + // standard messsage is just "OK" but ca... [truncated message content] |