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

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


    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)));

    GraphPattern gp = (GraphPattern) selectQuery.getQueryPattern()
        .getGraphPatterns().toArray()[0];
    Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass()));
    BasicGraphPattern bgp = (BasicGraphPattern) gp;

    Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
    Assert.assertTrue(triplePatterns.size()==1);

    ResourceOrVariable s = new ResourceOrVariable(new UriRef(subject));
    UriRefOrVariable p = new UriRefOrVariable(new UriRef(predicate));
    ResourceOrVariable o = new ResourceOrVariable(new Variable(variable));

    Assert.assertTrue(triplePatterns.contains(
        new SimpleTriplePattern(s, p, o)));
  }
View Full Code Here


    SelectQuery q = (SelectQuery) QueryParser.getInstance().parse(
        "SELECT ?a ?b WHERE {?a ?x ?b}");
    Set<Variable> selectionSet = new HashSet<Variable>(
        q.getSelection());
    Set<Variable> expected = new HashSet<Variable>();
    expected.add(new Variable("a"));
    expected.add(new Variable("b"));
    Assert.assertEquals(expected, selectionSet);
    Assert.assertFalse(q.isSelectAll());

  }
View Full Code Here

    SelectQuery q = (SelectQuery) QueryParser.getInstance().parse(
        "SELECT * WHERE {?a ?x ?b}");
    Set<Variable> selectionSet = new HashSet<Variable>(
        q.getSelection());
    Set<Variable> expected = new HashSet<Variable>();
    expected.add(new Variable("a"));
    expected.add(new Variable("b"));
    expected.add(new Variable("x"));
    Assert.assertEquals(expected, selectionSet);
    Assert.assertTrue(q.isSelectAll());

  }
View Full Code Here

    Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
    Assert.assertTrue(triplePatterns.size()==2);

    Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern(
        new Variable("a"), new Variable("x"),
        new PlainLiteralImpl("tiger"))));

    Assert.assertTrue(triplePatterns.contains(new SimpleTriplePattern(
        new Variable("a"), new Variable("x"),
        new PlainLiteralImpl("lion", new Language("en")))));
  }
View Full Code Here

        "SELECT * WHERE {?a ?x ?b} ORDER BY DESC(?b)");

    List<OrderCondition> oc = ((QueryWithSolutionModifier) q).getOrderConditions();
    Assert.assertTrue(oc.size()==1);
    Assert.assertFalse(oc.get(0).isAscending());
    Variable b = new Variable("b");
    Assert.assertEquals(b, oc.get(0).getExpression());
  }
View Full Code Here

        .getConstructTemplate();
    Assert.assertTrue(triplePatterns.size()==1);

    ResourceOrVariable s = new ResourceOrVariable(new UriRef(subject1));
    UriRefOrVariable p = new UriRefOrVariable(new UriRef(predicate1));
    ResourceOrVariable o = new ResourceOrVariable(new Variable(variable1));

    Assert.assertTrue(triplePatterns.contains(
        new SimpleTriplePattern(s, p, o)));

    GraphPattern gp = (GraphPattern) constructQuery.getQueryPattern()
        .getGraphPatterns().toArray()[0];
    Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass()));
    BasicGraphPattern bgp = (BasicGraphPattern) gp;
    triplePatterns = bgp.getTriplePatterns();
    Assert.assertTrue(triplePatterns.size()==1);

    s = new ResourceOrVariable(new Variable(variable2));
    p = new UriRefOrVariable(new UriRef(predicate2));

    Assert.assertTrue(triplePatterns.contains(
        new SimpleTriplePattern(s, p, o)));
  }
View Full Code Here

    Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
    Assert.assertTrue(triplePatterns.size()==1);

    Assert.assertTrue(triplePatterns.contains(
        new SimpleTriplePattern(new Variable(variable),
        new UriRef(predicate), new PlainLiteralImpl(object))));
  }
View Full Code Here

    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()
        .getGraphPatterns().toArray()[0];
    Assert.assertTrue(BasicGraphPattern.class.isAssignableFrom(gp.getClass()));
    BasicGraphPattern bgp = (BasicGraphPattern) gp;

    Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
    Assert.assertTrue(triplePatterns.size()==1);

    ResourceOrVariable s = new ResourceOrVariable(new UriRef(base+subject));
    UriRefOrVariable p = new UriRefOrVariable(new UriRef(prefixUri+predicate));
    ResourceOrVariable o = new ResourceOrVariable(new Variable(variable));

    Assert.assertTrue(triplePatterns.contains(
        new SimpleTriplePattern(s, p, o)));
  }
View Full Code Here

    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);
    vars.add(var1);
    vars.add(var2);
    Assert.assertTrue(selectQuery.getSelection().containsAll(vars));

    GroupGraphPattern ggp = selectQuery.getQueryPattern();
    List<Expression> constraints = ggp.getFilter();
    Assert.assertTrue(UnaryOperation.class.isAssignableFrom(constraints
        .get(0).getClass()));
    UnaryOperation uop = (UnaryOperation) constraints.get(0);
    Assert.assertTrue(uop.getOperatorString().equals("!"));
    Assert.assertTrue(BuiltInCall.class.isAssignableFrom(uop.getOperand()
        .getClass()));
    BuiltInCall bic = (BuiltInCall) uop.getOperand();
    Assert.assertTrue(bic.getName().equals("BOUND"));
    Variable var3 = new Variable(variable3);
    Assert.assertTrue(bic.getArguements().get(0).equals(var3));

    GraphPattern gp = (GraphPattern) ggp.getGraphPatterns().toArray()[0];
    Assert.assertTrue(OptionalGraphPattern.class.isAssignableFrom(gp.getClass()));
    OptionalGraphPattern ogp = (OptionalGraphPattern) gp;
View Full Code Here

  Jena2TriaUtil convertor = new Jena2TriaUtil(new HashMap<Node,BNode>());
  public HashMapSolutionMapping(QuerySolution querySolution) {
    final Iterator<String> varNames = querySolution.varNames();
    while (varNames.hasNext()) {
      final String varName = varNames.next();
      put(new Variable(varName), toResource(querySolution.get(varName)));
    }
  }
View Full Code Here

TOP

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

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.