Package org.apache.clerezza.rdf.core.sparql.query

Examples of org.apache.clerezza.rdf.core.sparql.query.Query


    queryStrBuf.append("SELECT ?").append(variable)
        .append(" FROM <").append(defaultGraph)
        .append("> WHERE { <").append(subject).append("> <")
        .append(predicate).append("> ?").append(variable).append(" . }");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass()));
    SelectQuery selectQuery = (SelectQuery) q;
    Assert.assertTrue(selectQuery.getSelection().get(0)
        .equals(new Variable(variable)));
    Assert.assertTrue(selectQuery.getDataSet().getDefaultGraphs().toArray()[0]
        .equals(new UriRef(defaultGraph)));
View Full Code Here


        new SimpleTriplePattern(s, p, o)));
  }

  @Test(expected=ParseException.class)
  public void testInvalidQuery() throws ParseException {
    Query q = QueryParser.getInstance().parse("Hello");
  }
View Full Code Here

    queryStrBuf.append("CONSTRUCT { <").append(subject1).append("> <")
        .append(predicate1).append("> ?").append(variable1)
        .append("} WHERE { ?").append(variable2).append(" <")
        .append(predicate2).append("> ?").append(variable1).append("}");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(ConstructQuery.class.isAssignableFrom(q.getClass()));
    ConstructQuery constructQuery = (ConstructQuery) q;
    Set<TriplePattern> triplePatterns = constructQuery
        .getConstructTemplate();
    Assert.assertTrue(triplePatterns.size()==1);
View Full Code Here

    final String resource = "http://example.org/book/book1";

    StringBuffer queryStrBuf = new StringBuffer();
    queryStrBuf.append("DESCRIBE <").append(resource).append(">");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(DescribeQuery.class.isAssignableFrom(q.getClass()));
    DescribeQuery describeQuery = (DescribeQuery) q;
    Assert.assertTrue(describeQuery.getResourcesToDescribe().get(0)
        .getResource().equals(new UriRef(resource)));
  }
View Full Code Here

    StringBuffer queryStrBuf = new StringBuffer();
    queryStrBuf.append("ASK { ?").append(variable).append(" <")
        .append(predicate).append("> \"").append(object).append("\" }");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(AskQuery.class.isAssignableFrom(q.getClass()));
    AskQuery askQuery = (AskQuery) q;

    GraphPattern gp = (GraphPattern) askQuery.getQueryPattern()
        .getGraphPatterns().toArray()[0];
    Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass()));
View Full Code Here

        .append(prefixUri).append("> SELECT $").append(variable)
        .append(" WHERE { <").append(subject).append("> ")
        .append(prefix).append(":").append(predicate).append(" ?")
        .append(variable).append(" }");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass()));
    SelectQuery selectQuery = (SelectQuery) q;
    Assert.assertTrue(selectQuery.getSelection().get(0)
        .equals(new Variable(variable)));

    GraphPattern gp = (GraphPattern) selectQuery.getQueryPattern()
View Full Code Here

        .append(" ?").append(variable2).append(" . OPTIONAL { ?")
        .append(variable1).append(" ").append(prefix2).append(":")
        .append(predicate2).append(" ?").append(variable3)
        .append(" .} FILTER ( ! bound(?").append(variable3).append(") ) }");

    Query q = QueryParser.getInstance().parse(queryStrBuf.toString());
    Assert.assertTrue(SelectQuery.class.isAssignableFrom(q.getClass()));
    SelectQuery selectQuery = (SelectQuery) q;
    Assert.assertTrue(selectQuery.getSelection().size() == 2);
    Set<Variable> vars = new HashSet<Variable>(2);
    Variable var1 = new Variable(variable1);
    Variable var2 = new Variable(variable2);
View Full Code Here

          || defaultGraphUri.getUnicodeString().equals("")) {
        defaultGraph = contentGraph;
      } else {
        defaultGraph = tcManager.getTriples(defaultGraphUri);
      }
      Query query = QueryParser.getInstance().parse(queryString);
      result = tcManager.executeSparqlQuery(query, defaultGraph);
      if (result instanceof Graph) {
        return (Graph) result;
      } else if ((result instanceof ResultSet)
          || (result instanceof Boolean)) {
View Full Code Here

        if(parsedQuery == null){
            throw new IllegalArgumentException("The parsed query MUST NOT be NULL!");
        }
        final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
        int limit = QueryUtils.getLimit(query, getConfig().getDefaultQueryResultNumber(), getConfig().getMaxQueryResultNumber());
        Query sparqlQuery;
        //NOTE:
        // - use the endpoint type standard, because we do not know what type of
        //   SPARQL implementation is configured for Clerezza via OSGI
        String sparqlQueryString = SparqlQueryUtils.createSparqlConstructQuery(
            query, limit,EndpointTypeEnum.Standard);
View Full Code Here

                       + " " + Symbols.hasRule.toString() + " ?rule . " + "  ?rule "
                       + Symbols.ruleName.toString() + " ?ruleName . " + "  ?rule "
                       + Symbols.ruleBody.toString() + " ?ruleBody . " + "  ?rule "
                       + Symbols.ruleHead.toString() + " ?ruleHead . " + "}";

        Query sparql;
        try {
            sparql = QueryParser.getInstance().parse(query);

            ResultSet resultSet = tcManager.executeSparqlQuery((SelectQuery) sparql, recipeGraph);
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.sparql.query.Query

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.