@Override public boolean hasNext() { return currentState.hasNext(); }
@Override public void reset() { currentState.reset(); }
@Override public List<String> getResultVars() { return currentState.getResultVars(); }
private int[] colWidths(ResultSetRewindable rs) { int numCols = rs.getResultVars().size() ; int numRows = 0 ; int[] colWidths = new int[numCols] ; // Widths at least that of the variable name. Assumes we will print col headings. for ( int i = 0 ; i < numCols ; i++ ) colWidths[i] = (rs.getResultVars().get(i)).length() ; // Preparation pass : find the maximum width for each column for ( ; rs.hasNext() ; ) { numRows++ ; QuerySolution rBind = rs.nextSolution() ; int col = -1 ; for ( Iterator<String> iter = rs.getResultVars().iterator() ; iter.hasNext() ; ) { col++ ; String rVar = iter.next() ; String s = getVarValueAsString(rBind, rVar) ; if ( colWidths[col] < s.length() ) colWidths[col] = s.length() ; } } rs.reset() ; return colWidths ; }
int numCols = resultSetRewindable.getResultVars().size() ; int[] colWidths = colWidths(resultSetRewindable) ; pw.println() ; for ( ; resultSetRewindable.hasNext() ; ) QuerySolution rBind = resultSetRewindable.nextSolution() ; for ( int col = 0 ; col < numCols ; col++ )
@Override public QuerySolution nextSolution() { return currentState.nextSolution(); }
@Override public int getRowNumber() { return currentState.getRowNumber(); }
@Override public Model getResourceModel() { return currentState.getResourceModel(); }
@Override public QuerySolution next() { return currentState.nextSolution(); }
/** * Turn an existing result set into a rewindable one. * May take a copy but this is not guarantted * Uses up the result set passed in which is no longer valid as a ResultSet. * * @param resultSet * @return ResultSetRewindable */ static public ResultSetRewindable makeRewindable(ResultSet resultSet) { if ( resultSet instanceof ResultSetRewindable ) { ResultSetRewindable rsw = (ResultSetRewindable)resultSet ; rsw.reset() ; return rsw ; } return new ResultSetMem(resultSet); }
/** compare two result sets for equivalence. Equivalance means: * A row rs1 has one matching row in rs2, and vice versa. * A row is only matched once. * Rows match if they have the same variables with the same values, * bNodes must map to a consistent other bNodes. * Term comparisons of nodes. * * Destructive - rs1 and rs2 are both read, possibly to exhaustion. * @param rs1 * @param rs2 * @return true if they are equivalent */ public static boolean equalsByTerm(ResultSet rs1, ResultSet rs2) { if ( ! compareHeader(rs1, rs2) ) return false ; //return equivalent(convert(rs1), convert(rs2), new BNodeIso(NodeUtils.sameTerm)) ; ResultSetRewindable rs1a = ResultSetFactory.makeRewindable(rs1) ; ResultSetRewindable rs2a = ResultSetFactory.makeRewindable(rs2) ; if ( equivalent(convert(rs1a), convert(rs2a), new BNodeIso(NodeUtils.sameTerm)) ) return true ; rs1a.reset() ; rs2a.reset() ; return isomorphic(rs1, rs2) ; }
/** Compare two result sets for equivalence. Equivalance means: * A row rs1 has one matching row in rs2, and vice versa. * A row is only matched once. * Rows match if they have the same variables with the same values. * bNodes must map to a consistent other bNodes. Value comparisons of nodes. * * Destructive - rs1 and rs2 are both read, possibly to exhaustion. * @param rs1 * @param rs2 * @return true if they are equivalent */ public static boolean equalsByValue(ResultSet rs1, ResultSet rs2) { if ( ! compareHeader(rs1, rs2) ) return false ; //return equivalent(convert(rs1), convert(rs2), new BNodeIso(NodeUtils.sameValue)) ; // Add the isomprohism test // Imperfect - need by-value and isomorphism - but this covers test suite needs. ResultSetRewindable rs1a = ResultSetFactory.makeRewindable(rs1) ; ResultSetRewindable rs2a = ResultSetFactory.makeRewindable(rs2) ; if ( equivalent(convert(rs1a), convert(rs2a), new BNodeIso(NodeUtils.sameValue)) ) return true ; rs1a.reset() ; rs2a.reset() ; return isomorphic(rs1, rs2) ; }