Package uk.ac.osswatch.simal.model.jena

Examples of uk.ac.osswatch.simal.model.jena.SparqlResult


  private static final String QUERY_INVALID = QUERY_PREFIX + "SELECT *";

  @Test
  public void testSparqlQuery() {
    SparqlResult projects;
    String expectedVarName = "project";
    int expectedNrProjects = 10;
   
    try {
      projects = getJenaSimalRepository().getSparqlQueryResult(
          QUERY_ALL_PROJECTS);
      List<String> actualVarNames = projects.getVarNames();
      assertEquals(1, actualVarNames.size());
      assertEquals(expectedVarName, actualVarNames.get(0));
     
      Iterator<List<RDFNode>> projIter  = projects.getResultsIterator();
      int actualNrProjects =0;
      while (projIter.hasNext()) {
        List<RDFNode> curResult = projIter.next();
        assertEquals(1, curResult.size());
        assertNotNull(curResult.get(0));
View Full Code Here


   * @return
   * @throws SimalRepositoryException
   */
  public SparqlResult getSparqlQueryResult(String queryStr)
      throws SimalRepositoryException {
    SparqlResult sparqlResult = null;
    QueryExecution qe = null;

    try {
      Query query = QueryFactory.create(queryStr);
      qe = QueryExecutionFactory.create(query, model);
      ResultSet results = qe.execSelect();
      sparqlResult = new SparqlResult(results.getResultVars());

      while (results.hasNext()) {
        QuerySolution soln = results.nextSolution();
        List<RDFNode> result = new ArrayList<RDFNode>();
        Iterator<String> varNamesIter = soln.varNames();
        while (varNamesIter.hasNext()) {
          String varName = varNamesIter.next();
          result.add(soln.get(varName));
        }
        sparqlResult.addResult(result);
      }

    } catch (QueryException e) {
      String message = "QueryException when trying to SPARQLquery with query: "
          + queryStr;
View Full Code Here

TOP

Related Classes of uk.ac.osswatch.simal.model.jena.SparqlResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.