From: <lor...@us...> - 2013-01-22 21:41:24
|
Revision: 3889 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3889&view=rev Author: lorenz_b Date: 2013-01-22 21:41:16 +0000 (Tue, 22 Jan 2013) Log Message: ----------- Added options to set prefixes in QTL output and to enable numeric SPARQL FILTER expression learning. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-01-22 13:22:29 UTC (rev 3888) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-01-22 21:41:16 UTC (rev 3889) @@ -22,9 +22,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -116,6 +118,8 @@ private SortedSet<String> lggInstances; private Set<String> objectNamespacesToIgnore = new HashSet<String>(); + private Map<String, String> prefixes = new HashMap<String, String>(); + private boolean enableNumericLiteralFilters = false; public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); @@ -125,7 +129,6 @@ } public QTL() { - } public QTL(AbstractLearningProblem learningProblem, SparqlEndpointKS endpointKS) throws LearningProblemUnsupportedException{ @@ -219,6 +222,14 @@ return maxQueryTreeDepth; } + public void setPrefixes(Map<String, String> prefixes) { + this.prefixes = prefixes; + } + + public Map<String, String> getPrefixes() { + return prefixes; + } + public String getSPARQLQuery(){ if(lgg == null){ lgg = lggGenerator.getLGG(getQueryTrees(posExamples)); @@ -256,6 +267,7 @@ if(logger.isDebugEnabled()){ logger.debug("Tree for resource " + resource); logger.debug(tree.getStringRepresentation()); + } trees.add(tree); } @@ -330,9 +342,17 @@ if(logger.isDebugEnabled()){ logger.debug("LGG: \n" + lgg.getStringRepresentation()); } - logger.info(lgg.toSPARQLQuery()); + logger.info(lgg.toSPARQLQueryString(enableNumericLiteralFilters, prefixes)); } - + + public void setEnableNumericLiteralFilters(boolean enableNumericLiteralFilters) { + this.enableNumericLiteralFilters = enableNumericLiteralFilters; + } + + public boolean isEnableNumericLiteralFilters() { + return enableNumericLiteralFilters; + } + @Override public List<String> getCurrentlyBestSPARQLQueries(int nrOfSPARQLQueries) { return Collections.singletonList(getBestSPARQLQuery()); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-01-22 13:22:29 UTC (rev 3888) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-01-22 21:41:16 UTC (rev 3889) @@ -22,6 +22,7 @@ import java.io.PrintWriter; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.Set; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; @@ -131,6 +132,8 @@ String toSPARQLQueryString(boolean filtered); + String toSPARQLQueryString(boolean filtered, Map<String, String> prefixMap); + Query toSPARQLQuery(); int getTriplePatternCount(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-01-22 13:22:29 UTC (rev 3888) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-01-22 21:41:16 UTC (rev 3889) @@ -31,6 +31,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; import java.util.regex.Pattern; @@ -712,6 +713,11 @@ @Override public String toSPARQLQueryString(boolean filtered) { + return toSPARQLQueryString(filtered, Collections.<String, String>emptyMap()); + } + + @Override + public String toSPARQLQueryString(boolean filtered, Map<String, String> prefixMap) { if(children.isEmpty()){ return "SELECT ?x0 WHERE {?x0 ?y ?z.}"; } @@ -724,7 +730,16 @@ sb.append(filter).append("\n"); } sb.append("}"); - return sb.toString(); + Query query = QueryFactory.create(sb.toString(), Syntax.syntaxARQ); + query.setPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); + query.setPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); + + for (Entry<String, String> entry : prefixMap.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + query.setPrefix(key, value); + } + return query.toString(); } private void buildSPARQLQueryString(QueryTree<N> tree, StringBuilder sb, boolean filtered, List<String> filters){ @@ -785,7 +800,7 @@ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ min = (l.getInt() < min.getInt()) ? l : min; - } else if(l.getDatatype() == XSDDatatype.XSDdouble){ + } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ min = (l.getDouble() < min.getDouble()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdate){ min = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(min.getLexicalForm())) == -1) ? l : min; @@ -802,7 +817,7 @@ l = iter.next(); if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ max = (l.getInt() > max.getInt()) ? l : max; - } else if(l.getDatatype() == XSDDatatype.XSDdouble){ + } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ max = (l.getDouble() > max.getDouble()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdate){ max = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(max.getLexicalForm())) == 1) ? l : max; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2013-01-22 13:22:29 UTC (rev 3888) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java 2013-01-22 21:41:16 UTC (rev 3889) @@ -247,7 +247,8 @@ if(lit.getDatatype() == XSDDatatype.XSDinteger || lit.getDatatype() == XSDDatatype.XSDdouble || lit.getDatatype() == XSDDatatype.XSDdate - || lit.getDatatype() == XSDDatatype.XSDint){ + || lit.getDatatype() == XSDDatatype.XSDint + || lit.getDatatype() == XSDDatatype.XSDdecimal){ subTree.addLiteral(lit); } tree.addChild(subTree, st.getPredicate().toString()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |