@Test public void testDBSort() throws Exception { RemoteCursor cursor = kb.dbSort(Arrays.asList(new String[]{"a","b","A","B"," a","á"}), 100); while (cursor.next()) { System.out.println(cursor.getString(1)); } cursor.close(); }
@Override public ResultSetCursor dbSort(List<String> index, int maxLength) throws Exception { String prefix = "SELECT * FROM ( VALUES "; String suffix = " ) AS t(string) order by string"; StringBuilder b = new StringBuilder(); for (int i = 0; i < index.size(); i++) { b.append("(?)"); b.append(","); } String sql; if (b.length() > 0) { sql = prefix + b.substring(0, b.length() - 1) + suffix; } else { return null; } try { PreparedStatement pstmt = connection.prepareStatement(sql); for (int i = 0; i < index.size(); i++) { int min = Math.min(maxLength, index.get(i).length()); pstmt.setString(i + 1, index.get(i).substring(0, min)); } ResultSet rs = executeQuery(pstmt, sql); return new ResultSetCursor(rs); } catch (Exception e) { log.log(Level.SEVERE, "an error occurred in executing SQL query: " + sql, e); throw e; } }
PostgresKB implements KnowledgeBase { @Override public ResultSetCursor dbSort(List<String> index, int maxLength) throws Exception { String prefix = "SELECT * FROM ( VALUES "; String suffix = " ) AS t(string) order by string"; StringBuilder b = new StringBuilder(); for (int i = 0; i < index.size(); i++) { b.append("(?)"); b.append(","); } String sql; if (b.length() > 0) { sql = prefix + b.substring(0, b.length() - 1) + suffix; } else { return null; } try { PreparedStatement pstmt = connection.prepareStatement(sql); for (int i = 0; i < index.size(); i++) { int min = Math.min(maxLength, index.get(i).length()); pstmt.setString(i + 1, index.get(i).substring(0, min)); } ResultSet rs = executeQuery(pstmt, sql); return new ResultSetCursor(rs); } catch (Exception e) { log.log(Level.SEVERE, "an error occurred in executing SQL query: " + sql, e); throw e; } } }
PostgresKB implements KnowledgeBase { @Override public ResultSetCursor dbSort(List<String> index, int maxLength) throws Exception { String prefix = "SELECT * FROM ( VALUES "; String suffix = " ) AS t(string) order by string"; StringBuilder b = new StringBuilder(); for (int i = 0; i < index.size(); i++) { b.append("(?)"); b.append(","); } String sql; if (b.length() > 0) { sql = prefix + b.substring(0, b.length() - 1) + suffix; } else { return null; } try { PreparedStatement pstmt = connection.prepareStatement(sql); for (int i = 0; i < index.size(); i++) { int min = Math.min(maxLength, index.get(i).length()); pstmt.setString(i + 1, index.get(i).substring(0, min)); } ResultSet rs = executeQuery(pstmt, sql); return new ResultSetCursor(rs); } catch (Exception e) { log.log(Level.SEVERE, "an error occurred in executing SQL query: " + sql, e); throw e; } } PostgresKB(Connection connection, String session, URI uri); protected  PostgresKB(Connection connection, String session, URI uri, String dbSchema, String indexSchema); }
PostgresKB implements KnowledgeBase { @Override public ResultSetCursor dbSort(List<String> index, int maxLength) throws Exception { String prefix = "SELECT * FROM ( VALUES "; String suffix = " ) AS t(string) order by string"; StringBuilder b = new StringBuilder(); for (int i = 0; i < index.size(); i++) { b.append("(?)"); b.append(","); } String sql; if (b.length() > 0) { sql = prefix + b.substring(0, b.length() - 1) + suffix; } else { return null; } try { PreparedStatement pstmt = connection.prepareStatement(sql); for (int i = 0; i < index.size(); i++) { int min = Math.min(maxLength, index.get(i).length()); pstmt.setString(i + 1, index.get(i).substring(0, min)); } ResultSet rs = executeQuery(pstmt, sql); return new ResultSetCursor(rs); } catch (Exception e) { log.log(Level.SEVERE, "an error occurred in executing SQL query: " + sql, e); throw e; } } PostgresKB(Connection connection, String session, URI uri); protected  PostgresKB(Connection connection, String session, URI uri, String dbSchema, String indexSchema); @Override URI getUri(); @Override ResultSetCursor getDatatypePropertyValues(
			int[] datatypePropertyFilter, SuffixArray suffixArray); @Override ResultSetCursor getInstanceCandidates(
			Map<Integer, Set<Integer>> literalKeys); @Override ResultSetCursor dbSort(List<String> index, int maxLength); @Override int getLiteralIndex(String literal); @Override String getURI(int index); @Override String getLiteral(int index); @Override int getUriIndex(String uri); @Override ResultSetCursor getOutgoingRelations(int[] instances); @Override ResultSetCursor getIncomingRelations(int[] instances); @Override ResultSetCursor getRDFTypesForInstances(int[] subjects); @Override ResultSetCursor getInstancesOfTypes(int type, int count); @Override ResultSetCursor getRDFTypes(); @Override int[] getClusters(); @Override int[] getDatatypePropertyByClass(int cluster, double t); @Override Collection<int[]> getConnectingClusters(int objectProperty, double t); @Override int getCluster(int[] types); @Override int getPropertyType(int property); @Override void preprocessRdfData(InputStream[] datasets,
			MediaType rdfMimeType, MediaType fileMimeType,
			String absoluteBaseURI, LiteralHashing hashing); @Override void calculateCardinalities(); @Override double getSubjectCardinality(int p); @Override void calculateMarkovChain(int[] blackListedProperties,
			int sampleCount); @Override double getMarkovProbability(int subject, int predicate, int object); @Override List<double[]> getMaxMarkovProbability(int subject, int object, int k); @Override TIntObjectHashMap<TIntObjectHashMap<double[]>> getCoverageAmbiguity(); @Override void calculateProperNameStatistics(TextCorpus corpus, Pipeline pipe); @Override DoubleMatrix getTypeCorrelations(int samples); @Override void clusterCorrelatingClasses(int samples, double biasThreshold,
			double pruningThreshold); @Override void calculateRegexDistributions(String[] regexs); @Override TIntDoubleHashMap getDatatypePropertiesForRegex(String regex); @Override String[] getRegexs(); }
PostgresKB implements KnowledgeBase { @Override public ResultSetCursor dbSort(List<String> index, int maxLength) throws Exception { String prefix = "SELECT * FROM ( VALUES "; String suffix = " ) AS t(string) order by string"; StringBuilder b = new StringBuilder(); for (int i = 0; i < index.size(); i++) { b.append("(?)"); b.append(","); } String sql; if (b.length() > 0) { sql = prefix + b.substring(0, b.length() - 1) + suffix; } else { return null; } try { PreparedStatement pstmt = connection.prepareStatement(sql); for (int i = 0; i < index.size(); i++) { int min = Math.min(maxLength, index.get(i).length()); pstmt.setString(i + 1, index.get(i).substring(0, min)); } ResultSet rs = executeQuery(pstmt, sql); return new ResultSetCursor(rs); } catch (Exception e) { log.log(Level.SEVERE, "an error occurred in executing SQL query: " + sql, e); throw e; } } PostgresKB(Connection connection, String session, URI uri); protected  PostgresKB(Connection connection, String session, URI uri, String dbSchema, String indexSchema); @Override URI getUri(); @Override ResultSetCursor getDatatypePropertyValues(
			int[] datatypePropertyFilter, SuffixArray suffixArray); @Override ResultSetCursor getInstanceCandidates(
			Map<Integer, Set<Integer>> literalKeys); @Override ResultSetCursor dbSort(List<String> index, int maxLength); @Override int getLiteralIndex(String literal); @Override String getURI(int index); @Override String getLiteral(int index); @Override int getUriIndex(String uri); @Override ResultSetCursor getOutgoingRelations(int[] instances); @Override ResultSetCursor getIncomingRelations(int[] instances); @Override ResultSetCursor getRDFTypesForInstances(int[] subjects); @Override ResultSetCursor getInstancesOfTypes(int type, int count); @Override ResultSetCursor getRDFTypes(); @Override int[] getClusters(); @Override int[] getDatatypePropertyByClass(int cluster, double t); @Override Collection<int[]> getConnectingClusters(int objectProperty, double t); @Override int getCluster(int[] types); @Override int getPropertyType(int property); @Override void preprocessRdfData(InputStream[] datasets,
			MediaType rdfMimeType, MediaType fileMimeType,
			String absoluteBaseURI, LiteralHashing hashing); @Override void calculateCardinalities(); @Override double getSubjectCardinality(int p); @Override void calculateMarkovChain(int[] blackListedProperties,
			int sampleCount); @Override double getMarkovProbability(int subject, int predicate, int object); @Override List<double[]> getMaxMarkovProbability(int subject, int object, int k); @Override TIntObjectHashMap<TIntObjectHashMap<double[]>> getCoverageAmbiguity(); @Override void calculateProperNameStatistics(TextCorpus corpus, Pipeline pipe); @Override DoubleMatrix getTypeCorrelations(int samples); @Override void clusterCorrelatingClasses(int samples, double biasThreshold,
			double pruningThreshold); @Override void calculateRegexDistributions(String[] regexs); @Override TIntDoubleHashMap getDatatypePropertiesForRegex(String regex); @Override String[] getRegexs();  }