Examples of SPARQLResult


Examples of no.priv.garshol.duke.utils.SparqlResult

    assertEquals("http://example.org", row[1]);
  }

  @Test
  public void testTwoRow2Col() throws IOException {
    SparqlResult result = load("sparql-tworow2col.xml");

    assertEquals(2, result.getVariables().size());
    assertEquals("x", result.getVariables().get(0));
    assertEquals("y", result.getVariables().get(1));

    List<String[]> results = result.getRows();
    assertEquals(2, results.size());
    String[] row = results.get(0);
    assertEquals(2, row.length);
    assertEquals("1", row[0]);
    assertEquals("http://example.org", row[1]);
View Full Code Here

Examples of no.priv.garshol.duke.utils.SparqlResult

    assertEquals("http://example.com", row[1]);   
  }

  @Test
  public void testTwoRow2ColInconsistent() throws IOException {
    SparqlResult result = load("sparql-tworow2col-inconsistent.xml");

    assertEquals(2, result.getVariables().size());
    assertEquals("x", result.getVariables().get(0));
    assertEquals("y", result.getVariables().get(1));

    List<String[]> results = result.getRows();
    assertEquals(2, results.size());
    String[] row = results.get(0);
    assertEquals(2, row.length);
    assertEquals("1", row[0]);
    assertEquals("http://example.org", row[1]);
View Full Code Here

Examples of no.priv.garshol.duke.utils.SparqlResult

    assertEquals("http://example.com", row[1]);   
  }

  @Test
  public void testBnode() throws IOException {
    SparqlResult result = load("sparql-bnode.xml");
    assertEquals(1, result.getVariables().size());
    assertEquals("x", result.getVariables().get(0));
   
    assertEquals(1, result.getRows().size());
    String[] row = result.getRows().get(0);
    assertEquals(1, row.length);
    assertEquals("r2", row[0]);
}
View Full Code Here

Examples of org.apache.marmotta.client.model.sparql.SPARQLResult

                    if(!results.getHandledTuple() || results.getBindingSets().isEmpty()) {
                        return null;
                    } else {
                        List<String> fieldNames = results.getBindingNames();

                        SPARQLResult result = new SPARQLResult(new LinkedHashSet<String>(fieldNames));

                        //List<?> bindings = resultMap.get("results").get("bindings");
                        for(BindingSet nextRow : results.getBindingSets()) {
                            Map<String,RDFNode> row = new HashMap<String, RDFNode>();
                           
                            for(String nextBindingName : fieldNames) {
                                if(nextRow.hasBinding(nextBindingName)) {
                                    Binding nextBinding = nextRow.getBinding(nextBindingName);
                                    //Map<String,String> nodeDef = (Map<String,String>) entry.getValue();
                                    Value nodeDef = nextBinding.getValue();
                                    RDFNode node = null;
                                    if(nodeDef instanceof org.openrdf.model.URI) {
                                        node = new URI(nodeDef.stringValue());
                                    } else if(nodeDef instanceof org.openrdf.model.BNode) {
                                        node = new BNode(((org.openrdf.model.BNode)nodeDef).getID());
                                    } else if(nodeDef instanceof org.openrdf.model.Literal) {
                                        org.openrdf.model.Literal nodeLiteral = (org.openrdf.model.Literal)nodeDef;
                                        if(nodeLiteral.getLanguage() != null) {
                                            node = new Literal(nodeLiteral.getLabel(), nodeLiteral.getLanguage());
                                        } else if(nodeLiteral.getDatatype() != null) {
                                            node = new Literal(nodeLiteral.getLabel(), new URI(nodeLiteral.getDatatype().stringValue()));
                                        } else {
                                            node = new Literal(nodeLiteral.getLabel());
                                        }
                                    } else {
                                        log.error("unknown result node type: {}",nodeDef);
                                    }
                                   
                                    if(node != null) {
                                        row.put(nextBindingName, node);
                                    }
                                }
                            }
                            result.add(row);
                        }
                        return result;
                    }
                default:
                    log.error("error evaluating SPARQL Select Query {}: {} {}",new Object[] {query,response.getStatusLine().getStatusCode(),response.getStatusLine().getReasonPhrase()});
View Full Code Here

Examples of org.apache.marmotta.client.model.sparql.SPARQLResult

    @Test
    public void testSparqlSelect() throws Exception {
        SPARQLClient client = new SPARQLClient(config);

        SPARQLResult result = client.select("SELECT ?r ?n WHERE { ?r <http://xmlns.com/foaf/0.1/name> ?n }");
        Assert.assertEquals(3, result.size());
        Assert.assertThat(result, (Matcher) hasItems(hasKey("r"), hasKey("n")));
        Assert.assertThat(result,(Matcher)hasItem(hasValue(hasProperty("content", equalTo("Sepp Huber")))));
    }
View Full Code Here

Examples of org.apache.marmotta.client.model.sparql.SPARQLResult

                            if(o instanceof String) {
                                fieldNames.add((String)o);
                            }
                        }

                        SPARQLResult result = new SPARQLResult(fieldNames);

                        List<?> bindings = resultMap.get("results").get("bindings");
                        for(Object o : bindings) {
                            if(o instanceof Map) {
                                Map<String,RDFNode> row = new HashMap<String, RDFNode>();
                                for(Map.Entry<String,?> entry : ((Map<String,?>)o).entrySet()) {
                                    Map<String,String> nodeDef = (Map<String,String>) entry.getValue();
                                    RDFNode node = null;
                                    if("uri".equalsIgnoreCase(nodeDef.get("type"))) {
                                        node = new URI(nodeDef.get("value"));
                                    } else if("literal".equalsIgnoreCase(nodeDef.get("type")) ||
                                              "typed-literal".equalsIgnoreCase(nodeDef.get("type"))) {
                                        String lang = nodeDef.get("xml:lang");
                                        String datatype = nodeDef.get("datatype");

                                        if(lang != null) {
                                            node = new Literal(nodeDef.get("value"),lang);
                                        } else if(datatype != null) {
                                            node = new Literal(nodeDef.get("value"),new URI(datatype));
                                        } else {
                                            node = new Literal(nodeDef.get("value"));
                                        }
                                    } else if("bnode".equalsIgnoreCase(nodeDef.get("type"))) {
                                        node = new BNode(nodeDef.get("value"));
                                    } else {
                                        log.error("unknown result node type: {}",nodeDef.get("type"));
                                    }
                                   
                                    if(node != null) {
                                        row.put(entry.getKey(),node);
                                    }
                                }
                                result.add(row);
                            }
                        }
                        return result;
                    }
                default:
View Full Code Here

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

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

   * @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
Copyright © 2018 www.massapi.com. 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.