Search in sources :

Example 1 with ResultSetRewindable

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.");
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) Extractor(infoeval.main.WikiData.Extractor) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) RDFNode(org.apache.jena.rdf.model.RDFNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ResultSetRewindable

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;
}
Also used : ResultSetRewindable(org.apache.jena.query.ResultSetRewindable)

Example 3 with ResultSetRewindable

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;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable)

Example 4 with ResultSetRewindable

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable)

Example 5 with ResultSetRewindable

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();
}
Also used : ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)33 Test (org.junit.Test)16 BaseTest (org.apache.jena.atlas.junit.BaseTest)8 Extractor (infoeval.main.WikiData.Extractor)6 QuerySolution (org.apache.jena.query.QuerySolution)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ResultSet (org.apache.jena.query.ResultSet)4 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)3 Ignore (org.junit.Ignore)3 TableEntry (infoeval.main.mysql.TableEntry)2 Date (java.sql.Date)2 RowSet (org.apache.jena.sparql.exec.RowSet)2 Item (org.apache.jena.sparql.sse.Item)2 SqlTablesFiller (infoeval.main.WikiData.SqlTablesFiller)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1