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

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


        Query q = QueryParser.getInstance().parse("Hello");
    }

    @Test
    public void testSelectQuerySelection() throws ParseException {
        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


    }

    @Test
    public void testSelectAll() throws ParseException {
        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

    }

    @Test
    public void testPlainLiteral() throws ParseException {
        SelectQuery q = (SelectQuery) QueryParser.getInstance().parse(
                "SELECT * WHERE {?a ?x 'tiger' . ?a ?x 'lion'@en . }");

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

        Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
View Full Code Here

                new PlainLiteralImpl("lion", new Language("en")))));
    }

    @Test
    public void testOrderBy() throws ParseException {
        SelectQuery q = (SelectQuery) QueryParser.getInstance().parse(
                "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());
View Full Code Here

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

        Set<TriplePattern> triplePatterns = bgp.getTriplePatterns();
View Full Code Here

                .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);
        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("!"));
View Full Code Here

                        "?type = t:Organization " +
                        ")" +
                        "} ";
        Collection<CalaisEntityOccurrence> result = new ArrayList<CalaisEntityOccurrence>();
        try {
            SelectQuery sQuery = (SelectQuery) QueryParser.getInstance().parse(query);
            ResultSet rs = tcManager.executeSparqlQuery(sQuery, model);
            while (rs.hasNext()) {
                SolutionMapping row = rs.next();
                CalaisEntityOccurrence occ = new CalaisEntityOccurrence();
                Resource disambiguated = row.get("did");
View Full Code Here

    }
  }

  private void addField(SolrContentItem sci, SolrInputDocument doc,
      SolrFieldName fieldName) {
    SelectQuery query = null;
    try {
      query = (SelectQuery) QueryParser.getInstance().parse(
          QueryGenerator.getFieldQuery(fieldName));
    } catch (ParseException e) {
      log.debug("Should never reach here!");
View Full Code Here

      log.error("", ex);
      throw new StoreException(ex.getMessage(), ex);
    }

    String enhancementQuery = QueryGenerator.getEnhancementsOfContent(id);
    SelectQuery selectQuery = null;
    try {
      selectQuery = (SelectQuery) QueryParser.getInstance().parse(
          enhancementQuery);
    } catch (ParseException e) {
      String msg = "Cannot parse the SPARQL while trying to retrieve the enhancements of the ContentItem";
View Full Code Here

                        "?type = t:Organization " +
                        ")" +
                        "} ";
        Collection<CalaisEntityOccurrence> result = new ArrayList<CalaisEntityOccurrence>();
        try {
            SelectQuery sQuery = (SelectQuery) QueryParser.getInstance().parse(query);
            ResultSet rs = tcManager.executeSparqlQuery(sQuery, model);
            while (rs.hasNext()) {
                SolutionMapping row = rs.next();
                CalaisEntityOccurrence occ = new CalaisEntityOccurrence();
                Resource disambiguated = row.get("did");
View Full Code Here

TOP

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

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.