You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ton...@us...> - 2008-01-19 16:20:55
|
Revision: 402 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=402&view=rev Author: tonytacker Date: 2008-01-19 08:20:53 -0800 (Sat, 19 Jan 2008) Log Message: ----------- - fixes at KnowledgeSource for choosing sparql Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-19 16:04:43 UTC (rev 401) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-19 16:20:53 UTC (rev 402) @@ -55,7 +55,7 @@ private Config config; private int choosenClassIndex; private List<Class<? extends KnowledgeSource>> sources; - private JLabel infoLabel = new JLabel("choose lokal file or type URL"); + private JLabel infoLabel = new JLabel("choose local file or type URL"); KnowledgeSourcePanel(final Config config) { super(new BorderLayout()); @@ -169,9 +169,11 @@ private void checkIfSparcle() { if (sources.get(choosenClassIndex).toString().contains("Sparql")) { openButton.setEnabled(false); + infoLabel.setText("type URL"); } else { openButton.setEnabled(true); + infoLabel.setText("choose local file or type URL"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-01-19 16:04:45
|
Revision: 401 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=401&view=rev Author: tonytacker Date: 2008-01-19 08:04:43 -0800 (Sat, 19 Jan 2008) Log Message: ----------- - improved button for local file or URL @ KnowledgeSourcePanel - deleted myrun-variable @ StartGUI - add ComponentManager.getName($class) for class-names Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-19 14:32:48 UTC (rev 400) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-19 16:04:43 UTC (rev 401) @@ -27,10 +27,11 @@ import javax.swing.event.*; import java.awt.BorderLayout; +import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.GridBagLayout; -//import org.dllearner.kb.*; import org.dllearner.core.KnowledgeSource; @@ -50,10 +51,11 @@ private JTextField fileDisplay; private String[] kbBoxItems = {}; private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel openPanel; + private JPanel centerPanel, choosePanel, initPanel; private Config config; private int choosenClassIndex; private List<Class<? extends KnowledgeSource>> sources; + private JLabel infoLabel = new JLabel("choose lokal file or type URL"); KnowledgeSourcePanel(final Config config) { super(new BorderLayout()); @@ -62,7 +64,7 @@ sources = config.getComponentManager().getKnowledgeSources(); fc = new JFileChooser(new File("examples/")); - openButton = new JButton("Open local file or type URL"); + openButton = new JButton("choose local file"); openButton.addActionListener(this); initButton = new JButton("Init KnowledgeSource"); @@ -86,24 +88,41 @@ // add to comboBox for (int i=0; i<sources.size(); i++) { - cb.addItem(sources.get(i).getSimpleName()); + // cb.addItem(sources.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName(sources.get(i))); } cb.addActionListener(this); - openPanel = new JPanel(); - - JPanel choosePanel = new JPanel(); + choosePanel = new JPanel(); choosePanel.add(cb); - JPanel initPanel = new JPanel(); + initPanel = new JPanel(); initPanel.add(initButton); - openPanel.add(fileDisplay); - openPanel.add(openButton); + centerPanel = new JPanel(); + // define GridBag + GridBagLayout gridbag = new GridBagLayout(); + centerPanel.setLayout(gridbag); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + + buildConstraints(constraints, 0, 0, 1, 1, 100, 100); + gridbag.setConstraints(infoLabel, constraints); + centerPanel.add(infoLabel); + + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(fileDisplay, constraints); + centerPanel.add(fileDisplay); + + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(openButton, constraints); + centerPanel.add(openButton); + add(choosePanel, BorderLayout.PAGE_START); - add(openPanel, BorderLayout.CENTER); + add(centerPanel, BorderLayout.CENTER); add(initPanel, BorderLayout.PAGE_END); choosenClassIndex = cb.getSelectedIndex(); @@ -112,6 +131,7 @@ public void actionPerformed(ActionEvent e) { // read selected KnowledgeSourceClass choosenClassIndex = cb.getSelectedIndex(); + checkIfSparcle(); // open File if (e.getSource() == openButton) { @@ -133,5 +153,26 @@ System.out.println("init KnowledgeSource with \n" + sources.get(choosenClassIndex) + " and \n" + config.getURI() + "\n"); } } + + /* + * Define GridBagConstraints + */ + private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { + gbc.gridx = gx; + gbc.gridy = gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } + + private void checkIfSparcle() { + if (sources.get(choosenClassIndex).toString().contains("Sparql")) { + openButton.setEnabled(false); + } + else { + openButton.setEnabled(true); + } + } } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-19 14:32:48 UTC (rev 400) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-19 16:04:43 UTC (rev 401) @@ -67,7 +67,9 @@ // add into comboBox learners = config.getComponentManager().getLearningAlgorithms(); for (int i=0; i<learners.size(); i++) { - cb.addItem(learners.get(i).getSimpleName()); + //cb.addItem(learners.get(i).getSimpleName()); + //System.out.println(learners.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName(learners.get(i))); } } @@ -80,7 +82,7 @@ config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); config.getLearningAlgorithm().init(); } - if (config.getStatus(5)) { // exemples are set + if (config.getStatus(5)) { // examples are set System.out.println("LearningAlgorithm: " + config.getLearningAlgorithm() + "\n"); } } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-19 14:32:48 UTC (rev 400) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-19 16:04:43 UTC (rev 401) @@ -88,7 +88,8 @@ // add into comboBox for (int i=0; i<problems.size(); i++) { - cb.addItem(problems.get(i).getSimpleName()); + //cb.addItem(problems.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName(problems.get(i))); } // read choosen LearningProblem Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-19 14:32:48 UTC (rev 400) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-19 16:04:43 UTC (rev 401) @@ -66,7 +66,8 @@ // add into comboBox reasoners = config.getComponentManager().getReasonerComponents(); for (int i=0; i<reasoners.size(); i++) { - cb.addItem(reasoners.get(i).getSimpleName()); + //cb.addItem(reasoners.get(i).getSimpleName()); + cb.addItem(config.getComponentManager().getComponentName(reasoners.get(i))); } } Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-19 14:32:48 UTC (rev 400) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-19 16:04:43 UTC (rev 401) @@ -38,8 +38,6 @@ private static final long serialVersionUID = -739265982906533775L; - protected static StartGUI myrun; - public JTabbedPane tabPane = new JTabbedPane(); private JPanel tab1 = new JPanel(); @@ -77,15 +75,12 @@ logger.addAppender(consoleAppender); logger.setLevel(Level.INFO); - myrun = new StartGUI(); + new StartGUI(); } protected void renew() { tabPane.repaint(); } - protected StartGUI getStartGUI() { - return myrun; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-19 14:32:51
|
Revision: 400 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=400&view=rev Author: jenslehmann Date: 2008-01-19 06:32:48 -0800 (Sat, 19 Jan 2008) Log Message: ----------- - added log4j logging framework (update your classpath) - added logging initialisation for all interfaces: CLI, GUI, Web-Service; consider using log statements instead of System.out.println in the future - some smaller fixes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java Added Paths: ----------- trunk/lib/log4j.jar Added: trunk/lib/log4j.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/log4j.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-01-19 14:32:48 UTC (rev 400) @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.LinkedList; +import org.apache.log4j.Logger; import org.dllearner.algorithms.gp.Program; import org.dllearner.algorithms.gp.GPUtilities; import org.dllearner.core.LearningAlgorithm; @@ -43,6 +44,8 @@ private int numberOfTrees; private int maxDepth; + private static Logger logger = Logger.getLogger(RandomGuesser.class); + public RandomGuesser(LearningProblem learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; } @@ -103,12 +106,9 @@ } } - System.out.print("Random-Guesser (" + numberOfTrees + " trials, "); - System.out.println("maximum depth " + maxDepth + ")"); - System.out.println("best solution: " + bestDefinition); - System.out.println("fitness: " + bestFitness); - - // System.out.println(bestScore); + logger.info("Random-Guesser (" + numberOfTrees + " trials, maximum depth " + maxDepth + ")"); + logger.info("best solution: " + bestDefinition); + logger.info("fitness: " + bestFitness); } @Override Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-19 14:32:48 UTC (rev 400) @@ -34,6 +34,12 @@ 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.refinement.ROLearner; import org.dllearner.core.Component; @@ -92,11 +98,20 @@ public static void main(String[] args) { File file = new File(args[args.length - 1]); String baseDir = file.getParentFile().getPath(); - + boolean inQueryMode = false; if (args.length > 1 && args[0].equals("-q")) inQueryMode = true; + // create logger (a simple logger which outputs + // its messages to the console) + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + Logger logger = Logger.getRootLogger(); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + // create component manager instance System.out.print("starting component manager ... "); long cmStartTime = System.nanoTime(); @@ -173,19 +188,16 @@ laClass = ROLearner.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); la = cm.learningAlgorithm(laClass, lp, rs); configureComponent(cm, la, componentPrefixMapping, parser); initComponent(cm, la); - - // initialise all structures -// for (KnowledgeSource source : sources) -// initComponent(cm, source); -// initComponent(cm, reasoner); -// initComponent(cm, lp); -// initComponent(cm, la); // perform file exports performExports(parser, baseDir, sources, rs); Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-19 14:32:48 UTC (rev 400) @@ -22,6 +22,11 @@ import javax.swing.*; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; + /** * StartGUI * @@ -64,6 +69,14 @@ } public static void main(String[] args) { + // create GUI logger + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + Logger logger = Logger.getRootLogger(); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + myrun = new StartGUI(); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-19 14:32:48 UTC (rev 400) @@ -30,10 +30,12 @@ import java.util.Set; import java.util.Vector; +import org.apache.log4j.Logger; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.OntologyFormat; import org.dllearner.core.OntologyFormatUnsupportedException; import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.CommonConfigOptions; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.IntegerConfigOption; @@ -61,7 +63,7 @@ // ConfigOptions private URL url; - String host; + // String host; private Set<String> instances = new HashSet<String>();; private URL dumpFile; private int recursionDepth = 1; @@ -82,7 +84,8 @@ private int numberOfInstancesUsedForRoleLearning = 40; private String role = ""; private String blankNodeIdentifier = "bnode"; - +// private String verbosity = "warning"; + //LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); @@ -130,9 +133,11 @@ private KB kb; public static String getName() { - return "SPARQL Endpoint Restructured"; + return "SPARQL Endpoint"; } + private static Logger logger = Logger.getLogger(SparqlKnowledgeSource.class); + /** * sets the ConfigOptions for this KnowledgeSource * @@ -141,7 +146,7 @@ public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); +// options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); options .add(new StringSetConfigOption("instances", "relevant instances e.g. positive and negative examples in a learning problem")); @@ -193,6 +198,7 @@ "numberOfInstancesUsedForRoleLearning", "")); options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + options.add(CommonConfigOptions.getVerbosityOption()); return options; } @@ -213,8 +219,8 @@ throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), "malformed URL " + s); } - } else if (option.equals("host")) { - host = (String) entry.getValue(); +// } else if (option.equals("host")) { +// host = (String) entry.getValue(); } else if (option.equals("instances")) { instances = (Set<String>) entry.getValue(); } else if (option.equals("recursionDepth")) { @@ -257,6 +263,8 @@ numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); } else if (option.equals("closeAfterRecursion")) { closeAfterRecursion = (Boolean) entry.getValue(); +// } else if (option.equals("verbosity")) { +// verbosity = (String) entry.getValue(); } } @@ -268,7 +276,7 @@ */ @Override public void init() { - System.out.println("SparqlModul: Collecting Ontology"); + logger.info("SparqlModul: Collecting Ontology"); // SparqlOntologyCollector oc= // new SparqlOntologyCollector(Datastructures.setToArray(instances), // numberOfRecursions, filterMode, @@ -327,7 +335,7 @@ break; } pos = tmp; - System.out.println("Instances used: " + pos.size()); + logger.info("Instances used: " + pos.size()); tmp = new HashSet<String>(); for (String one : neg) { @@ -343,10 +351,10 @@ instances.addAll(neg); for (String one : pos) { - System.out.println("+\"" + one + "\""); + logger.info("+\"" + one + "\""); } for (String one : neg) { - System.out.println("-\"" + one + "\""); + logger.info("-\"" + one + "\""); } /* @@ -365,12 +373,12 @@ } // the actual extraction is started here ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: " + logger.info("Number of cached SPARQL queries: " + m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: " + logger.info("Number of uncached SPARQL queries: " + m.getConfiguration().numberOfUncachedSparqlQueries); - System.out.println("Finished collecting Fragment"); + logger.info("Finished collecting Fragment"); if (dumpToFile) { String filename = System.currentTimeMillis() + ".nt"; @@ -401,7 +409,7 @@ } catch (Exception e) { e.printStackTrace(); } - System.out.println("SparqlModul: ****Finished"); + logger.info("SparqlModul: ****Finished"); } /* @@ -446,7 +454,7 @@ * @param limit */ public void calculateSubjects(String label, int limit) { - System.out.println("SparqlModul: Collecting Subjects"); + logger.info("SparqlModul: Collecting Subjects"); // oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); // try { Vector<String> v = (SparqlQuery.makeLabelQuery(label, limit, sse) @@ -458,7 +466,7 @@ // subjects = new String[1]; // subjects[0] = "[Error]Sparql Endpoint could not be reached."; // } - System.out.println("SparqlModul: ****Finished"); + logger.info("SparqlModul: ****Finished"); } /** @@ -467,7 +475,7 @@ * @param subject */ public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); + logger.info("SparqlModul: Collecting Triples"); Vector<StringTuple> v = (SparqlQuery.makeArticleQuery(subject, sse) .getAsVectorOfTupels("predicate", "objcet")); //String[] subjects = (String[]) v.toArray(new String[v.size()]); @@ -484,7 +492,7 @@ // triples = new String[1]; // triples[0] = "[Error]Sparql Endpoint could not be reached."; //} - System.out.println("SparqlModul: ****Finished"); + logger.info("SparqlModul: ****Finished"); } /** @@ -493,7 +501,7 @@ * @param concept */ public void calculateConceptSubjects(String concept) { - System.out.println("SparqlModul: Collecting Subjects"); + logger.info("SparqlModul: Collecting Subjects"); Vector<String> v = (SparqlQuery.makeConceptQuery(concept, sse) .getAsVector("subject")); conceptSubjects = (String[]) v.toArray(new String[v.size()]); @@ -506,7 +514,7 @@ // conceptSubjects = new String[1]; // conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; // } - System.out.println("SparqlModul: ****Finished"); + logger.info("SparqlModul: ****Finished"); } public boolean subjectThreadIsRunning() { Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-19 14:32:48 UTC (rev 400) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2008-01-19 10:16:30 UTC (rev 399) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWSStart.java 2008-01-19 14:32:48 UTC (rev 400) @@ -1,7 +1,24 @@ +/** + * 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.server; - - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -11,61 +28,78 @@ import javax.xml.ws.Endpoint; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; + import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpServer; - +/** + * Starts the DL-Learner web service. + * + * @author Jens Lehmann + * @author Sebastian Hellmann + * + */ public class DLLearnerWSStart { public static void main(String[] args) { - //String url = "http://139.18.114.78:8181/services"; - /*String url=""; - if (args.length > 0) - url = args[0];*/ - try{ - - InetSocketAddress isa=new InetSocketAddress("localhost",8181); - HttpServer server = HttpServer.create(isa, 5); - ExecutorService threads = Executors.newFixedThreadPool(5); - server.setExecutor(threads); - server.start(); - - System.out.print("Starting DL-Learner web service at http://" + - isa.getHostName()+":"+isa.getPort()+ "/services ... "); - Endpoint endpoint = Endpoint.create(new DLLearnerWS()); - //Endpoint endpoint = Endpoint.create(new CustomDataClass()); + + // create web service logger + SimpleLayout layout = new SimpleLayout(); + ConsoleAppender consoleAppender = new ConsoleAppender(layout); + Logger logger = Logger.getRootLogger(); + logger.removeAllAppenders(); + logger.addAppender(consoleAppender); + logger.setLevel(Level.INFO); + + InetSocketAddress isa = new InetSocketAddress("localhost", 8181); + HttpServer server = null; + try { + server = HttpServer.create(isa, 0); + } catch (IOException e1) { + e1.printStackTrace(); + } + ExecutorService threads = Executors.newFixedThreadPool(10); + server.setExecutor(threads); + server.start(); + + System.out.println("Starting DL-Learner web service at http://" + isa.getHostName() + ":" + + isa.getPort() + "/services ... "); + Endpoint endpoint = Endpoint.create(new DLLearnerWS()); + // Endpoint endpoint = Endpoint.create(new CustomDataClass()); HttpContext context = server.createContext("/services"); - endpoint.publish(context); - //Endpoint endpoint = Endpoint.publish(url, new DLLearnerWS()); - + endpoint.publish(context); + // Endpoint endpoint = Endpoint.publish(url, new DLLearnerWS()); + System.out.println("OK."); - - System.out.println("Type \"exit\" to terminate web service."); boolean terminate = false; String inputString = ""; do { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); - + try { inputString = input.readLine(); } catch (IOException e) { e.printStackTrace(); } - + if (inputString.equals("exit")) terminate = true; - + } while (!terminate); System.out.print("Stopping web service ... "); endpoint.stop(); - - server.stop(1); - threads.shutdown(); + + server.stop(1); + threads.shutdown(); System.out.println("OK."); - }catch (Exception e) {e.printStackTrace();} + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-19 10:16:34
|
Revision: 399 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=399&view=rev Author: jenslehmann Date: 2008-01-19 02:16:30 -0800 (Sat, 19 Jan 2008) Log Message: ----------- - added JUnit library for unit tests (please update your classpath) - implemented first unit test - added missing getName() methods Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java Added Paths: ----------- trunk/lib/junit-4.4.jar trunk/src/dl-learner/org/dllearner/test/ trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java trunk/src/dl-learner/org/dllearner/test/ComponentTests.java trunk/src/dl-learner/org/dllearner/test/package.html Added: trunk/lib/junit-4.4.jar =================================================================== (Binary files differ) Property changes on: trunk/lib/junit-4.4.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-01-19 08:11:27 UTC (rev 398) +++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2008-01-19 10:16:30 UTC (rev 399) @@ -72,6 +72,10 @@ this.learningProblem = learningProblem; } + public static String getName() { + return "brute force learning algorithm"; + } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(LearningProblem.class); Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-01-19 08:11:27 UTC (rev 398) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2008-01-19 10:16:30 UTC (rev 399) @@ -47,6 +47,10 @@ this.learningProblem = learningProblem; } + public static String getName() { + return "random guesser learning algorithm"; + } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(LearningProblem.class); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-01-19 08:11:27 UTC (rev 398) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2008-01-19 10:16:30 UTC (rev 399) @@ -140,7 +140,11 @@ this.learningProblem = learningProblem; this.rs = rs; } - + + public static String getName() { + return "genetic programming learning algorithm"; + } + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-01-19 08:11:27 UTC (rev 398) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-01-19 10:16:30 UTC (rev 399) @@ -83,6 +83,10 @@ // hier muss nichts getan werden } + public static String getName() { + return "fast retrieval reasoner"; + } + /* (non-Javadoc) * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) */ Modified: trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2008-01-19 08:11:27 UTC (rev 398) +++ trunk/src/dl-learner/org/dllearner/reasoning/KAON2Reasoner.java 2008-01-19 10:16:30 UTC (rev 399) @@ -244,6 +244,10 @@ } */ + public static String getName() { + return "KAON2 reasoner"; + } + // TODO: hier werden momentan keine allowed concepts berücksichtigt // (benötigt rekursive Aufrufe, da ein erlaubtes Konzept von einem nicht // erlaubten verdeckt werden könnte) Added: trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/AllTestsRunner.java 2008-01-19 10:16:30 UTC (rev 399) @@ -0,0 +1,39 @@ +/** + * 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.test; + +import org.junit.runner.JUnitCore; + +/** + * Class designed to run all DL-Learner component tests. Note, + * that in Eclipse (and similar in other IDEs) you can run + * JUnit tests by clicking on a file containing methods annotated + * with @Test and "Run As JUnit Test". + * + * @author Jens Lehmann + * + */ +public class AllTestsRunner { + + public static void main(String[] args) { + JUnitCore.main("org.dllearner.test.ComponentTests"); + } + +} Added: trunk/src/dl-learner/org/dllearner/test/ComponentTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTests.java 2008-01-19 10:16:30 UTC (rev 399) @@ -0,0 +1,54 @@ +/** + * 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.test; + +import java.util.List; + +import org.dllearner.core.Component; +import org.dllearner.core.ComponentManager; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * A suite of JUnit tests related to the DL-Learner component architecture. + * + * @author Jens Lehmann + * + */ +public class ComponentTests { + + /** + * Checks whether all components implement the getName() method. While it + * cannot be enforced to implement a static method, it should be done (e.g. + * to be used as label for the component in GUIs). + */ + @Test + public void nameTest() { + String defaultName = Component.getName(); + ComponentManager cm = ComponentManager.getInstance(); + List<Class<? extends Component>> components = cm.getComponents(); + for (Class<? extends Component> component : components) { + String componentName = cm.getComponentName(component); + assertFalse(component + " does not overwrite getName().", componentName + .equals(defaultName)); + } + } + +} Added: trunk/src/dl-learner/org/dllearner/test/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/test/package.html (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/package.html 2008-01-19 10:16:30 UTC (rev 399) @@ -0,0 +1,7 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head></head> +<body bgcolor="white"> +<p>DL-Learner JUnit tests.</p> +</body> +</html> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-19 08:11:30
|
Revision: 398 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=398&view=rev Author: jenslehmann Date: 2008-01-19 00:11:27 -0800 (Sat, 19 Jan 2008) Log Message: ----------- - fixed/suppressed remaining warnings in SPARQL component - deleted deprecated files in SPARQL component Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/old/ Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-01-19 02:08:16 UTC (rev 397) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-01-19 08:11:27 UTC (rev 398) @@ -20,7 +20,6 @@ package org.dllearner.kb.sparql; import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.old.oldSparqlFilter; /** * Can assemble sparql queries. can make queries for subject, predicate, object @@ -137,6 +136,7 @@ * special object encapsulating all options * @return sparql query */ + /* public static String makeQueryFilter(String subject, oldSparqlFilter sf) { String Filter = ""; @@ -157,7 +157,8 @@ // System.out.println(ret); return ret; } - +*/ + /* * moved to SparqlQuery TODO remove here creates a query for subjects with * the specified label @param label a phrase that is part of the label of a Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-19 02:08:16 UTC (rev 397) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-19 08:11:27 UTC (rev 398) @@ -120,6 +120,7 @@ * * @return jena List<ResultBinding> */ + @SuppressWarnings({"unchecked"}) public List<ResultBinding> getAsList() { ResultSet rs = send(); return ResultSetFormatter.toList(rs); @@ -133,6 +134,7 @@ * @param varName * @return Vector<String> */ + @SuppressWarnings({"unchecked"}) public Vector<String> getAsVector(String varName) { ResultSet rs = send(); Vector<String> vret = new Vector<String>(); @@ -152,6 +154,7 @@ * @param varName2 * @return Vector<StringTuple> */ + @SuppressWarnings({"unchecked"}) public Vector<StringTuple> getAsVectorOfTupels(String varName1, String varName2) { ResultSet rs = send(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java 2008-01-19 02:08:16 UTC (rev 397) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java 2008-01-19 08:11:27 UTC (rev 398) @@ -61,6 +61,7 @@ return ""; } + @SuppressWarnings({"unchecked"}) public static void testSaving(List<ResultBinding> l) { System.out.println(l + "\n****************************"); try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-19 02:08:22
|
Revision: 397 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=397&view=rev Author: kurzum Date: 2008-01-18 18:08:16 -0800 (Fri, 18 Jan 2008) Log Message: ----------- I made some test classes, problem with TestStaticQueries everything in .sparql.old can be removed the extraction algorithm might not be working, because of problems with the cache or so check also how to return literals and such Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestExtraction.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestStaticQueries.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-19 01:26:40 UTC (rev 396) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-19 02:08:16 UTC (rev 397) @@ -155,9 +155,13 @@ public Vector<StringTuple> getAsVectorOfTupels(String varName1, String varName2) { ResultSet rs = send(); + Vector<StringTuple> vret = new Vector<StringTuple>(); List<ResultBinding> l = ResultSetFormatter.toList(rs); + //System.out.println(l); + //System.out.println(ResultSetFormatter.asXMLString(rs)); for (ResultBinding resultBinding : l) { + vret.add(new StringTuple(resultBinding.get(varName1).toString(), resultBinding.get(varName2).toString())); } @@ -200,7 +204,7 @@ //TODO maybe use http://xmlns:com/foaf/0.1/page String queryString= "SELECT DISTINCT ?subject\n"+ - "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object bif:contains '\""+label+"\"'@en}\n"+ + "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object. ?object bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; return new SparqlQuery( queryString,endpoint); } @@ -225,7 +229,7 @@ */ public static SparqlQuery makeArticleQuery(String subject,SparqlEndpoint endpoint){ String queryString = - "SELECT ?predicate,?object\n"+ + "SELECT ?predicate ?object\n"+ "WHERE { <"+subject+"> ?predicate ?object}\n"; return new SparqlQuery( queryString,endpoint); } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java 2008-01-19 01:26:40 UTC (rev 396) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java 2008-01-19 02:08:16 UTC (rev 397) @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql.test; - -import java.io.File; -import java.io.FileWriter; -import java.net.URI; - -import org.dllearner.kb.sparql.Manager; - -/** - * Test class, uses the whole thing - * - * @author Sebastian Hellmann - * - */ -public class Test { - - public static void main(String[] args) { - System.out.println("Start"); - // String test2 = "http://www.extraction.org/config#dbpediatest"; - // String test = "http://www.extraction.org/config#localjoseki"; - try { - // URI u = new URI(test); - Manager m = new Manager(); - // m.usePredefinedConfiguration(u); - - URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); - - String filename = System.currentTimeMillis() + ".nt"; - FileWriter fw = new FileWriter(new File(filename), true); - fw.write(m.extract(u2)); - fw.flush(); - fw.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestExtraction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestExtraction.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestExtraction.java 2008-01-19 02:08:16 UTC (rev 397) @@ -0,0 +1,69 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.sparql.test; + +import java.io.File; +import java.io.FileWriter; +import java.net.URI; +import java.util.LinkedList; + +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.Manipulator; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.utilities.StringTuple; + +/** + * Test class, uses the whole thing + * + * @author Sebastian Hellmann + * + */ +public class TestExtraction { + + public static void main(String[] args) { + System.out.println("Start"); + // String test2 = "http://www.extraction.org/config#dbpediatest"; + // String test = "http://www.extraction.org/config#localjoseki"; + try { + // URI u = new URI(test); + Manager m = new Manager(); + // m.usePredefinedConfiguration(u); + + URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); + m.useConfiguration( + SparqlQueryType.getFilterByNumber(1),SparqlEndpoint.getEndpointByNumber(1), + new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), + 1,true,true); + //, , + //manipulator, recursiondepth, getAllSuperClasses, closeAfterRecursion) + + String filename = System.currentTimeMillis() + ".nt"; + FileWriter fw = new FileWriter(new File(filename), true); + fw.write(m.extract(u2)); + fw.flush(); + fw.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestStaticQueries.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestStaticQueries.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestStaticQueries.java 2008-01-19 02:08:16 UTC (rev 397) @@ -0,0 +1,72 @@ +/** + * 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.kb.sparql.test; + +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.query.SparqlQuery; + +public class TestStaticQueries { + + // tests makeArticleQuery + // + // + public static void main(String[] args) { + String test1="http://dbpedia.org/resource/Angela_Merkel"; + String test2="http://dbpedia.org/resource/Leipzig"; + String test3="http://dbpedia.org/class/yago/Woman110787470"; + boolean one=false; + boolean two=true; + boolean three=false; + try { + if(one){ + //System.out.println(SparqlQuery.makeArticleQuery(test1, + // SparqlEndpoint.getEndpointByNumber(1)).getAsXMLString()); + //System.out.println(SparqlQuery.makeArticleQuery(test1, + // SparqlEndpoint.getEndpointByNumber(1)).getAsList()); + System.out.println(SparqlQuery.makeArticleQuery(test1, + SparqlEndpoint.getEndpointByNumber(1)).getAsVectorOfTupels("predicate", "object")); + } + + if(two){ + System.out.println(SparqlQuery.makeLabelQuery(test2,10, + SparqlEndpoint.getEndpointByNumber(1)).getAsXMLString()); + System.out.println(SparqlQuery.makeLabelQuery(test2,10, + SparqlEndpoint.getEndpointByNumber(1)).getAsList()); + System.out.println(SparqlQuery.makeLabelQuery(test2,10, + SparqlEndpoint.getEndpointByNumber(1)).getAsVector("subject")); + } + if(three){ + System.out.println(SparqlQuery.makeConceptQuery(test3, + SparqlEndpoint.getEndpointByNumber(1)).getAsXMLString()); + System.out.println(SparqlQuery.makeConceptQuery(test3, + SparqlEndpoint.getEndpointByNumber(1)).getAsList()); + System.out.println(SparqlQuery.makeConceptQuery(test3, + SparqlEndpoint.getEndpointByNumber(1)).getAsVector("subject")); + } + + + + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-19 01:26:41
|
Revision: 396 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=396&view=rev Author: kurzum Date: 2008-01-18 17:26:40 -0800 (Fri, 18 Jan 2008) Log Message: ----------- more changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/SparqlQueryConventional.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-19 01:26:40 UTC (rev 396) @@ -19,7 +19,6 @@ */ package org.dllearner.kb.sparql; -import java.io.IOException; import java.net.URI; import java.util.HashSet; import java.util.Set; @@ -27,10 +26,9 @@ import java.util.TreeSet; import org.dllearner.kb.sparql.configuration.Configuration; -import org.dllearner.kb.sparql.configuration.SparqlQueryType; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; import org.dllearner.kb.sparql.datastructure.Node; -import org.dllearner.kb.sparql.old.oldSparqlOntologyCollector; import org.dllearner.utilities.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-19 01:26:40 UTC (rev 396) @@ -36,23 +36,21 @@ * */ public class Manipulator { - public String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + public String blankNodeIdentifier = "bnode"; public int breakSuperClassRetrievalAfter=200; public LinkedList<StringTuple> replacePredicate; public LinkedList<StringTuple> replaceObject; - String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - String classns = "http://www.w3.org/2002/07/owl#Class"; - String thing = "http://www.w3.org/2002/07/owl#Thing"; - + Set<String> classproperties; - String[] defaultClasses = { "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Category:", "http://dbpedia.org/resource/Template:", - "http://www.w3.org/2004/02/skos/core", "http://dbpedia.org/class/" }; - public Manipulator(String blankNodeIdentifier,int breakSuperClassRetrievalAfter,LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) { this.blankNodeIdentifier = blankNodeIdentifier; this.replaceObject=replaceObject; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-19 01:26:40 UTC (rev 396) @@ -21,15 +21,14 @@ import java.io.File; import java.io.FileWriter; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Set; +import java.util.Vector; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.OntologyFormat; @@ -45,7 +44,6 @@ import org.dllearner.core.dl.KB; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.old.oldSparqlOntologyCollector; import org.dllearner.kb.sparql.query.SparqlQuery; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; @@ -85,7 +83,7 @@ private String role = ""; private String blankNodeIdentifier = "bnode"; - LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + //LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); @@ -276,14 +274,15 @@ // numberOfRecursions, filterMode, // Datastructures.setToArray(predList),Datastructures.setToArray( // objList),Datastructures.setToArray(classList),format,url,useLits); + Manager m = new Manager(); SparqlQueryType sqt = null; // get Options for Manipulator Manipulator man = new Manipulator(blankNodeIdentifier, breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); + //HashMap<String, String> parameters = new HashMap<String, String>(); + //parameters.put("default-graph-uri", "http://dbpedia.org"); + //parameters.put("format", "application/sparql-results.xml"); // get Options for endpoints if (predefinedEndpoint >= 1) { @@ -296,10 +295,10 @@ // get Options for Filters if (predefinedFilter >= 1) { - sqt = SparqlQueryType.getFilter(predefinedFilter); + sqt = SparqlQueryType.getFilterByNumber(predefinedFilter); } else { - sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + sqt = new SparqlQueryType("forbid", objList, predList, useLits ); } // give everything to the manager @@ -355,8 +354,7 @@ * * * Object[] arr=instances.toArray(); - * while(instances.size()>=30){ - * } + * while(instances.size()>=30){ } */ // add the role to the filter(a solution is always EXISTS // role.TOP) @@ -443,20 +441,23 @@ } /** - * TODO SparqlOntologyCollector needs to be removed * * @param label * @param limit */ public void calculateSubjects(String label, int limit) { System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - subjects = oc.getSubjectsFromLabel(label, limit); - } catch (IOException e) { - subjects = new String[1]; - subjects[0] = "[Error]Sparql Endpoint could not be reached."; - } + // oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + // try { + Vector<String> v = (SparqlQuery.makeLabelQuery(label, limit, sse) + .getAsVector("subject")); + subjects = (String[]) v.toArray(new String[v.size()]); + // subjects = oc.getSubjectsFromLabel(label, limit); + // } catch (IOException e) { + // TODO I removed IOException, please check + // subjects = new String[1]; + // subjects[0] = "[Error]Sparql Endpoint could not be reached."; + // } System.out.println("SparqlModul: ****Finished"); } @@ -467,30 +468,44 @@ */ public void calculateTriples(String subject) { System.out.println("SparqlModul: Collecting Triples"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - triples = oc.collectTriples(subject); - } catch (IOException e) { - triples = new String[1]; - triples[0] = "[Error]Sparql Endpoint could not be reached."; + Vector<StringTuple> v = (SparqlQuery.makeArticleQuery(subject, sse) + .getAsVectorOfTupels("predicate", "objcet")); + //String[] subjects = (String[]) v.toArray(new String[v.size()]); + String[] tmp = new String[v.size()]; + int i=0; + for (StringTuple stringTuple : v) { + tmp[i++]=stringTuple.a+"<"+stringTuple.b; } + triples=tmp; + //oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + //try { + // triples = oc.collectTriples(subject); + //} catch (IOException e) { + // triples = new String[1]; + // triples[0] = "[Error]Sparql Endpoint could not be reached."; + //} System.out.println("SparqlModul: ****Finished"); } /** - * TODO SparqlOntologyCollector needs to be removed * + * * @param concept */ public void calculateConceptSubjects(String concept) { System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - conceptSubjects = oc.getSubjectsFromConcept(concept); - } catch (IOException e) { - conceptSubjects = new String[1]; - conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; - } + Vector<String> v = (SparqlQuery.makeConceptQuery(concept, sse) + .getAsVector("subject")); + conceptSubjects = (String[]) v.toArray(new String[v.size()]); + + // oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + // try { + // conceptSubjects = oc.getSubjectsFromConcept(concept); + // } catch (IOException e) { + // TODO I removed IOException, please check + // conceptSubjects = new String[1]; + // conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + // } System.out.println("SparqlModul: ****Finished"); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-01-19 01:26:40 UTC (rev 396) @@ -22,22 +22,16 @@ import org.dllearner.kb.sparql.configuration.SparqlQueryType; import org.dllearner.kb.sparql.old.oldSparqlFilter; - /** - * Can assemble sparql queries. + * Can assemble sparql queries. can make queries for subject, predicate, object + * according to the filter settings object not yet implemented * * @author Sebastian Hellmann - * + * */ public class SparqlQueryMaker { - String lineend="\n"; - boolean print_flag=false; - /* can make queries for subject, predicate, object - * according to the filter settings - * object not yet implemented - * - * */ - + String lineend = "\n"; + boolean print_flag = false; private SparqlQueryType sparqlQueryType; public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { @@ -45,49 +39,51 @@ } public String makeSubjectQueryUsingFilters(String subject) { - + String Filter = internalFilterAssemblySubject(); - String ret = "SELECT * WHERE { " + lineend + "<" + subject + "> ?predicate ?object. " - + lineend + "FILTER( " + lineend + "(" + Filter + ").}"; + String ret = "SELECT * WHERE { " + lineend + "<" + subject + + "> ?predicate ?object. " + lineend + "FILTER( " + lineend + + "(" + Filter + ").}"; // System.out.println(ret); - //System.out.println(sparqlQueryType.getPredicatefilterlist().length); + // System.out.println(sparqlQueryType.getPredicatefilterlist().length); return ret; } public String makeRoleQueryUsingFilters(String role) { - + String Filter = internalFilterAssemblyRole(); - String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role + "> ?object. " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; + String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role + + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter + + ").}"; // System.out.println(ret); return ret; } - public String makeRoleQueryUsingFilters(String role,boolean domain) { - + + public String makeRoleQueryUsingFilters(String role, boolean domain) { + String Filter = internalFilterAssemblyRole(); - String ret=""; - if(domain){ - ret = "SELECT * WHERE { " + lineend + - "?subject <" + role + "> ?object; a []. " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}" ; - //"ORDER BY ?subject"; - // System.out.println(ret); - }else{ - ret = "SELECT * WHERE { " + lineend + - "?object a [] . " + - "?subject <" + role + "> ?object . " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; - //"ORDER BY ?object"; - + String ret = ""; + if (domain) { + ret = "SELECT * WHERE { " + lineend + "?subject <" + role + + "> ?object; a []. " + lineend + "FILTER( " + lineend + + "(" + Filter + ").}"; + // "ORDER BY ?subject"; + // System.out.println(ret); + } else { + ret = "SELECT * WHERE { " + lineend + "?object a [] . " + + "?subject <" + role + "> ?object . " + lineend + + "FILTER( " + lineend + "(" + Filter + ").}"; + // "ORDER BY ?object"; + } - //System.out.println(ret); + // System.out.println(ret); return ret; } private String internalFilterAssemblySubject() { - + String Filter = ""; if (!this.sparqlQueryType.isLiterals()) Filter += "!isLiteral(?object))"; @@ -101,7 +97,7 @@ } private String internalFilterAssemblyRole() { - + String Filter = ""; if (!this.sparqlQueryType.isLiterals()) Filter += "!isLiteral(?object))"; @@ -125,69 +121,65 @@ public static String filterObject(String ns) { return "&&( !regex(str(?object), '" + ns + "') )"; } - - public void p(String str){ - if(print_flag){ + + public void p(String str) { + if (print_flag) { System.out.println(str); } } - + /** - * creates a query with the specified filters for alls triples with subject - * @param subject the searched subject - * @param sf special object encapsulating all options + * creates a query with the specified filters for all triples with subject + * + * @param subject + * the searched subject + * @param sf + * special object encapsulating all options * @return sparql query */ - public static String makeQueryFilter(String subject, oldSparqlFilter sf){ - - - String Filter=""; - if(!sf.useLiterals)Filter+="!isLiteral(?object)"; - for (String p : sf.getPredFilter()) { - Filter+="\n" + filterPredicate(p); + public static String makeQueryFilter(String subject, oldSparqlFilter sf) { + + String Filter = ""; + if (!sf.useLiterals) + Filter += "!isLiteral(?object)"; + for (String p : sf.getPredFilter()) { + Filter += "\n" + filterPredicate(p); } - for (String o : sf.getObjFilter()) { - Filter+="\n" + filterObject(o); + for (String o : sf.getObjFilter()) { + Filter += "\n" + filterObject(o); } - - String ret= - "SELECT * WHERE { \n" + - "<"+ - subject+ - "> ?predicate ?object.\n"; - if (!(Filter.length()==0)) - ret+="FILTER( \n" + - "(" +Filter+"))."; - ret+="}"; - //System.out.println(ret); + + String ret = "SELECT * WHERE { \n" + "<" + subject + + "> ?predicate ?object.\n"; + if (!(Filter.length() == 0)) + ret += "FILTER( \n" + "(" + Filter + "))."; + ret += "}"; + // System.out.println(ret); return ret; - } - - /** - * creates a query for subjects with the specified label - * @param label a phrase that is part of the label of a subject - * @param limit this limits the amount of results - * @return - */ - public static String makeLabelQuery(String label,int limit){ - //TODO maybe use http://xmlns:com/foaf/0.1/page - return "SELECT DISTINCT ?subject\n"+ - "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object bif:contains '\""+label+"\"'@en}\n"+ - "LIMIT "+limit; } - - /** - * creates a query for all subjects that are of the type concept - * @param concept the type that subjects are searched for - * @return + + /* + * moved to SparqlQuery TODO remove here creates a query for subjects with + * the specified label @param label a phrase that is part of the label of a + * subject @param limit this limits the amount of results @return + * + * @Deprecated public static String makeLabelQuery(String label,int limit){ + * //TODO maybe use http://xmlns:com/foaf/0.1/page return + * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject + * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object + * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; } + * + * + * creates a query for all subjects that are of the type concept @param + * concept the type that subjects are searched for @return + * + * + * moved to SparqlQuery TODO remove here + * @Deprecated public static String makeConceptQuery(String concept){ return + * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a + * <"+concept+">}\n"; } moved to SparqlQuery TODO remove here + * @Deprecated public static String makeArticleQuery(String subject){ return + * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+"> + * ?predicate ?object}\n"; } */ - public static String makeConceptQuery(String concept){ - return "SELECT DISTINCT ?subject\n"+ - "WHERE { ?subject a <"+concept+">}\n"; - } - - public static String makeArticleQuery(String subject){ - return "SELECT ?predicate,?object\n"+ - "WHERE { <"+subject+"> ?predicate ?object}\n"; - } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-19 01:26:40 UTC (rev 396) @@ -19,23 +19,12 @@ */ package org.dllearner.kb.sparql; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; import java.net.URI; -import java.net.URLEncoder; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.dllearner.kb.sparql.configuration.Configuration; -import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.query.Cache; -import org.dllearner.kb.sparql.query.CachedSparqlQuery; import org.dllearner.kb.sparql.query.SparqlQuery; import org.dllearner.utilities.StringTuple; @@ -52,7 +41,7 @@ // private SparqlHTTPRequest SparqlHTTPRequest; private SparqlQueryMaker sparqlQueryMaker; // private SparqlQuery sparqlQuery; - private CachedSparqlQuery cachedSparqlQuery; + //private CachedSparqlQuery cachedSparqlQuery; Cache cache; public TypedSparqlQuery(Configuration Configuration) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-19 01:26:40 UTC (rev 396) @@ -19,10 +19,8 @@ */ package org.dllearner.kb.sparql; -import java.io.IOException; import java.net.URI; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.Set; import org.dllearner.kb.sparql.configuration.Configuration; @@ -181,7 +179,7 @@ } private String sendAndReceiveSPARQL(String sparql) { - LinkedHashSet l = new LinkedHashSet<String>(); + return new SparqlQuery(sparql, configuration.getSparqlEndpoint()) .getAsXMLString(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java 2008-01-19 01:26:40 UTC (rev 396) @@ -33,7 +33,7 @@ * see the other classes, which are used as attributes here * */ - private SparqlEndpoint specificSparqlEndpoint; + private SparqlEndpoint endpoint; private SparqlQueryType sparqlQueryType; private Manipulator manipulator; // the following needs to be moved to @@ -47,7 +47,7 @@ public Configuration(SparqlEndpoint specificSparqlEndpoint, SparqlQueryType sparqlQueryType, Manipulator manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion) { - this.specificSparqlEndpoint = specificSparqlEndpoint; + this.endpoint = specificSparqlEndpoint; this.sparqlQueryType = sparqlQueryType; this.manipulator = manipulator; this.recursiondepth = recursiondepth; @@ -58,7 +58,7 @@ public Configuration changeQueryType(SparqlQueryType sqt) { // TODO must clone here - return new Configuration(this.specificSparqlEndpoint, sqt, this.manipulator, + return new Configuration(this.endpoint, sqt, this.manipulator, this.recursiondepth, this.getAllSuperClasses,this.closeAfterRecursion); } @@ -68,7 +68,7 @@ } public SparqlEndpoint getSparqlEndpoint() { - return specificSparqlEndpoint; + return endpoint; } public SparqlQueryType getSparqlQueryType() { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java 2008-01-19 01:26:40 UTC (rev 396) @@ -64,17 +64,19 @@ public static SparqlEndpoint getEndpointByNumber(int i) { switch (i) { - case 0: + case 0:break; + //should not be filled + case 1: return dbpediaEndpoint(); - case 1: + case 2: return localJoseki(); - case 2: + case 3: return govTrack(); - case 3: + case 4: return revyu(); - case 4: + case 5: return myopenlink(); - case 5: + case 6: return worldFactBook(); } return null; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-01-19 01:26:40 UTC (rev 396) @@ -29,20 +29,13 @@ * */ public class SparqlQueryType { - // TODO make sets out of them - private String mode = "forbid"; - private String[] objectfilterlist = { "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/resource/Category", "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons" }; - private String[] predicatefilterlist = { "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", "http://dbpedia.org/property/reference" }; + private Set<String> objectfilterlist; + private Set<String> predicatefilterlist; private boolean literals = false; - public SparqlQueryType(String mode, String[] obectfilterlist, String[] predicatefilterlist, + public SparqlQueryType(String mode, Set<String> obectfilterlist, Set<String> predicatefilterlist, boolean literals) { super(); this.mode = mode; @@ -51,25 +44,6 @@ this.literals = literals; } - public SparqlQueryType(String mode, Set<String> objectfilterlist, - Set<String> predicatefilterlist, String literals) { - super(); - this.mode = mode; - this.literals = (literals.equals("true")) ? true : false; - - Object[] arr = objectfilterlist.toArray(); - Object[] arr2 = predicatefilterlist.toArray(); - this.objectfilterlist = new String[arr.length]; - this.predicatefilterlist = new String[arr2.length]; - for (int i = 0; i < arr.length; i++) { - this.objectfilterlist[i] = (String) arr[i]; - } - for (int i = 0; i < arr2.length; i++) { - this.predicatefilterlist[i] = (String) arr2[i]; - } - - } - public boolean isLiterals() { return literals; } @@ -78,30 +52,24 @@ return mode; } - public String[] getObjectfilterlist() { + public Set<String> getObjectfilterlist() { return objectfilterlist; } - public String[] getPredicatefilterlist() { + public Set<String> getPredicatefilterlist() { return predicatefilterlist; } public void addPredicateFilter(String filter) { - String[] tmp = new String[predicatefilterlist.length + 1]; - int i = 0; - for (; i < predicatefilterlist.length; i++) { - tmp[i] = predicatefilterlist[i]; - //System.out.println(tmp[i]); - } - tmp[i] = filter; - predicatefilterlist=tmp; + predicatefilterlist.add(filter); //System.out.println("added filter: "+filter); - } - public static SparqlQueryType getFilter(int i) { + public static SparqlQueryType getFilterByNumber(int i) { switch (i) { + case 0:break; + //should not be filled case 1: return YagoFilter(); case 2: @@ -126,7 +94,7 @@ pred.add("http://dbpedia.org/property/wikipage"); pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); pred.add("http://dbpedia.org/property/relatedInstance"); - + Set<String> obj = new HashSet<String>(); //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); //obj.add("http://dbpedia.org/resource/Category:Articles_"); @@ -140,7 +108,7 @@ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); obj.add("http://www.w3.org/2004/02/skos/core"); - return new SparqlQueryType("forbid", obj, pred, "false"); + return new SparqlQueryType("forbid", obj, pred, false); } public static SparqlQueryType YagoSpecialHierarchy(){ Set<String> pred = new HashSet<String>(); @@ -168,7 +136,7 @@ obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); obj.add("http://www.w3.org/2004/02/skos/core"); - return new SparqlQueryType("forbid", obj, pred, "false"); + return new SparqlQueryType("forbid", obj, pred, false); } @@ -200,7 +168,7 @@ obj.add("http://dbpedia.org/resource/Template"); - return new SparqlQueryType("forbid", obj, pred, "false"); + return new SparqlQueryType("forbid", obj, pred, false); } public static SparqlQueryType YAGOSKOS(){ Set<String> pred = new HashSet<String>(); @@ -230,7 +198,7 @@ obj.add("http://dbpedia.org/resource/Template"); - return new SparqlQueryType("forbid", obj, pred, "false"); + return new SparqlQueryType("forbid", obj, pred, false); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java 2008-01-19 01:26:40 UTC (rev 396) @@ -39,18 +39,17 @@ public ClassNode(URI u) { super(u); - this.type = "class"; + // this.type = "class"; } - //expands all directly connected nodes + // expands all directly connected nodes @Override public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { + Set<StringTuple> s = tsq.query(this.uri); // see manipulator s = m.check(s, this); Vector<Node> Nodes = new Vector<Node>(); - - Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { StringTuple t = (StringTuple) it.next(); @@ -58,7 +57,8 @@ // substitute rdf:type with owl:subclassof if (t.a.equals(m.type) || t.a.equals(m.subclass)) { ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(m.subclass), this, tmp)); + properties.add(new PropertyNode(new URI(m.subclass), this, + tmp)); Nodes.add(tmp); } else { // further expansion stops here @@ -67,7 +67,7 @@ properties.add(new PropertyNode(new URI(t.a), this, tmp)); // System.out.println(m.blankNodeIdentifier); // System.out.println("XXXXX"+t.b); - + // if o is a blank node expand further if (t.b.startsWith(m.blankNodeIdentifier)) { tmp.expand(tsq, m); @@ -87,29 +87,26 @@ // gets the types for properties recursively @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - // TODO return type doesn't make sense - return new Vector<Node>(); + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { } @Override public Set<String> toNTriple() { Set<String> s = new HashSet<String>(); - s.add("<" + this.uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Class" + ">."); + s.add("<" + this.uri + "><" + rdftype + "><" + classns + ">."); for (PropertyNode one : properties) { - s.add("<" + this.uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.add("<" + this.uri + "><" + one.getURI() + "><" + + one.getB().getURI() + ">."); s.addAll(one.getB().toNTriple()); } return s; } - + @Override - public int compareTo(Node n){ + public int compareTo(Node n) { return super.compareTo(n); - // } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java 2008-01-19 01:26:40 UTC (rev 396) @@ -33,7 +33,7 @@ * A node in the graph that is an instance. * * @author Sebastian Hellmann - * + * */ public class InstanceNode extends Node { @@ -43,11 +43,11 @@ public InstanceNode(URI u) { super(u); - this.type = "instance"; + // this.type = "instance"; } - //expands all directly connected nodes + // expands all directly connected nodes @Override public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { @@ -85,34 +85,33 @@ // gets the types for properties recursively @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { for (PropertyNode one : properties) { one.expandProperties(tsq, m); } - return new Vector<Node>(); + } @Override public Set<String> toNTriple() { Set<String> s = new HashSet<String>(); - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Thing" + ">."); + s.add("<" + uri + "><" + rdftype + "><" + thing + ">."); for (ClassNode one : classes) { - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one.getURI() + ">."); + s.add("<" + uri + "><" + rdftype + "><" + one.getURI() + ">."); s.addAll(one.toNTriple()); } for (PropertyNode one : properties) { - s.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + + ">."); s.addAll(one.toNTriple()); s.addAll(one.getB().toNTriple()); } return s; } - + @Override - public int compareTo(Node n){ + public int compareTo(Node n) { return super.compareTo(n); // } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java 2008-01-19 01:26:40 UTC (rev 396) @@ -30,37 +30,73 @@ * Abstract class. * * @author Sebastian Hellmann + * + */ +/** + * @author sebastian * */ public abstract class Node implements Comparable<Node> { + + final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + final String rdftype = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + URI uri; - protected String type; + //protected String type; protected boolean expanded = false; public Node(URI u) { this.uri = u; } - public abstract Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m); + /** + * Nodes are expanded with a certain context, given by + * the typedSparqlQuery and the manipulator + * @param typedSparqlQuery + * @param manipulator + * @return Vector<Node> all Nodes that are new because of expansion + */ + public abstract Vector<Node> expand(TypedSparqlQueryInterface typedSparqlQuery, + Manipulator manipulator); - public abstract Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m); + + /** + * used to get type defs for properties like rdf:type SymmetricProperties + * + * @param typedSparqlQuery + * @param manipulator + * @return Vector<Node> + */ + public abstract void expandProperties( + TypedSparqlQueryInterface typedSparqlQuery, Manipulator manipulator); + /** + * output + * @return a set of n-triple + */ public abstract Set<String> toNTriple(); @Override public String toString() { - return "Node: " + uri + ":" + type; + return "Node: " + uri + ":" + this.getClass(); } public URI getURI() { return uri; } - public boolean equals(Node n){ - if(this.uri.equals(n.uri))return true; - else return false; + + public boolean equals(Node n) { + if (this.uri.equals(n.uri)) + return true; + else + return false; } - public int compareTo(Node n){ + + public int compareTo(Node n) { return this.uri.toString().compareTo(n.uri.toString()); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java 2008-01-19 01:26:40 UTC (rev 396) @@ -30,11 +30,19 @@ import org.dllearner.utilities.StringTuple; /** - * Property node. + * Property node, has connection to a and b part * * @author Sebastian Hellmann * */ +/** + * @author sebastian + * + */ +/** + * @author sebastian + * + */ public class PropertyNode extends Node { // the a and b part of a property @@ -43,25 +51,27 @@ // specialtypes like owl:symmetricproperty private Set<String> specialTypes; - public PropertyNode(URI u) { - super(u); - this.type = "property"; - - } - public PropertyNode(URI u, Node a, Node b) { super(u); - this.type = "property"; + //this.type = "property"; this.a = a; this.b = b; this.specialTypes = new HashSet<String>(); } + + // Property Nodes are normally not expanded, + // this function is never called @Override public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { + return null; + } + + // gets the types for properties recursively + @Override + public void expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { + b.expandProperties(tsq, m); Set<StringTuple> s = tsq.query(uri); - Vector<Node> Nodes = new Vector<Node>(); - // Manipulation Iterator<StringTuple> it = s.iterator(); while (it.hasNext()) { @@ -76,16 +86,10 @@ } } - return Nodes; + + } - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - b.expandProperties(tsq, m); - return this.expand(tsq, m); - } - public Node getA() { return a; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/old/SparqlQueryConventional.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/SparqlQueryConventional.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/SparqlQueryConventional.java 2008-01-19 01:26:40 UTC (rev 396) @@ -7,9 +7,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; -import java.net.URLEncoder; -import java.util.Iterator; -import java.util.Set; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java 2008-01-19 01:26:40 UTC (rev 396) @@ -130,6 +130,7 @@ return ret; } + /* public String[] collectTriples(String subject) throws IOException{ System.out.println("Searching for Article: "+subject); String sparql=SparqlQueryMaker.makeArticleQuery(subject); @@ -148,6 +149,7 @@ return processArticle(xml); } + */ public String[] processArticle(String xml) { @@ -180,7 +182,7 @@ return vec.toArray(ret); } - public String[] getSubjectsFromLabel(String label, int limit) throws IOException{ + /*public String[] getSubjectsFromLabel(String label, int limit) throws IOException{ System.out.println("Searching for Label: "+label); String sparql=SparqlQueryMaker.makeLabelQuery(label,limit); String FromCache=cache.get(label, sparql); @@ -197,9 +199,9 @@ } return processSubjects(xml); - } + }*/ - public String[] getSubjectsFromConcept(String concept) throws IOException + /*public String[] getSubjectsFromConcept(String concept) throws IOException { System.out.println("Searching for Subjects of type: "+concept); String sparql=SparqlQueryMaker.makeConceptQuery(concept); @@ -217,13 +219,14 @@ } return processSubjects(xml); - } + }*/ /** * calls getRecursive for each subject in list * @param subjects * @param NumberofRecursions */ + public void getRecursiveList(String[] subjects,int NumberofRecursions) throws IOException{ for (int i = 0; i < subjects.length; i++) { getRecursive(subjects[i], NumberofRecursions); @@ -236,6 +239,7 @@ * @param StartingSubject * @param NumberofRecursions */ + public void getRecursive(String StartingSubject,int NumberofRecursions) throws IOException{ System.out.print("SparqlModul: Depth: "+NumberofRecursions+" @ "+StartingSubject+" "); if(NumberofRecursions<=0) Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java 2008-01-19 01:26:40 UTC (rev 396) @@ -2,6 +2,13 @@ import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +/** + * Does the same as SparqlQuery, but uses the cache. key should be an uri or + * something that can be mapped to a file see cache + * + * @author Jens Lehmann + * + */ public class CachedSparqlQuery { String key; @@ -11,19 +18,29 @@ SparqlQuery sparqlQuery; boolean debug_no_cache = false; - public CachedSparqlQuery(SparqlEndpoint e, Cache c, String key, + /** + * key should be an uri or something that can be mapped to a file see cache + * + * @param endpoint + * @param cache + * @param key + * @param queryString + */ + public CachedSparqlQuery(SparqlEndpoint endpoint, Cache cache, String key, String queryString) { - this.endpoint = e; - this.cache = c; + this.endpoint = endpoint; + this.cache = cache; this.key = key; this.queryString = queryString; - this.sparqlQuery = new SparqlQuery(queryString, e); + this.sparqlQuery = new SparqlQuery(queryString, endpoint); } - // URI u, String sparql - @Deprecated - public String send() { - + /** + * sends a query and returns XML using cache + * + * @return String xml + */ + public String getAsXMLString() { String FromCache = cache.get(key, queryString); if (debug_no_cache) { FromCache = null; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-19 01:26:40 UTC (rev 396) @@ -35,7 +35,7 @@ import com.hp.hpl.jena.sparql.core.ResultBinding; /** - * Represents a SPARQL query. It includes support for stopping the SPARQL query + * Represents one SPARQL query. It includes support for stopping the SPARQL query * (which may be necessary if a timeout is reached). * * @author Jens Lehmann @@ -49,17 +49,33 @@ private QueryExecution queryExecution; SparqlEndpoint endpoint; - public SparqlQuery(String queryString, URL u) { + /** + * simplest contructor, works only with some endpoints, + * not with DBpedia + * @param queryString + * @param url + */ + public SparqlQuery(String queryString, URL url) { this.queryString = queryString; - this.endpoint = new SparqlEndpoint(u); + this.endpoint = new SparqlEndpoint(url); } - public SparqlQuery(String queryString, SparqlEndpoint se) { + /** + * standard constructor + * @param queryString + * @param endpoint + */ + public SparqlQuery(String queryString, SparqlEndpoint endpoint) { this.queryString = queryString; - this.endpoint = se; + this.endpoint = endpoint; } - public ResultSet send() { + + /** + * method used for sending over Jena + * @return jena ResultSet + */ + protected ResultSet send() { isRunning = true; p(queryString); @@ -88,16 +104,35 @@ return isRunning; } + /** + * sends a query and returns XML + * + * @return String xml + */ public String getAsXMLString() { ResultSet rs = send(); return ResultSetFormatter.asXMLString(rs); } + /** + * sends a query and returns complicated Jena List with ResultBindings + * + * + * @return jena List<ResultBinding> + */ public List<ResultBinding> getAsList() { ResultSet rs = send(); return ResultSetFormatter.toList(rs); } + + /** + * sends a query and returns the results for variable + * TODO untested and not used, feel free to change + * varName as Vector<String> + * @param varName + * @return Vector<String> + */ public Vector<String> getAsVector(String varName) { ResultSet rs = send(); Vector<String> vret = new Vector<String>(); @@ -108,6 +143,15 @@ return vret; } + /** + * sends a query and returns the results for two variables + * ex: getAsVectorOfTupels("predicate", "object") + * TODO untested and not used, feel free to change + * + * @param varName1 + * @param varName2 + * @return Vector<StringTuple> + */ public Vector<StringTuple> getAsVectorOfTupels(String varName1, String varName2) { ResultSet rs = send(); @@ -120,7 +164,13 @@ return vret; } - @Deprecated + + /** + * sends a query and returns the results for n variables + * TODO not working, finish + * @param varNames + * @return Vector<Vector<String>> + */ public Vector<Vector<String>> getAsVectorOfVectors(Vector<String> varNames) { // ResultSet rs = send(); Vector<Vector<String>> vret = new Vector<Vector<String>>(); @@ -138,6 +188,48 @@ * public Model asJenaModel(){ ResultSet rs=send(); return * ResultSetFormatter.toModel(rs); } */ + + /** + * creates a query for subjects with the specified label + * @param label a phrase that is part of the label of a subject + * @param limit this limits the amount of results + * @param endpoint a SparqlEndpoint + * @return SparqlQuery + */ + public static SparqlQuery makeLabelQuery(String label,int limit,SparqlEndpoint endpoint){ + //TODO maybe use http://xmlns:com/foaf/0.1/page + String queryString= + "SELECT DISTINCT ?subject\n"+ + "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object bif:contains '\""+label+"\"'@en}\n"+ + "LIMIT "+limit; + return new SparqlQuery( queryString,endpoint); + } + + /** + * creates a query for all subjects that are of the type concept + * @param concept the type that subjects are searched for + * @param endpoint a SparqlEndpoint + * @return SparqlQuery + */ + public static SparqlQuery makeConceptQuery(String concept, SparqlEndpoint endpoint){ + String queryString = + "SELECT DISTINCT ?subject\n"+ + "WHERE { ?subject a <"+concept+">}\n"; + return new SparqlQuery( queryString,endpoint); + } + + /** + * @param subject + * @param endpoint a SparqlEndpoint + * @return SparqlQuery + */ + public static SparqlQuery makeArticleQuery(String subject,SparqlEndpoint endpoint){ + String queryString = + "SELECT ?predicate,?object\n"+ + "WHERE { <"+subject+"> ?predicate ?object}\n"; + return new SparqlQuery( queryString,endpoint); + } + public void p(String str) { if (print_flag) { Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java 2008-01-19 01:26:40 UTC (rev 396) @@ -26,7 +26,7 @@ import org.dllearner.kb.sparql.Manager; /** - * Test class. + * Test class, uses the whole thing * * @author Sebastian Hellmann * Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java 2008-01-19 01:26:40 UTC (rev 396) @@ -27,20 +27,12 @@ import java.util.List; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; -import org.dllearner.kb.sparql.old.SparqlQueryConventional; import org.dllearner.kb.sparql.query.SparqlQuery; import com.hp.hpl.jena.sparql.core.ResultBinding; public class TestResultSet { - // this is a working Jena script - // TODO: query runtime seems to be much too high (compared to running it in - // http://dbpedia.org/sparql) - // verify whether our SPARQL query implementation is faster and why; - // TODO: check whether Jena works with the other endpoints in - // PredefinedEndpoint; if not - // check whether it can be configured to run with these public static void main(String[] args) { String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " @@ -69,7 +61,7 @@ return ""; } - public static void testSaving(List l) { + public static void testSaving(List<ResultBinding> l) { System.out.println(l + "\n****************************"); try { // FileWriter fw=new FileWriter(new File(Filename),true); @@ -96,8 +88,8 @@ SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); - SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); - + //SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); + // first query is not counted long now = System.currentTimeMillis(); long tmp = now; @@ -142,10 +134,10 @@ public static void compareResults(String queryString) { SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); - SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); + // SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); System.out.println(sqJena.getAsXMLString()); - System.out.println(sqConv.getAsXMLString(queryString)); + //System.out.println(sqConv.getAsXMLString(queryString)); } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestSparqlQuery.java 2008-01-18 23:21:56 UTC (rev 395) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestSparqlQuery.java 2008-01-19 01:26:40 UTC (rev 396) @@ -20,30 +20,11 @@ package org.dllearner.kb.sparql.test; import org.dllearner.kb.sparql.configuration.SparqlEndpoint; -import org.dllearner.kb.sparql.old.SparqlQueryConventional; import org.dllearner.kb.sparql.query.SparqlQuery; -/** - * Represents a SPARQL query. It includes support for stopping the SPARQL query - * (which may be necessary if a timeout is reached). - * - * TODO: It is probably good to change all SPARQL query calls to use only this - * class. - * - * TODO: Could we use Jena as a solid foundation here? (com.hp.jena.query) - * - * @author Jens Lehmann - * - */ + public class TestSparqlQuery { - // this is a working Jena script - // TODO: query runtime seems to be much too high (compared to running it in - // http://dbpedia.org/sparql) - // verify whether our SPARQL query implementation is faster and why; - // TODO: check whether Jena works with the other endpoints in - // PredefinedEndpoint; if not - // check whether it can be configured to run with these public static void main(String[] args) { String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " @@ -61,7 +42,7 @@ public static void testTime(int howOften, String queryString) { SparqlEndpoint sse = SparqlEndpoint.dbpediaEndpoint(); SparqlQuery sqJena = new SparqlQuery(queryString, sse); - SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); + //SparqlQueryConventional sqConv = new SparqlQueryConventional(sse); // first query is not counted sqJena.getAsList(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 23:22:04
|
Revision: 395 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=395&view=rev Author: kurzum Date: 2008-01-18 15:21:56 -0800 (Fri, 18 Jan 2008) Log Message: ----------- a lot of changes, see email, will remove warnings soon Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/old/SparqlQueryConventional.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/ trunk/src/dl-learner/org/dllearner/kb/sparql/test/JenaTestScript.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestResultSet.java trunk/src/dl-learner/org/dllearner/kb/sparql/test/TestSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 23:21:56 UTC (rev 395) @@ -43,11 +43,9 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.dl.KB; -import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; -import org.dllearner.kb.sparql.configuration.PredefinedFilter; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.configuration.SparqlEndpoint; -import org.dllearner.kb.sparql.old.*; +import org.dllearner.kb.sparql.old.oldSparqlOntologyCollector; import org.dllearner.kb.sparql.query.SparqlQuery; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; @@ -66,13 +64,13 @@ // ConfigOptions private URL url; String host; - private Set<String> instances=new HashSet<String>();; + private Set<String> instances = new HashSet<String>();; private URL dumpFile; private int recursionDepth = 1; private int predefinedFilter = 0; private int predefinedEndpoint = 0; - private Set<String> predList=new HashSet<String>(); - private Set<String> objList=new HashSet<String>(); + private Set<String> predList = new HashSet<String>(); + private Set<String> objList = new HashSet<String>(); // private Set<String> classList; private String format = "N-TRIPLES"; private boolean dumpToFile = true; @@ -83,16 +81,16 @@ private boolean learnDomain = false; private boolean learnRange = false; - private int numberOfInstancesUsedForRoleLearning=40; - private String role=""; + private int numberOfInstancesUsedForRoleLearning = 40; + private String role = ""; private String blankNodeIdentifier = "bnode"; - + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); SparqlEndpoint sse = null; - + /** * Holds the results of the calculateSubjects method */ @@ -146,37 +144,58 @@ Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances", - "relevant instances e.g. positive and negative examples in a learning problem")); + options + .add(new StringSetConfigOption("instances", + "relevant instances e.g. positive and negative examples in a learning problem")); options.add(new IntegerConfigOption("recursionDepth", "recursion depth of KB fragment selection", 2)); - options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); - options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedFilter", + "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint", + "the mode of the SPARQL Filter")); - options.add(new StringSetConfigOption("predList", "list of all ignored roles")); - options.add(new StringSetConfigOption("objList", "list of all ignored objects")); - options.add(new StringSetConfigOption("classList", "list of all ignored classes")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); - options.add(new BooleanConfigOption("dumpToFile", - "Specifies whether the extracted ontology is written to a file or not.", true)); - options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); + options.add(new StringSetConfigOption("predList", + "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", + "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", + "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", + "N-TRIPLES")); + options + .add(new BooleanConfigOption( + "dumpToFile", + "Specifies whether the extracted ontology is written to a file or not.", + true)); + options.add(new BooleanConfigOption("useLits", + "use Literals in SPARQL query")); + options + .add(new BooleanConfigOption( + "getAllSuperClasses", + "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", + true)); - options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain/Range from")); + options.add(new BooleanConfigOption("learnDomain", + "learns the Domain for a Role")); + options.add(new BooleanConfigOption("learnRange", + "learns the Range for a Role")); + options.add(new StringConfigOption("role", + "role to learn Domain/Range from")); options.add(new StringConfigOption("blankNodeIdentifier", "used to identify blanknodes in Tripels")); options.add(new StringTupleListConfigOption("example", "example")); - options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); - options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); - options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); - options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); - options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); - - - + options.add(new StringTupleListConfigOption("replacePredicate", + "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", + "rule for replacing predicates")); + options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", + "stops a cyclic hierarchy after specified number of classes")); + options.add(new IntegerConfigOption( + "numberOfInstancesUsedForRoleLearning", "")); + options.add(new BooleanConfigOption("closeAfterRecursion", + "gets all classes for all instances")); + return options; } @@ -185,15 +204,16 @@ */ @Override @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + public <T> void applyConfigEntry(ConfigEntry<T> entry) + throws InvalidConfigOptionValueException { String option = entry.getOptionName(); if (option.equals("url")) { String s = (String) entry.getValue(); try { url = new URL(s); } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), - "malformed URL " + s); + throw new InvalidConfigOptionValueException(entry.getOption(), + entry.getValue(), "malformed URL " + s); } } else if (option.equals("host")) { host = (String) entry.getValue(); @@ -205,8 +225,8 @@ predList = (Set<String>) entry.getValue(); } else if (option.equals("objList")) { objList = (Set<String>) entry.getValue(); - //} else if (option.equals("classList")) { - // classList = (Set<String>) entry.getValue(); + // } else if (option.equals("classList")) { + // classList = (Set<String>) entry.getValue(); } else if (option.equals("predefinedEndpoint")) { predefinedEndpoint = (Integer) entry.getValue(); } else if (option.equals("predefinedFilter")) { @@ -221,26 +241,26 @@ getAllSuperClasses = (Boolean) entry.getValue(); } else if (option.equals("learnDomain")) { learnDomain = (Boolean) entry.getValue(); - }else if (option.equals("learnRange")) { + } else if (option.equals("learnRange")) { learnRange = (Boolean) entry.getValue(); } else if (option.equals("role")) { role = (String) entry.getValue(); } else if (option.equals("blankNodeIdentifier")) { blankNodeIdentifier = (String) entry.getValue(); } else if (option.equals("example")) { - //System.out.println(entry.getValue()); - }else if (option.equals("replacePredicate")) { - replacePredicate = (LinkedList)entry.getValue(); - }else if (option.equals("replaceObject")) { - replaceObject = (LinkedList)entry.getValue(); - }else if (option.equals("breakSuperClassRetrievalAfter")) { + // System.out.println(entry.getValue()); + } else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList) entry.getValue(); + } else if (option.equals("replaceObject")) { + replaceObject = (LinkedList) entry.getValue(); + } else if (option.equals("breakSuperClassRetrievalAfter")) { breakSuperClassRetrievalAfter = (Integer) entry.getValue(); - }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { + } else if (option.equals("numberOfInstancesUsedForRoleLearning")) { numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); - }else if (option.equals("closeAfterRecursion")) { + } else if (option.equals("closeAfterRecursion")) { closeAfterRecursion = (Boolean) entry.getValue(); - } - + } + } /* @@ -259,92 +279,99 @@ Manager m = new Manager(); SparqlQueryType sqt = null; // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); + Manipulator man = new Manipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("default-graph-uri", "http://dbpedia.org"); parameters.put("format", "application/sparql-results.xml"); // get Options for endpoints if (predefinedEndpoint >= 1) { - sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); + sse = SparqlEndpoint.getEndpointByNumber(predefinedEndpoint); } else { - sse = new SparqlEndpoint(url, host, parameters); + // TODO this is not optimal, because not all options are used + sse = new SparqlEndpoint(url); } // get Options for Filters - + if (predefinedFilter >= 1) { - sqt = PredefinedFilter.getFilter(predefinedFilter); + sqt = SparqlQueryType.getFilter(predefinedFilter); } else { sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - + } // give everything to the manager - m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses, + closeAfterRecursion); try { String ont = ""; - //System.out.println(learnDomain); + // System.out.println(learnDomain); // used to learn a domain of a role if (learnDomain || learnRange) { - Set<String> pos=new HashSet<String>(); - Set<String> neg=new HashSet<String>(); - if(learnDomain){ + Set<String> pos = new HashSet<String>(); + Set<String> neg = new HashSet<String>(); + if (learnDomain) { pos = m.getDomainInstancesForRole(role); neg = m.getRangeInstancesForRole(role); - }else if(learnRange){ + } else if (learnRange) { neg = m.getDomainInstancesForRole(role); pos = m.getRangeInstancesForRole(role); } - //choose 30 - - - Set<String> tmp=new HashSet<String>(); - for(String one:pos){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - pos=tmp; - System.out.println("Instances used: "+pos.size()); - - tmp=new HashSet<String>(); - for(String one:neg){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - neg=tmp; - - instances=new HashSet<String>(); - instances.addAll(pos); - - instances.addAll(neg); - - for(String one:pos){ - System.out.println("+\""+one+"\""); - } - for(String one:neg){ - System.out.println("-\""+one+"\""); - } - - /*Random r= new Random(); - - - Object[] arr=instances.toArray(); - while(instances.size()>=30){ - - }*/ + // choose 30 + + Set<String> tmp = new HashSet<String>(); + for (String one : pos) { + tmp.add(one); + if (tmp.size() >= numberOfInstancesUsedForRoleLearning) + break; + } + pos = tmp; + System.out.println("Instances used: " + pos.size()); + + tmp = new HashSet<String>(); + for (String one : neg) { + tmp.add(one); + if (tmp.size() >= numberOfInstancesUsedForRoleLearning) + break; + } + neg = tmp; + + instances = new HashSet<String>(); + instances.addAll(pos); + + instances.addAll(neg); + + for (String one : pos) { + System.out.println("+\"" + one + "\""); + } + for (String one : neg) { + System.out.println("-\"" + one + "\""); + } + + /* + * Random r= new Random(); + * + * + * Object[] arr=instances.toArray(); + * while(instances.size()>=30){ + * } + */ // add the role to the filter(a solution is always EXISTS // role.TOP) m.addPredicateFilter(role); - //System.out.println(instances); - // THIS is a workaround - + // System.out.println(instances); + // THIS is a workaround + } // the actual extraction is started here ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); - + System.out.println("Number of cached SPARQL queries: " + + m.getConfiguration().numberOfCachedSparqlQueries); + System.out.println("Number of uncached SPARQL queries: " + + m.getConfiguration().numberOfUncachedSparqlQueries); + System.out.println("Finished collecting Fragment"); if (dumpToFile) { @@ -354,7 +381,8 @@ if (!new File(basedir).exists()) new File(basedir).mkdir(); - FileWriter fw = new FileWriter(new File(basedir + filename), true); + FileWriter fw = new FileWriter( + new File(basedir + filename), true); fw.write(ont); fw.flush(); fw.close(); @@ -366,8 +394,8 @@ } if (format.equals("KB")) { try { - //kb = KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); + // kb = KBParser.parseKBFile(new StringReader(ont)); + kb = KBParser.parseKBFile(dumpFile); } catch (Exception e) { e.printStackTrace(); } @@ -386,7 +414,8 @@ @Override public String toDIG(URI kbURI) { if (format.equals("N-TRIPLES")) - return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); + return JenaOWLDIGConverter.getTellsString(dumpFile, + OntologyFormat.N_TRIPLES, kbURI); else return DIGConverter.getDIGString(kb, kbURI).toString(); } @@ -398,7 +427,8 @@ * org.dllearner.core.OntologyFormat) */ @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { + public void export(File file, OntologyFormat format) + throws OntologyFormatUnsupportedException { // currently no export functions implemented, so we just throw an // exception throw new OntologyFormatUnsupportedException("export", format); @@ -412,9 +442,9 @@ return ontArray; } - /** * TODO SparqlOntologyCollector needs to be removed + * * @param label * @param limit */ @@ -432,6 +462,7 @@ /** * TODO SparqlOntologyCollector needs to be removed + * * @param subject */ public void calculateTriples(String subject) { @@ -448,6 +479,7 @@ /** * TODO SparqlOntologyCollector needs to be removed + * * @param concept */ public void calculateConceptSubjects(String concept) { @@ -521,8 +553,8 @@ public String[] getConceptSubjects() { return conceptSubjects; } - + public SparqlQuery sparqlQuery(String query) { - return new SparqlQuery(sse, query); + return new SparqlQuery(query, sse); } } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java 2008-01-18 23:21:56 UTC (rev 395) @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.io.File; -import java.io.FileWriter; -import java.net.URI; - -/** - * Test class. - * - * @author Sebastian Hellmann - * - */ -public class Test { - - public static void main(String[] args) { - System.out.println("Start"); - // String test2 = "http://www.extraction.org/config#dbpediatest"; - // String test = "http://www.extraction.org/config#localjoseki"; - try { - // URI u = new URI(test); - Manager m = new Manager(); - // m.usePredefinedConfiguration(u); - - URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); - - String filename = System.currentTimeMillis() + ".nt"; - FileWriter fw = new FileWriter(new File(filename), true); - fw.write(m.extract(u2)); - fw.flush(); - fw.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 23:21:56 UTC (rev 395) @@ -43,15 +43,15 @@ * Can execute different queries. * * @author Sebastian Hellmann - * + * */ -public class TypedSparqlQuery implements TypedSparqlQueryInterface{ - boolean print_flag=false; - boolean debug_no_cache=false;// true means no cahce is used +public class TypedSparqlQuery implements TypedSparqlQueryInterface { + boolean print_flag = false; + boolean debug_no_cache = false;// true means no cahce is used private Configuration configuration; // private SparqlHTTPRequest SparqlHTTPRequest; private SparqlQueryMaker sparqlQueryMaker; - private SparqlQuery sparqlQuery; + // private SparqlQuery sparqlQuery; private CachedSparqlQuery cachedSparqlQuery; Cache cache; @@ -59,16 +59,20 @@ this.configuration = Configuration; // this.SparqlHTTPRequest = new // SparqlHTTPRequest(Configuration.getSparqlEndpoint()); - this.sparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); - this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); + this.sparqlQueryMaker = new SparqlQueryMaker(Configuration + .getSparqlQueryType()); + // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); this.cache = new Cache("cache"); - this.cachedSparqlQuery=new CachedSparqlQuery(this.sparqlQuery,this.cache); + // this.cachedSparqlQuery=new + // CachedSparqlQuery(this.sparqlQuery,this.cache); } + // standard query get a tupels (p,o) for subject s public Set<StringTuple> query(URI u) { // getQuery - String sparql = sparqlQueryMaker.makeSubjectQueryUsingFilters(u.toString()); + String sparql = sparqlQueryMaker.makeSubjectQueryUsingFilters(u + .toString()); return cachedSparql(u, sparql, "predicate", "object"); } @@ -77,17 +81,20 @@ public Set<StringTuple> getTupelsForRole(URI u) { // getQuery - String sparql = sparqlQueryMaker.makeRoleQueryUsingFilters(u.toString()); + String sparql = sparqlQueryMaker + .makeRoleQueryUsingFilters(u.toString()); Set<StringTuple> s = cachedSparql(u, sparql, "subject", "object"); // System.out.println(s); return s; } - public Set<StringTuple> getTupelsForRole(URI u,boolean domain) { + public Set<StringTuple> getTupelsForRole(URI u, boolean domain) { + // getQuery - String sparql = sparqlQueryMaker.makeRoleQueryUsingFilters(u.toString(),domain); + String sparql = sparqlQueryMaker.makeRoleQueryUsingFilters( + u.toString(), domain); Set<StringTuple> s = cachedSparql(u, sparql, "subject", "object"); // System.out.println(s); @@ -95,106 +102,135 @@ } - - // uses a cache - private Set<StringTuple> cachedSparql(URI u, String sparql, String a, String b) { + // uses a cache + private Set<StringTuple> cachedSparql(URI u, String sparql, String a, + String b) { // check cache - String xml=this.cachedSparqlQuery.getAsXMLString(u, sparql); + String FromCache = cache.get(u.toString(), sparql); + if (debug_no_cache) { + FromCache = null; + } + String xml = null; + // if not in cache get it from EndPoint + if (FromCache == null) { + configuration.increaseNumberOfuncachedSparqlQueries(); + // try { + xml = sendAndReceiveSPARQL(sparql); + /* + * } catch (IOException e) {e.printStackTrace();} + */ + p(sparql); + // System.out.println(xml); + if (!debug_no_cache) { + cache.put(u.toString(), sparql, xml); + } + // System.out.print("\n"); + } else { + configuration.increaseNumberOfCachedSparqlQueries(); + xml = FromCache; + // System.out.println("FROM CACHE"); + } // System.out.println(sparql); // System.out.println(xml); // process XML Set<StringTuple> s = processResult(xml, a, b); try { - //System.out.println("retrieved " + s.size() + " tupels\n"); + // System.out.println("retrieved " + s.size() + " tupels\n"); } catch (Exception e) { } return s; + } public Set<StringTuple> processResult(String xml, String a, String b) { Set<StringTuple> ret = new HashSet<StringTuple>(); // TODO if result is empty, catch exceptions - String resEnd="</result>"; + String resEnd = "</result>"; String one = "binding name=\"" + a + "\""; String two = "binding name=\"" + b + "\""; - String endbinding= "binding"; - String uri="uri"; - //String uridel = "<uri>"; + String endbinding = "binding"; + String uri = "uri"; + // String uridel = "<uri>"; String bnode = "<bnode>"; - //String uriend = "</uri>"; + // String uriend = "</uri>"; String predtmp = ""; String objtmp = ""; - //System.out.println(getNextResult(xml)); - String nextResult=""; - while ((nextResult=getNextResult( xml))!=null){ - //System.out.println(xml.indexOf(resEnd)); - //System.out.println(xml); - if(nextResult.indexOf(bnode)!=-1) - {xml=xml.substring(xml.indexOf(resEnd)+resEnd.length());continue;} + // System.out.println(getNextResult(xml)); + String nextResult = ""; + while ((nextResult = getNextResult(xml)) != null) { + // System.out.println(xml.indexOf(resEnd)); + // System.out.println(xml); + if (nextResult.indexOf(bnode) != -1) { + xml = xml.substring(xml.indexOf(resEnd) + resEnd.length()); + continue; + } // get pred - //predtmp = nextResult.substring(nextResult.indexOf(one) + one.length()); - predtmp=getinTag(nextResult, one,endbinding); - predtmp=getinTag(predtmp, uri,uri); - //System.out.println(predtmp); - + // predtmp = nextResult.substring(nextResult.indexOf(one) + + // one.length()); + predtmp = getinTag(nextResult, one, endbinding); + predtmp = getinTag(predtmp, uri, uri); + // System.out.println(predtmp); + // getobj - objtmp=getinTag(nextResult, two,endbinding); - objtmp=getinTag(objtmp, uri,uri); - //System.out.println(objtmp); - - StringTuple st=new StringTuple(predtmp, objtmp); - //System.out.println(st); + objtmp = getinTag(nextResult, two, endbinding); + objtmp = getinTag(objtmp, uri, uri); + // System.out.println(objtmp); + + StringTuple st = new StringTuple(predtmp, objtmp); + // System.out.println(st); ret.add(st); - xml=xml.substring(xml.indexOf(resEnd)+resEnd.length()); - + xml = xml.substring(xml.indexOf(resEnd) + resEnd.length()); + } - /*while (xml.indexOf(one) != -1) { - - + /* + * while (xml.indexOf(one) != -1) { + * + * + * + * // System.out.println(new Tupel(predtmp,objtmp)); } + */ - - // System.out.println(new Tupel(predtmp,objtmp)); - }*/ - return ret; } - - private String getNextResult(String xml){ - String res1="<result>"; - String res2="</result>"; - if(xml.indexOf(res1)==-1)return null; + + private String getNextResult(String xml) { + String res1 = "<result>"; + String res2 = "</result>"; + if (xml.indexOf(res1) == -1) + return null; xml = xml.substring(xml.indexOf(res1) + res1.length()); - xml = xml.substring(0,xml.indexOf(res2) ); - //System.out.println(xml); + xml = xml.substring(0, xml.indexOf(res2)); + // System.out.println(xml); return xml; } - private String getinTag(String xml, String starttag, String endtag){ - String res1="<"+starttag+">"; - //System.out.println(res1); - String res2="</"+endtag+">"; - if(xml.indexOf(res1)==-1)return null; + + private String getinTag(String xml, String starttag, String endtag) { + String res1 = "<" + starttag + ">"; + // System.out.println(res1); + String res2 = "</" + endtag + ">"; + if (xml.indexOf(res1) == -1) + return null; xml = xml.substring(xml.indexOf(res1) + res1.length()); - //System.out.println(xml); - xml = xml.substring(0,xml.indexOf(res2) ); - //System.out.println(xml); - + // System.out.println(xml); + xml = xml.substring(0, xml.indexOf(res2)); + // System.out.println(xml); + return xml; } - public String sendAndReceiveSPARQL(String queryString){ - //SparqlQuery sq=new SparqlQuery(configuration.getSparqlEndpoint()); - return sparqlQuery.getAsXMLString(queryString); + public String sendAndReceiveSPARQL(String queryString) { + // SparqlQuery sq=new SparqlQuery(configuration.getSparqlEndpoint()); + return new SparqlQuery(queryString, configuration.getSparqlEndpoint()) + .getAsXMLString(); } - - public void p(String str){ - if(print_flag){ + + public void p(String str) { + if (print_flag) { System.out.println(str); } } - - } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-18 23:21:56 UTC (rev 395) @@ -19,88 +19,76 @@ */ package org.dllearner.kb.sparql; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; import java.net.URI; -import java.net.URLEncoder; import java.util.HashSet; -import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.Set; import org.dllearner.kb.sparql.configuration.Configuration; -import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.query.Cache; +import org.dllearner.kb.sparql.query.SparqlQuery; import org.dllearner.utilities.StringTuple; /** * Can execute different queries. * * @author Sebastian Hellmann - * + * */ -public class TypedSparqlQueryClasses implements TypedSparqlQueryInterface{ - boolean print_flag=false; - boolean debug_no_cache=false; +public class TypedSparqlQueryClasses implements TypedSparqlQueryInterface { + boolean print_flag = false; + boolean debug_no_cache = false; private Configuration configuration; // private SparqlHTTPRequest SparqlHTTPRequest; - //private SparqlQueryMaker sparqlQueryMaker; + // private SparqlQueryMaker sparqlQueryMaker; Cache cache; - public TypedSparqlQueryClasses(Configuration configuration) { this.configuration = configuration; this.cache = new Cache("cache"); } - + // standard query get a tupels (p,o) for subject s public Set<StringTuple> query(URI u) { // getQuery - String sparql = "SELECT ?predicate ?object " + - "WHERE {" + - "<"+u.toString()+"> ?predicate ?object;" + - "a ?object . " + - " FILTER (!regex(str(?object),'http://xmlns.com/foaf/0.1/'))"+ - "}"; - + String sparql = "SELECT ?predicate ?object " + "WHERE {" + "<" + + u.toString() + "> ?predicate ?object;" + "a ?object . " + + " FILTER (!regex(str(?object),'http://xmlns.com/foaf/0.1/'))" + + "}"; + return cachedSparql(u, sparql, "predicate", "object"); } - - - // uses a cache - private Set<StringTuple> cachedSparql(URI u, String sparql, String a, String b) { + // uses a cache + private Set<StringTuple> cachedSparql(URI u, String sparql, String a, + String b) { // check cache String FromCache = cache.get(u.toString(), sparql); - if(debug_no_cache) { - FromCache=null; - } + if (debug_no_cache) { + FromCache = null; + } String xml = null; // if not in cache get it from EndPoint if (FromCache == null) { configuration.increaseNumberOfuncachedSparqlQueries(); - try { - xml = sendAndReceiveSPARQL(sparql); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + // try { + xml = sendAndReceiveSPARQL(sparql); + /* + * } catch (IOException e) {e.printStackTrace();} + */ p(sparql); // System.out.println(xml); - if(!debug_no_cache) { + if (!debug_no_cache) { cache.put(u.toString(), sparql, xml); } - //System.out.print("\n"); + // System.out.print("\n"); } else { configuration.increaseNumberOfCachedSparqlQueries(); xml = FromCache; - //System.out.println("FROM CACHE"); + // System.out.println("FROM CACHE"); } // System.out.println(sparql); @@ -108,7 +96,7 @@ // process XML Set<StringTuple> s = processResult(xml, a, b); try { - //System.out.println("retrieved " + s.size() + " tupels\n"); + // System.out.println("retrieved " + s.size() + " tupels\n"); } catch (Exception e) { } return s; @@ -118,136 +106,89 @@ Set<StringTuple> ret = new HashSet<StringTuple>(); // TODO if result is empty, catch exceptions - String resEnd="</result>"; + String resEnd = "</result>"; String one = "binding name=\"" + a + "\""; String two = "binding name=\"" + b + "\""; - String endbinding= "binding"; - String uri="uri"; - //String uridel = "<uri>"; + String endbinding = "binding"; + String uri = "uri"; + // String uridel = "<uri>"; String bnode = "<bnode>"; - //String uriend = "</uri>"; + // String uriend = "</uri>"; String predtmp = ""; String objtmp = ""; - //System.out.println(getNextResult(xml)); - String nextResult=""; - while ((nextResult=getNextResult( xml))!=null){ - //System.out.println(xml.indexOf(resEnd)); - //System.out.println(xml); - if(nextResult.indexOf(bnode)!=-1) - {xml=xml.substring(xml.indexOf(resEnd)+resEnd.length());continue;} + // System.out.println(getNextResult(xml)); + String nextResult = ""; + while ((nextResult = getNextResult(xml)) != null) { + // System.out.println(xml.indexOf(resEnd)); + // System.out.println(xml); + if (nextResult.indexOf(bnode) != -1) { + xml = xml.substring(xml.indexOf(resEnd) + resEnd.length()); + continue; + } // get pred - //predtmp = nextResult.substring(nextResult.indexOf(one) + one.length()); - predtmp=getinTag(nextResult, one,endbinding); - predtmp=getinTag(predtmp, uri,uri); - //System.out.println(predtmp); - + // predtmp = nextResult.substring(nextResult.indexOf(one) + + // one.length()); + predtmp = getinTag(nextResult, one, endbinding); + predtmp = getinTag(predtmp, uri, uri); + // System.out.println(predtmp); + // getobj - objtmp=getinTag(nextResult, two,endbinding); - objtmp=getinTag(objtmp, uri,uri); - //System.out.println(objtmp); - - StringTuple st=new StringTuple(predtmp, objtmp); - //System.out.println(st); + objtmp = getinTag(nextResult, two, endbinding); + objtmp = getinTag(objtmp, uri, uri); + // System.out.println(objtmp); + + StringTuple st = new StringTuple(predtmp, objtmp); + // System.out.println(st); ret.add(st); - xml=xml.substring(xml.indexOf(resEnd)+resEnd.length()); - + xml = xml.substring(xml.indexOf(resEnd) + resEnd.length()); + } - /*while (xml.indexOf(one) != -1) { - - + /* + * while (xml.indexOf(one) != -1) { + * + * + * + * // System.out.println(new Tupel(predtmp,objtmp)); } + */ - - // System.out.println(new Tupel(predtmp,objtmp)); - }*/ - return ret; } - - private String getNextResult(String xml){ - String res1="<result>"; - String res2="</result>"; - if(xml.indexOf(res1)==-1)return null; + + private String getNextResult(String xml) { + String res1 = "<result>"; + String res2 = "</result>"; + if (xml.indexOf(res1) == -1) + return null; xml = xml.substring(xml.indexOf(res1) + res1.length()); - xml = xml.substring(0,xml.indexOf(res2) ); - //System.out.println(xml); + xml = xml.substring(0, xml.indexOf(res2)); + // System.out.println(xml); return xml; } - private String getinTag(String xml, String starttag, String endtag){ - String res1="<"+starttag+">"; - //System.out.println(res1); - String res2="</"+endtag+">"; - if(xml.indexOf(res1)==-1)return null; + + private String getinTag(String xml, String starttag, String endtag) { + String res1 = "<" + starttag + ">"; + // System.out.println(res1); + String res2 = "</" + endtag + ">"; + if (xml.indexOf(res1) == -1) + return null; xml = xml.substring(xml.indexOf(res1) + res1.length()); - //System.out.println(xml); - xml = xml.substring(0,xml.indexOf(res2) ); - //System.out.println(xml); - + // System.out.println(xml); + xml = xml.substring(0, xml.indexOf(res2)); + // System.out.println(xml); + return xml; } - private String sendAndReceiveSPARQL(String sparql) throws IOException { - p("sendAndReceiveSPARQL"); - StringBuilder answer = new StringBuilder(); - //sparql="SELECT * WHERE {?a ?b ?c}LIMIT 10"; + private String sendAndReceiveSPARQL(String sparql) { + LinkedHashSet l = new LinkedHashSet<String>(); - // String an Sparql-Endpoint schicken - HttpURLConnection connection; - SparqlEndpoint se = configuration.getSparqlEndpoint(); - p("URL: "+se.getURL()); - p("Host: "+se.getHost()); - - connection = (HttpURLConnection) se.getURL().openConnection(); - connection.setDoOutput(true); - - //connection.addRequestProperty("Host", se.getHost()); - connection.addRequestProperty("Connection", "close"); - connection - .addRequestProperty( - "Accept", - "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); - connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); - connection - .addRequestProperty( - "User-Agent", - "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); - - OutputStream os = connection.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - - Set<String> s = se.getParameters().keySet(); - Iterator<String> it = s.iterator(); - String FullURI = ""; - while (it.hasNext()) { - String element = it.next(); - FullURI += "" + URLEncoder.encode(element, "UTF-8") + "=" - + URLEncoder.encode(se.getParameters().get(element), "UTF-8") + "&"; - } - - FullURI += "" + se.getHasQueryParameter() + "=" + URLEncoder.encode(sparql, "UTF-8"); - p(FullURI); - osw.write(FullURI); - osw.close(); - - // receive answer - InputStream is = connection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - BufferedReader br = new BufferedReader(isr); - - String line; - do { - line = br.readLine(); - if (line != null) - answer.append(line); - } while (line != null); - - br.close(); - p(answer.toString()); - return answer.toString(); + return new SparqlQuery(sparql, configuration.getSparqlEndpoint()) + .getAsXMLString(); } - public void p(String str){ - if(print_flag){ + + public void p(String str) { + if (print_flag) { System.out.println(str); } } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java 2008-01-18 23:21:56 UTC (rev 395) @@ -1,168 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql.configuration; - -import java.net.URL; -import java.util.HashMap; - - -/** - * Holds some predefined endpoints. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedEndpoint { - public static SparqlEndpoint getEndpoint(int i) { - - switch (i) { - case 1: - return dbpediaEndpoint(); - case 2: - return localJoseki(); - case 3: - return govTrack(); - case 4: - return revyu(); - case 5: - return myopenlink(); - case 6: - return worldFactBook(); - } - return null; - } - - public static SparqlEndpoint dbpediaEndpoint() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://dbpedia.org"); - m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "dbpedia.openlinksw.com", m); - } - - public static SparqlEndpoint localJoseki() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://localhost:2020/books"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "localhost", m); - } - public static SparqlEndpoint worldFactBook() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - - /* - * it only has 4 classes - public static SpecificSparqlEndpoint dblp() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - */ - public static SparqlEndpoint govTrack() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www.rdfabout.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "www.rdfabout.com", m); - } - public static SparqlEndpoint revyu() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://revyu.com/sparql?query=SELECT DISTINCT * WHERE {[] a ?c} - try { - u = new URL("http://revyu.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "revyu.com", m); - } - - // returns strange xml - /*public static SpecificSparqlEndpoint dbtune() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 - http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - http://dbtune.org:2020/evaluateQuery - ?repository=default&serialization=rdfxml&queryLanguage=SPARQL - &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - try { - u = new URL("http://dbtune.org:2020/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbtune.org", m); - }*/ - - public static SparqlEndpoint myopenlink() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://myopenlink.net/dataspace"); - m.put("format", "application/sparql-results.xml"); - //http://myopenlink.net:8890/sparql/?query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D - try { - u = new URL("http://myopenlink.net:8890/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SparqlEndpoint(u, "myopenlink.net", m); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java 2008-01-18 23:21:56 UTC (rev 395) @@ -1,171 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql.configuration; - -import java.util.HashSet; -import java.util.Set; - - -/** - * Predefined filters. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedFilter { - - - public static SparqlQueryType getFilter(int i) { - - switch (i) { - case 1: - return YagoFilter(); - case 2: - return SKOS(); - case 3: - return YAGOSKOS(); - case 4: - return YagoSpecialHierarchy(); - } - return null; - } - - - public static SparqlQueryType YagoFilter(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Category:"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - public static SparqlQueryType YagoSpecialHierarchy(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - pred.add("http://dbpedia.org/property/monarch"); - - - Set<String> obj = new HashSet<String>(); - obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - - - public static SparqlQueryType SKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - public static SparqlQueryType YAGOSKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - //obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - - - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java 2008-01-18 23:21:56 UTC (rev 395) @@ -20,55 +20,175 @@ package org.dllearner.kb.sparql.configuration; import java.net.URL; -import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; /** - * One sparql endpoint configuration. + * One sparql endpoint configuration, + * made to comply with Jena * * @author Sebastian Hellmann * */ public class SparqlEndpoint { - - String host; - String hasQueryParameter; URL url; - public HashMap<String, String> parameters = new HashMap<String, String>(); + LinkedList<String> defaultGraphURIs; + LinkedList<String> namedGraphURIs; + //public HashMap<String, String> parameters = new HashMap<String, String>(); - public SparqlEndpoint(URL url, String host, HashMap<String, String> parameters) { - super(); - this.host = host; - this.url = url; - this.hasQueryParameter = "query"; - this.parameters = parameters; + public SparqlEndpoint(URL u) { + this.url = u; + this.defaultGraphURIs=new LinkedList<String>(); + this.namedGraphURIs=new LinkedList<String>(); } + + public SparqlEndpoint(URL u,List<String> defaultGraphURIs,List<String> namedGraphURIs) { + this.url = u; + this.defaultGraphURIs=new LinkedList<String>(); + this.namedGraphURIs=new LinkedList<String>(); + } + - public String getHasQueryParameter() { - return hasQueryParameter; + public URL getURL() { + return this.url; } - public void setHasQueryParameter(String hasQueryParameter) { - this.hasQueryParameter = hasQueryParameter; + public LinkedList<String> getDefaultGraphURIs() { + return defaultGraphURIs; } - public String getHost() { - return host; + public LinkedList<String> getNamedGraphURIs() { + return namedGraphURIs; } + + public static SparqlEndpoint getEndpointByNumber(int i) { - public void setHost(String host) { - this.host = host; + switch (i) { + case 0: + return dbpediaEndpoint(); + case 1: + return localJoseki(); + case 2: + return govTrack(); + case 3: + return revyu(); + case 4: + return myopenlink(); + case 5: + return worldFactBook(); + } + return null; } + + public static SparqlEndpoint dbpediaEndpoint() { + URL u = null; + try { + u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + LinkedList<String> defaultGraphURIs=new LinkedList<String>(); + defaultGraphURIs.add("http://dbpedia.org"); + return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); + } - public HashMap<String, String> getParameters() { - return parameters; + public static SparqlEndpoint localJoseki() { + URL u = null; + try { + u = new URL("http://localhost:2020/books"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>()); } + + public static SparqlEndpoint worldFactBook() { + URL u = null; + try { + u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>()); + } + - public void setParameters(HashMap<String, String> parameters) { - this.parameters = parameters; + public static SparqlEndpoint govTrack() { + URL u = null; + try { + u = new URL("http://www.rdfabout.com/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>()); } + + public static SparqlEndpoint revyu() { + URL u = null; + try { + u = new URL("http://revyu.com/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SparqlEndpoint(u, new LinkedList<String>(), new LinkedList<String>()); + } + + public static SparqlEndpoint myopenlink() { + URL u = null; + try { + u = new URL("http://myopenlink.net:8890/sparql/"); + } catch (Exception e) { + e.printStackTrace(); + } + LinkedList<String> defaultGraphURIs=new LinkedList<String>(); + defaultGraphURIs.add("http://myopenlink.net/dataspace"); + return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); - public URL getURL() { - return this.url; + } + + + // returns strange xml + /*public static SpecificSparqlEndpoint dbtune() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + // m.put("default-graph-uri", "http://dbpedia.org"); + // m.put("format", "application/sparql-results.xml"); + //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 + http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D + &resultFormat=xml + &resourceFormat=ns&entailment=none + http://dbtune.org:2020/evaluateQuery + ?repository=default&serialization=rdfxml&queryLanguage=SPARQL + &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D + &resultFormat=xml + &resourceFormat=ns&entailment=none + try { + u = new URL("http://dbtune.org:2020/sparql/"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "dbtune.org", m); + }*/ + + + + + /* + * it only has 4 classes + public static SpecificSparqlEndpoint dblp() { + URL u = null; + HashMap<String, String> m = new HashMap<String, String>(); + // m.put("default-graph-uri", "http://dbpedia.org"); + // m.put("format", "application/sparql-results.xml"); + try { + u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql"); + } catch (Exception e) { + e.printStackTrace(); + } + return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); } + */ + + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-01-18 18:49:49 UTC (rev 394) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java 2008-01-18 23:21:56 UTC (rev 395) @@ -19,6 +19,7 @@ */ package org.dllearner.kb.sparql.configuration; +import java.util.HashSet; import java.util.Set; /** @@ -97,5 +98,142 @@ //System.out.println("added filter: "+filter); } + + public static SparqlQueryType getFilter(int i) { + switch (i) { + case 1: + return YagoFilter(); + case 2: + return SKOS(); + case 3: + return YAGOSKOS(); + case 4: + return YagoSpecialHierarchy(); + } + return null; + } + + + public static SparqlQueryType YagoFilter(){ + Set<String> pred = new HashSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + + Set<String> obj = new HashSet<String>(); + //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + //obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Category:"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); + + return new SparqlQueryType("forbid", obj, pred, "false"); + } + public static SparqlQueryType YagoSpecialHierarchy(){ + Set<String> pred = new HashSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + pred.add("http://dbpedia.org/property/monarch"); + + + Set<String> obj = new HashSet<String>(); + obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://up... [truncated message content] |
From: <ton...@us...> - 2008-01-18 18:49:54
|
Revision: 394 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=394&view=rev Author: tonytacker Date: 2008-01-18 10:49:49 -0800 (Fri, 18 Jan 2008) Log Message: ----------- + all reasoners + all LearningAlgorithms Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-18 16:40:00 UTC (rev 393) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-01-18 18:49:49 UTC (rev 394) @@ -22,12 +22,12 @@ import javax.swing.*; -import org.dllearner.algorithms.refinement.ROLearner; - import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; +import org.dllearner.core.LearningAlgorithm; /** @@ -40,30 +40,49 @@ public class LearningAlgorithmPanel extends JPanel implements ActionListener { private static final long serialVersionUID = 8721490771860452959L; + private Config config; + private List<Class<? extends LearningAlgorithm>> learners; + private JPanel choosePanel = new JPanel(); + private JPanel initPanel = new JPanel(); + private JButton initButton; + private String[] cbItems = {}; + private JComboBox cb = new JComboBox(cbItems); + private int choosenClassIndex; - private JPanel laPanel = new JPanel(); - private JButton laButton; - private Config config; - LearningAlgorithmPanel(Config config) { super(new BorderLayout()); this.config = config; - laButton = new JButton("Use ROLearner"); - laButton.addActionListener(this); + initButton = new JButton("Init LearingAlgorithm"); + initButton.addActionListener(this); - laPanel.add(laButton); - add(laPanel, BorderLayout.PAGE_START); + initPanel.add(initButton); + choosePanel.add(cb); + + add(choosePanel, BorderLayout.PAGE_START); + add(initPanel, BorderLayout.PAGE_END); + + // add into comboBox + learners = config.getComponentManager().getLearningAlgorithms(); + for (int i=0; i<learners.size(); i++) { + cb.addItem(learners.get(i).getSimpleName()); + } } public void actionPerformed(ActionEvent e) { - if (e.getSource() == laButton) { + // read selected Class + choosenClassIndex = cb.getSelectedIndex(); + + if (e.getSource() == initButton) { if (config.getStatus(6)) { - config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm(ROLearner.class, config.getLearningProblem(), config.getReasoningService())); + config.setLearningAlgorithm(config.getComponentManager().learningAlgorithm(learners.get(choosenClassIndex), config.getLearningProblem(), config.getReasoningService())); config.getLearningAlgorithm().init(); } + if (config.getStatus(5)) { // exemples are set + System.out.println("LearningAlgorithm: " + config.getLearningAlgorithm() + "\n"); + } } } } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 16:40:00 UTC (rev 393) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 18:49:49 UTC (rev 394) @@ -23,50 +23,62 @@ import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; import javax.swing.*; -import org.dllearner.reasoning.DIGReasoner; +import org.dllearner.core.ReasonerComponent; -//import org.dllearner.core.ReasonerComponent; -//import org.dllearner.reasoning.DIGReasoner; -//import org.dllearner.core.ComponentManager; -//import org.dllearner.core.ReasoningService; - /** * ReasonerPanel * * @author Tilo Hielscher * */ - public class ReasonerPanel extends JPanel implements ActionListener { private static final long serialVersionUID = -7678275020058043937L; - private JPanel digPanel = new JPanel(); + private List<Class<? extends ReasonerComponent>> reasoners; + private JPanel choosePanel = new JPanel(); + private JPanel initPanel = new JPanel(); private JButton initButton; private Config config; - + private String[] cbItems = {}; + private JComboBox cb = new JComboBox(cbItems); + private int choosenClassIndex; + ReasonerPanel(final Config config) { super(new BorderLayout()); this.config = config; - initButton = new JButton("Use DIG by default"); + initButton = new JButton("Init Reasoner"); initButton.addActionListener(this); + initPanel.add(initButton); - digPanel.add(initButton); - add(digPanel, BorderLayout.PAGE_START); + choosePanel.add(cb); + + add(choosePanel, BorderLayout.PAGE_START); + add(initPanel, BorderLayout.PAGE_END); + + // add into comboBox + reasoners = config.getComponentManager().getReasonerComponents(); + for (int i=0; i<reasoners.size(); i++) { + cb.addItem(reasoners.get(i).getSimpleName()); + } } public void actionPerformed(ActionEvent e) { + // read selected Class + choosenClassIndex = cb.getSelectedIndex(); + if (e.getSource() == initButton) { - if (config.getStatus(2)) { // no check if button init was used + if (config.getStatus(2)) { // no check if button initKnowledgeSource was pressed // set reasoner - config.setReasoner(config.getComponentManager().reasoner(DIGReasoner.class, config.getKnowledgeSource())); + config.setReasoner(config.getComponentManager().reasoner(reasoners.get(choosenClassIndex), config.getKnowledgeSource())); config.getReasoner().init(); // set ReasoningService This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-01-18 16:40:04
|
Revision: 393 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=393&view=rev Author: tonytacker Date: 2008-01-18 08:40:00 -0800 (Fri, 18 Jan 2008) Log Message: ----------- - add negative Examples - add all LearningProblems Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-18 16:40:00 UTC (rev 393) @@ -46,8 +46,8 @@ private String uri; private ReasonerComponent reasoner; private ReasoningService rs; - private String[] kbBoxItems = {"Pleae select a type", "KBFile", "OWLFile", "SparqleEndpoint"}; - private Set<String> exampleSet = new HashSet<String>(); + private Set<String> posExampleSet = new HashSet<String>(); + private Set<String> negExampleSet = new HashSet<String>(); private LearningProblem lp; private LearningAlgorithm la; @@ -106,10 +106,6 @@ rs = input; } - protected String[] getKBBoxItems() { - return kbBoxItems; - } - protected KnowledgeSource getKnowledgeSource() { return source; } @@ -119,15 +115,24 @@ source = input; } - protected void setExampleSet(Set<String> input) { + protected void setPosExampleSet(Set<String> posExampleSet) { status[5] = true; - exampleSet = input; + this.posExampleSet = posExampleSet; } - protected Set<String> getExampleSet () { - return exampleSet; + protected Set<String> getPosExampleSet () { + return this.posExampleSet; } + protected void setNegExampleSet(Set<String> negExampleSet) { + status[5] = true; + this.negExampleSet = negExampleSet; + } + + protected Set<String> getNegExampleSet () { + return this.negExampleSet; + } + protected void setLearningProblem (LearningProblem input) { status[6] = true; lp = input; Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -71,7 +71,7 @@ fileDisplay = new JTextField(35); fileDisplay.setEditable(true); - // update config if textfield changed + // update config if textfield fileDisplay changed fileDisplay.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { config.setURI(fileDisplay.getText()); @@ -84,10 +84,9 @@ } }); - // parse + // add to comboBox for (int i=0; i<sources.size(); i++) { - String ksClass = sources.get(i).toString().substring(23).concat(".class"); - cb.addItem(ksClass); + cb.addItem(sources.get(i).getSimpleName()); } cb.addActionListener(this); @@ -119,7 +118,7 @@ int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String URI = "file://"; - URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI's + URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI config.setURI(URI); //save variable fileDisplay.setText(URI); } Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -21,12 +21,23 @@ */ import java.awt.BorderLayout; +import java.awt.GridBagLayout; +import java.awt.GridBagConstraints; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; -import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.dl.Individual; +//import org.dllearner.learningproblems.*; /** * LearningProblemPanel @@ -39,32 +50,166 @@ private static final long serialVersionUID = -3819627680918930203L; + private List<Class<? extends LearningProblem>> problems; + private String[] lpBoxItems = {}; + private JComboBox cb = new JComboBox(lpBoxItems); + private JPanel choosePanel = new JPanel(); + private JPanel centerPanel = new JPanel(); private JPanel lpPanel = new JPanel(); - private JButton lpButton; + private JLabel posLabel = new JLabel("positive Examples"); + private JLabel negLabel = new JLabel("negative Examples"); + private JButton initButton, readListButton; + private int choosenClassIndex; + private List<Individual> individuals; + private JList posList = new JList(); + private JList negList = new JList(); private Config config; - LearningProblemPanel(Config config) { + LearningProblemPanel(final Config config) { super(new BorderLayout()); this.config = config; - lpButton = new JButton("Use PosOnlyDefinitionLP"); - lpButton.addActionListener(this); + initButton = new JButton("Init LearningProblem"); + initButton.addActionListener(this); - lpPanel.add(lpButton); - add(lpPanel, BorderLayout.PAGE_START); + readListButton = new JButton("Read List"); + readListButton.addActionListener(this); + + choosePanel.add(cb); + choosePanel.add(readListButton); + lpPanel.add(initButton); + add(choosePanel, BorderLayout.PAGE_START); + add(centerPanel, BorderLayout.CENTER); + add(lpPanel, BorderLayout.PAGE_END); + + problems = config.getComponentManager().getLearningProblems(); + + // add into comboBox + for (int i=0; i<problems.size(); i++) { + cb.addItem(problems.get(i).getSimpleName()); + } + + // read choosen LearningProblem + choosenClassIndex = cb.getSelectedIndex(); + + // create a scrollable list of positive examples + posList = new JList(); + posList.setLayoutOrientation(JList.VERTICAL); + posList.setVisibleRowCount(-1); + JScrollPane posListScroller = new JScrollPane(posList); + posListScroller.setPreferredSize(new Dimension(300, 200)); + + // create a scrollable list of negative examples + negList = new JList(); + negList.setLayoutOrientation(JList.VERTICAL); + negList.setVisibleRowCount(-1); + JScrollPane negListScroller = new JScrollPane(negList); + negListScroller.setPreferredSize(new Dimension(300, 200)); + + // define GridBag + GridBagLayout gridbag = new GridBagLayout(); + centerPanel.setLayout(gridbag); + GridBagConstraints constraints = new GridBagConstraints(); + constraints.fill = GridBagConstraints.BOTH; + constraints.anchor = GridBagConstraints.CENTER; + + buildConstraints(constraints, 0, 0, 1, 1, 100, 100); + gridbag.setConstraints(posLabel, constraints); + centerPanel.add(posLabel); + + buildConstraints(constraints, 1, 0, 1, 1, 100, 100); + gridbag.setConstraints(negLabel, constraints); + centerPanel.add(negLabel); + + buildConstraints(constraints, 0, 1, 1, 1, 100, 100); + gridbag.setConstraints(posListScroller, constraints); + centerPanel.add(posListScroller); + + buildConstraints(constraints, 1, 1, 1, 1, 100, 100); + gridbag.setConstraints(negListScroller, constraints); + centerPanel.add(negListScroller); + + add(centerPanel, BorderLayout.CENTER); + + // listener for posList + posList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> posExampleSet = new HashSet<String>(); + int[] selectedIndices = posList.getSelectedIndices(); + for(int i : selectedIndices) + posExampleSet.add(individuals.get(i).toString()); + config.setPosExampleSet(posExampleSet); + System.out.println("posList: " + config.getPosExampleSet() ); + } + }); + + // listener for negList + negList.addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent evt) { + if (evt.getValueIsAdjusting()) + return; + // detect witch examples have been selected + Set<String> negExampleSet = new HashSet<String>(); + int[] selectedIndices = negList.getSelectedIndices(); + for(int i : selectedIndices) + negExampleSet.add(individuals.get(i).toString()); + config.setNegExampleSet(negExampleSet); + System.out.println("negList: " + config.getNegExampleSet() ); + } + }); } public void actionPerformed(ActionEvent e) { - if (e.getSource() == lpButton) { + // read selected LearningProblemClass + choosenClassIndex = cb.getSelectedIndex(); + + // later for read options + //List a = config.getComponentManager().getConfigOptions(problems.get(cb.getSelectedIndex())); + //System.out.println("optionName: " + a); + + // get list after reasoner init + if (e.getSource() == readListButton) { + // fill lists + if (config.getStatus(4)) { // only with a reasoner + Set<Individual> individualsSet = config.getReasoningService().getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + DefaultListModel listModel = new DefaultListModel(); + for(Individual ind : individuals) { + listModel.addElement(ind); + } + posList.setModel(listModel); + negList.setModel(listModel); + } + } + + //init + if (e.getSource() == initButton) { if (config.getStatus(5)) { - System.out.println(config.getExampleSet()); - config.setLearningProblem(config.getComponentManager().learningProblem(PosOnlyDefinitionLP.class, config.getReasoningService())); - config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", config.getExampleSet()); + config.setLearningProblem(config.getComponentManager().learningProblem(problems.get(choosenClassIndex), config.getReasoningService())); + config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "positiveExamples", config.getPosExampleSet()); + config.getComponentManager().applyConfigEntry(config.getLearningProblem(), "negativeExamples", config.getNegExampleSet()); config.getLearningProblem().init(); + System.out.println("init LearningProblem with \n" + problems.get(choosenClassIndex) + "\nand " + "\nposExample: " + + config.getPosExampleSet() + "\nand negExample: " + config.getNegExampleSet()); } } } + /* + * Define GridBagConstraints + */ + private void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy) { + gbc.gridx = gx; + gbc.gridy = gy; + gbc.gridwidth = gw; + gbc.gridheight = gh; + gbc.weightx = wx; + gbc.weighty = wy; + } + } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 13:10:58 UTC (rev 392) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-18 16:40:00 UTC (rev 393) @@ -21,18 +21,11 @@ */ import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; import javax.swing.*; -import javax.swing.event.*; -import org.dllearner.core.dl.Individual; import org.dllearner.reasoning.DIGReasoner; //import org.dllearner.core.ReasonerComponent; @@ -53,10 +46,7 @@ private static final long serialVersionUID = -7678275020058043937L; private JPanel digPanel = new JPanel(); - private JPanel centerPanel = new JPanel(); - private JButton digButton; - private JList digList = new JList(); - private List<Individual> individuals; + private JButton initButton; private Config config; ReasonerPanel(final Config config) { @@ -64,67 +54,30 @@ this.config = config; - digButton = new JButton("Use DIG by default"); - digButton.addActionListener(this); + initButton = new JButton("Use DIG by default"); + initButton.addActionListener(this); - // create a scrollable list of examples - digList = new JList(); - digList.setLayoutOrientation(JList.VERTICAL); - digList.setVisibleRowCount(-1); - JScrollPane listScroller = new JScrollPane(digList); - listScroller.setPreferredSize(new Dimension(550, 350)); - - digPanel.add(digButton); + digPanel.add(initButton); add(digPanel, BorderLayout.PAGE_START); - - centerPanel.add(listScroller); - add(centerPanel, BorderLayout.CENTER); - - digList.addListSelectionListener(new ListSelectionListener() { - public void valueChanged(ListSelectionEvent evt) { - if (evt.getValueIsAdjusting()) - return; - //System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); - // detect which examples have been selected - Set<String> exampleSet = new HashSet<String>(); - int[] selectedIndices = digList.getSelectedIndices(); - for(int i : selectedIndices) - exampleSet.add(individuals.get(i).toString()); - config.setExampleSet(exampleSet); //error - System.out.println("digList: " + config.getExampleSet() ); //error - } - }); - } public void actionPerformed(ActionEvent e) { - if (e.getSource() == digButton) { - // set reasoner - config.setReasoner(config.getComponentManager().reasoner(DIGReasoner.class, config.getKnowledgeSource())); - //System.out.println(StartGUI.myconfig.getKnowledgeSource()); - config.getReasoner().init(); - //System.out.println(StartGUI.myconfig.getReasoner()); + if (e.getSource() == initButton) { + if (config.getStatus(2)) { // no check if button init was used + // set reasoner + config.setReasoner(config.getComponentManager().reasoner(DIGReasoner.class, config.getKnowledgeSource())); + config.getReasoner().init(); - // set ReasoningService - config.setReasoningService(config.getComponentManager().reasoningService(config.getReasoner())); - - // get list from ReasoningService - Set<Individual> individualsSet = config.getReasoningService().getIndividuals(); - //System.out.println("IndividualsSet: " + individualsSet); - individuals = new LinkedList<Individual>(individualsSet); - //System.out.println("individuals: " + individuals); - - // make list - DefaultListModel listModel = new DefaultListModel(); - for(Individual ind : individuals) - listModel.addElement(ind); - - digList.setModel(listModel); - - // graphic - digList.setModel(listModel); - StartGUI.myrun.renew(); + // set ReasoningService + config.setReasoningService(config.getComponentManager().reasoningService(config.getReasoner())); + } + if (config.getStatus(3)) { // Reasoner is set + System.out.println("Reasoner: " + config.getReasoner()); + } + if (config.getStatus(4)) { // ReasoningServic is set + System.out.println("ReasoningService: " + config.getReasoningService()); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-01-18 13:11:00
|
Revision: 392 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=392&view=rev Author: jenslehmann Date: 2008-01-18 05:10:58 -0800 (Fri, 18 Jan 2008) Log Message: ----------- - corrected Sparql component entry in components.ini (such that it can be used in DL-Learner) - implemented interruptable Jena SPARQL query Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/lib/components.ini 2008-01-18 13:10:58 UTC (rev 392) @@ -3,7 +3,7 @@ # knowledge sources org.dllearner.kb.OWLFile org.dllearner.kb.KBFile -org.dllearner.kb.sparql.SparqlEndpoint +org.dllearner.kb.sparql.SparqlKnowledgeSource # reasoners org.dllearner.reasoning.OWLAPIReasoner org.dllearner.reasoning.DIGReasoner Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-18 13:10:58 UTC (rev 392) @@ -60,7 +60,7 @@ import org.dllearner.core.dl.Individual; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; Deleted: trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java 2008-01-18 13:10:58 UTC (rev 392) @@ -1,524 +0,0 @@ -/** - * Copyright (C) 2007, 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.kb; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.OntologyFormat; -import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -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.dl.KB; -import org.dllearner.kb.sparql.Manager; -import org.dllearner.kb.sparql.Manipulator; -import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; -import org.dllearner.kb.sparql.configuration.PredefinedFilter; -import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; -import org.dllearner.kb.sparql.old.*; -import org.dllearner.parser.KBParser; -import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.utilities.StringTuple; - -/** - * Represents a SPARQL Endpoint. - * - * @author Jens Lehmann - * @author Sebastian Knappe - * @author Sebastian Hellmann - */ -public class SparqlKnowledgeSource extends KnowledgeSource { - - // ConfigOptions - private URL url; - String host; - private Set<String> instances=new HashSet<String>();; - private URL dumpFile; - private int recursionDepth = 1; - private int predefinedFilter = 0; - private int predefinedEndpoint = 0; - private Set<String> predList=new HashSet<String>(); - private Set<String> objList=new HashSet<String>(); - // private Set<String> classList; - private String format = "N-TRIPLES"; - private boolean dumpToFile = true; - private boolean useLits = false; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - private int breakSuperClassRetrievalAfter = 200; - - private boolean learnDomain = false; - private boolean learnRange = false; - private int numberOfInstancesUsedForRoleLearning=40; - private String role=""; - private String blankNodeIdentifier = "bnode"; - - LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); - - /** - * Holds the results of the calculateSubjects method - */ - private String[] subjects; - - /** - * Holds the results of the calculateTriples method - */ - private String[] triples; - - /** - * Holds the results of the calculateConceptSubjects method - */ - private String[] conceptSubjects; - - /** - * if a method is running this becomes true - */ - private boolean subjectThreadRunning = false; - - private boolean triplesThreadRunning = false; - - private boolean conceptThreadRunning = false; - - /** - * the Thread that is running a method - */ - private Thread subjectThread; - - private Thread triplesThread; - - private Thread conceptThread; - - // received ontology as array, used if format=Array(an element of the - // array consists of the subject, predicate and object separated by '<' - private String[] ontArray; - - // received ontology as KB, the internal format - private KB kb; - - public static String getName() { - return "SPARQL Endpoint Restructured"; - } - - /** - * sets the ConfigOptions for this KnowledgeSource - * - * @return - */ - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances", - "relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("recursionDepth", - "recursion depth of KB fragment selection", 2)); - options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); - options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); - - options.add(new StringSetConfigOption("predList", "list of all ignored roles")); - options.add(new StringSetConfigOption("objList", "list of all ignored objects")); - options.add(new StringSetConfigOption("classList", "list of all ignored classes")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); - options.add(new BooleanConfigOption("dumpToFile", - "Specifies whether the extracted ontology is written to a file or not.", true)); - options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); - - options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain/Range from")); - options.add(new StringConfigOption("blankNodeIdentifier", - "used to identify blanknodes in Tripels")); - - options.add(new StringTupleListConfigOption("example", "example")); - options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); - options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); - options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); - options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); - options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); - - - - return options; - } - - /* - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String option = entry.getOptionName(); - if (option.equals("url")) { - String s = (String) entry.getValue(); - try { - url = new URL(s); - } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), - "malformed URL " + s); - } - } else if (option.equals("host")) { - host = (String) entry.getValue(); - } else if (option.equals("instances")) { - instances = (Set<String>) entry.getValue(); - } else if (option.equals("recursionDepth")) { - recursionDepth = (Integer) entry.getValue(); - } else if (option.equals("predList")) { - predList = (Set<String>) entry.getValue(); - } else if (option.equals("objList")) { - objList = (Set<String>) entry.getValue(); - //} else if (option.equals("classList")) { - // classList = (Set<String>) entry.getValue(); - } else if (option.equals("predefinedEndpoint")) { - predefinedEndpoint = (Integer) entry.getValue(); - } else if (option.equals("predefinedFilter")) { - predefinedFilter = (Integer) entry.getValue(); - } else if (option.equals("format")) { - format = (String) entry.getValue(); - } else if (option.equals("dumpToFile")) { - dumpToFile = (Boolean) entry.getValue(); - } else if (option.equals("useLits")) { - useLits = (Boolean) entry.getValue(); - } else if (option.equals("getAllSuperClasses")) { - getAllSuperClasses = (Boolean) entry.getValue(); - } else if (option.equals("learnDomain")) { - learnDomain = (Boolean) entry.getValue(); - }else if (option.equals("learnRange")) { - learnRange = (Boolean) entry.getValue(); - } else if (option.equals("role")) { - role = (String) entry.getValue(); - } else if (option.equals("blankNodeIdentifier")) { - blankNodeIdentifier = (String) entry.getValue(); - } else if (option.equals("example")) { - //System.out.println(entry.getValue()); - }else if (option.equals("replacePredicate")) { - replacePredicate = (LinkedList)entry.getValue(); - }else if (option.equals("replaceObject")) { - replaceObject = (LinkedList)entry.getValue(); - }else if (option.equals("breakSuperClassRetrievalAfter")) { - breakSuperClassRetrievalAfter = (Integer) entry.getValue(); - }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { - numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); - }else if (option.equals("closeAfterRecursion")) { - closeAfterRecursion = (Boolean) entry.getValue(); - } - - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - System.out.println("SparqlModul: Collecting Ontology"); - // SparqlOntologyCollector oc= - // new SparqlOntologyCollector(Datastructures.setToArray(instances), - // numberOfRecursions, filterMode, - // Datastructures.setToArray(predList),Datastructures.setToArray( - // objList),Datastructures.setToArray(classList),format,url,useLits); - Manager m = new Manager(); - SpecificSparqlEndpoint sse = null; - SparqlQueryType sqt = null; - // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); - - // get Options for endpoints - if (predefinedEndpoint >= 1) { - sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); - } else { - sse = new SpecificSparqlEndpoint(url, host, parameters); - } - - // get Options for Filters - - if (predefinedFilter >= 1) { - sqt = PredefinedFilter.getFilter(predefinedFilter); - - } else { - sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - - } - // give everything to the manager - m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); - try { - String ont = ""; - //System.out.println(learnDomain); - // used to learn a domain of a role - if (learnDomain || learnRange) { - Set<String> pos=new HashSet<String>(); - Set<String> neg=new HashSet<String>(); - if(learnDomain){ - pos = m.getDomainInstancesForRole(role); - neg = m.getRangeInstancesForRole(role); - }else if(learnRange){ - neg = m.getDomainInstancesForRole(role); - pos = m.getRangeInstancesForRole(role); - } - //choose 30 - - - Set<String> tmp=new HashSet<String>(); - for(String one:pos){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - pos=tmp; - System.out.println("Instances used: "+pos.size()); - - tmp=new HashSet<String>(); - for(String one:neg){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - neg=tmp; - - instances=new HashSet<String>(); - instances.addAll(pos); - - instances.addAll(neg); - - for(String one:pos){ - System.out.println("+\""+one+"\""); - } - for(String one:neg){ - System.out.println("-\""+one+"\""); - } - - /*Random r= new Random(); - - - Object[] arr=instances.toArray(); - while(instances.size()>=30){ - - }*/ - // add the role to the filter(a solution is always EXISTS - // role.TOP) - m.addPredicateFilter(role); - //System.out.println(instances); - // THIS is a workaround - - } - // the actual extraction is started here - ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); - - System.out.println("Finished collecting Fragment"); - - if (dumpToFile) { - String filename = System.currentTimeMillis() + ".nt"; - String basedir = "cache" + File.separator; - try { - if (!new File(basedir).exists()) - new File(basedir).mkdir(); - - FileWriter fw = new FileWriter(new File(basedir + filename), true); - fw.write(ont); - fw.flush(); - fw.close(); - - dumpFile = (new File(basedir + filename)).toURI().toURL(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (format.equals("KB")) { - try { - //kb = KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("SparqlModul: ****Finished"); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ - @Override - public String toDIG(URI kbURI) { - if (format.equals("N-TRIPLES")) - return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); - else - return DIGConverter.getDIGString(kb, kbURI).toString(); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#export(java.io.File, - * org.dllearner.core.OntologyFormat) - */ - @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { - // currently no export functions implemented, so we just throw an - // exception - throw new OntologyFormatUnsupportedException("export", format); - } - - public URL getURL() { - return url; - } - - public String[] getOntArray() { - return ontArray; - } - - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param label - * @param limit - */ - public void calculateSubjects(String label, int limit) { - System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - subjects = oc.getSubjectsFromLabel(label, limit); - } catch (IOException e) { - subjects = new String[1]; - subjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param subject - */ - public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - triples = oc.collectTriples(subject); - } catch (IOException e) { - triples = new String[1]; - triples[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param concept - */ - public void calculateConceptSubjects(String concept) { - System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - conceptSubjects = oc.getSubjectsFromConcept(concept); - } catch (IOException e) { - conceptSubjects = new String[1]; - conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public boolean subjectThreadIsRunning() { - return subjectThreadRunning; - } - - public void setSubjectThreadRunning(boolean bool) { - subjectThreadRunning = bool; - } - - public boolean triplesThreadIsRunning() { - return triplesThreadRunning; - } - - public void setTriplesThreadRunning(boolean bool) { - triplesThreadRunning = bool; - } - - public boolean conceptThreadIsRunning() { - return conceptThreadRunning; - } - - public void setConceptThreadRunning(boolean bool) { - conceptThreadRunning = bool; - } - - public String[] getSubjects() { - return subjects; - } - - public Thread getSubjectThread() { - return subjectThread; - } - - public void setSubjectThread(Thread subjectThread) { - this.subjectThread = subjectThread; - } - - public Thread getTriplesThread() { - return triplesThread; - } - - public void setTriplesThread(Thread triplesThread) { - this.triplesThread = triplesThread; - } - - public Thread getConceptThread() { - return conceptThread; - } - - public void setConceptThread(Thread conceptThread) { - this.conceptThread = conceptThread; - } - - public String[] getTriples() { - return triples; - } - - public String[] getConceptSubjects() { - return conceptSubjects; - } -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 13:10:58 UTC (rev 392) @@ -28,7 +28,7 @@ import org.dllearner.kb.sparql.configuration.Configuration; import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.datastructure.Node; import org.dllearner.kb.sparql.old.oldSparqlOntologyCollector; import org.dllearner.utilities.StringTuple; @@ -46,7 +46,7 @@ private ExtractionAlgorithm extractionAlgorithm; public void useConfiguration(SparqlQueryType SparqlQueryType, - SpecificSparqlEndpoint SparqlEndpoint, Manipulator manipulator, int recursiondepth, + SparqlEndpoint SparqlEndpoint, Manipulator manipulator, int recursiondepth, boolean getAllSuperClasses,boolean closeAfterRecursion) { this.configuration = new Configuration(SparqlEndpoint, SparqlQueryType, manipulator, Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java (from rev 391, trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 13:10:58 UTC (rev 392) @@ -0,0 +1,528 @@ +/** + * Copyright (C) 2007, 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.kb.sparql; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.OntologyFormat; +import org.dllearner.core.OntologyFormatUnsupportedException; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +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.dl.KB; +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.PredefinedFilter; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; +import org.dllearner.kb.sparql.old.*; +import org.dllearner.kb.sparql.query.SparqlQuery; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.DIGConverter; +import org.dllearner.reasoning.JenaOWLDIGConverter; +import org.dllearner.utilities.StringTuple; + +/** + * Represents a SPARQL Endpoint. + * + * @author Jens Lehmann + * @author Sebastian Knappe + * @author Sebastian Hellmann + */ +public class SparqlKnowledgeSource extends KnowledgeSource { + + // ConfigOptions + private URL url; + String host; + private Set<String> instances=new HashSet<String>();; + private URL dumpFile; + private int recursionDepth = 1; + private int predefinedFilter = 0; + private int predefinedEndpoint = 0; + private Set<String> predList=new HashSet<String>(); + private Set<String> objList=new HashSet<String>(); + // private Set<String> classList; + private String format = "N-TRIPLES"; + private boolean dumpToFile = true; + private boolean useLits = false; + private boolean getAllSuperClasses = true; + private boolean closeAfterRecursion = true; + private int breakSuperClassRetrievalAfter = 200; + + private boolean learnDomain = false; + private boolean learnRange = false; + private int numberOfInstancesUsedForRoleLearning=40; + private String role=""; + private String blankNodeIdentifier = "bnode"; + + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); + + SparqlEndpoint sse = null; + + /** + * Holds the results of the calculateSubjects method + */ + private String[] subjects; + + /** + * Holds the results of the calculateTriples method + */ + private String[] triples; + + /** + * Holds the results of the calculateConceptSubjects method + */ + private String[] conceptSubjects; + + /** + * if a method is running this becomes true + */ + private boolean subjectThreadRunning = false; + + private boolean triplesThreadRunning = false; + + private boolean conceptThreadRunning = false; + + /** + * the Thread that is running a method + */ + private Thread subjectThread; + + private Thread triplesThread; + + private Thread conceptThread; + + // received ontology as array, used if format=Array(an element of the + // array consists of the subject, predicate and object separated by '<' + private String[] ontArray; + + // received ontology as KB, the internal format + private KB kb; + + public static String getName() { + return "SPARQL Endpoint Restructured"; + } + + /** + * sets the ConfigOptions for this KnowledgeSource + * + * @return + */ + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances", + "relevant instances e.g. positive and negative examples in a learning problem")); + options.add(new IntegerConfigOption("recursionDepth", + "recursion depth of KB fragment selection", 2)); + options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); + + options.add(new StringSetConfigOption("predList", "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); + options.add(new BooleanConfigOption("dumpToFile", + "Specifies whether the extracted ontology is written to a file or not.", true)); + options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); + options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); + + options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); + options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); + options.add(new StringConfigOption("role", "role to learn Domain/Range from")); + options.add(new StringConfigOption("blankNodeIdentifier", + "used to identify blanknodes in Tripels")); + + options.add(new StringTupleListConfigOption("example", "example")); + options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); + options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); + options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); + options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + + + + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), + "malformed URL " + s); + } + } else if (option.equals("host")) { + host = (String) entry.getValue(); + } else if (option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } else if (option.equals("recursionDepth")) { + recursionDepth = (Integer) entry.getValue(); + } else if (option.equals("predList")) { + predList = (Set<String>) entry.getValue(); + } else if (option.equals("objList")) { + objList = (Set<String>) entry.getValue(); + //} else if (option.equals("classList")) { + // classList = (Set<String>) entry.getValue(); + } else if (option.equals("predefinedEndpoint")) { + predefinedEndpoint = (Integer) entry.getValue(); + } else if (option.equals("predefinedFilter")) { + predefinedFilter = (Integer) entry.getValue(); + } else if (option.equals("format")) { + format = (String) entry.getValue(); + } else if (option.equals("dumpToFile")) { + dumpToFile = (Boolean) entry.getValue(); + } else if (option.equals("useLits")) { + useLits = (Boolean) entry.getValue(); + } else if (option.equals("getAllSuperClasses")) { + getAllSuperClasses = (Boolean) entry.getValue(); + } else if (option.equals("learnDomain")) { + learnDomain = (Boolean) entry.getValue(); + }else if (option.equals("learnRange")) { + learnRange = (Boolean) entry.getValue(); + } else if (option.equals("role")) { + role = (String) entry.getValue(); + } else if (option.equals("blankNodeIdentifier")) { + blankNodeIdentifier = (String) entry.getValue(); + } else if (option.equals("example")) { + //System.out.println(entry.getValue()); + }else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList)entry.getValue(); + }else if (option.equals("replaceObject")) { + replaceObject = (LinkedList)entry.getValue(); + }else if (option.equals("breakSuperClassRetrievalAfter")) { + breakSuperClassRetrievalAfter = (Integer) entry.getValue(); + }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { + numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); + }else if (option.equals("closeAfterRecursion")) { + closeAfterRecursion = (Boolean) entry.getValue(); + } + + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + System.out.println("SparqlModul: Collecting Ontology"); + // SparqlOntologyCollector oc= + // new SparqlOntologyCollector(Datastructures.setToArray(instances), + // numberOfRecursions, filterMode, + // Datastructures.setToArray(predList),Datastructures.setToArray( + // objList),Datastructures.setToArray(classList),format,url,useLits); + Manager m = new Manager(); + SparqlQueryType sqt = null; + // get Options for Manipulator + Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + + // get Options for endpoints + if (predefinedEndpoint >= 1) { + sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); + } else { + sse = new SparqlEndpoint(url, host, parameters); + } + + // get Options for Filters + + if (predefinedFilter >= 1) { + sqt = PredefinedFilter.getFilter(predefinedFilter); + + } else { + sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + + } + // give everything to the manager + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); + try { + String ont = ""; + //System.out.println(learnDomain); + // used to learn a domain of a role + if (learnDomain || learnRange) { + Set<String> pos=new HashSet<String>(); + Set<String> neg=new HashSet<String>(); + if(learnDomain){ + pos = m.getDomainInstancesForRole(role); + neg = m.getRangeInstancesForRole(role); + }else if(learnRange){ + neg = m.getDomainInstancesForRole(role); + pos = m.getRangeInstancesForRole(role); + } + //choose 30 + + + Set<String> tmp=new HashSet<String>(); + for(String one:pos){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + pos=tmp; + System.out.println("Instances used: "+pos.size()); + + tmp=new HashSet<String>(); + for(String one:neg){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + neg=tmp; + + instances=new HashSet<String>(); + instances.addAll(pos); + + instances.addAll(neg); + + for(String one:pos){ + System.out.println("+\""+one+"\""); + } + for(String one:neg){ + System.out.println("-\""+one+"\""); + } + + /*Random r= new Random(); + + + Object[] arr=instances.toArray(); + while(instances.size()>=30){ + + }*/ + // add the role to the filter(a solution is always EXISTS + // role.TOP) + m.addPredicateFilter(role); + //System.out.println(instances); + // THIS is a workaround + + } + // the actual extraction is started here + ont = m.extract(instances); + System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); + System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); + + System.out.println("Finished collecting Fragment"); + + if (dumpToFile) { + String filename = System.currentTimeMillis() + ".nt"; + String basedir = "cache" + File.separator; + try { + if (!new File(basedir).exists()) + new File(basedir).mkdir(); + + FileWriter fw = new FileWriter(new File(basedir + filename), true); + fw.write(ont); + fw.flush(); + fw.close(); + + dumpFile = (new File(basedir + filename)).toURI().toURL(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (format.equals("KB")) { + try { + //kb = KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("SparqlModul: ****Finished"); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + if (format.equals("N-TRIPLES")) + return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); + else + return DIGConverter.getDIGString(kb, kbURI).toString(); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#export(java.io.File, + * org.dllearner.core.OntologyFormat) + */ + @Override + public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { + // currently no export functions implemented, so we just throw an + // exception + throw new OntologyFormatUnsupportedException("export", format); + } + + public URL getURL() { + return url; + } + + public String[] getOntArray() { + return ontArray; + } + + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param label + * @param limit + */ + public void calculateSubjects(String label, int limit) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + subjects = oc.getSubjectsFromLabel(label, limit); + } catch (IOException e) { + subjects = new String[1]; + subjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param subject + */ + public void calculateTriples(String subject) { + System.out.println("SparqlModul: Collecting Triples"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + triples = oc.collectTriples(subject); + } catch (IOException e) { + triples = new String[1]; + triples[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param concept + */ + public void calculateConceptSubjects(String concept) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + conceptSubjects = oc.getSubjectsFromConcept(concept); + } catch (IOException e) { + conceptSubjects = new String[1]; + conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public boolean subjectThreadIsRunning() { + return subjectThreadRunning; + } + + public void setSubjectThreadRunning(boolean bool) { + subjectThreadRunning = bool; + } + + public boolean triplesThreadIsRunning() { + return triplesThreadRunning; + } + + public void setTriplesThreadRunning(boolean bool) { + triplesThreadRunning = bool; + } + + public boolean conceptThreadIsRunning() { + return conceptThreadRunning; + } + + public void setConceptThreadRunning(boolean bool) { + conceptThreadRunning = bool; + } + + public String[] getSubjects() { + return subjects; + } + + public Thread getSubjectThread() { + return subjectThread; + } + + public void setSubjectThread(Thread subjectThread) { + this.subjectThread = subjectThread; + } + + public Thread getTriplesThread() { + return triplesThread; + } + + public void setTriplesThread(Thread triplesThread) { + this.triplesThread = triplesThread; + } + + public Thread getConceptThread() { + return conceptThread; + } + + public void setConceptThread(Thread conceptThread) { + this.conceptThread = conceptThread; + } + + public String[] getTriples() { + return triples; + } + + public String[] getConceptSubjects() { + return conceptSubjects; + } + + public SparqlQuery sparqlQuery(String query) { + return new SparqlQuery(sse, query); + } +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 13:10:58 UTC (rev 392) @@ -33,7 +33,7 @@ import java.util.Set; import org.dllearner.kb.sparql.configuration.Configuration; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.query.Cache; import org.dllearner.kb.sparql.query.CachedSparqlQuery; import org.dllearner.kb.sparql.query.SparqlQuery; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java 2008-01-18 13:10:58 UTC (rev 392) @@ -33,7 +33,7 @@ import java.util.Set; import org.dllearner.kb.sparql.configuration.Configuration; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import org.dllearner.kb.sparql.query.Cache; import org.dllearner.utilities.StringTuple; @@ -193,7 +193,7 @@ // String an Sparql-Endpoint schicken HttpURLConnection connection; - SpecificSparqlEndpoint se = configuration.getSparqlEndpoint(); + SparqlEndpoint se = configuration.getSparqlEndpoint(); p("URL: "+se.getURL()); p("Host: "+se.getHost()); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java 2008-01-18 13:10:58 UTC (rev 392) @@ -33,7 +33,7 @@ * see the other classes, which are used as attributes here * */ - private SpecificSparqlEndpoint specificSparqlEndpoint; + private SparqlEndpoint specificSparqlEndpoint; private SparqlQueryType sparqlQueryType; private Manipulator manipulator; // the following needs to be moved to @@ -44,7 +44,7 @@ public int numberOfUncachedSparqlQueries=0; public int numberOfCachedSparqlQueries=0; - public Configuration(SpecificSparqlEndpoint specificSparqlEndpoint, + public Configuration(SparqlEndpoint specificSparqlEndpoint, SparqlQueryType sparqlQueryType, Manipulator manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion) { this.specificSparqlEndpoint = specificSparqlEndpoint; @@ -67,7 +67,7 @@ return this.manipulator; } - public SpecificSparqlEndpoint getSparqlEndpoint() { + public SparqlEndpoint getSparqlEndpoint() { return specificSparqlEndpoint; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java 2008-01-18 13:10:58 UTC (rev 392) @@ -30,7 +30,7 @@ * */ public class PredefinedEndpoint { - public static SpecificSparqlEndpoint getEndpoint(int i) { + public static SparqlEndpoint getEndpoint(int i) { switch (i) { case 1: @@ -49,7 +49,7 @@ return null; } - public static SpecificSparqlEndpoint dbpediaEndpoint() { + public static SparqlEndpoint dbpediaEndpoint() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); m.put("default-graph-uri", "http://dbpedia.org"); @@ -59,10 +59,10 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); + return new SparqlEndpoint(u, "dbpedia.openlinksw.com", m); } - public static SpecificSparqlEndpoint localJoseki() { + public static SparqlEndpoint localJoseki() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); // m.put("default-graph-uri", "http://dbpedia.org"); @@ -72,9 +72,9 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "localhost", m); + return new SparqlEndpoint(u, "localhost", m); } - public static SpecificSparqlEndpoint worldFactBook() { + public static SparqlEndpoint worldFactBook() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); // m.put("default-graph-uri", "http://dbpedia.org"); @@ -84,7 +84,7 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); + return new SparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); } /* @@ -102,7 +102,7 @@ return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); } */ - public static SpecificSparqlEndpoint govTrack() { + public static SparqlEndpoint govTrack() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); // m.put("default-graph-uri", "http://dbpedia.org"); @@ -112,9 +112,9 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "www.rdfabout.com", m); + return new SparqlEndpoint(u, "www.rdfabout.com", m); } - public static SpecificSparqlEndpoint revyu() { + public static SparqlEndpoint revyu() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); // m.put("default-graph-uri", "http://dbpedia.org"); @@ -125,7 +125,7 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "revyu.com", m); + return new SparqlEndpoint(u, "revyu.com", m); } // returns strange xml @@ -151,7 +151,7 @@ return new SpecificSparqlEndpoint(u, "dbtune.org", m); }*/ - public static SpecificSparqlEndpoint myopenlink() { + public static SparqlEndpoint myopenlink() { URL u = null; HashMap<String, String> m = new HashMap<String, String>(); m.put("default-graph-uri", "http://myopenlink.net/dataspace"); @@ -162,7 +162,7 @@ } catch (Exception e) { e.printStackTrace(); } - return new SpecificSparqlEndpoint(u, "myopenlink.net", m); + return new SparqlEndpoint(u, "myopenlink.net", m); } } Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java (from rev 391, trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlEndpoint.java 2008-01-18 13:10:58 UTC (rev 392) @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.sparql.configuration; + +import java.net.URL; +import java.util.HashMap; + +/** + * One sparql endpoint configuration. + * + * @author Sebastian Hellmann + * + */ +public class SparqlEndpoint { + + String host; + String hasQueryParameter; + URL url; + public HashMap<String, String> parameters = new HashMap<String, String>(); + + public SparqlEndpoint(URL url, String host, HashMap<String, String> parameters) { + super(); + this.host = host; + this.url = url; + this.hasQueryParameter = "query"; + this.parameters = parameters; + } + + public String getHasQueryParameter() { + return hasQueryParameter; + } + + public void setHasQueryParameter(String hasQueryParameter) { + this.hasQueryParameter = hasQueryParameter; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public HashMap<String, String> getParameters() { + return parameters; + } + + public void setParameters(HashMap<String, String> parameters) { + this.parameters = parameters; + } + + public URL getURL() { + return this.url; + } + +} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java 2008-01-18 13:10:58 UTC (rev 392) @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql.configuration; - -import java.net.URL; -import java.util.HashMap; - -/** - * One sparql endpoint configuration. - * - * @author Sebastian Hellmann - * - */ -public class SpecificSparqlEndpoint { - - String host; - String hasQueryParameter; - URL url; - public HashMap<String, String> parameters = new HashMap<String, String>(); - - public SpecificSparqlEndpoint(URL url, String host, HashMap<String, String> parameters) { - super(); - this.host = host; - this.url = url; - this.hasQueryParameter = "query"; - this.parameters = parameters; - } - - public String getHasQueryParameter() { - return hasQueryParameter; - } - - public void setHasQueryParameter(String hasQueryParameter) { - this.hasQueryParameter = hasQueryParameter; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public HashMap<String, String> getParameters() { - return parameters; - } - - public void setParameters(HashMap<String, String> parameters) { - this.parameters = parameters; - } - - public URL getURL() { - return this.url; - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java 2008-01-18 13:10:58 UTC (rev 392) @@ -2,7 +2,7 @@ import java.net.URI; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFormatter; @@ -14,7 +14,7 @@ SparqlQuery sparqlQuery; boolean debug_no_cache=false; - public CachedSparqlQuery(SpecificSparqlEndpoint endpoint,Cache c) { + public CachedSparqlQuery(SparqlEndpoint endpoint,Cache c) { //this.specificSparqlEndpoint=endpoint; this.sparqlQuery=new SparqlQuery(endpoint); this.cache=c; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java 2008-01-18 13:10:58 UTC (rev 392) @@ -20,7 +20,7 @@ package org.dllearner.kb.sparql.query; import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 13:10:58 UTC (rev 392) @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -35,21 +35,58 @@ * Represents a SPARQL query. It includes support for stopping the SPARQL * query (which may be necessary if a timeout is reached). * - * TODO: It is probably good to change all SPARQL query calls to use only - * this class. - * - * TODO: Could we use Jena as a solid foundation here? (com.hp.jena.query) - * * @author Jens Lehmann * */ public class SparqlQuery extends SparqlQueryAbstract{ - public SparqlQuery(SpecificSparqlEndpoint endpoint) { + private boolean isRunning = false; + private String queryString; + private QueryExecution queryExecution; + + public SparqlQuery(SparqlEndpoint endpoint, String queryString) { super(endpoint); - // TODO Auto-generated constructor stub + this.queryString = queryString; } + + public ResultSet send() { + isRunning = true; + + p(queryString); + // create a query and parse it into Jena + Query query = QueryFactory.create(queryString); + // query.validate(); + // Jena access to DBpedia SPARQL endpoint + String service=specificSparqlEndpoint.getURL().toString(); + + // TODO: the graph uri should be a parameter of SparqlQuery + ArrayList<String> al=new ArrayList<String>(); + al.add("http://dbpedia.org"); + QueryExecution queryExecution = + QueryExecutionFactory.sparqlService(service, query, al, new ArrayList<String>()); + p("query SPARQL server"); + ResultSet rs = queryExecution.execSelect(); + isRunning = false; + return rs; + } + + public void stop() { + queryExecution.abort(); + isRunning = false; + } + public boolean isRunning() { + return isRunning; + } + + + + // CODE BY SEBASTIAN H. BELOW // + + public SparqlQuery(SparqlEndpoint endpoint) { + super(endpoint); + } + private ResultSet sendAndReceive(String queryString){ p(queryString); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java 2008-01-18 13:10:58 UTC (rev 392) @@ -1,33 +1,15 @@ package org.dllearner.kb.sparql.query; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; public abstract class SparqlQueryAbstract { - private boolean isRunning = false; boolean print_flag=false; - SpecificSparqlEndpoint specificSparqlEndpoint; + SparqlEndpoint specificSparqlEndpoint; - public SparqlQueryAbstract(SpecificSparqlEndpoint endpoint) { + public SparqlQueryAbstract(SparqlEndpoint endpoint) { this.specificSparqlEndpoint=endpoint; } - public void send() { - isRunning = true; - - // ... send query - // ... check periodically whether isRunning is still true, if not - // abort the query - } - - public void stop() { - isRunning = false; - } - - public boolean isRunning() { - return isRunning; - } - - public abstract String getAsXMLString(String queryString); //public abstract String getAsXMLString(String queryString); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java 2008-01-18 13:10:58 UTC (rev 392) @@ -11,7 +11,7 @@ import java.util.Iterator; import java.util.Set; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFormatter; @@ -22,7 +22,7 @@ - public SparqlQueryConventional(SpecificSparqlEndpoint specificSparqlEndpoint) { + public SparqlQueryConventional(SparqlEndpoint specificSparqlEndpoint) { super(specificSparqlEndpoint); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 13:10:58 UTC (rev 392) @@ -20,7 +20,7 @@ package org.dllearner.kb.sparql.query; import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.configuration.SparqlEndpoint; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -65,7 +65,7 @@ } public static void testTime(int howOften, String queryString){ - SpecificSparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); + SparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); SparqlQuery sqJena=new SparqlQuery(sse); SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); @@ -97,7 +97,7 @@ } public static void compareResults( String queryString){ - SpecificSparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); + SparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); SparqlQuery sqJena=new SparqlQuery(sse); SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-01-18 13:10:58 UTC (rev 392) @@ -33,7 +33,7 @@ import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; /** * Stores the state of a DL-Learner client session. Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-18 11:59:56 UTC (rev 391) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-18 13:10:58 UTC (rev 392) @@ -46,7 +46,7 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefin... [truncated message content] |
From: <ku...@us...> - 2008-01-18 12:00:02
|
Revision: 391 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=391&view=rev Author: kurzum Date: 2008-01-18 03:59:56 -0800 (Fri, 18 Jan 2008) Log Message: ----------- sparql query mit default graph uri Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 10:52:00 UTC (rev 390) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) @@ -19,6 +19,9 @@ */ package org.dllearner.kb.sparql.query; +import java.util.ArrayList; +import java.util.List; + import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; import com.hp.hpl.jena.query.Query; @@ -54,9 +57,13 @@ Query query = QueryFactory.create(queryString); query.validate(); // Jena access to DBpedia SPARQL endpoint + String service=specificSparqlEndpoint.getURL().toString(); + ArrayList al=new ArrayList(); + al.add("http://dbpedia.org"); + //QueryExecution queryExecution = + //QueryExecutionFactory.sparqlService(specificSparqlEndpoint.getURL().toString(), query); QueryExecution queryExecution = - QueryExecutionFactory.sparqlService(specificSparqlEndpoint.getURL().toString(), query); - + QueryExecutionFactory.sparqlService(service, query, al, new ArrayList()); p("query SPARQL server"); ResultSet rs = queryExecution.execSelect(); @@ -70,4 +77,10 @@ return ResultSetFormatter.asXMLString(rs); } + public List asList(String queryString){ + ResultSet rs=sendAndReceive(queryString); + return ResultSetFormatter.toList(rs); + + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java 2008-01-18 10:52:00 UTC (rev 390) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java 2008-01-18 11:59:56 UTC (rev 391) @@ -29,6 +29,7 @@ public abstract String getAsXMLString(String queryString); + //public abstract String getAsXMLString(String queryString); public void p(String str){ if(print_flag){ Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 10:52:00 UTC (rev 390) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 11:59:56 UTC (rev 391) @@ -57,7 +57,7 @@ " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + " ?episode dbpedia2:blackboard ?chalkboard_gag }"; - testTime(5,queryString); + testTime(20,queryString); //compareResults( queryString); @@ -69,19 +69,31 @@ SparqlQuery sqJena=new SparqlQuery(sse); SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); - + // first query is not counted + sqJena.asList(queryString); long now=System.currentTimeMillis(); + long tmp=now; for (int i = 0; i < howOften; i++) { - sqJena.getAsXMLString(queryString); + //sqConv.getAsXMLString(queryString); + sqJena.asList(queryString); + System.out.println("Conv needed: "+(System.currentTimeMillis()-tmp)); + tmp=System.currentTimeMillis(); } - System.out.println("Jena needed: "+(System.currentTimeMillis()-now)); + System.out.println("Conv total: "+(System.currentTimeMillis()-now)); + // first query is not counted + sqJena.getAsXMLString(queryString); now=System.currentTimeMillis(); + tmp=now; for (int i = 0; i < howOften; i++) { - sqConv.getAsXMLString(queryString); + + sqJena.getAsXMLString(queryString); + System.out.println("Jena needed: "+(System.currentTimeMillis()-tmp)); + tmp=System.currentTimeMillis(); + } - System.out.println("Conv needed: "+(System.currentTimeMillis()-now)); + System.out.println("Jena total: "+(System.currentTimeMillis()-now)); } public static void compareResults( String queryString){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 10:52:02
|
Revision: 390 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=390&view=rev Author: kurzum Date: 2008-01-18 02:52:00 -0800 (Fri, 18 Jan 2008) Log Message: ----------- bugfix Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/ClientState.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/ClientState.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-01-18 10:48:33 UTC (rev 389) +++ trunk/src/dl-learner/org/dllearner/server/ClientState.java 2008-01-18 10:52:00 UTC (rev 390) @@ -33,7 +33,7 @@ import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningService; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.SparqlKnowledgeSource; /** * Stores the state of a DL-Learner client session. @@ -113,7 +113,7 @@ while(it.hasNext()) { KnowledgeSource source = it.next(); if((source instanceof OWLFile && ((OWLFile)source).getURL().toString().equals(url)) - || (source instanceof SparqlEndpoint && ((SparqlEndpoint)source).getURL().toString().equals(url)) ) { + || (source instanceof SparqlKnowledgeSource && ((SparqlKnowledgeSource)source).getURL().toString().equals(url)) ) { it.remove(); return true; } Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-18 10:48:33 UTC (rev 389) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-01-18 10:52:00 UTC (rev 390) @@ -46,7 +46,7 @@ import org.dllearner.core.dl.Concept; import org.dllearner.core.dl.Individual; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -79,7 +79,7 @@ public DLLearnerWS() { knowledgeSourceMapping.put("owlfile", OWLFile.class); - knowledgeSourceMapping.put("sparql", SparqlEndpoint.class); + knowledgeSourceMapping.put("sparql", SparqlKnowledgeSource.class); reasonerMapping.put("dig", DIGReasoner.class); learningProblemMapping.put("posNegDefinition", PosNegDefinitionLP.class); learningProblemMapping.put("posNegInclusion", PosNegInclusionLP.class); @@ -500,10 +500,10 @@ thread = new Thread() { @Override public void run() { - ((SparqlEndpoint)component).setSubjectThread(this); - ((SparqlEndpoint)component).setSubjectThreadRunning(true); - ((SparqlEndpoint)component).calculateSubjects(label,limit); - ((SparqlEndpoint)component).setSubjectThreadRunning(false); + ((SparqlKnowledgeSource)component).setSubjectThread(this); + ((SparqlKnowledgeSource)component).setSubjectThreadRunning(true); + ((SparqlKnowledgeSource)component).calculateSubjects(label,limit); + ((SparqlKnowledgeSource)component).setSubjectThreadRunning(false); } }; } else if (method.equals("triples")){ @@ -511,10 +511,10 @@ thread = new Thread() { @Override public void run() { - ((SparqlEndpoint)component).setTriplesThread(this); - ((SparqlEndpoint)component).setTriplesThreadRunning(true); - ((SparqlEndpoint)component).calculateTriples(subject); - ((SparqlEndpoint)component).setTriplesThreadRunning(false); + ((SparqlKnowledgeSource)component).setTriplesThread(this); + ((SparqlKnowledgeSource)component).setTriplesThreadRunning(true); + ((SparqlKnowledgeSource)component).calculateTriples(subject); + ((SparqlKnowledgeSource)component).setTriplesThreadRunning(false); } }; } else if (method.equals("conceptSubjects")){ @@ -522,10 +522,10 @@ thread = new Thread() { @Override public void run() { - ((SparqlEndpoint)component).setConceptThread(this); - ((SparqlEndpoint)component).setConceptThreadRunning(true); - ((SparqlEndpoint)component).calculateConceptSubjects(concept); - ((SparqlEndpoint)component).setConceptThreadRunning(false); + ((SparqlKnowledgeSource)component).setConceptThread(this); + ((SparqlKnowledgeSource)component).setConceptThreadRunning(true); + ((SparqlKnowledgeSource)component).calculateConceptSubjects(concept); + ((SparqlKnowledgeSource)component).setConceptThreadRunning(false); } }; } @@ -538,11 +538,11 @@ ClientState state = getState(id); Component component = state.getComponent(componentID); if (option.equals("subjects")) - return ((SparqlEndpoint)component).subjectThreadIsRunning(); + return ((SparqlKnowledgeSource)component).subjectThreadIsRunning(); else if (option.equals("triples")) - return ((SparqlEndpoint)component).triplesThreadIsRunning(); + return ((SparqlKnowledgeSource)component).triplesThreadIsRunning(); else if (option.equals("conceptSubjects")) - return ((SparqlEndpoint)component).conceptThreadIsRunning(); + return ((SparqlKnowledgeSource)component).conceptThreadIsRunning(); return true; } @@ -552,11 +552,11 @@ ClientState state = getState(id); Component component = state.getComponent(componentID); if (option.equals("subjects")) - ((SparqlEndpoint)component).getSubjectThread().stop(); + ((SparqlKnowledgeSource)component).getSubjectThread().stop(); else if (option.equals("triples")) - ((SparqlEndpoint)component).getTriplesThread().stop(); + ((SparqlKnowledgeSource)component).getTriplesThread().stop(); else if (option.equals("conceptSubjects")) - ((SparqlEndpoint)component).getConceptThread().stop(); + ((SparqlKnowledgeSource)component).getConceptThread().stop(); } @WebMethod @@ -565,11 +565,11 @@ ClientState state = getState(id); Component component = state.getComponent(componentID); if (option.equals("subjects")) - return ((SparqlEndpoint)component).getSubjects(); + return ((SparqlKnowledgeSource)component).getSubjects(); else if (option.equals("triples")) - return ((SparqlEndpoint)component).getTriples(); + return ((SparqlKnowledgeSource)component).getTriples(); else if (option.equals("conceptSubjects")) - return ((SparqlEndpoint)component).getConceptSubjects(); + return ((SparqlKnowledgeSource)component).getConceptSubjects(); return new String[0]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 10:48:35
|
Revision: 389 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=389&view=rev Author: kurzum Date: 2008-01-18 02:48:33 -0800 (Fri, 18 Jan 2008) Log Message: ----------- Bugfix Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-18 10:47:32 UTC (rev 388) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-18 10:48:33 UTC (rev 389) @@ -60,7 +60,7 @@ import org.dllearner.core.dl.Individual; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; -import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.SparqlKnowledgeSource; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -229,7 +229,7 @@ private static Map<Class<? extends Component>, String> createComponentPrefixMapping() { Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); // knowledge sources - componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); + componentPrefixMapping.put(SparqlKnowledgeSource.class, "sparql"); // reasoners componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); @@ -383,7 +383,7 @@ else if (formatString.equals("KB")) ksClass = KBFile.class; else if (formatString.equals("SPARQL")) - ksClass = SparqlEndpoint.class; + ksClass = SparqlKnowledgeSource.class; else if (formatString.equals("NT")) ksClass = OWLFile.class; else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 10:47:36
|
Revision: 388 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=388&view=rev Author: kurzum Date: 2008-01-18 02:47:32 -0800 (Fri, 18 Jan 2008) Log Message: ----------- renamed knowledgeSource Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Copied: trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java (from rev 386, trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlKnowledgeSource.java 2008-01-18 10:47:32 UTC (rev 388) @@ -0,0 +1,524 @@ +/** + * Copyright (C) 2007, 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.kb; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.OntologyFormat; +import org.dllearner.core.OntologyFormatUnsupportedException; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +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.dl.KB; +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.Manipulator; +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.PredefinedFilter; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.old.*; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.DIGConverter; +import org.dllearner.reasoning.JenaOWLDIGConverter; +import org.dllearner.utilities.StringTuple; + +/** + * Represents a SPARQL Endpoint. + * + * @author Jens Lehmann + * @author Sebastian Knappe + * @author Sebastian Hellmann + */ +public class SparqlKnowledgeSource extends KnowledgeSource { + + // ConfigOptions + private URL url; + String host; + private Set<String> instances=new HashSet<String>();; + private URL dumpFile; + private int recursionDepth = 1; + private int predefinedFilter = 0; + private int predefinedEndpoint = 0; + private Set<String> predList=new HashSet<String>(); + private Set<String> objList=new HashSet<String>(); + // private Set<String> classList; + private String format = "N-TRIPLES"; + private boolean dumpToFile = true; + private boolean useLits = false; + private boolean getAllSuperClasses = true; + private boolean closeAfterRecursion = true; + private int breakSuperClassRetrievalAfter = 200; + + private boolean learnDomain = false; + private boolean learnRange = false; + private int numberOfInstancesUsedForRoleLearning=40; + private String role=""; + private String blankNodeIdentifier = "bnode"; + + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); + + /** + * Holds the results of the calculateSubjects method + */ + private String[] subjects; + + /** + * Holds the results of the calculateTriples method + */ + private String[] triples; + + /** + * Holds the results of the calculateConceptSubjects method + */ + private String[] conceptSubjects; + + /** + * if a method is running this becomes true + */ + private boolean subjectThreadRunning = false; + + private boolean triplesThreadRunning = false; + + private boolean conceptThreadRunning = false; + + /** + * the Thread that is running a method + */ + private Thread subjectThread; + + private Thread triplesThread; + + private Thread conceptThread; + + // received ontology as array, used if format=Array(an element of the + // array consists of the subject, predicate and object separated by '<' + private String[] ontArray; + + // received ontology as KB, the internal format + private KB kb; + + public static String getName() { + return "SPARQL Endpoint Restructured"; + } + + /** + * sets the ConfigOptions for this KnowledgeSource + * + * @return + */ + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances", + "relevant instances e.g. positive and negative examples in a learning problem")); + options.add(new IntegerConfigOption("recursionDepth", + "recursion depth of KB fragment selection", 2)); + options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); + + options.add(new StringSetConfigOption("predList", "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); + options.add(new BooleanConfigOption("dumpToFile", + "Specifies whether the extracted ontology is written to a file or not.", true)); + options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); + options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); + + options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); + options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); + options.add(new StringConfigOption("role", "role to learn Domain/Range from")); + options.add(new StringConfigOption("blankNodeIdentifier", + "used to identify blanknodes in Tripels")); + + options.add(new StringTupleListConfigOption("example", "example")); + options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); + options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); + options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); + options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + + + + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), + "malformed URL " + s); + } + } else if (option.equals("host")) { + host = (String) entry.getValue(); + } else if (option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } else if (option.equals("recursionDepth")) { + recursionDepth = (Integer) entry.getValue(); + } else if (option.equals("predList")) { + predList = (Set<String>) entry.getValue(); + } else if (option.equals("objList")) { + objList = (Set<String>) entry.getValue(); + //} else if (option.equals("classList")) { + // classList = (Set<String>) entry.getValue(); + } else if (option.equals("predefinedEndpoint")) { + predefinedEndpoint = (Integer) entry.getValue(); + } else if (option.equals("predefinedFilter")) { + predefinedFilter = (Integer) entry.getValue(); + } else if (option.equals("format")) { + format = (String) entry.getValue(); + } else if (option.equals("dumpToFile")) { + dumpToFile = (Boolean) entry.getValue(); + } else if (option.equals("useLits")) { + useLits = (Boolean) entry.getValue(); + } else if (option.equals("getAllSuperClasses")) { + getAllSuperClasses = (Boolean) entry.getValue(); + } else if (option.equals("learnDomain")) { + learnDomain = (Boolean) entry.getValue(); + }else if (option.equals("learnRange")) { + learnRange = (Boolean) entry.getValue(); + } else if (option.equals("role")) { + role = (String) entry.getValue(); + } else if (option.equals("blankNodeIdentifier")) { + blankNodeIdentifier = (String) entry.getValue(); + } else if (option.equals("example")) { + //System.out.println(entry.getValue()); + }else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList)entry.getValue(); + }else if (option.equals("replaceObject")) { + replaceObject = (LinkedList)entry.getValue(); + }else if (option.equals("breakSuperClassRetrievalAfter")) { + breakSuperClassRetrievalAfter = (Integer) entry.getValue(); + }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { + numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); + }else if (option.equals("closeAfterRecursion")) { + closeAfterRecursion = (Boolean) entry.getValue(); + } + + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + System.out.println("SparqlModul: Collecting Ontology"); + // SparqlOntologyCollector oc= + // new SparqlOntologyCollector(Datastructures.setToArray(instances), + // numberOfRecursions, filterMode, + // Datastructures.setToArray(predList),Datastructures.setToArray( + // objList),Datastructures.setToArray(classList),format,url,useLits); + Manager m = new Manager(); + SpecificSparqlEndpoint sse = null; + SparqlQueryType sqt = null; + // get Options for Manipulator + Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + + // get Options for endpoints + if (predefinedEndpoint >= 1) { + sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); + } else { + sse = new SpecificSparqlEndpoint(url, host, parameters); + } + + // get Options for Filters + + if (predefinedFilter >= 1) { + sqt = PredefinedFilter.getFilter(predefinedFilter); + + } else { + sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + + } + // give everything to the manager + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); + try { + String ont = ""; + //System.out.println(learnDomain); + // used to learn a domain of a role + if (learnDomain || learnRange) { + Set<String> pos=new HashSet<String>(); + Set<String> neg=new HashSet<String>(); + if(learnDomain){ + pos = m.getDomainInstancesForRole(role); + neg = m.getRangeInstancesForRole(role); + }else if(learnRange){ + neg = m.getDomainInstancesForRole(role); + pos = m.getRangeInstancesForRole(role); + } + //choose 30 + + + Set<String> tmp=new HashSet<String>(); + for(String one:pos){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + pos=tmp; + System.out.println("Instances used: "+pos.size()); + + tmp=new HashSet<String>(); + for(String one:neg){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + neg=tmp; + + instances=new HashSet<String>(); + instances.addAll(pos); + + instances.addAll(neg); + + for(String one:pos){ + System.out.println("+\""+one+"\""); + } + for(String one:neg){ + System.out.println("-\""+one+"\""); + } + + /*Random r= new Random(); + + + Object[] arr=instances.toArray(); + while(instances.size()>=30){ + + }*/ + // add the role to the filter(a solution is always EXISTS + // role.TOP) + m.addPredicateFilter(role); + //System.out.println(instances); + // THIS is a workaround + + } + // the actual extraction is started here + ont = m.extract(instances); + System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); + System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); + + System.out.println("Finished collecting Fragment"); + + if (dumpToFile) { + String filename = System.currentTimeMillis() + ".nt"; + String basedir = "cache" + File.separator; + try { + if (!new File(basedir).exists()) + new File(basedir).mkdir(); + + FileWriter fw = new FileWriter(new File(basedir + filename), true); + fw.write(ont); + fw.flush(); + fw.close(); + + dumpFile = (new File(basedir + filename)).toURI().toURL(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (format.equals("KB")) { + try { + //kb = KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("SparqlModul: ****Finished"); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + if (format.equals("N-TRIPLES")) + return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); + else + return DIGConverter.getDIGString(kb, kbURI).toString(); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#export(java.io.File, + * org.dllearner.core.OntologyFormat) + */ + @Override + public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { + // currently no export functions implemented, so we just throw an + // exception + throw new OntologyFormatUnsupportedException("export", format); + } + + public URL getURL() { + return url; + } + + public String[] getOntArray() { + return ontArray; + } + + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param label + * @param limit + */ + public void calculateSubjects(String label, int limit) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + subjects = oc.getSubjectsFromLabel(label, limit); + } catch (IOException e) { + subjects = new String[1]; + subjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param subject + */ + public void calculateTriples(String subject) { + System.out.println("SparqlModul: Collecting Triples"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + triples = oc.collectTriples(subject); + } catch (IOException e) { + triples = new String[1]; + triples[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param concept + */ + public void calculateConceptSubjects(String concept) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + conceptSubjects = oc.getSubjectsFromConcept(concept); + } catch (IOException e) { + conceptSubjects = new String[1]; + conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public boolean subjectThreadIsRunning() { + return subjectThreadRunning; + } + + public void setSubjectThreadRunning(boolean bool) { + subjectThreadRunning = bool; + } + + public boolean triplesThreadIsRunning() { + return triplesThreadRunning; + } + + public void setTriplesThreadRunning(boolean bool) { + triplesThreadRunning = bool; + } + + public boolean conceptThreadIsRunning() { + return conceptThreadRunning; + } + + public void setConceptThreadRunning(boolean bool) { + conceptThreadRunning = bool; + } + + public String[] getSubjects() { + return subjects; + } + + public Thread getSubjectThread() { + return subjectThread; + } + + public void setSubjectThread(Thread subjectThread) { + this.subjectThread = subjectThread; + } + + public Thread getTriplesThread() { + return triplesThread; + } + + public void setTriplesThread(Thread triplesThread) { + this.triplesThread = triplesThread; + } + + public Thread getConceptThread() { + return conceptThread; + } + + public void setConceptThread(Thread conceptThread) { + this.conceptThread = conceptThread; + } + + public String[] getTriples() { + return triples; + } + + public String[] getConceptSubjects() { + return conceptSubjects; + } +} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 10:29:26 UTC (rev 387) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 10:47:32 UTC (rev 388) @@ -1,522 +0,0 @@ -/** - * Copyright (C) 2007, 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.kb.sparql; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.OntologyFormat; -import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -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.dl.KB; -import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; -import org.dllearner.kb.sparql.configuration.PredefinedFilter; -import org.dllearner.kb.sparql.configuration.SparqlQueryType; -import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; -import org.dllearner.kb.sparql.old.*; -import org.dllearner.parser.KBParser; -import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.utilities.StringTuple; - -/** - * Represents a SPARQL Endpoint. - * - * @author Jens Lehmann - * @author Sebastian Knappe - * @author Sebastian Hellmann - */ -public class SparqlKnowledgeSource extends KnowledgeSource { - - // ConfigOptions - private URL url; - String host; - private Set<String> instances=new HashSet<String>();; - private URL dumpFile; - private int recursionDepth = 1; - private int predefinedFilter = 0; - private int predefinedEndpoint = 0; - private Set<String> predList=new HashSet<String>(); - private Set<String> objList=new HashSet<String>(); - // private Set<String> classList; - private String format = "N-TRIPLES"; - private boolean dumpToFile = true; - private boolean useLits = false; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - private int breakSuperClassRetrievalAfter = 200; - - private boolean learnDomain = false; - private boolean learnRange = false; - private int numberOfInstancesUsedForRoleLearning=40; - private String role=""; - private String blankNodeIdentifier = "bnode"; - - LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); - - /** - * Holds the results of the calculateSubjects method - */ - private String[] subjects; - - /** - * Holds the results of the calculateTriples method - */ - private String[] triples; - - /** - * Holds the results of the calculateConceptSubjects method - */ - private String[] conceptSubjects; - - /** - * if a method is running this becomes true - */ - private boolean subjectThreadRunning = false; - - private boolean triplesThreadRunning = false; - - private boolean conceptThreadRunning = false; - - /** - * the Thread that is running a method - */ - private Thread subjectThread; - - private Thread triplesThread; - - private Thread conceptThread; - - // received ontology as array, used if format=Array(an element of the - // array consists of the subject, predicate and object separated by '<' - private String[] ontArray; - - // received ontology as KB, the internal format - private KB kb; - - public static String getName() { - return "SPARQL Endpoint Restructured"; - } - - /** - * sets the ConfigOptions for this KnowledgeSource - * - * @return - */ - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances", - "relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("recursionDepth", - "recursion depth of KB fragment selection", 2)); - options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); - options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); - - options.add(new StringSetConfigOption("predList", "list of all ignored roles")); - options.add(new StringSetConfigOption("objList", "list of all ignored objects")); - options.add(new StringSetConfigOption("classList", "list of all ignored classes")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); - options.add(new BooleanConfigOption("dumpToFile", - "Specifies whether the extracted ontology is written to a file or not.", true)); - options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); - - options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain/Range from")); - options.add(new StringConfigOption("blankNodeIdentifier", - "used to identify blanknodes in Tripels")); - - options.add(new StringTupleListConfigOption("example", "example")); - options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); - options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); - options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); - options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); - options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); - - - - return options; - } - - /* - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String option = entry.getOptionName(); - if (option.equals("url")) { - String s = (String) entry.getValue(); - try { - url = new URL(s); - } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), - "malformed URL " + s); - } - } else if (option.equals("host")) { - host = (String) entry.getValue(); - } else if (option.equals("instances")) { - instances = (Set<String>) entry.getValue(); - } else if (option.equals("recursionDepth")) { - recursionDepth = (Integer) entry.getValue(); - } else if (option.equals("predList")) { - predList = (Set<String>) entry.getValue(); - } else if (option.equals("objList")) { - objList = (Set<String>) entry.getValue(); - //} else if (option.equals("classList")) { - // classList = (Set<String>) entry.getValue(); - } else if (option.equals("predefinedEndpoint")) { - predefinedEndpoint = (Integer) entry.getValue(); - } else if (option.equals("predefinedFilter")) { - predefinedFilter = (Integer) entry.getValue(); - } else if (option.equals("format")) { - format = (String) entry.getValue(); - } else if (option.equals("dumpToFile")) { - dumpToFile = (Boolean) entry.getValue(); - } else if (option.equals("useLits")) { - useLits = (Boolean) entry.getValue(); - } else if (option.equals("getAllSuperClasses")) { - getAllSuperClasses = (Boolean) entry.getValue(); - } else if (option.equals("learnDomain")) { - learnDomain = (Boolean) entry.getValue(); - }else if (option.equals("learnRange")) { - learnRange = (Boolean) entry.getValue(); - } else if (option.equals("role")) { - role = (String) entry.getValue(); - } else if (option.equals("blankNodeIdentifier")) { - blankNodeIdentifier = (String) entry.getValue(); - } else if (option.equals("example")) { - //System.out.println(entry.getValue()); - }else if (option.equals("replacePredicate")) { - replacePredicate = (LinkedList)entry.getValue(); - }else if (option.equals("replaceObject")) { - replaceObject = (LinkedList)entry.getValue(); - }else if (option.equals("breakSuperClassRetrievalAfter")) { - breakSuperClassRetrievalAfter = (Integer) entry.getValue(); - }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { - numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); - }else if (option.equals("closeAfterRecursion")) { - closeAfterRecursion = (Boolean) entry.getValue(); - } - - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - System.out.println("SparqlModul: Collecting Ontology"); - // SparqlOntologyCollector oc= - // new SparqlOntologyCollector(Datastructures.setToArray(instances), - // numberOfRecursions, filterMode, - // Datastructures.setToArray(predList),Datastructures.setToArray( - // objList),Datastructures.setToArray(classList),format,url,useLits); - Manager m = new Manager(); - SpecificSparqlEndpoint sse = null; - SparqlQueryType sqt = null; - // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); - - // get Options for endpoints - if (predefinedEndpoint >= 1) { - sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); - } else { - sse = new SpecificSparqlEndpoint(url, host, parameters); - } - - // get Options for Filters - - if (predefinedFilter >= 1) { - sqt = PredefinedFilter.getFilter(predefinedFilter); - - } else { - sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - - } - // give everything to the manager - m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); - try { - String ont = ""; - //System.out.println(learnDomain); - // used to learn a domain of a role - if (learnDomain || learnRange) { - Set<String> pos=new HashSet<String>(); - Set<String> neg=new HashSet<String>(); - if(learnDomain){ - pos = m.getDomainInstancesForRole(role); - neg = m.getRangeInstancesForRole(role); - }else if(learnRange){ - neg = m.getDomainInstancesForRole(role); - pos = m.getRangeInstancesForRole(role); - } - //choose 30 - - - Set<String> tmp=new HashSet<String>(); - for(String one:pos){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - pos=tmp; - System.out.println("Instances used: "+pos.size()); - - tmp=new HashSet<String>(); - for(String one:neg){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - neg=tmp; - - instances=new HashSet<String>(); - instances.addAll(pos); - - instances.addAll(neg); - - for(String one:pos){ - System.out.println("+\""+one+"\""); - } - for(String one:neg){ - System.out.println("-\""+one+"\""); - } - - /*Random r= new Random(); - - - Object[] arr=instances.toArray(); - while(instances.size()>=30){ - - }*/ - // add the role to the filter(a solution is always EXISTS - // role.TOP) - m.addPredicateFilter(role); - //System.out.println(instances); - // THIS is a workaround - - } - // the actual extraction is started here - ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); - - System.out.println("Finished collecting Fragment"); - - if (dumpToFile) { - String filename = System.currentTimeMillis() + ".nt"; - String basedir = "cache" + File.separator; - try { - if (!new File(basedir).exists()) - new File(basedir).mkdir(); - - FileWriter fw = new FileWriter(new File(basedir + filename), true); - fw.write(ont); - fw.flush(); - fw.close(); - - dumpFile = (new File(basedir + filename)).toURI().toURL(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (format.equals("KB")) { - try { - //kb = KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("SparqlModul: ****Finished"); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ - @Override - public String toDIG(URI kbURI) { - if (format.equals("N-TRIPLES")) - return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); - else - return DIGConverter.getDIGString(kb, kbURI).toString(); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#export(java.io.File, - * org.dllearner.core.OntologyFormat) - */ - @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { - // currently no export functions implemented, so we just throw an - // exception - throw new OntologyFormatUnsupportedException("export", format); - } - - public URL getURL() { - return url; - } - - public String[] getOntArray() { - return ontArray; - } - - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param label - * @param limit - */ - public void calculateSubjects(String label, int limit) { - System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - subjects = oc.getSubjectsFromLabel(label, limit); - } catch (IOException e) { - subjects = new String[1]; - subjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param subject - */ - public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - triples = oc.collectTriples(subject); - } catch (IOException e) { - triples = new String[1]; - triples[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - /** - * TODO SparqlOntologyCollector needs to be removed - * @param concept - */ - public void calculateConceptSubjects(String concept) { - System.out.println("SparqlModul: Collecting Subjects"); - oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); - try { - conceptSubjects = oc.getSubjectsFromConcept(concept); - } catch (IOException e) { - conceptSubjects = new String[1]; - conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public boolean subjectThreadIsRunning() { - return subjectThreadRunning; - } - - public void setSubjectThreadRunning(boolean bool) { - subjectThreadRunning = bool; - } - - public boolean triplesThreadIsRunning() { - return triplesThreadRunning; - } - - public void setTriplesThreadRunning(boolean bool) { - triplesThreadRunning = bool; - } - - public boolean conceptThreadIsRunning() { - return conceptThreadRunning; - } - - public void setConceptThreadRunning(boolean bool) { - conceptThreadRunning = bool; - } - - public String[] getSubjects() { - return subjects; - } - - public Thread getSubjectThread() { - return subjectThread; - } - - public void setSubjectThread(Thread subjectThread) { - this.subjectThread = subjectThread; - } - - public Thread getTriplesThread() { - return triplesThread; - } - - public void setTriplesThread(Thread triplesThread) { - this.triplesThread = triplesThread; - } - - public Thread getConceptThread() { - return conceptThread; - } - - public void setConceptThread(Thread conceptThread) { - this.conceptThread = conceptThread; - } - - public String[] getTriples() { - return triples; - } - - public String[] getConceptSubjects() { - return conceptSubjects; - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 10:29:29
|
Revision: 387 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=387&view=rev Author: kurzum Date: 2008-01-18 02:29:26 -0800 (Fri, 18 Jan 2008) Log Message: ----------- sparql queries are now made by Jena. Jena is 6 times slower, see TestSparqlQuery XML processing is still the old thing Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 08:57:51 UTC (rev 386) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 10:29:26 UTC (rev 387) @@ -19,6 +19,7 @@ */ package org.dllearner.kb.sparql; +import java.io.IOException; import java.net.URI; import java.util.HashSet; import java.util.Set; @@ -29,6 +30,7 @@ import org.dllearner.kb.sparql.configuration.SparqlQueryType; import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; import org.dllearner.kb.sparql.datastructure.Node; +import org.dllearner.kb.sparql.old.oldSparqlOntologyCollector; import org.dllearner.utilities.StringTuple; /** @@ -145,5 +147,53 @@ public Configuration getConfiguration(){ return configuration; } + + /*public void calculateSubjects(String label, int limit) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + subjects = oc.getSubjectsFromLabel(label, limit); + } catch (IOException e) { + subjects = new String[1]; + subjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + /** + * TODO SparqlOntologyCollector needs to be removed + * @param subject + */ + /* + public void calculateTriples(String subject) { + System.out.println("SparqlModul: Collecting Triples"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + triples = oc.collectTriples(subject); + } catch (IOException e) { + triples = new String[1]; + triples[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } +*/ + /** + * TODO SparqlOntologyCollector needs to be removed + * @param concept + */ + + /*public void calculateConceptSubjects(String concept) { + System.out.println("SparqlModul: Collecting Subjects"); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); + try { + conceptSubjects = oc.getSubjectsFromConcept(concept); + } catch (IOException e) { + conceptSubjects = new String[1]; + conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + */ + + } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 08:57:51 UTC (rev 386) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 10:29:26 UTC (rev 387) @@ -35,6 +35,8 @@ import org.dllearner.kb.sparql.configuration.Configuration; import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; import org.dllearner.kb.sparql.query.Cache; +import org.dllearner.kb.sparql.query.CachedSparqlQuery; +import org.dllearner.kb.sparql.query.SparqlQuery; import org.dllearner.utilities.StringTuple; /** @@ -49,6 +51,8 @@ private Configuration configuration; // private SparqlHTTPRequest SparqlHTTPRequest; private SparqlQueryMaker sparqlQueryMaker; + private SparqlQuery sparqlQuery; + private CachedSparqlQuery cachedSparqlQuery; Cache cache; public TypedSparqlQuery(Configuration Configuration) { @@ -56,7 +60,9 @@ // this.SparqlHTTPRequest = new // SparqlHTTPRequest(Configuration.getSparqlEndpoint()); this.sparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); + this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); this.cache = new Cache("cache"); + this.cachedSparqlQuery=new CachedSparqlQuery(this.sparqlQuery,this.cache); } // standard query get a tupels (p,o) for subject s public Set<StringTuple> query(URI u) { @@ -93,31 +99,7 @@ // uses a cache private Set<StringTuple> cachedSparql(URI u, String sparql, String a, String b) { // check cache - String FromCache = cache.get(u.toString(), sparql); - if(debug_no_cache) { - FromCache=null; - } - String xml = null; - // if not in cache get it from EndPoint - if (FromCache == null) { - configuration.increaseNumberOfuncachedSparqlQueries(); - try { - xml = sendAndReceiveSPARQL(sparql); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - p(sparql); - // System.out.println(xml); - if(!debug_no_cache) { - cache.put(u.toString(), sparql, xml); - } - //System.out.print("\n"); - } else { - configuration.increaseNumberOfCachedSparqlQueries(); - xml = FromCache; - //System.out.println("FROM CACHE"); - } + String xml=this.cachedSparqlQuery.getAsXMLString(u, sparql); // System.out.println(sparql); // System.out.println(xml); @@ -202,66 +184,11 @@ return xml; } - private String sendAndReceiveSPARQL(String sparql) throws IOException { - p("sendAndReceiveSPARQL"); - StringBuilder answer = new StringBuilder(); - //sparql="SELECT * WHERE {?a ?b ?c}LIMIT 10"; - - // String an Sparql-Endpoint schicken - HttpURLConnection connection; - SpecificSparqlEndpoint se = configuration.getSparqlEndpoint(); - p("URL: "+se.getURL()); - p("Host: "+se.getHost()); - - connection = (HttpURLConnection) se.getURL().openConnection(); - connection.setDoOutput(true); - - //connection.addRequestProperty("Host", se.getHost()); - connection.addRequestProperty("Connection", "close"); - connection - .addRequestProperty( - "Accept", - "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); - connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); - connection - .addRequestProperty( - "User-Agent", - "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); - - OutputStream os = connection.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - - Set<String> s = se.getParameters().keySet(); - Iterator<String> it = s.iterator(); - String FullURI = ""; - while (it.hasNext()) { - String element = it.next(); - FullURI += "" + URLEncoder.encode(element, "UTF-8") + "=" - + URLEncoder.encode(se.getParameters().get(element), "UTF-8") + "&"; - } - - FullURI += "" + se.getHasQueryParameter() + "=" + URLEncoder.encode(sparql, "UTF-8"); - p(FullURI); - osw.write(FullURI); - osw.close(); - - // receive answer - InputStream is = connection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - BufferedReader br = new BufferedReader(isr); - - String line; - do { - line = br.readLine(); - if (line != null) - answer.append(line); - } while (line != null); - - br.close(); - p(answer.toString()); - return answer.toString(); + public String sendAndReceiveSPARQL(String queryString){ + //SparqlQuery sq=new SparqlQuery(configuration.getSparqlEndpoint()); + return sparqlQuery.getAsXMLString(queryString); } + public void p(String str){ if(print_flag){ System.out.println(str); Added: trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/CachedSparqlQuery.java 2008-01-18 10:29:26 UTC (rev 387) @@ -0,0 +1,57 @@ +package org.dllearner.kb.sparql.query; + +import java.net.URI; + +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; + +public class CachedSparqlQuery { + +//SpecificSparqlEndpoint specificSparqlEndpoint; +Cache cache; +SparqlQuery sparqlQuery; +boolean debug_no_cache=false; + + public CachedSparqlQuery(SpecificSparqlEndpoint endpoint,Cache c) { + //this.specificSparqlEndpoint=endpoint; + this.sparqlQuery=new SparqlQuery(endpoint); + this.cache=c; + + } + public CachedSparqlQuery(SparqlQuery sparqlQuery,Cache c) { + + this.sparqlQuery=sparqlQuery; + this.cache=c; + + } + + public String getAsXMLString(URI u, String sparql){ + String FromCache = cache.get(u.toString(), sparql); + if(debug_no_cache) { + FromCache=null; + } + String xml = null; + // if not in cache get it from EndPoint + if (FromCache == null) { + //configuration.increaseNumberOfuncachedSparqlQueries(); + + xml = this.sparqlQuery.getAsXMLString(sparql); + //sendAndReceiveSPARQL(sparql); + + //p(sparql); + // System.out.println(xml); + if(!debug_no_cache) { + cache.put(u.toString(), sparql, xml); + } + //System.out.print("\n"); + } else { + //configuration.increaseNumberOfCachedSparqlQueries(); + xml = FromCache; + //System.out.println("FROM CACHE"); + } + + return xml; + } +} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/JenaTestScript.java 2008-01-18 10:29:26 UTC (rev 387) @@ -0,0 +1,70 @@ +/** + * 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.kb.sparql.query; + +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; + +/** + * Represents a SPARQL query. It includes support for stopping the SPARQL + * query (which may be necessary if a timeout is reached). + * + * TODO: It is probably good to change all SPARQL query calls to use only + * this class. + * + * TODO: Could we use Jena as a solid foundation here? (com.hp.jena.query) + * + * @author Jens Lehmann + * + */ +public class JenaTestScript { + // this is a working Jena script + // TODO: query runtime seems to be much too high (compared to running it in http://dbpedia.org/sparql) + // verify whether our SPARQL query implementation is faster and why; + // TODO: check whether Jena works with the other endpoints in PredefinedEndpoint; if not + // check whether it can be configured to run with these + public static void main(String[] args) { + + + String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " + + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" + + "SELECT ?episode ?chalkboard_gag WHERE { ?episode skos:subject" + + " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + + " ?episode dbpedia2:blackboard ?chalkboard_gag }"; + + //System.out.println(queryString); + // create a query and parse it into Jena + Query query = QueryFactory.create(queryString); + query.validate(); + // Jena access to DBpedia SPARQL endpoint + QueryExecution queryExecution = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); + System.out.println("query SPARQL server"); + ResultSet rs = queryExecution.execSelect(); + ResultSetFormatter.out(System.out, rs, query) ; + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 08:57:51 UTC (rev 386) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java 2008-01-18 10:29:26 UTC (rev 387) @@ -40,52 +40,34 @@ * @author Jens Lehmann * */ -public class SparqlQuery { - - private boolean isRunning = false; - - public SparqlQuery(SpecificSparqlEndpoint endpoint, String query) { +public class SparqlQuery extends SparqlQueryAbstract{ + public SparqlQuery(SpecificSparqlEndpoint endpoint) { + super(endpoint); + // TODO Auto-generated constructor stub } - - public void send() { - isRunning = true; - - // ... send query - // ... check periodically whether isRunning is still true, if not - // abort the query - } - - public void stop() { - isRunning = false; - } - public boolean isRunning() { - return isRunning; - } - - // this is a working Jena script - // TODO: query runtime seems to be much too high (compared to running it in http://dbpedia.org/sparql) - // verify whether our SPARQL query implementation is faster and why; - // TODO: check whether Jena works with the other endpoints in PredefinedEndpoint; if not - // check whether it can be configured to run with these - public static void main(String[] args) { + private ResultSet sendAndReceive(String queryString){ - String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " + - "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" + - "SELECT ?episode ?chalkboard_gag WHERE { ?episode skos:subject" + - " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + - " ?episode dbpedia2:blackboard ?chalkboard_gag }"; - - System.out.println(queryString); + p(queryString); // create a query and parse it into Jena Query query = QueryFactory.create(queryString); query.validate(); // Jena access to DBpedia SPARQL endpoint - QueryExecution queryExecution = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); - System.out.println("query SPARQL server"); + QueryExecution queryExecution = + QueryExecutionFactory.sparqlService(specificSparqlEndpoint.getURL().toString(), query); + + p("query SPARQL server"); ResultSet rs = queryExecution.execSelect(); - ResultSetFormatter.out(System.out, rs, query) ; + + //ResultSetFormatter.out(System.out, rs, query) ; + + return rs; } + public String getAsXMLString(String queryString){ + ResultSet rs=sendAndReceive(queryString); + return ResultSetFormatter.asXMLString(rs); + } + } Added: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryAbstract.java 2008-01-18 10:29:26 UTC (rev 387) @@ -0,0 +1,39 @@ +package org.dllearner.kb.sparql.query; + +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; + + public abstract class SparqlQueryAbstract { + private boolean isRunning = false; + boolean print_flag=false; + SpecificSparqlEndpoint specificSparqlEndpoint; + + public SparqlQueryAbstract(SpecificSparqlEndpoint endpoint) { + this.specificSparqlEndpoint=endpoint; + } + + public void send() { + isRunning = true; + + // ... send query + // ... check periodically whether isRunning is still true, if not + // abort the query + } + + public void stop() { + isRunning = false; + } + + public boolean isRunning() { + return isRunning; + } + + + public abstract String getAsXMLString(String queryString); + + public void p(String str){ + if(print_flag){ + System.out.println(str); + } + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQueryConventional.java 2008-01-18 10:29:26 UTC (rev 387) @@ -0,0 +1,100 @@ +package org.dllearner.kb.sparql.query; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Set; + +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; + +public class SparqlQueryConventional extends SparqlQueryAbstract{ + + + + + + public SparqlQueryConventional(SpecificSparqlEndpoint specificSparqlEndpoint) { + super(specificSparqlEndpoint); + } + + private String sendAndReceiveSPARQL(String sparql) throws IOException { + p("sendAndReceiveSPARQL"); + StringBuilder answer = new StringBuilder(); + //sparql="SELECT * WHERE {?a ?b ?c}LIMIT 10"; + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + + //SpecificSparqlEndpoint specificSparqlEndpoint = configuration.getSparqlEndpoint(); + p("URL: "+specificSparqlEndpoint.getURL()); + p("Host: "+specificSparqlEndpoint.getHost()); + + connection = (HttpURLConnection) specificSparqlEndpoint.getURL().openConnection(); + connection.setDoOutput(true); + + //connection.addRequestProperty("Host", specificSparqlEndpoint.getHost()); + connection.addRequestProperty("Connection", "close"); + connection + .addRequestProperty( + "Accept", + "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); + connection + .addRequestProperty( + "User-Agent", + "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + + Set<String> s = specificSparqlEndpoint.getParameters().keySet(); + Iterator<String> it = s.iterator(); + String FullURI = ""; + while (it.hasNext()) { + String element = it.next(); + FullURI += "" + URLEncoder.encode(element, "UTF-8") + "=" + + URLEncoder.encode(specificSparqlEndpoint.getParameters().get(element), "UTF-8") + "&"; + } + + FullURI += "" + specificSparqlEndpoint.getHasQueryParameter() + "=" + URLEncoder.encode(sparql, "UTF-8"); + p(FullURI); + osw.write(FullURI); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if (line != null) + answer.append(line); + } while (line != null); + + br.close(); + p(answer.toString()); + return answer.toString(); + } + + public String getAsXMLString(String queryString){ + try{ + return sendAndReceiveSPARQL(queryString); + }catch (IOException e) {e.printStackTrace();} + return null; + } + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 10:29:26 UTC (rev 387) @@ -0,0 +1,96 @@ +/** + * 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.kb.sparql.query; + +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.reasoner.rulesys.impl.oldCode.TestTrail; + +/** + * Represents a SPARQL query. It includes support for stopping the SPARQL + * query (which may be necessary if a timeout is reached). + * + * TODO: It is probably good to change all SPARQL query calls to use only + * this class. + * + * TODO: Could we use Jena as a solid foundation here? (com.hp.jena.query) + * + * @author Jens Lehmann + * + */ +public class TestSparqlQuery { + + // this is a working Jena script + // TODO: query runtime seems to be much too high (compared to running it in http://dbpedia.org/sparql) + // verify whether our SPARQL query implementation is faster and why; + // TODO: check whether Jena works with the other endpoints in PredefinedEndpoint; if not + // check whether it can be configured to run with these + public static void main(String[] args) { + + String queryString = "PREFIX dbpedia2: <http://dbpedia.org/property/> " + + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" + + "SELECT ?episode ?chalkboard_gag WHERE { ?episode skos:subject" + + " <http://dbpedia.org/resource/Category:The_Simpsons_episodes%2C_season_12>." + + " ?episode dbpedia2:blackboard ?chalkboard_gag }"; + + testTime(5,queryString); + + //compareResults( queryString); + + + } + + public static void testTime(int howOften, String queryString){ + SpecificSparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena=new SparqlQuery(sse); + SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); + + + long now=System.currentTimeMillis(); + for (int i = 0; i < howOften; i++) { + sqJena.getAsXMLString(queryString); + + + } + System.out.println("Jena needed: "+(System.currentTimeMillis()-now)); + now=System.currentTimeMillis(); + for (int i = 0; i < howOften; i++) { + sqConv.getAsXMLString(queryString); + } + System.out.println("Conv needed: "+(System.currentTimeMillis()-now)); + } + + public static void compareResults( String queryString){ + SpecificSparqlEndpoint sse= PredefinedEndpoint.dbpediaEndpoint(); + SparqlQuery sqJena=new SparqlQuery(sse); + SparqlQueryConventional sqConv=new SparqlQueryConventional(sse); + + System.out.println(sqJena.getAsXMLString(queryString)); + System.out.println(sqConv.getAsXMLString(queryString)); + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 08:57:54
|
Revision: 386 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=386&view=rev Author: kurzum Date: 2008-01-18 00:57:51 -0800 (Fri, 18 Jan 2008) Log Message: ----------- package old can be removed after three functions in Sparqlknowledgesource are improved, see todo Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:57:51 UTC (rev 386) @@ -47,7 +47,7 @@ import org.dllearner.kb.sparql.configuration.PredefinedFilter; import org.dllearner.kb.sparql.configuration.SparqlQueryType; import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; -import org.dllearner.kb.sparql.old.SparqlOntologyCollector; +import org.dllearner.kb.sparql.old.*; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; @@ -410,9 +410,15 @@ return ontArray; } + + /** + * TODO SparqlOntologyCollector needs to be removed + * @param label + * @param limit + */ public void calculateSubjects(String label, int limit) { System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); try { subjects = oc.getSubjectsFromLabel(label, limit); } catch (IOException e) { @@ -422,9 +428,13 @@ System.out.println("SparqlModul: ****Finished"); } + /** + * TODO SparqlOntologyCollector needs to be removed + * @param subject + */ public void calculateTriples(String subject) { System.out.println("SparqlModul: Collecting Triples"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); try { triples = oc.collectTriples(subject); } catch (IOException e) { @@ -434,9 +444,13 @@ System.out.println("SparqlModul: ****Finished"); } + /** + * TODO SparqlOntologyCollector needs to be removed + * @param concept + */ public void calculateConceptSubjects(String concept) { System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + oldSparqlOntologyCollector oc = new oldSparqlOntologyCollector(url); try { conceptSubjects = oc.getSubjectsFromConcept(concept); } catch (IOException e) { Added: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-01-18 08:57:51 UTC (rev 386) @@ -0,0 +1,193 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.sparql; + +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.old.oldSparqlFilter; + + +/** + * Can assemble sparql queries. + * + * @author Sebastian Hellmann + * + */ +public class SparqlQueryMaker { + String lineend="\n"; + boolean print_flag=false; + /* can make queries for subject, predicate, object + * according to the filter settings + * object not yet implemented + * + * */ + + private SparqlQueryType sparqlQueryType; + + public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { + this.sparqlQueryType = SparqlQueryType; + } + + public String makeSubjectQueryUsingFilters(String subject) { + + String Filter = internalFilterAssemblySubject(); + String ret = "SELECT * WHERE { " + lineend + "<" + subject + "> ?predicate ?object. " + + lineend + "FILTER( " + lineend + "(" + Filter + ").}"; + // System.out.println(ret); + //System.out.println(sparqlQueryType.getPredicatefilterlist().length); + return ret; + } + + public String makeRoleQueryUsingFilters(String role) { + + String Filter = internalFilterAssemblyRole(); + String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role + "> ?object. " + lineend + + "FILTER( " + lineend + "(" + Filter + ").}"; + // System.out.println(ret); + + return ret; + } + public String makeRoleQueryUsingFilters(String role,boolean domain) { + + String Filter = internalFilterAssemblyRole(); + String ret=""; + if(domain){ + ret = "SELECT * WHERE { " + lineend + + "?subject <" + role + "> ?object; a []. " + lineend + + "FILTER( " + lineend + "(" + Filter + ").}" ; + //"ORDER BY ?subject"; + // System.out.println(ret); + }else{ + ret = "SELECT * WHERE { " + lineend + + "?object a [] . " + + "?subject <" + role + "> ?object . " + lineend + + "FILTER( " + lineend + "(" + Filter + ").}"; + //"ORDER BY ?object"; + + } + //System.out.println(ret); + + return ret; + } + + private String internalFilterAssemblySubject() { + + String Filter = ""; + if (!this.sparqlQueryType.isLiterals()) + Filter += "!isLiteral(?object))"; + for (String p : sparqlQueryType.getPredicatefilterlist()) { + Filter += lineend + filterPredicate(p); + } + for (String o : sparqlQueryType.getObjectfilterlist()) { + Filter += lineend + filterObject(o); + } + return Filter; + } + + private String internalFilterAssemblyRole() { + + String Filter = ""; + if (!this.sparqlQueryType.isLiterals()) + Filter += "!isLiteral(?object))"; + for (String s : sparqlQueryType.getObjectfilterlist()) { + Filter += lineend + filterSubject(s); + } + for (String o : sparqlQueryType.getObjectfilterlist()) { + Filter += lineend + filterObject(o); + } + return Filter; + } + + public String filterSubject(String ns) { + return "&&( !regex(str(?subject), '" + ns + "') )"; + } + + public static String filterPredicate(String ns) { + return "&&( !regex(str(?predicate), '" + ns + "') )"; + } + + public static String filterObject(String ns) { + return "&&( !regex(str(?object), '" + ns + "') )"; + } + + public void p(String str){ + if(print_flag){ + System.out.println(str); + } + } + + /** + * creates a query with the specified filters for alls triples with subject + * @param subject the searched subject + * @param sf special object encapsulating all options + * @return sparql query + */ + public static String makeQueryFilter(String subject, oldSparqlFilter sf){ + + + String Filter=""; + if(!sf.useLiterals)Filter+="!isLiteral(?object)"; + for (String p : sf.getPredFilter()) { + Filter+="\n" + filterPredicate(p); + } + for (String o : sf.getObjFilter()) { + Filter+="\n" + filterObject(o); + } + + String ret= + "SELECT * WHERE { \n" + + "<"+ + subject+ + "> ?predicate ?object.\n"; + if (!(Filter.length()==0)) + ret+="FILTER( \n" + + "(" +Filter+"))."; + ret+="}"; + //System.out.println(ret); + return ret; + } + + /** + * creates a query for subjects with the specified label + * @param label a phrase that is part of the label of a subject + * @param limit this limits the amount of results + * @return + */ + public static String makeLabelQuery(String label,int limit){ + //TODO maybe use http://xmlns:com/foaf/0.1/page + return "SELECT DISTINCT ?subject\n"+ + "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object bif:contains '\""+label+"\"'@en}\n"+ + "LIMIT "+limit; + } + + /** + * creates a query for all subjects that are of the type concept + * @param concept the type that subjects are searched for + * @return + */ + public static String makeConceptQuery(String concept){ + return "SELECT DISTINCT ?subject\n"+ + "WHERE { ?subject a <"+concept+">}\n"; + } + + public static String makeArticleQuery(String subject){ + return "SELECT ?predicate,?object\n"+ + "WHERE { <"+subject+"> ?predicate ?object}\n"; + } +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2008-01-18 08:57:51 UTC (rev 386) @@ -34,7 +34,6 @@ import org.dllearner.kb.sparql.configuration.Configuration; import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; -import org.dllearner.kb.sparql.old.SparqlQueryMaker; import org.dllearner.kb.sparql.query.Cache; import org.dllearner.utilities.StringTuple; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java 2008-01-18 08:57:51 UTC (rev 386) @@ -90,7 +90,7 @@ public String get(String key, String sparql){ String ret=null; try{ - SparqlCache c =readFromFile(makeFilename(key)); + oldSparqlCache c =readFromFile(makeFilename(key)); if(c==null)return null; if(!c.checkFreshness())return null; if(!c.validate(sparql))return null; @@ -109,7 +109,7 @@ * @param sparql the sparql query */ public void put(String key, String content, String sparql){ - SparqlCache c=new SparqlCache(content,sparql); + oldSparqlCache c=new oldSparqlCache(content,sparql); putIntoFile(makeFilename(key), c); } @@ -173,7 +173,7 @@ * @param Filename * @param content */ - public void putIntoFile(String Filename,SparqlCache content){ + public void putIntoFile(String Filename,oldSparqlCache content){ try{ FileOutputStream fos = new FileOutputStream( Filename , false ); ObjectOutputStream o = new ObjectOutputStream( fos ); @@ -189,12 +189,12 @@ * @param Filename * @return one entry object */ - public SparqlCache readFromFile(String Filename){ - SparqlCache content=null; + public oldSparqlCache readFromFile(String Filename){ + oldSparqlCache content=null; try{ FileInputStream fos = new FileInputStream( Filename ); ObjectInputStream o = new ObjectInputStream( fos ); - content=(SparqlCache)o.readObject(); + content=(oldSparqlCache)o.readObject(); }catch (Exception e) {} return content; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java 2008-01-18 08:57:51 UTC (rev 386) @@ -29,7 +29,7 @@ * @author Sebastian Knappe * */ -public class SparqlFilter { +public class oldSparqlFilter { public int mode=0; // 0 yago, 1 only cat, 2 skos+cat String[] PredFilter=null; @@ -79,7 +79,7 @@ "http://dbpedia.org/resource/Template", "http://upload.wikimedia.org/wikipedia/commons"}; - public SparqlFilter(int mode, String[] pred, String[] obj) { + public oldSparqlFilter(int mode, String[] pred, String[] obj) { if (mode==-1 && (pred==null || obj==null)) {mode=0;} this.mode=mode; @@ -104,7 +104,7 @@ } } - public SparqlFilter(int mode, String[] pred, String[] obj,boolean uselits) throws Exception{ + public oldSparqlFilter(int mode, String[] pred, String[] obj,boolean uselits) throws Exception{ this(mode,pred,obj); this.useLiterals=uselits; } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java 2008-01-18 08:57:51 UTC (rev 386) @@ -33,7 +33,7 @@ import java.util.Iterator; import java.util.Vector; -import org.dllearner.kb.sparql.old.SparqlQueryMaker; +import org.dllearner.kb.sparql.SparqlQueryMaker; /** @@ -45,13 +45,13 @@ * @author Sebastian Knappe * */ -public class SparqlOntologyCollector { +public class oldSparqlOntologyCollector { boolean print_flag=false; SparqlQueryMaker queryMaker; - SparqlCache cache; + oldSparqlCache cache; URL url; - SparqlFilter sf; + oldSparqlFilter sf; String[] subjectList; int numberOfRecursions; HashSet<String> properties; @@ -86,18 +86,18 @@ * @param FilterObjList * @param defClasses */ - public SparqlOntologyCollector(String[] subjectList,int numberOfRecursions, + public oldSparqlOntologyCollector(String[] subjectList,int numberOfRecursions, int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses, String format, URL url, boolean useLits){ this.subjectList=subjectList; this.numberOfRecursions=numberOfRecursions; this.format=format; //this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); + this.cache=new oldSparqlCache("cache"); if(defClasses!=null && defClasses.length>0 ){ this.defaultClasses=defClasses; } try{ - this.sf=new SparqlFilter(filterMode,FilterPredList,FilterObjList,useLits); + this.sf=new oldSparqlFilter(filterMode,FilterPredList,FilterObjList,useLits); this.url=url; this.properties=new HashSet<String>(); this.classes=new HashSet<String>(); @@ -107,10 +107,10 @@ } - public SparqlOntologyCollector(URL url) + public oldSparqlOntologyCollector(URL url) { // this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); + this.cache=new oldSparqlCache("cache"); this.url=url; } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java 2008-01-18 08:57:51 UTC (rev 386) @@ -1,192 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql.old; - -import org.dllearner.kb.sparql.configuration.SparqlQueryType; - - -/** - * Can assemble sparql queries. - * - * @author Sebastian Hellmann - * - */ -public class SparqlQueryMaker { - String lineend="\n"; - boolean print_flag=false; - /* can make queries for subject, predicate, object - * according to the filter settings - * object not yet implemented - * - * */ - - private SparqlQueryType sparqlQueryType; - - public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { - this.sparqlQueryType = SparqlQueryType; - } - - public String makeSubjectQueryUsingFilters(String subject) { - - String Filter = internalFilterAssemblySubject(); - String ret = "SELECT * WHERE { " + lineend + "<" + subject + "> ?predicate ?object. " - + lineend + "FILTER( " + lineend + "(" + Filter + ").}"; - // System.out.println(ret); - //System.out.println(sparqlQueryType.getPredicatefilterlist().length); - return ret; - } - - public String makeRoleQueryUsingFilters(String role) { - - String Filter = internalFilterAssemblyRole(); - String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role + "> ?object. " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; - // System.out.println(ret); - - return ret; - } - public String makeRoleQueryUsingFilters(String role,boolean domain) { - - String Filter = internalFilterAssemblyRole(); - String ret=""; - if(domain){ - ret = "SELECT * WHERE { " + lineend + - "?subject <" + role + "> ?object; a []. " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}" ; - //"ORDER BY ?subject"; - // System.out.println(ret); - }else{ - ret = "SELECT * WHERE { " + lineend + - "?object a [] . " + - "?subject <" + role + "> ?object . " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; - //"ORDER BY ?object"; - - } - //System.out.println(ret); - - return ret; - } - - private String internalFilterAssemblySubject() { - - String Filter = ""; - if (!this.sparqlQueryType.isLiterals()) - Filter += "!isLiteral(?object))"; - for (String p : sparqlQueryType.getPredicatefilterlist()) { - Filter += lineend + filterPredicate(p); - } - for (String o : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterObject(o); - } - return Filter; - } - - private String internalFilterAssemblyRole() { - - String Filter = ""; - if (!this.sparqlQueryType.isLiterals()) - Filter += "!isLiteral(?object))"; - for (String s : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterSubject(s); - } - for (String o : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterObject(o); - } - return Filter; - } - - public String filterSubject(String ns) { - return "&&( !regex(str(?subject), '" + ns + "') )"; - } - - public static String filterPredicate(String ns) { - return "&&( !regex(str(?predicate), '" + ns + "') )"; - } - - public static String filterObject(String ns) { - return "&&( !regex(str(?object), '" + ns + "') )"; - } - - public void p(String str){ - if(print_flag){ - System.out.println(str); - } - } - - /** - * creates a query with the specified filters for alls triples with subject - * @param subject the searched subject - * @param sf special object encapsulating all options - * @return sparql query - */ - public static String makeQueryFilter(String subject, SparqlFilter sf){ - - - String Filter=""; - if(!sf.useLiterals)Filter+="!isLiteral(?object)"; - for (String p : sf.getPredFilter()) { - Filter+="\n" + filterPredicate(p); - } - for (String o : sf.getObjFilter()) { - Filter+="\n" + filterObject(o); - } - - String ret= - "SELECT * WHERE { \n" + - "<"+ - subject+ - "> ?predicate ?object.\n"; - if (!(Filter.length()==0)) - ret+="FILTER( \n" + - "(" +Filter+"))."; - ret+="}"; - //System.out.println(ret); - return ret; - } - - /** - * creates a query for subjects with the specified label - * @param label a phrase that is part of the label of a subject - * @param limit this limits the amount of results - * @return - */ - public static String makeLabelQuery(String label,int limit){ - //TODO maybe use http://xmlns:com/foaf/0.1/page - return "SELECT DISTINCT ?subject\n"+ - "WHERE { ?subject <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object bif:contains '\""+label+"\"'@en}\n"+ - "LIMIT "+limit; - } - - /** - * creates a query for all subjects that are of the type concept - * @param concept the type that subjects are searched for - * @return - */ - public static String makeConceptQuery(String concept){ - return "SELECT DISTINCT ?subject\n"+ - "WHERE { ?subject a <"+concept+">}\n"; - } - - public static String makeArticleQuery(String subject){ - return "SELECT ?predicate,?object\n"+ - "WHERE { <"+subject+"> ?predicate ?object}\n"; - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 08:43:11 UTC (rev 385) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java 2008-01-18 08:57:51 UTC (rev 386) @@ -1,13 +0,0 @@ -package org.dllearner.kb.sparql.query; - -public class TestSparqlQuery { - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 08:43:29
|
Revision: 385 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=385&view=rev Author: kurzum Date: 2008-01-18 00:43:11 -0800 (Fri, 18 Jan 2008) Log Message: ----------- changed package structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/ trunk/src/dl-learner/org/dllearner/kb/sparql/query/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,235 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.URLEncoder; -import java.util.HashMap; - -/** - * SPARQL query cache to avoid possibly expensive multiple queries. An object of - * this class can be the cache itself or a cache object(one entry), We could - * split that in two classes, but one entry o object only has contains data and - * one additional function and would just be a data class - * - * it writes the files according to one resource in the basedir and saves the - * cache object in it. Filename is the subject, a resource - * e.g. http://dbpedia.org/resource/Angela_Merkel which is first urlencoded - * and so serves as the hash for the filename. - * - * the cache object in the file remembers: a timestamp, - * a hashmap SparqlQuery -> SparqlXMLResult - * Cache validates if timestamp too old and Sparql-Query the same - * before returning the SPARQL xml-result - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - */ -public class Cache implements Serializable { - - /** - * This maps sparql query to sparql result - */ - protected HashMap<String, String> hm; - - final static long serialVersionUID = 104; - transient String basedir = ""; - transient String fileending = ".cache"; - transient boolean debug_print_flag = false; - long timestamp; - /** - * After how many days cache entries get invalid - */ - protected long daysoffreshness = 15; - protected long multiplier = 24 * 60 * 60 * 1000;// h m s ms - - // private HashMap<String, String> inmem_cache; - - // - /** - * constructor for the cache itself - * Called once at the startup - * @param path - * Where the base path to the cache is - */ - public Cache(String path) { - this.basedir = path + File.separator; - if (!new File(path).exists()) { - System.out.println("created directory: " + path + " : " - + new File(path).mkdir()); - - } - } - - - /** - * constructor for single cache object(one entry) - * @param sparqlQuery - * query - * @param content - * that is the sparql query result as xml - */ - protected Cache(String sparqlQuery, String content) { - // this.content = c; - // this.sparqlquery = sparql; - this.timestamp = System.currentTimeMillis(); - this.hm = new HashMap<String, String>(); - hm.put(sparqlQuery, content); - } - - /** - * gets a chached sparqlQuery for a resource(key) and returns the - * sparqlXMLResult or null, if none is found. - * - * @param key - * is the resource, the identifier - * @param sparqlQuery - * is a special sparql query about that resource - * @return sparqlXMLResult - */ - public String get(String key, String sparqlQuery) { - // System.out.println("get From "+key); - String ret = null; - try { - Cache c = readFromFile(makeFilename(key)); - if (c == null) - return null; - // System.out.println(" file found"); - if (!c.checkFreshness()) - return null; - // System.out.println("fresh"); - String xml = ""; - try { - xml = c.hm.get(sparqlQuery); - } catch (Exception e) { - return null; - } - return xml; - // System.out.println("valid"); - // ret = c.content; - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - /** - * @param key - * is the resource, the identifier - * @param sparqlquery - * is the query used as another identifier - * @param content - * is the result of the query - */ - public void put(String key, String sparqlquery, String content) { - // System.out.println("put into "+key); - Cache c = readFromFile(makeFilename(key)); - if (c == null) { - c = new Cache(sparqlquery, content); - putIntoFile(makeFilename(key), c); - } else { - c.hm.put(sparqlquery, content); - putIntoFile(makeFilename(key), c); - } - - } - - /** - * this function takes a resource string and then URIencodes it and makes a - * filename out of it for the use in the hashmap - * - * @param key - * @return the complete key for filename in the hashmap - */ - protected String makeFilename(String key) { - String ret = ""; - try { - ret = basedir + URLEncoder.encode(key, "UTF-8") + fileending; - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - public void checkFile(String Filename) { - if (!new File(Filename).exists()) { - try { - new File(Filename).createNewFile(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - } - - /** - * puts a cache entry in a file - * - * @param Filename - * @param c - */ - protected void putIntoFile(String Filename, Cache c) { - try { - // FileWriter fw=new FileWriter(new File(Filename),true); - FileOutputStream fos = new FileOutputStream(Filename, false); - ObjectOutputStream o = new ObjectOutputStream(fos); - o.writeObject(c); - fos.flush(); - fos.close(); - } catch (Exception e) { - System.out.println("Not in cache creating: " + Filename); - } - } - - /** - * reads a cache entry from a file - * - * @param Filename - * @return cache entry - */ - protected Cache readFromFile(String Filename) { - Cache content = null; - try { - FileInputStream fos = new FileInputStream(Filename); - ObjectInputStream o = new ObjectInputStream(fos); - content = (Cache) o.readObject(); - // FileReader fr=new FileReader(new File(Filename,"r")); - // BufferedReader br=new BufferedReader(fr); - } catch (Exception e) { - } - return content; - - } - - protected boolean checkFreshness() { - if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) - // fresh - return true; - else - return false; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,113 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * Is a node in the graph that is a class. - * - * @author Sebastian Hellmann - */ -public class ClassNode extends Node { - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public ClassNode(URI u) { - super(u); - this.type = "class"; - } - - //expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - Set<StringTuple> s = tsq.query(this.uri); - // see manipulator - s = m.check(s, this); - Vector<Node> Nodes = new Vector<Node>(); - - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - // substitute rdf:type with owl:subclassof - if (t.a.equals(m.type) || t.a.equals(m.subclass)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(m.subclass), this, tmp)); - Nodes.add(tmp); - } else { - // further expansion stops here - // Nodes.add(tmp); is missing on purpose - ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(t.a), this, tmp)); - // System.out.println(m.blankNodeIdentifier); - // System.out.println("XXXXX"+t.b); - - // if o is a blank node expand further - if (t.b.startsWith(m.blankNodeIdentifier)) { - tmp.expand(tsq, m); - System.out.println(m.blankNodeIdentifier); - System.out.println("XXXXX" + t.b); - } - // Nodes.add(tmp); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - // TODO return type doesn't make sense - return new Vector<Node>(); - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + this.uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Class" + ">."); - - for (PropertyNode one : properties) { - s.add("<" + this.uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - // - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,94 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -/** - * Stores all configuration settings. - * - * @author Sebastian Hellmann - */ -public class Configuration { - - /* - * this class colects all configuration information - * see the other classes, which are used as attributes here - * */ - - private SpecificSparqlEndpoint specificSparqlEndpoint; - private SparqlQueryType sparqlQueryType; - private Manipulator manipulator; - // the following needs to be moved to - // class extraction algorithm or manipulator - private int recursiondepth = 2; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - public int numberOfUncachedSparqlQueries=0; - public int numberOfCachedSparqlQueries=0; - - public Configuration(SpecificSparqlEndpoint specificSparqlEndpoint, - SparqlQueryType sparqlQueryType, Manipulator manipulator, int recursiondepth, - boolean getAllSuperClasses, boolean closeAfterRecursion) { - this.specificSparqlEndpoint = specificSparqlEndpoint; - this.sparqlQueryType = sparqlQueryType; - this.manipulator = manipulator; - this.recursiondepth = recursiondepth; - this.getAllSuperClasses = getAllSuperClasses; - this.closeAfterRecursion=closeAfterRecursion; - - } - - public Configuration changeQueryType(SparqlQueryType sqt) { - // TODO must clone here - return new Configuration(this.specificSparqlEndpoint, sqt, this.manipulator, - this.recursiondepth, this.getAllSuperClasses,this.closeAfterRecursion); - - } - - public Manipulator getManipulator() { - return this.manipulator; - } - - public SpecificSparqlEndpoint getSparqlEndpoint() { - return specificSparqlEndpoint; - } - - public SparqlQueryType getSparqlQueryType() { - return sparqlQueryType; - } - - public boolean isGetAllSuperClasses() { - return getAllSuperClasses; - } - public boolean isCloseAfterRecursion() { - return closeAfterRecursion; - } - - public int getRecursiondepth() { - return recursiondepth; - } - - public void increaseNumberOfuncachedSparqlQueries(){ - numberOfUncachedSparqlQueries++; - } - public void increaseNumberOfCachedSparqlQueries(){ - numberOfCachedSparqlQueries++; - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-01-18 08:43:11 UTC (rev 385) @@ -23,6 +23,11 @@ import java.util.HashSet; import java.util.Vector; +import org.dllearner.kb.sparql.configuration.Configuration; +import org.dllearner.kb.sparql.datastructure.ClassNode; +import org.dllearner.kb.sparql.datastructure.InstanceNode; +import org.dllearner.kb.sparql.datastructure.Node; + /** * This class is used to extract the information recursively. * @@ -127,10 +132,10 @@ //classes.remove(next); Node next = classes.remove(0); - if(!hadAlready.contains(next.uri.toString())){ + if(!hadAlready.contains(next.getURI().toString())){ p("Expanding: " + next); //System.out.println(hadAlready.size()); - hadAlready.add(next.uri.toString()); + hadAlready.add(next.getURI().toString()); tmp=next.expand(tsp, manipulator); classes.addAll(tmp); tmp=new Vector<Node>(); Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,118 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * A node in the graph that is an instance. - * - * @author Sebastian Hellmann - * - */ -public class InstanceNode extends Node { - - Set<ClassNode> classes = new HashSet<ClassNode>(); - Set<StringTuple> datatypes = new HashSet<StringTuple>(); - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public InstanceNode(URI u) { - super(u); - this.type = "instance"; - - } - - //expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - - Set<StringTuple> s = tsq.query(uri); - // see Manipulator - m.check(s, this); - // System.out.println("fffffff"+m); - Vector<Node> Nodes = new Vector<Node>(); - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - // basically : if p is rdf:type then o is a class - // else it is an instance - try { - if (t.a.equals(m.type)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - classes.add(tmp); - Nodes.add(tmp); - } else { - InstanceNode tmp = new InstanceNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(t.a), this, tmp)); - Nodes.add(tmp); - - } - } catch (Exception e) { - System.out.println("Problem with: " + t); - e.printStackTrace(); - } - - } - expanded = true; - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - for (PropertyNode one : properties) { - one.expandProperties(tsq, m); - } - return new Vector<Node>(); - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Thing" + ">."); - for (ClassNode one : classes) { - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one.getURI() + ">."); - s.addAll(one.toNTriple()); - } - for (PropertyNode one : properties) { - s.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); - s.addAll(one.toNTriple()); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - // - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 08:43:11 UTC (rev 385) @@ -25,6 +25,10 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.kb.sparql.configuration.Configuration; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.datastructure.Node; import org.dllearner.utilities.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-18 08:43:11 UTC (rev 385) @@ -24,6 +24,9 @@ import java.util.LinkedList; import java.util.Set; +import org.dllearner.kb.sparql.datastructure.ClassNode; +import org.dllearner.kb.sparql.datastructure.InstanceNode; +import org.dllearner.kb.sparql.datastructure.Node; import org.dllearner.utilities.StringTuple; /** Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,64 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.net.URI; -import java.util.Set; -import java.util.Vector; - -/** - * Abstract class. - * - * @author Sebastian Hellmann - * - */ -public abstract class Node implements Comparable<Node> { - URI uri; - protected String type; - protected boolean expanded = false; - - public Node(URI u) { - this.uri = u; - } - - public abstract Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m); - - public abstract Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m); - - public abstract Set<String> toNTriple(); - - @Override - public String toString() { - return "Node: " + uri + ":" + type; - - } - - public URI getURI() { - return uri; - } - public boolean equals(Node n){ - if(this.uri.equals(n.uri))return true; - else return false; - } - public int compareTo(Node n){ - return this.uri.toString().compareTo(n.uri.toString()); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,167 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.net.URL; -import java.util.HashMap; - -/** - * Holds some predefined endpoints. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedEndpoint { - public static SpecificSparqlEndpoint getEndpoint(int i) { - - switch (i) { - case 1: - return dbpediaEndpoint(); - case 2: - return localJoseki(); - case 3: - return govTrack(); - case 4: - return revyu(); - case 5: - return myopenlink(); - case 6: - return worldFactBook(); - } - return null; - } - - public static SpecificSparqlEndpoint dbpediaEndpoint() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://dbpedia.org"); - m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); - } - - public static SpecificSparqlEndpoint localJoseki() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://localhost:2020/books"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "localhost", m); - } - public static SpecificSparqlEndpoint worldFactBook() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - - /* - * it only has 4 classes - public static SpecificSparqlEndpoint dblp() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - */ - public static SpecificSparqlEndpoint govTrack() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www.rdfabout.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www.rdfabout.com", m); - } - public static SpecificSparqlEndpoint revyu() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://revyu.com/sparql?query=SELECT DISTINCT * WHERE {[] a ?c} - try { - u = new URL("http://revyu.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "revyu.com", m); - } - - // returns strange xml - /*public static SpecificSparqlEndpoint dbtune() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 - http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - http://dbtune.org:2020/evaluateQuery - ?repository=default&serialization=rdfxml&queryLanguage=SPARQL - &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - try { - u = new URL("http://dbtune.org:2020/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbtune.org", m); - }*/ - - public static SpecificSparqlEndpoint myopenlink() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://myopenlink.net/dataspace"); - m.put("format", "application/sparql-results.xml"); - //http://myopenlink.net:8890/sparql/?query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D - try { - u = new URL("http://myopenlink.net:8890/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "myopenlink.net", m); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,170 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.util.HashSet; -import java.util.Set; - -/** - * Predefined filters. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedFilter { - - - public static SparqlQueryType getFilter(int i) { - - switch (i) { - case 1: - return YagoFilter(); - case 2: - return SKOS(); - case 3: - return YAGOSKOS(); - case 4: - return YagoSpecialHierarchy(); - } - return null; - } - - - public static SparqlQueryType YagoFilter(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Category:"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - public static SparqlQueryType YagoSpecialHierarchy(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - pred.add("http://dbpedia.org/property/monarch"); - - - Set<String> obj = new HashSet<String>(); - obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - - - public static SparqlQueryType SKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - public static SparqlQueryType YAGOSKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - //obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, "false"); - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,120 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * Property node. - * - * @author Sebastian Hellmann - * - */ -public class PropertyNode extends Node { - - // the a and b part of a property - private Node a; - private Node b; - // specialtypes like owl:symmetricproperty - private Set<String> specialTypes; - - public PropertyNode(URI u) { - super(u); - this.type = "property"; - - } - - public PropertyNode(URI u, Node a, Node b) { - super(u); - this.type = "property"; - this.a = a; - this.b = b; - this.specialTypes = new HashSet<String>(); - } - - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - Set<StringTuple> s = tsq.query(uri); - Vector<Node> Nodes = new Vector<Node>(); - // Manipulation - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - if (t.a.equals(m.type)) { - specialTypes.add(t.b); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - b.expandProperties(tsq, m); - return this.expand(tsq, m); - } - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); - for (String one : specialTypes) { - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one + ">."); - - } - - return s; - } - - @Override - public boolean equals(Node n){ - if(this.uri.equals(n.uri))return true; - else return false; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,202 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.URLEncoder; -/** - * - * This is a primitive cache. - * The objects of this class can be either the cache itself or just on entry in the cache - * - * the cache remembers: a timestamp, the original sparql-query, the result - * key is the subject http://dbpedia.org/resource/Angela_Merkel which is first urlencoded - * and so serves as the hash for the filename. - * Cache validates if timestamp too old and Sparql-Query the same - * before returning the SPARQL xml-result - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - */ -public class SparqlCache implements Serializable{ - - final static long serialVersionUID=104; - transient String basedir=""; - transient String fileending=".cache"; - long timestamp; - String content=""; - long daysoffreshness=15; - long multiplier=24*60*60*1000;//h m s ms - String sparqlquery=""; - - - /** - * Constructor for the cache itself. - * Called once at the beginning - * - * @param path Where the base path to the cache is - */ - public SparqlCache(String path){ - this.basedir=path+File.separator; - if(!new File(path).exists()) - {System.out.println(new File(path).mkdir());;} - - } - -// - /** - * Constructor for single cache object(one entry) - * - * @param content the sparql xml result - * @param sparql the sparql query - */ - public SparqlCache(String content, String sparql){ - this.content=content; - this.sparqlquery=sparql; - this.timestamp=System.currentTimeMillis(); - } - - - - /** - * use only on the cache object describing the cache itself - * - * @param key the individual - * @param sparql the sparql query - * @return the cached sparql result or null - */ - public String get(String key, String sparql){ - String ret=null; - try{ - SparqlCache c =readFromFile(makeFilename(key)); - if(c==null)return null; - if(!c.checkFreshness())return null; - if(!c.validate(sparql))return null; - - ret=c.content; - }catch (Exception e) {e.printStackTrace();} - return ret; - } - - /** - * - * constructor for single cache object(one entry) - * - * @param key the individual - * @param content the sparql result - * @param sparql the sparql query - */ - public void put(String key, String content, String sparql){ - SparqlCache c=new SparqlCache(content,sparql); - putIntoFile(makeFilename(key), c); - } - - - /** - * to normalize the filenames - * - * @param key - * @return - */ - String makeFilename(String key){ - String ret=""; - try{ - ret=basedir+URLEncoder.encode(key, "UTF-8")+fileending; - }catch (Exception e) {e.printStackTrace();} - return ret; - } - - /** - * how old is the result - * @return - */ - boolean checkFreshness(){ - if((System.currentTimeMillis()-this.timestamp)<=(daysoffreshness*multiplier)) - //fresh - return true; - else return false; - } - - - /** - * some sparql query - * @param sparql - * @return - */ - boolean validate(String sparql){ - if(this.sparqlquery.equals(sparql)) - //valid - return true; - else return false; - } - - /** - * makes a new file if none exists - * @param Filename - */ - public void checkFile(String Filename){ - if(!new File(Filename).exists()){ - try{ - new File(Filename).createNewFile(); - }catch (Exception e) {e.printStackTrace();} - - } - - } - - /** - * internal saving function - * puts a cache object into a file - * - * @param Filename - * @param content - */ - public void putIntoFile(String Filename,SparqlCache content){ - try{ - FileOutputStream fos = new FileOutputStream( Filename , false ); - ObjectOutputStream o = new ObjectOutputStream( fos ); - o.writeObject( content ); - fos.flush(); - fos.close(); - }catch (Exception e) {System.out.println("Not in cache creating: "+Filename);} - } - - /** - * internal retrieval function - * - * @param Filename - * @return one entry object - */ - public SparqlCache readFromFile(String Filename){ - SparqlCache content=null; - try{ - FileInputStream fos = new FileInputStream( Filename ); - ObjectInputStream o = new ObjectInputStream( fos ); - content=(SparqlCache)o.readObject(); - }catch (Exception e) {} - return content; - - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,119 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -/** - * - * - * encapsulates all the options - * see the documentation for more help - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - * - */ -public class SparqlFilter { - public int mode=0; - // 0 yago, 1 only cat, 2 skos+cat - String[] PredFilter=null; - String[] ObjFilter=null; - public boolean useLiterals=false; - - - String[] yagoPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] yagoObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/resource/Category", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - String[] onlyCatPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] onlyCatObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - String[] skosPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core#narrower", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] skosObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - public SparqlFilter(int mode, String[] pred, String[] obj) { - if (mode==-1 && (pred==null || obj==null)) - {mode=0;} - this.mode=mode; - - switch (mode){ - case 0: //yago - ObjFilter=yagoObjFilterDefault; - PredFilter=yagoPredFilterDefault; - break; - case 1: // only Categories - ObjFilter=onlyCatObjFilterDefault; - PredFilter=onlyCatPredFilterDefault; - break; - case 2: // there are some other changes to, which are made directly in other functions - ObjFilter=skosObjFilterDefault; - PredFilter=skosPredFilterDefault; - break; - default: - ObjFilter=obj; - PredFilter=pred; - break; - } - } - - public SparqlFilter(int mode, String[] pred, String[] obj,boolean uselits) throws Exception{ - this(mode,pred,obj); - this.useLiterals=uselits; - } - - public String[] getObjFilter(){ - return this.ObjFilter; - } - - public String[] getPredFilter(){ - return this.PredFilter; - } -} \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:43:11 UTC (rev 385) @@ -43,6 +43,11 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.dl.KB; +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.PredefinedFilter; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.old.SparqlOntologyCollector; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,511 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Vector; - -import org.dllearner.kb.sparql.SparqlQueryMaker; - - -/** - * This class collects the ontology from dbpedia, - * everything is saved in hashsets, so the doublettes are taken care of - * - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - * - */ -public class SparqlOntologyCollector { - - boolean print_flag=false; - SparqlQueryMaker queryMaker; - SparqlCache cache; - URL url; - SparqlFilter sf; - String[] subjectList; - int numberOfRecursions; - HashSet<String> properties; - HashSet<String> classes; - HashSet<String> instances; - HashSet<String> triples; - String format; - - // some namespaces - String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - String type="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - String objectProperty="http://www.w3.org/2002/07/owl#ObjectProperty"; - String classns="http://www.w3.org/2002/07/owl#Class"; - String thing="http://www.w3.org/2002/07/owl#Thing"; - - - String[] defaultClasses={ - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Category:", - "http://dbpedia.org/resource/Template:", - "http://www.w3.org/2004/02/skos/core", - "http://dbpedia.org/class/"}; - - - /** - * - * - * @param subjectList - * @param numberOfRecursions - * @param filterMode - * @param FilterPredList - * @param FilterObjList - * @param defClasses - */ - public SparqlOntologyCollector(String[] subjectList,int numberOfRecursions, - int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses, String format, URL url, boolean useLits){ - this.subjectList=subjectList; - this.numberOfRecursions=numberOfRecursions; - this.format=format; - //this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); - if(defClasses!=null && defClasses.length>0 ){ - this.defaultClasses=defClasses; - } - try{ - this.sf=new SparqlFilter(filterMode,FilterPredList,FilterObjList,useLits); - this.url=url; - this.properties=new HashSet<String>(); - this.classes=new HashSet<String>(); - this.instances=new HashSet<String>(); - this.triples=new HashSet<String>(); - }catch (Exception e) {e.printStackTrace();} - - } - - public SparqlOntologyCollector(URL url) - { - // this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); - this.url=url; - } - - /** - * first collects the ontology - * then types everything so it becomes owl-dl - * - * @return all triples in n-triple format - */ - public String collectOntology() throws IOException{ - getRecursiveList(subjectList, numberOfRecursions); - finalize(); - String ret=""; - for (Iterator<String> iter = triples.iterator(); iter.hasNext();) { - ret += iter.next(); - } - return ret; - } - - public String[] collectTriples(String subject) throws IOException{ - System.out.println("Searching for Article: "+subject); - String sparql=SparqlQueryMaker.makeArticleQuery(subject); - String fromCache=cache.get(subject, sparql); - String xml; - // if not in cache get it from dbpedia - if(fromCache==null){ - xml=sendAndReceive(sparql); - cache.put(subject, xml, sparql); - System.out.print("\n"); - } - else{ - xml=fromCache; - System.out.println("FROM CACHE"); - } - - return processArticle(xml); - } - - public String[] processArticle(String xml) - { - Vector<String> vec=new Vector<String>(); - String one="<binding name=\"predicate\"><uri>"; - String two="<binding name=\"object\">"; - String end="</uri></binding>"; - String predtmp=""; - String objtmp=""; - // ArrayList<String> al=new ArrayList<String>(); - while(xml.indexOf(one)!=-1){ - //get pred - xml=xml.substring(xml.indexOf(one)+one.length()); - predtmp=xml.substring(0,xml.indexOf(end)); - //getobj - xml=xml.substring(xml.indexOf(two)+two.length()); - if (xml.startsWith("<literal xml:lang=\"en\">")){ - xml=xml.substring(xml.indexOf(">")+1); - objtmp=xml.substring(0,xml.indexOf("</literal>")); - } - else if (xml.startsWith("<uri>")) objtmp=xml.substring(5,xml.indexOf(end)); - else continue; - - System.out.println("Pred: "+predtmp+" Obj: "+objtmp); - - vec.add(predtmp+"<"+objtmp); - } - - String[] ret=new String[vec.size()]; - return vec.toArray(ret); - } - - public String[] getSubjectsFromLabel(String label, int limit) throws IOException{ - System.out.println("Searching for Label: "+label); - String sparql=SparqlQueryMaker.makeLabelQuery(label,limit); - String FromCache=cache.get(label, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(label, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - return processSubjects(xml); - } - - public String[] getSubjectsFromConcept(String concept) throws IOException - { - System.out.println("Searching for Subjects of type: "+concept); - String sparql=SparqlQueryMaker.makeConceptQuery(concept); - String FromCache=cache.get(concept, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(concept, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - return processSubjects(xml); - } - - /** - * calls getRecursive for each subject in list - * @param subjects - * @param NumberofRecursions - */ - public void getRecursiveList(String[] subjects,int NumberofRecursions) throws IOException{ - for (int i = 0; i < subjects.length; i++) { - getRecursive(subjects[i], NumberofRecursions); - } - } - - /** - * gets all triples until numberofrecursion-- gets 0 - * - * @param StartingSubject - * @param NumberofRecursions - */ - public void getRecursive(String StartingSubject,int NumberofRecursions) throws IOException{ - System.out.print("SparqlModul: Depth: "+NumberofRecursions+" @ "+StartingSubject+" "); - if(NumberofRecursions<=0) - return; - else {NumberofRecursions--;} - - String sparql=SparqlQueryMaker.makeQueryFilter(StartingSubject,this.sf); - // checks cache - String FromCache=cache.get(StartingSubject, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(StartingSubject, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - // get new Subjects - String[] newSubjects=processResult(StartingSubject,xml); - - for (int i = 0; (i < newSubjects.length)&& NumberofRecursions!=0; i++) { - getRecursive(newSubjects[i], NumberofRecursions); - } - } - - /** - * process the sparql result xml in a simple manner - * - * - * @param subject - * @param xml - * @return list of new individuals - */ - public String[] processResult(String subject,String xml){ - //TODO if result is empty, catch exceptions - String one="<binding name=\"predicate\"><uri>"; - String two="<binding name=\"object\">"; - String end="</uri></binding>"; - String predtmp=""; - String objtmp=""; - ArrayList<String> al=new ArrayList<String>(); - while(xml.indexOf(one)!=-1){ - //get pred - xml=xml.substring(xml.indexOf(one)+one.length()); - predtmp=xml.substring(0,... [truncated message content] |
From: <ku...@us...> - 2008-01-18 08:14:42
|
Revision: 384 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=384&view=rev Author: kurzum Date: 2008-01-18 00:14:37 -0800 (Fri, 18 Jan 2008) Log Message: ----------- changed name Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 07:49:29 UTC (rev 383) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 08:14:37 UTC (rev 384) @@ -35,10 +35,17 @@ * one additional function and would just be a data class * * it writes the files according to one resource in the basedir and saves the - * cache object in it. + * cache object in it. Filename is the subject, a resource + * e.g. http://dbpedia.org/resource/Angela_Merkel which is first urlencoded + * and so serves as the hash for the filename. * + * the cache object in the file remembers: a timestamp, + * a hashmap SparqlQuery -> SparqlXMLResult + * Cache validates if timestamp too old and Sparql-Query the same + * before returning the SPARQL xml-result + * * @author Sebastian Hellmann - * + * @author Sebastian Knappe */ public class Cache implements Serializable { @@ -63,9 +70,9 @@ // /** * constructor for the cache itself - * + * Called once at the startup * @param path - * where the cache files will be + * Where the base path to the cache is */ public Cache(String path) { this.basedir = path + File.separator; @@ -76,32 +83,33 @@ } } - // constructor for single cache object(one entry) + /** - * @param sparql + * constructor for single cache object(one entry) + * @param sparqlQuery * query * @param content * that is the sparql query result as xml */ - protected Cache(String sparql, String content) { + protected Cache(String sparqlQuery, String content) { // this.content = c; // this.sparqlquery = sparql; this.timestamp = System.currentTimeMillis(); this.hm = new HashMap<String, String>(); - hm.put(sparql, content); + hm.put(sparqlQuery, content); } /** - * gets a chached sparqlquery for a resource(key) and returns the + * gets a chached sparqlQuery for a resource(key) and returns the * sparqlXMLResult or null, if none is found. * * @param key * is the resource, the identifier - * @param sparqlquery + * @param sparqlQuery * is a special sparql query about that resource * @return sparqlXMLResult */ - public String get(String key, String sparqlquery) { + public String get(String key, String sparqlQuery) { // System.out.println("get From "+key); String ret = null; try { @@ -114,7 +122,7 @@ // System.out.println("fresh"); String xml = ""; try { - xml = c.hm.get(sparqlquery); + xml = c.hm.get(sparqlQuery); } catch (Exception e) { return null; } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-01-18 07:49:29 UTC (rev 383) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2008-01-18 08:14:37 UTC (rev 384) @@ -1,503 +0,0 @@ -/** - * Copyright (C) 2007, 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.kb.sparql; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.OntologyFormat; -import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -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.dl.KB; -import org.dllearner.parser.KBParser; -import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.utilities.StringTuple; - -/** - * Represents a SPARQL Endpoint. - * - * @author Jens Lehmann - * @author Sebastian Knappe - * @author Sebastian Hellmann - */ -public class SparqlEndpoint extends KnowledgeSource { - - // ConfigOptions - private URL url; - String host; - private Set<String> instances=new HashSet<String>();; - private URL dumpFile; - private int recursionDepth = 1; - private int predefinedFilter = 0; - private int predefinedEndpoint = 0; - private Set<String> predList=new HashSet<String>(); - private Set<String> objList=new HashSet<String>(); - // private Set<String> classList; - private String format = "N-TRIPLES"; - private boolean dumpToFile = true; - private boolean useLits = false; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - private int breakSuperClassRetrievalAfter = 200; - - private boolean learnDomain = false; - private boolean learnRange = false; - private int numberOfInstancesUsedForRoleLearning=40; - private String role=""; - private String blankNodeIdentifier = "bnode"; - - LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); - - /** - * Holds the results of the calculateSubjects method - */ - private String[] subjects; - - /** - * Holds the results of the calculateTriples method - */ - private String[] triples; - - /** - * Holds the results of the calculateConceptSubjects method - */ - private String[] conceptSubjects; - - /** - * if a method is running this becomes true - */ - private boolean subjectThreadRunning = false; - - private boolean triplesThreadRunning = false; - - private boolean conceptThreadRunning = false; - - /** - * the Thread that is running a method - */ - private Thread subjectThread; - - private Thread triplesThread; - - private Thread conceptThread; - - // received ontology as array, used if format=Array(an element of the - // array consists of the subject, predicate and object separated by '<' - private String[] ontArray; - - // received ontology as KB, the internal format - private KB kb; - - public static String getName() { - return "SPARQL Endpoint Restructured"; - } - - /** - * sets the ConfigOptions for this KnowledgeSource - * - * @return - */ - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances", - "relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("recursionDepth", - "recursion depth of KB fragment selection", 2)); - options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); - options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); - - options.add(new StringSetConfigOption("predList", "list of all ignored roles")); - options.add(new StringSetConfigOption("objList", "list of all ignored objects")); - options.add(new StringSetConfigOption("classList", "list of all ignored classes")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); - options.add(new BooleanConfigOption("dumpToFile", - "Specifies whether the extracted ontology is written to a file or not.", true)); - options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); - - options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain/Range from")); - options.add(new StringConfigOption("blankNodeIdentifier", - "used to identify blanknodes in Tripels")); - - options.add(new StringTupleListConfigOption("example", "example")); - options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); - options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); - options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); - options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); - options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); - - - - return options; - } - - /* - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String option = entry.getOptionName(); - if (option.equals("url")) { - String s = (String) entry.getValue(); - try { - url = new URL(s); - } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), - "malformed URL " + s); - } - } else if (option.equals("host")) { - host = (String) entry.getValue(); - } else if (option.equals("instances")) { - instances = (Set<String>) entry.getValue(); - } else if (option.equals("recursionDepth")) { - recursionDepth = (Integer) entry.getValue(); - } else if (option.equals("predList")) { - predList = (Set<String>) entry.getValue(); - } else if (option.equals("objList")) { - objList = (Set<String>) entry.getValue(); - //} else if (option.equals("classList")) { - // classList = (Set<String>) entry.getValue(); - } else if (option.equals("predefinedEndpoint")) { - predefinedEndpoint = (Integer) entry.getValue(); - } else if (option.equals("predefinedFilter")) { - predefinedFilter = (Integer) entry.getValue(); - } else if (option.equals("format")) { - format = (String) entry.getValue(); - } else if (option.equals("dumpToFile")) { - dumpToFile = (Boolean) entry.getValue(); - } else if (option.equals("useLits")) { - useLits = (Boolean) entry.getValue(); - } else if (option.equals("getAllSuperClasses")) { - getAllSuperClasses = (Boolean) entry.getValue(); - } else if (option.equals("learnDomain")) { - learnDomain = (Boolean) entry.getValue(); - }else if (option.equals("learnRange")) { - learnRange = (Boolean) entry.getValue(); - } else if (option.equals("role")) { - role = (String) entry.getValue(); - } else if (option.equals("blankNodeIdentifier")) { - blankNodeIdentifier = (String) entry.getValue(); - } else if (option.equals("example")) { - //System.out.println(entry.getValue()); - }else if (option.equals("replacePredicate")) { - replacePredicate = (LinkedList)entry.getValue(); - }else if (option.equals("replaceObject")) { - replaceObject = (LinkedList)entry.getValue(); - }else if (option.equals("breakSuperClassRetrievalAfter")) { - breakSuperClassRetrievalAfter = (Integer) entry.getValue(); - }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { - numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); - }else if (option.equals("closeAfterRecursion")) { - closeAfterRecursion = (Boolean) entry.getValue(); - } - - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - System.out.println("SparqlModul: Collecting Ontology"); - // SparqlOntologyCollector oc= - // new SparqlOntologyCollector(Datastructures.setToArray(instances), - // numberOfRecursions, filterMode, - // Datastructures.setToArray(predList),Datastructures.setToArray( - // objList),Datastructures.setToArray(classList),format,url,useLits); - Manager m = new Manager(); - SpecificSparqlEndpoint sse = null; - SparqlQueryType sqt = null; - // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); - - // get Options for endpoints - if (predefinedEndpoint >= 1) { - sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); - } else { - sse = new SpecificSparqlEndpoint(url, host, parameters); - } - - // get Options for Filters - - if (predefinedFilter >= 1) { - sqt = PredefinedFilter.getFilter(predefinedFilter); - - } else { - sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - - } - // give everything to the manager - m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); - try { - String ont = ""; - //System.out.println(learnDomain); - // used to learn a domain of a role - if (learnDomain || learnRange) { - Set<String> pos=new HashSet<String>(); - Set<String> neg=new HashSet<String>(); - if(learnDomain){ - pos = m.getDomainInstancesForRole(role); - neg = m.getRangeInstancesForRole(role); - }else if(learnRange){ - neg = m.getDomainInstancesForRole(role); - pos = m.getRangeInstancesForRole(role); - } - //choose 30 - - - Set<String> tmp=new HashSet<String>(); - for(String one:pos){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - pos=tmp; - System.out.println("Instances used: "+pos.size()); - - tmp=new HashSet<String>(); - for(String one:neg){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - neg=tmp; - - instances=new HashSet<String>(); - instances.addAll(pos); - - instances.addAll(neg); - - for(String one:pos){ - System.out.println("+\""+one+"\""); - } - for(String one:neg){ - System.out.println("-\""+one+"\""); - } - - /*Random r= new Random(); - - - Object[] arr=instances.toArray(); - while(instances.size()>=30){ - - }*/ - // add the role to the filter(a solution is always EXISTS - // role.TOP) - m.addPredicateFilter(role); - //System.out.println(instances); - // THIS is a workaround - - } - // the actual extraction is started here - ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); - - System.out.println("Finished collecting Fragment"); - - if (dumpToFile) { - String filename = System.currentTimeMillis() + ".nt"; - String basedir = "cache" + File.separator; - try { - if (!new File(basedir).exists()) - new File(basedir).mkdir(); - - FileWriter fw = new FileWriter(new File(basedir + filename), true); - fw.write(ont); - fw.flush(); - fw.close(); - - dumpFile = (new File(basedir + filename)).toURI().toURL(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (format.equals("KB")) { - try { - //kb = KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("SparqlModul: ****Finished"); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ - @Override - public String toDIG(URI kbURI) { - if (format.equals("N-TRIPLES")) - return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); - else - return DIGConverter.getDIGString(kb, kbURI).toString(); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#export(java.io.File, - * org.dllearner.core.OntologyFormat) - */ - @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { - // currently no export functions implemented, so we just throw an - // exception - throw new OntologyFormatUnsupportedException("export", format); - } - - public URL getURL() { - return url; - } - - public String[] getOntArray() { - return ontArray; - } - - public void calculateSubjects(String label, int limit) { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - subjects = oc.getSubjectsFromLabel(label, limit); - } catch (IOException e) { - subjects = new String[1]; - subjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - triples = oc.collectTriples(subject); - } catch (IOException e) { - triples = new String[1]; - triples[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateConceptSubjects(String concept) { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - conceptSubjects = oc.getSubjectsFromConcept(concept); - } catch (IOException e) { - conceptSubjects = new String[1]; - conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public boolean subjectThreadIsRunning() { - return subjectThreadRunning; - } - - public void setSubjectThreadRunning(boolean bool) { - subjectThreadRunning = bool; - } - - public boolean triplesThreadIsRunning() { - return triplesThreadRunning; - } - - public void setTriplesThreadRunning(boolean bool) { - triplesThreadRunning = bool; - } - - public boolean conceptThreadIsRunning() { - return conceptThreadRunning; - } - - public void setConceptThreadRunning(boolean bool) { - conceptThreadRunning = bool; - } - - public String[] getSubjects() { - return subjects; - } - - public Thread getSubjectThread() { - return subjectThread; - } - - public void setSubjectThread(Thread subjectThread) { - this.subjectThread = subjectThread; - } - - public Thread getTriplesThread() { - return triplesThread; - } - - public void setTriplesThread(Thread triplesThread) { - this.triplesThread = triplesThread; - } - - public Thread getConceptThread() { - return conceptThread; - } - - public void setConceptThread(Thread conceptThread) { - this.conceptThread = conceptThread; - } - - public String[] getTriples() { - return triples; - } - - public String[] getConceptSubjects() { - return conceptSubjects; - } -} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java (from rev 382, trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:14:37 UTC (rev 384) @@ -0,0 +1,503 @@ +/** + * Copyright (C) 2007, 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.kb.sparql; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.OntologyFormat; +import org.dllearner.core.OntologyFormatUnsupportedException; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +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.dl.KB; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.DIGConverter; +import org.dllearner.reasoning.JenaOWLDIGConverter; +import org.dllearner.utilities.StringTuple; + +/** + * Represents a SPARQL Endpoint. + * + * @author Jens Lehmann + * @author Sebastian Knappe + * @author Sebastian Hellmann + */ +public class SparqlKnowledgeSource extends KnowledgeSource { + + // ConfigOptions + private URL url; + String host; + private Set<String> instances=new HashSet<String>();; + private URL dumpFile; + private int recursionDepth = 1; + private int predefinedFilter = 0; + private int predefinedEndpoint = 0; + private Set<String> predList=new HashSet<String>(); + private Set<String> objList=new HashSet<String>(); + // private Set<String> classList; + private String format = "N-TRIPLES"; + private boolean dumpToFile = true; + private boolean useLits = false; + private boolean getAllSuperClasses = true; + private boolean closeAfterRecursion = true; + private int breakSuperClassRetrievalAfter = 200; + + private boolean learnDomain = false; + private boolean learnRange = false; + private int numberOfInstancesUsedForRoleLearning=40; + private String role=""; + private String blankNodeIdentifier = "bnode"; + + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); + + /** + * Holds the results of the calculateSubjects method + */ + private String[] subjects; + + /** + * Holds the results of the calculateTriples method + */ + private String[] triples; + + /** + * Holds the results of the calculateConceptSubjects method + */ + private String[] conceptSubjects; + + /** + * if a method is running this becomes true + */ + private boolean subjectThreadRunning = false; + + private boolean triplesThreadRunning = false; + + private boolean conceptThreadRunning = false; + + /** + * the Thread that is running a method + */ + private Thread subjectThread; + + private Thread triplesThread; + + private Thread conceptThread; + + // received ontology as array, used if format=Array(an element of the + // array consists of the subject, predicate and object separated by '<' + private String[] ontArray; + + // received ontology as KB, the internal format + private KB kb; + + public static String getName() { + return "SPARQL Endpoint Restructured"; + } + + /** + * sets the ConfigOptions for this KnowledgeSource + * + * @return + */ + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances", + "relevant instances e.g. positive and negative examples in a learning problem")); + options.add(new IntegerConfigOption("recursionDepth", + "recursion depth of KB fragment selection", 2)); + options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); + + options.add(new StringSetConfigOption("predList", "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); + options.add(new BooleanConfigOption("dumpToFile", + "Specifies whether the extracted ontology is written to a file or not.", true)); + options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); + options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); + + options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); + options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); + options.add(new StringConfigOption("role", "role to learn Domain/Range from")); + options.add(new StringConfigOption("blankNodeIdentifier", + "used to identify blanknodes in Tripels")); + + options.add(new StringTupleListConfigOption("example", "example")); + options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); + options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); + options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); + options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + + + + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), + "malformed URL " + s); + } + } else if (option.equals("host")) { + host = (String) entry.getValue(); + } else if (option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } else if (option.equals("recursionDepth")) { + recursionDepth = (Integer) entry.getValue(); + } else if (option.equals("predList")) { + predList = (Set<String>) entry.getValue(); + } else if (option.equals("objList")) { + objList = (Set<String>) entry.getValue(); + //} else if (option.equals("classList")) { + // classList = (Set<String>) entry.getValue(); + } else if (option.equals("predefinedEndpoint")) { + predefinedEndpoint = (Integer) entry.getValue(); + } else if (option.equals("predefinedFilter")) { + predefinedFilter = (Integer) entry.getValue(); + } else if (option.equals("format")) { + format = (String) entry.getValue(); + } else if (option.equals("dumpToFile")) { + dumpToFile = (Boolean) entry.getValue(); + } else if (option.equals("useLits")) { + useLits = (Boolean) entry.getValue(); + } else if (option.equals("getAllSuperClasses")) { + getAllSuperClasses = (Boolean) entry.getValue(); + } else if (option.equals("learnDomain")) { + learnDomain = (Boolean) entry.getValue(); + }else if (option.equals("learnRange")) { + learnRange = (Boolean) entry.getValue(); + } else if (option.equals("role")) { + role = (String) entry.getValue(); + } else if (option.equals("blankNodeIdentifier")) { + blankNodeIdentifier = (String) entry.getValue(); + } else if (option.equals("example")) { + //System.out.println(entry.getValue()); + }else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList)entry.getValue(); + }else if (option.equals("replaceObject")) { + replaceObject = (LinkedList)entry.getValue(); + }else if (option.equals("breakSuperClassRetrievalAfter")) { + breakSuperClassRetrievalAfter = (Integer) entry.getValue(); + }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { + numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); + }else if (option.equals("closeAfterRecursion")) { + closeAfterRecursion = (Boolean) entry.getValue(); + } + + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + System.out.println("SparqlModul: Collecting Ontology"); + // SparqlOntologyCollector oc= + // new SparqlOntologyCollector(Datastructures.setToArray(instances), + // numberOfRecursions, filterMode, + // Datastructures.setToArray(predList),Datastructures.setToArray( + // objList),Datastructures.setToArray(classList),format,url,useLits); + Manager m = new Manager(); + SpecificSparqlEndpoint sse = null; + SparqlQueryType sqt = null; + // get Options for Manipulator + Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + + // get Options for endpoints + if (predefinedEndpoint >= 1) { + sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); + } else { + sse = new SpecificSparqlEndpoint(url, host, parameters); + } + + // get Options for Filters + + if (predefinedFilter >= 1) { + sqt = PredefinedFilter.getFilter(predefinedFilter); + + } else { + sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + + } + // give everything to the manager + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); + try { + String ont = ""; + //System.out.println(learnDomain); + // used to learn a domain of a role + if (learnDomain || learnRange) { + Set<String> pos=new HashSet<String>(); + Set<String> neg=new HashSet<String>(); + if(learnDomain){ + pos = m.getDomainInstancesForRole(role); + neg = m.getRangeInstancesForRole(role); + }else if(learnRange){ + neg = m.getDomainInstancesForRole(role); + pos = m.getRangeInstancesForRole(role); + } + //choose 30 + + + Set<String> tmp=new HashSet<String>(); + for(String one:pos){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + pos=tmp; + System.out.println("Instances used: "+pos.size()); + + tmp=new HashSet<String>(); + for(String one:neg){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + neg=tmp; + + instances=new HashSet<String>(); + instances.addAll(pos); + + instances.addAll(neg); + + for(String one:pos){ + System.out.println("+\""+one+"\""); + } + for(String one:neg){ + System.out.println("-\""+one+"\""); + } + + /*Random r= new Random(); + + + Object[] arr=instances.toArray(); + while(instances.size()>=30){ + + }*/ + // add the role to the filter(a solution is always EXISTS + // role.TOP) + m.addPredicateFilter(role); + //System.out.println(instances); + // THIS is a workaround + + } + // the actual extraction is started here + ont = m.extract(instances); + System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); + System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); + + System.out.println("Finished collecting Fragment"); + + if (dumpToFile) { + String filename = System.currentTimeMillis() + ".nt"; + String basedir = "cache" + File.separator; + try { + if (!new File(basedir).exists()) + new File(basedir).mkdir(); + + FileWriter fw = new FileWriter(new File(basedir + filename), true); + fw.write(ont); + fw.flush(); + fw.close(); + + dumpFile = (new File(basedir + filename)).toURI().toURL(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (format.equals("KB")) { + try { + //kb = KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("SparqlModul: ****Finished"); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + if (format.equals("N-TRIPLES")) + return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); + else + return DIGConverter.getDIGString(kb, kbURI).toString(); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#export(java.io.File, + * org.dllearner.core.OntologyFormat) + */ + @Override + public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { + // currently no export functions implemented, so we just throw an + // exception + throw new OntologyFormatUnsupportedException("export", format); + } + + public URL getURL() { + return url; + } + + public String[] getOntArray() { + return ontArray; + } + + public void calculateSubjects(String label, int limit) { + System.out.println("SparqlModul: Collecting Subjects"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + subjects = oc.getSubjectsFromLabel(label, limit); + } catch (IOException e) { + subjects = new String[1]; + subjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public void calculateTriples(String subject) { + System.out.println("SparqlModul: Collecting Triples"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + triples = oc.collectTriples(subject); + } catch (IOException e) { + triples = new String[1]; + triples[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public void calculateConceptSubjects(String concept) { + System.out.println("SparqlModul: Collecting Subjects"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + conceptSubjects = oc.getSubjectsFromConcept(concept); + } catch (IOException e) { + conceptSubjects = new String[1]; + conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public boolean subjectThreadIsRunning() { + return subjectThreadRunning; + } + + public void setSubjectThreadRunning(boolean bool) { + subjectThreadRunning = bool; + } + + public boolean triplesThreadIsRunning() { + return triplesThreadRunning; + } + + public void setTriplesThreadRunning(boolean bool) { + triplesThreadRunning = bool; + } + + public boolean conceptThreadIsRunning() { + return conceptThreadRunning; + } + + public void setConceptThreadRunning(boolean bool) { + conceptThreadRunning = bool; + } + + public String[] getSubjects() { + return subjects; + } + + public Thread getSubjectThread() { + return subjectThread; + } + + public void setSubjectThread(Thread subjectThread) { + this.subjectThread = subjectThread; + } + + public Thread getTriplesThread() { + return triplesThread; + } + + public void setTriplesThread(Thread triplesThread) { + this.triplesThread = triplesThread; + } + + public Thread getConceptThread() { + return conceptThread; + } + + public void setConceptThread(Thread conceptThread) { + this.conceptThread = conceptThread; + } + + public String[] getTriples() { + return triples; + } + + public String[] getConceptSubjects() { + return conceptSubjects; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-01-18 07:49:33
|
Revision: 383 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=383&view=rev Author: kurzum Date: 2008-01-17 23:49:29 -0800 (Thu, 17 Jan 2008) Log Message: ----------- commented cache Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-16 15:42:53 UTC (rev 382) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 07:49:29 UTC (rev 383) @@ -29,36 +29,61 @@ import java.util.HashMap; /** - * SPARQL query cache to avoid possibly expensive multiple queries. + * SPARQL query cache to avoid possibly expensive multiple queries. An object of + * this class can be the cache itself or a cache object(one entry), We could + * split that in two classes, but one entry o object only has contains data and + * one additional function and would just be a data class * + * it writes the files according to one resource in the basedir and saves the + * cache object in it. + * * @author Sebastian Hellmann - * + * */ public class Cache implements Serializable { - // Object can be the cache itself - // or a cache object(one entry) - // it now uses a hashmap and can contain different queries at once - private HashMap<String, String> hm; + /** + * This maps sparql query to sparql result + */ + protected HashMap<String, String> hm; + final static long serialVersionUID = 104; transient String basedir = ""; transient String fileending = ".cache"; + transient boolean debug_print_flag = false; long timestamp; - long daysoffreshness = 15; - long multiplier = 24 * 60 * 60 * 1000;// h m s ms + /** + * After how many days cache entries get invalid + */ + protected long daysoffreshness = 15; + protected long multiplier = 24 * 60 * 60 * 1000;// h m s ms + // private HashMap<String, String> inmem_cache; - // constructor for the cache itself + // + /** + * constructor for the cache itself + * + * @param path + * where the cache files will be + */ public Cache(String path) { this.basedir = path + File.separator; if (!new File(path).exists()) { - System.out.println(new File(path).mkdir()); - ; + System.out.println("created directory: " + path + " : " + + new File(path).mkdir()); + } } // constructor for single cache object(one entry) - public Cache(String sparql, String content) { + /** + * @param sparql + * query + * @param content + * that is the sparql query result as xml + */ + protected Cache(String sparql, String content) { // this.content = c; // this.sparqlquery = sparql; this.timestamp = System.currentTimeMillis(); @@ -66,7 +91,17 @@ hm.put(sparql, content); } - public String get(String key, String sparql) { + /** + * gets a chached sparqlquery for a resource(key) and returns the + * sparqlXMLResult or null, if none is found. + * + * @param key + * is the resource, the identifier + * @param sparqlquery + * is a special sparql query about that resource + * @return sparqlXMLResult + */ + public String get(String key, String sparqlquery) { // System.out.println("get From "+key); String ret = null; try { @@ -79,7 +114,7 @@ // System.out.println("fresh"); String xml = ""; try { - xml = c.hm.get(sparql); + xml = c.hm.get(sparqlquery); } catch (Exception e) { return null; } @@ -90,22 +125,37 @@ e.printStackTrace(); } return ret; - }; + } - public void put(String key, String sparql, String content) { + /** + * @param key + * is the resource, the identifier + * @param sparqlquery + * is the query used as another identifier + * @param content + * is the result of the query + */ + public void put(String key, String sparqlquery, String content) { // System.out.println("put into "+key); Cache c = readFromFile(makeFilename(key)); if (c == null) { - c = new Cache(sparql, content); + c = new Cache(sparqlquery, content); putIntoFile(makeFilename(key), c); } else { - c.hm.put(sparql, content); + c.hm.put(sparqlquery, content); putIntoFile(makeFilename(key), c); } } - String makeFilename(String key) { + /** + * this function takes a resource string and then URIencodes it and makes a + * filename out of it for the use in the hashmap + * + * @param key + * @return the complete key for filename in the hashmap + */ + protected String makeFilename(String key) { String ret = ""; try { ret = basedir + URLEncoder.encode(key, "UTF-8") + fileending; @@ -115,14 +165,6 @@ return ret; } - boolean checkFreshness() { - if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) - // fresh - return true; - else - return false; - } - public void checkFile(String Filename) { if (!new File(Filename).exists()) { try { @@ -135,12 +177,18 @@ } - public void putIntoFile(String Filename, Cache content) { + /** + * puts a cache entry in a file + * + * @param Filename + * @param c + */ + protected void putIntoFile(String Filename, Cache c) { try { // FileWriter fw=new FileWriter(new File(Filename),true); FileOutputStream fos = new FileOutputStream(Filename, false); ObjectOutputStream o = new ObjectOutputStream(fos); - o.writeObject(content); + o.writeObject(c); fos.flush(); fos.close(); } catch (Exception e) { @@ -148,7 +196,13 @@ } } - public Cache readFromFile(String Filename) { + /** + * reads a cache entry from a file + * + * @param Filename + * @return cache entry + */ + protected Cache readFromFile(String Filename) { Cache content = null; try { FileInputStream fos = new FileInputStream(Filename); @@ -161,5 +215,13 @@ return content; } - + + protected boolean checkFreshness() { + if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) + // fresh + return true; + else + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-01-16 15:42:56
|
Revision: 382 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=382&view=rev Author: sknappe Date: 2008-01-16 07:42:53 -0800 (Wed, 16 Jan 2008) Log Message: ----------- the uris are now identified out of the concept Modified Paths: -------------- trunk/src/dbpedia-navigator/NaturalConcepts.php Modified: trunk/src/dbpedia-navigator/NaturalConcepts.php =================================================================== --- trunk/src/dbpedia-navigator/NaturalConcepts.php 2008-01-16 15:39:43 UTC (rev 381) +++ trunk/src/dbpedia-navigator/NaturalConcepts.php 2008-01-16 15:42:53 UTC (rev 382) @@ -15,17 +15,30 @@ function identifyConcepts() { + $temp=$this->concept; $ret=array(); + $offset=0; while (true){ - $nextpos=strpos("http",$this->concept); - $nextend=strpos() + $nextpos=strpos($temp,"http",$offset); + if (!$nextpos) break; + $nextend=preg_match("/\040|.TOP|.BOTTOM|.EXISTS|.ALL|.\(/",$temp,$treffer,PREG_OFFSET_CAPTURE,$nextpos); + if (!$nextend){ + $uri=substr($temp,$nextpos,strlen($temp)-$nextpos); + $ret[]=$uri; + break; + } + $uri=substr($temp,$nextpos,$treffer[0][1]-$nextpos); + $ret[]=$uri; + $offset=$treffer[0][1]; } + + print_r($ret); return $ret; } } -$conc="EXISTS http://dbpedia.org/property/website AND http://dbpedia.org/resource/Berlin"; +$conc="EXISTS http://dbpedia.org/property/website.TOP AND http://dbpedia.org/resource/Berlin"; $nc=new NaturalConcepts($conc); $ic=$nc->getNaturalConcept(); -print_r($ic); +//print_r($ic); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-01-16 15:40:01
|
Revision: 381 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=381&view=rev Author: tonytacker Date: 2008-01-16 07:39:43 -0800 (Wed, 16 Jan 2008) Log Message: ----------- improved handling for URI Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-16 12:42:45 UTC (rev 380) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-16 15:39:43 UTC (rev 381) @@ -20,9 +20,9 @@ * */ -import java.io.File; import java.util.HashSet; import java.util.Set; +//import java.io.File; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-16 12:42:45 UTC (rev 380) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-16 15:39:43 UTC (rev 381) @@ -24,6 +24,7 @@ import java.util.List; import javax.swing.*; +import javax.swing.event.*; import java.awt.BorderLayout; import java.awt.event.ActionEvent; @@ -47,21 +48,21 @@ private JFileChooser fc; private JButton openButton, initButton; private JTextField fileDisplay; - private String[] kbBoxItems = {"Pleae select a type"}; - private JComboBox cb = new JComboBox(kbBoxItems); + private String[] kbBoxItems = {}; + private JComboBox cb = new JComboBox(kbBoxItems); private JPanel openPanel; private Config config; private int choosenClassIndex; private List<Class<? extends KnowledgeSource>> sources; - KnowledgeSourcePanel(Config config) { + KnowledgeSourcePanel(final Config config) { super(new BorderLayout()); this.config = config; sources = config.getComponentManager().getKnowledgeSources(); fc = new JFileChooser(new File("examples/")); - openButton = new JButton("Open local file otherwise type URL + ENTER"); + openButton = new JButton("Open local file or type URL"); openButton.addActionListener(this); initButton = new JButton("Init KnowledgeSource"); @@ -69,8 +70,21 @@ fileDisplay = new JTextField(35); fileDisplay.setEditable(true); - fileDisplay.addActionListener(this); + // update config if textfield changed + fileDisplay.getDocument().addDocumentListener(new DocumentListener() { + public void insertUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + public void removeUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + public void changedUpdate(DocumentEvent e) { + config.setURI(fileDisplay.getText()); + } + }); + + // parse for (int i=0; i<sources.size(); i++) { String ksClass = sources.get(i).toString().substring(23).concat(".class"); cb.addItem(ksClass); @@ -85,20 +99,21 @@ JPanel initPanel = new JPanel(); initPanel.add(initButton); + + openPanel.add(fileDisplay); + openPanel.add(openButton); add(choosePanel, BorderLayout.PAGE_START); add(openPanel, BorderLayout.CENTER); add(initPanel, BorderLayout.PAGE_END); + + choosenClassIndex = cb.getSelectedIndex(); } public void actionPerformed(ActionEvent e) { - // change URI - if (e.getSource() == fileDisplay) { - System.out.println(fileDisplay.getText()); - config.setURI(fileDisplay.getText()); - } + // read selected KnowledgeSourceClass + choosenClassIndex = cb.getSelectedIndex(); - // open File if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); @@ -110,35 +125,14 @@ } return; } - - - // something changes in cb - if (cb.isEnabled()) { - System.out.println("Item: " + cb.getSelectedItem()); - System.out.println("Item: " + cb.getSelectedIndex()); - - choosenClassIndex = cb.getSelectedIndex() -1; - - makeCenterClean(); - openPanel.add(fileDisplay); - openPanel.add(openButton); - - } - + // init if (e.getSource() == initButton) { - //String testURI = config.getURI(); config.setKnowledgeSource(config.getComponentManager().knowledgeSource(sources.get(choosenClassIndex))); config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", config.getURI()); config.getKnowledgeSource().init(); - System.out.println("init KnowledgeSource with " + sources.get(choosenClassIndex) + " and ..."); + System.out.println("init KnowledgeSource with \n" + sources.get(choosenClassIndex) + " and \n" + config.getURI() + "\n"); } } - - private void makeCenterClean() { - openPanel.remove(fileDisplay); - openPanel.remove(openButton); - openPanel.repaint(); - StartGUI.myrun.renew(); - } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-01-16 12:42:49
|
Revision: 380 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=380&view=rev Author: sknappe Date: 2008-01-16 04:42:45 -0800 (Wed, 16 Jan 2008) Log Message: ----------- some bugfixes and added class for finding natural terms for concepts Modified Paths: -------------- trunk/src/dbpedia-navigator/DLLearnerConnection.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/index.php Added Paths: ----------- trunk/src/dbpedia-navigator/NaturalConcepts.php trunk/src/dbpedia-navigator/learningExamples.txt Modified: trunk/src/dbpedia-navigator/DLLearnerConnection.php =================================================================== --- trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-16 02:39:20 UTC (rev 379) +++ trunk/src/dbpedia-navigator/DLLearnerConnection.php 2008-01-16 12:42:45 UTC (rev 380) @@ -45,7 +45,7 @@ function getConceptFromExamples($ttl,$posExamples,$negExamples) { - $this->client->applyConfigEntryInt($this->id, $this->ksID, "recursionDepth", 2); + $this->client->applyConfigEntryInt($this->id, $this->ksID, "recursionDepth",1); $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "instances", array_merge($posExamples,$negExamples)); // $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "predList", array()); // $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "objList", array()); Added: trunk/src/dbpedia-navigator/NaturalConcepts.php =================================================================== --- trunk/src/dbpedia-navigator/NaturalConcepts.php (rev 0) +++ trunk/src/dbpedia-navigator/NaturalConcepts.php 2008-01-16 12:42:45 UTC (rev 380) @@ -0,0 +1,31 @@ +<?php + +class NaturalConcepts +{ + private $concept; + + function NaturalConcepts($conc){ + $this->concept=$conc; + } + + function getNaturalConcept(){ + $identifiedConcepts=$this->identifyConcepts(); + return $identifiedConcepts; + } + + function identifyConcepts() + { + $ret=array(); + while (true){ + $nextpos=strpos("http",$this->concept); + $nextend=strpos() + } + return $ret; + } +} + +$conc="EXISTS http://dbpedia.org/property/website AND http://dbpedia.org/resource/Berlin"; +$nc=new NaturalConcepts($conc); +$ic=$nc->getNaturalConcept(); +print_r($ic); +?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-16 02:39:20 UTC (rev 379) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2008-01-16 12:42:45 UTC (rev 380) @@ -256,7 +256,7 @@ } $negInterests=""; if (isset($_SESSION['negative'])) foreach($_SESSION['negative'] as $neg){ - $negInterests=$negInterests.str_replace("_"," ",urldecode(substr (strrchr ($neg, "/"), 1)))." <a href=\"\" onclick=\"xajax_toPositive('".$neg."');return false;\"><img src=\"images/plus.jpg\" alt=\"Plus\"/></a> <a href=\"\" onclick=\"xajax_removeNegInterest('".$pos."');return false;\"><img src=\"images/remove.png\" alt=\"Minus\"/></a><br/>"; + $negInterests=$negInterests.str_replace("_"," ",urldecode(substr (strrchr ($neg, "/"), 1)))." <a href=\"\" onclick=\"xajax_toPositive('".$neg."');return false;\"><img src=\"images/plus.jpg\" alt=\"Plus\"/></a> <a href=\"\" onclick=\"xajax_removeNegInterest('".$neg."');return false;\"><img src=\"images/remove.png\" alt=\"Minus\"/></a><br/>"; } $objResponse=new xajaxResponse(); Modified: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2008-01-16 02:39:20 UTC (rev 379) +++ trunk/src/dbpedia-navigator/index.php 2008-01-16 12:42:45 UTC (rev 380) @@ -188,7 +188,8 @@ <div id="todo"> <b>ToDo:</b> <ul style="float:left"> - <li>Get learning process working (with new SPARQL component).</li> + <li>Get learning component fast.</li> + <li>Learning as a Thread.</li> <li>Get local DBpedia SPARQL endpoint working (next DBpedia release expected at the endof January and then every two months, so it would be nice to have a script based partly automated or at least documented solution for creating a DBpedia mirror).</li> Added: trunk/src/dbpedia-navigator/learningExamples.txt =================================================================== --- trunk/src/dbpedia-navigator/learningExamples.txt (rev 0) +++ trunk/src/dbpedia-navigator/learningExamples.txt 2008-01-16 12:42:45 UTC (rev 380) @@ -0,0 +1,37 @@ ++Pythagoras +-Plato +-------- +http://dbpedia.org/class/yago/ReligiousPerson109628382 + ++Angela Merkel +-Joschka Fischer +---------------- +http://dbpedia.org/class/yago/Adult109605289 (length 1, depth 1) +http://dbpedia.org/class/yago/Communicator109610660 (length 1, depth 1) +http://dbpedia.org/class/yago/Female109619168 (length 1, depth 1) +http://dbpedia.org/class/yago/Scientist110560637 (length 1, depth 1) + ++Germany +-Russia +-Mongolia +--------------- +http://dbpedia.org/class/yago/PhysicalEntity100001930 + ++Tiger +-Elefant +--------------- +http://dbpedia.org/class/yago/CausalAgent100007347 + ++Mother ++Father +-Child +----------------- +http://dbpedia.org/class/yago/Adult109605289 + ++Leipzig ++Dresden +-Berlin +-Hamburg +---------------- +EXISTS http://dbpedia.org/property/wappen.TOP +EXISTS http://dbpedia.org/property/wordnet_type.TOP \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-01-16 02:39:21
|
Revision: 379 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=379&view=rev Author: tonytacker Date: 2008-01-15 18:39:20 -0800 (Tue, 15 Jan 2008) Log Message: ----------- removed a small bug by opening/changing URI/FILE Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-16 01:53:33 UTC (rev 378) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-16 02:39:20 UTC (rev 379) @@ -61,7 +61,7 @@ sources = config.getComponentManager().getKnowledgeSources(); fc = new JFileChooser(new File("examples/")); - openButton = new JButton("Open local file otherwise type URL"); + openButton = new JButton("Open local file otherwise type URL + ENTER"); openButton.addActionListener(this); initButton = new JButton("Init KnowledgeSource"); @@ -69,6 +69,7 @@ fileDisplay = new JTextField(35); fileDisplay.setEditable(true); + fileDisplay.addActionListener(this); for (int i=0; i<sources.size(); i++) { String ksClass = sources.get(i).toString().substring(23).concat(".class"); @@ -91,6 +92,13 @@ } public void actionPerformed(ActionEvent e) { + // change URI + if (e.getSource() == fileDisplay) { + System.out.println(fileDisplay.getText()); + config.setURI(fileDisplay.getText()); + } + + // open File if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); @@ -119,11 +127,11 @@ // init if (e.getSource() == initButton) { - String testURI = config.getURI(); + //String testURI = config.getURI(); config.setKnowledgeSource(config.getComponentManager().knowledgeSource(sources.get(choosenClassIndex))); - config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", testURI); + config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", config.getURI()); config.getKnowledgeSource().init(); - System.out.println("init KnowledgeSource"); + System.out.println("init KnowledgeSource with " + sources.get(choosenClassIndex) + " and ..."); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2008-01-16 01:53:36
|
Revision: 378 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=378&view=rev Author: tonytacker Date: 2008-01-15 17:53:33 -0800 (Tue, 15 Jan 2008) Log Message: ----------- This Version runs with file and URL. At moment you have to click from left to right all tabs and in every tab the init-button. It will be improved later. Normally you can use both SparceEndpoints. If it is there something wrong with GUI let me know. I need some links for testing. Greetings -Tilo- Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/gui/Config.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/gui/StartGUI.java Modified: trunk/src/dl-learner/org/dllearner/gui/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-15 16:00:04 UTC (rev 377) +++ trunk/src/dl-learner/org/dllearner/gui/Config.java 2008-01-16 01:53:33 UTC (rev 378) @@ -43,7 +43,7 @@ public class Config { private ComponentManager cm = ComponentManager.getInstance(); private KnowledgeSource source; - private File selectedFile; + private String uri; private ReasonerComponent reasoner; private ReasoningService rs; private String[] kbBoxItems = {"Pleae select a type", "KBFile", "OWLFile", "SparqleEndpoint"}; @@ -55,7 +55,7 @@ * status should show witch variables are set * status[0] ... cm * status[1] ... KnowledgeSource - * status[2] ... File or URL + * status[2] ... URI * status[3] ... Resoner * status[4] ... ReasoningService * status[5] ... ExampleSet @@ -78,13 +78,13 @@ cm = input; } - protected File getFile () { - return selectedFile; + protected String getURI () { + return uri; } - protected void setFile (File input) { + protected void setURI (String input) { status[2] = true; - selectedFile = input; + uri = input; } protected ReasonerComponent getReasoner () { Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-15 16:00:04 UTC (rev 377) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-01-16 01:53:33 UTC (rev 378) @@ -21,7 +21,7 @@ */ import java.io.File; -//import java.util.List; +import java.util.List; import javax.swing.*; @@ -29,12 +29,10 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import org.dllearner.kb.OWLFile; -// import org.dllearner.kb.KBFile; +//import org.dllearner.kb.*; +import org.dllearner.core.KnowledgeSource; -//import org.dllearner.core.KnowledgeSource; - /** * KnowledgeSourcePanel * @@ -47,35 +45,49 @@ private static final long serialVersionUID = -7678275020058043937L; private JFileChooser fc; - private JButton openButton; + private JButton openButton, initButton; private JTextField fileDisplay; - private String[] kbBoxItems = {"Pleae select a type", "KBFile", "OWLFile", "SparqleEndpoint"}; + private String[] kbBoxItems = {"Pleae select a type"}; private JComboBox cb = new JComboBox(kbBoxItems); - private JPanel openPanel = new JPanel(); + private JPanel openPanel; private Config config; + private int choosenClassIndex; + private List<Class<? extends KnowledgeSource>> sources; KnowledgeSourcePanel(Config config) { super(new BorderLayout()); this.config = config; + sources = config.getComponentManager().getKnowledgeSources(); fc = new JFileChooser(new File("examples/")); - openButton = new JButton("Open File"); + openButton = new JButton("Open local file otherwise type URL"); openButton.addActionListener(this); + + initButton = new JButton("Init KnowledgeSource"); + initButton.addActionListener(this); + fileDisplay = new JTextField(35); - fileDisplay.setEditable(false); + fileDisplay.setEditable(true); - // test output - if you activat next 2 lines, it will show alle available kb.classes - // activate import too! - //List<Class<? extends KnowledgeSource>> sources = StartGUI.myconfig.getComponentManager().getKnowledgeSources(); - //for (int i=0; i<sources.size(); i++) cb.addItem(sources.get(i)); + for (int i=0; i<sources.size(); i++) { + String ksClass = sources.get(i).toString().substring(23).concat(".class"); + cb.addItem(ksClass); + } + cb.addActionListener(this); + openPanel = new JPanel(); + JPanel choosePanel = new JPanel(); choosePanel.add(cb); + JPanel initPanel = new JPanel(); + initPanel.add(initButton); + add(choosePanel, BorderLayout.PAGE_START); add(openPanel, BorderLayout.CENTER); + add(initPanel, BorderLayout.PAGE_END); } public void actionPerformed(ActionEvent e) { @@ -83,39 +95,35 @@ if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(KnowledgeSourcePanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { - config.setFile(fc.getSelectedFile()); //save variable - fileDisplay.setText(config.getFile().toString()); - //System.out.println("Init KnowledgeSource after loading file ... show over output"); - //System.out.println("test: " + StartGUI.myconfig.getFile().toURI().toString()); - config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", config.getFile().toURI().toString()); - config.getKnowledgeSource().init(); + String URI = "file://"; + URI = URI.concat(fc.getSelectedFile().toString()); // make "file://" before local URI's + config.setURI(URI); //save variable + fileDisplay.setText(URI); } return; } + - // choose none - if (cb.getSelectedItem().toString() == kbBoxItems[0]) { - //System.out.println("Item: " + cb.getSelectedItem()); + // something changes in cb + if (cb.isEnabled()) { + System.out.println("Item: " + cb.getSelectedItem()); + System.out.println("Item: " + cb.getSelectedIndex()); + + choosenClassIndex = cb.getSelectedIndex() -1; + makeCenterClean(); - } - // choose KB class - if (cb.getSelectedItem().toString() == kbBoxItems[1]) { - //System.out.println("Item: " + cb.getSelectedItem()); - makeCenterClean(); - } - // choose OWL class - if (cb.getSelectedItem().toString() == kbBoxItems[2]) { - //System.out.println("Item: " + cb.getSelectedItem()); - makeCenterClean(); openPanel.add(fileDisplay); openPanel.add(openButton); - openPanel.repaint(); - config.setKnowledgeSource(config.getComponentManager().knowledgeSource(OWLFile.class)); + } - // choose SPARCLE class - if (cb.getSelectedItem().toString() == kbBoxItems[3]) { - //System.out.println("Item: " + cb.getSelectedItem()); - makeCenterClean(); + + // init + if (e.getSource() == initButton) { + String testURI = config.getURI(); + config.setKnowledgeSource(config.getComponentManager().knowledgeSource(sources.get(choosenClassIndex))); + config.getComponentManager().applyConfigEntry(config.getKnowledgeSource(), "url", testURI); + config.getKnowledgeSource().init(); + System.out.println("init KnowledgeSource"); } } Modified: trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java 2008-01-15 16:00:04 UTC (rev 377) +++ trunk/src/dl-learner/org/dllearner/gui/OutputPanel.java 2008-01-16 01:53:33 UTC (rev 378) @@ -71,10 +71,12 @@ public void actionPerformed(ActionEvent e) { if (e.getSource() == showButton) { infoArea.setText(""); - if (config.getStatus(2)) { // file is selected and exist? + if (config.getStatus(1)) { // kb is set infoArea.append("SourceClass: " + config.getKnowledgeSource().toString() + "\n"); - infoArea.append("FILE: " + config.getFile() + "\n"); } + if (config.getStatus(2)) { // file is set + infoArea.append("URI: " + config.getURI() + "\n"); + } if (config.getStatus(3)) { // Reasoner is set infoArea.append("Reasoner: " + config.getReasoner() + "\n"); } Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-15 16:00:04 UTC (rev 377) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-01-16 01:53:33 UTC (rev 378) @@ -97,22 +97,7 @@ }); } - - public void valueChanged(ListSelectionEvent evt) { - System.out.println("s"); - if (evt.getValueIsAdjusting()) - return; - System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex()); - // detect which examples have been selected - Set<String> exampleSet = new HashSet<String>(); - int[] selectedIndices = digList.getSelectedIndices(); - for(int i : selectedIndices) - exampleSet.add(individuals.get(i).toString()); - //StartGUI.myconfig.setExampleSet(exampleSet); - //System.out.println("digList: " + config.getExampleSet() ); - } - - + public void actionPerformed(ActionEvent e) { if (e.getSource() == digButton) { // set reasoner @@ -140,8 +125,6 @@ // graphic digList.setModel(listModel); StartGUI.myrun.renew(); - - //return; } } } Modified: trunk/src/dl-learner/org/dllearner/gui/StartGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-15 16:00:04 UTC (rev 377) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI.java 2008-01-16 01:53:33 UTC (rev 378) @@ -35,8 +35,6 @@ protected static StartGUI myrun; - //protected static Config myconfig = new Config(); - public JTabbedPane tabPane = new JTabbedPane(); private JPanel tab1 = new JPanel(); @@ -50,7 +48,7 @@ this.setTitle("DL-Learner GUI"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationByPlatform(true); - this.setSize(640, 480); + this.setSize(800, 600); tab1.add(new KnowledgeSourcePanel(config)); tab2.add(new ReasonerPanel(config)); tab3.add(new LearningProblemPanel(config)); @@ -70,11 +68,11 @@ } protected void renew() { - myrun.tabPane.repaint(); + tabPane.repaint(); } - + protected StartGUI getStartGUI() { return myrun; } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |