use of org.apache.jena.query.ResultSetRewindable in project Info-Evaluation by TechnionYP5777.
the class ExtractorTest method abstractTest.
@Ignore
@Test
public void abstractTest() {
String name = "Jessica Zelinka", newName = WordUtils.capitalize(name).replaceAll(" ", "_");
Extractor extr = new Extractor(newName);
extr.executeQuery(QueryTypes.ABSTRACT);
ResultSetRewindable results = extr.getResults();
results.reset();
QuerySolution solution = results.nextSolution();
RDFNode overview = solution.get("abstract");
String overviewStr = "No Abstract";
if (overview != null)
if (overview.isResource())
overviewStr = (overview.asResource() + "").split("resource/")[1];
else if (overview.isLiteral())
overviewStr = (overview.asLiteral() + "").split("@")[0];
assertEquals(overviewStr, "Jessica Zelinka (born September 3, 1981 in London, Ontario) is a Canadian pentathlete, heptathlete, and 100 m hurdler. Her personal best score is 6599 points for the heptathlon. She was the gold medalist at the 2007 Pan American Games. Zelinka won silver at the 2010 Commonwealth Games and repeated her silver medal at the 2014 Commonwealth Games. At the 2012 Summer Olympics Zelinka finished in 7th overall in both the heptathlon and 100 m hurdles.");
}
use of org.apache.jena.query.ResultSetRewindable in project jena by apache.
the class QueryTest method runTestSelect.
void runTestSelect(Query query, QueryExecution qe) {
// Do the query!
ResultSetRewindable resultsActual = ResultSetFactory.makeRewindable(qe.execSelect());
qe.close();
if (results == null)
return;
// Assumes resultSetCompare can cope with full isomorphism possibilities.
ResultSetRewindable resultsExpected;
if (results.isResultSet())
resultsExpected = ResultSetFactory.makeRewindable(results.getResultSet());
else if (results.isModel())
resultsExpected = ResultSetFactory.makeRewindable(results.getModel());
else {
fail("Wrong result type for SELECT query");
// Keep the compiler happy
resultsExpected = null;
}
if (query.isReduced()) {
// Reduced - best we can do is DISTINCT
resultsExpected = unique(resultsExpected);
resultsActual = unique(resultsActual);
}
// Hack for CSV : tests involving bNodes need manually checking.
if (testItem.getResultFile().endsWith(".csv")) {
resultsActual = convertToStrings(resultsActual);
resultsActual.reset();
int nActual = ResultSetFormatter.consume(resultsActual);
int nExpected = ResultSetFormatter.consume(resultsExpected);
resultsActual.reset();
resultsExpected.reset();
assertEquals("CSV: Different number of rows", nExpected, nActual);
boolean b = resultSetEquivalent(query, resultsExpected, resultsActual);
if (!b)
System.out.println("Manual check of CSV results required: " + testItem.getName());
return;
}
boolean b = resultSetEquivalent(query, resultsExpected, resultsActual);
if (!b) {
resultsExpected.reset();
resultsActual.reset();
boolean b2 = resultSetEquivalent(query, resultsExpected, resultsActual);
printFailedResultSetTest(query, qe, resultsExpected, resultsActual);
}
assertTrue("Results do not match", b);
return;
}
use of org.apache.jena.query.ResultSetRewindable in project jena by apache.
the class TextOutput method write.
/** Textual representation : layout using given separator.
* Ensure the PrintWriter can handle UTF-8.
* @param pw PrintWriter
* @param colSep Column separator
*/
public void write(PrintWriter pw, ResultSet resultSet, String colStart, String colSep, String colEnd) {
if (resultSet.getResultVars().size() == 0) {
pw.println("==== No variables ====");
// return ;
}
ResultSetRewindable resultSetRewindable = ResultSetFactory.makeRewindable(resultSet);
int numCols = resultSetRewindable.getResultVars().size();
int[] colWidths = colWidths(resultSetRewindable);
String[] row = new String[numCols];
int lineWidth = 0;
for (int col = 0; col < numCols; col++) {
String rVar = resultSet.getResultVars().get(col);
row[col] = rVar;
lineWidth += colWidths[col];
if (col > 0)
lineWidth += colSep.length();
}
if (colStart != null)
lineWidth += colStart.length();
if (colEnd != null)
lineWidth += colEnd.length();
for (int i = 0; i < lineWidth; i++) pw.print('-');
pw.println();
printRow(pw, row, colWidths, colStart, colSep, colEnd);
for (int i = 0; i < lineWidth; i++) pw.print('=');
pw.println();
for (; resultSetRewindable.hasNext(); ) {
QuerySolution rBind = resultSetRewindable.nextSolution();
for (int col = 0; col < numCols; col++) {
String rVar = resultSet.getResultVars().get(col);
row[col] = this.getVarValueAsString(rBind, rVar);
}
printRow(pw, row, colWidths, colStart, colSep, colEnd);
}
for (int i = 0; i < lineWidth; i++) pw.print('-');
pw.println();
resultSetRewindable = null;
}
use of org.apache.jena.query.ResultSetRewindable in project jena by apache.
the class TestResultSetThrift method test.
private static ResultSetRewindable test(ResultSetRewindable resultSet) {
resultSet.reset();
ByteArrayOutputStream out = new ByteArrayOutputStream();
BinRDF.writeResultSet(out, resultSet, true);
resultSet.reset();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ResultSet rs$ = BinRDF.readResultSet(in);
ResultSetRewindable resultSet2 = ResultSetFactory.makeRewindable(rs$);
// Includes bnode labels.
ResultSetCompare.equalsExact(resultSet, resultSet2);
resultSet.reset();
resultSet2.reset();
return resultSet2;
}
use of org.apache.jena.query.ResultSetRewindable in project jena by apache.
the class TestResultSetThrift method resultSet_02.
@Test
public void resultSet_02() {
ResultSetRewindable r1 = test(rs1);
// not reordered
r1.reset();
rs2.reset();
assertFalse(ResultSetCompare.equalsByTermAndOrder(r1, rs2));
rs2.reset();
}
Aggregations