public static SPARQLResult copy(SPARQLResult that) { SPARQLResult result = that.isBoolean() ? new SPARQLResult(that.getBooleanResult()) : that.isDataset() ? new SPARQLResult(that.getDataset()) : that.isJson() ? new SPARQLResult(that.getJsonItems()) : that.isModel() ? new SPARQLResult(that.getModel()) : that.isResultSet() ? new SPARQLResult(that.getResultSet()) : null; return result; }
if (x.isResultSet()) RDFOutput.encodeAsRDF(model, x.getResultSet()); else if ( x.isBoolean() ) RDFOutput.encodeAsRDF(model, x.getBooleanResult()); else throw new ResultSetException("Not a result set");
@Override public ResultSet read(Reader in, Context context) { SPARQLResult result = ResultsStAX.read(in, null, context); return result.getResultSet(); } }
if ( results.isResultSet() ) resultsExpected = ResultSetFactory.makeRewindable(results.getResultSet()) ; else if ( results.isModel() ) resultsExpected = ResultSetFactory.makeRewindable(results.getModel()) ; else
/** Read a boolean result from the URI * * @param input * @return boolean */ public static boolean readBoolean(InputStream input) { Boolean b = readAny(input).getBooleanResult(); return b; }
void runTestAsk(Query query, QueryExecution qe) throws Exception { boolean result = qe.execAsk() ; if ( results != null ) { if ( results.isBoolean() ) { boolean b = results.getBooleanResult() ; assertEquals("ASK test results do not match", b, result) ; } else { Model resultsAsModel = results.getModel() ; StmtIterator sIter = results.getModel().listStatements(null, RDF.type, ResultSetGraphVocab.ResultSet) ; if ( !sIter.hasNext() ) throw new QueryTestException("Can't find the ASK result") ; Statement s = sIter.nextStatement() ; if ( sIter.hasNext() ) throw new QueryTestException("Too many result sets in ASK result") ; Resource r = s.getSubject() ; Property p = resultsAsModel.createProperty(ResultSetGraphVocab.getURI()+"boolean") ; boolean x = r.getRequiredProperty(p).getBoolean() ; if ( x != result ) assertEquals("ASK test results do not match", x,result); } } return ; }
private SPARQLResult read() { if ( isResultSet ) return new SPARQLResult(this); else return new SPARQLResult(askResult); }
private void compareDatasetResults(Dataset resultsActual, Query query) { if ( results != null ) { try { if ( ! results.isDataset() ) fail("Expected results are not a graph: "+testItem.getName()) ; Dataset resultsExpected = results.getDataset() ; if ( ! IsoMatcher.isomorphic( resultsExpected.asDatasetGraph(),resultsActual.asDatasetGraph() ) ) { printFailedDatasetTest(query, resultsExpected, resultsActual) ; fail("Results do not match: "+testItem.getName()) ; } } catch (Exception ex) { String typeName = (query.isConstructType()?"construct":"describe") ; fail("Exception in result testing ("+typeName+"): "+ex) ; } } }
public Boolean getBooleanResult() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isBoolean() ) throw new ResultSetException("Not a boolean result"); return booleanResult; }
public Model getModel() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isModel() ) throw new ResultSetException("Not a graph result"); return model; }
public Dataset getDataset() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isDataset() ) throw new ResultSetException("Not a dataset result"); return dataset; }
public ResultSet getResultSet() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isResultSet() ) throw new ResultSetException("Not a ResultSet result"); return resultSet; }
private void compareGraphResults(Model resultsActual, Query query) { if ( results != null ) { try { if ( ! results.isGraph() ) fail("Expected results are not a graph: "+testItem.getName()) ; Model resultsExpected = results.getModel() ; if ( ! resultsExpected.isIsomorphicWith(resultsActual) ) { printFailedModelTest(query, resultsExpected, resultsActual) ; fail("Results do not match: "+testItem.getName()) ; } } catch (Exception ex) { String typeName = (query.isConstructType()?"construct":"describe") ; fail("Exception in result testing ("+typeName+"): "+ex) ; } } }
public Iterator<JsonObject> getJsonItems() { if ( !hasBeenSet ) throw new ResultSetException("Not set"); if ( !isJson() ) throw new ResultSetException("Not a JSON result"); return jsonItems; }
/** * Read from an {@code InputStream} and produce a {@link ResultSet}. * Note that return result may stream and so the input stream may be read * while the {@link ResultSet} is used. * See {@link ResultSetFactory#copyResults(ResultSet)} for a ResultSet that is detached from the {@code InputStream}. * @param in InputStream to read from. * @param context * @return ResultSet */ public default ResultSet read(InputStream in, Context context) { return readAny(in, context).getResultSet(); }
/** Read a boolean result from the URI; * the input is expect to use syntax {@code lang} * * @param input * @param lang * @return boolean */ public static boolean readBoolean(InputStream input, Lang lang) { Boolean b = readAny(input, lang).getBooleanResult(); return b; }
@Override public SPARQLResult readAny(InputStream in, Context context) { // Not switchable. return new SPARQLResult(read(in, context)); } } ;
public SPARQLResultEx(SPARQLResult that) { if(that.isBoolean()) { set(that.getBooleanResult()); } else if(that.isDataset()) { set(that.getDataset()); } else if(that.isJson()) { set(that.getJsonItems()); } else if(that.isModel()) { set(that.getModel()); } else if(that.isResultSet()) { set(that.getResultSet()); } else { throw new IllegalArgumentException("Unknown SPARQLResult type"); } }
private ResultSet readResultSet(InputStream input, Lang lang) { return readAny(input, lang).getResultSet(); }
/** Read a boolean result from the URI * * @param urlOrFilename * @return boolean */ public static boolean readBoolean(String urlOrFilename) { Boolean b = readAny(urlOrFilename).getBooleanResult(); return b; }