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

Examples of org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSelectQuery


    final String queryString = "SELECT ?title FROM <http://example.org/library>" +
        " WHERE { <http://example.org/book/book1>" +
        " <http://purl.org/dc/elements/1.1/title> ?title . }";

    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    Variable variable = new Variable("title");
    selectQuery.addSelection(variable);
    UriRef defaultGraph = new UriRef("http://example.org/library");
    selectQuery.addDefaultGraph(defaultGraph);
    ResourceOrVariable subject = new ResourceOrVariable(
        new UriRef("http://example.org/book/book1"));
    UriRefOrVariable predicate = new UriRefOrVariable(
        new UriRef("http://purl.org/dc/elements/1.1/title"));
    ResourceOrVariable object = new ResourceOrVariable(variable);
    TriplePattern triplePattern = new SimpleTriplePattern(subject, predicate, object);
    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(triplePattern);

    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(bgp);
    selectQuery.setQueryPattern(queryPattern);

    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here


        "FILTER ((?price) < (\"30.5\"^^<http://www.w3.org/2001/XMLSchema#double>)) " +
        "}";

    Variable price = new Variable("price");
    Variable title = new Variable("title");
    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    selectQuery.addSelection(title);
    selectQuery.addSelection(price);

    Variable x = new Variable("x");
    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(new SimpleTriplePattern(x,
        new UriRef("http://example.org/ns#price"), price));
    triplePatterns.add(new SimpleTriplePattern(x,
        new UriRef("http://purl.org/dc/elements/1.1/title"), title));

    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(bgp);
    BinaryOperation constraint = new BinaryOperation("<",
        price, new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(30.5)));
    queryPattern.addConstraint(constraint);
    selectQuery.setQueryPattern(queryPattern);

    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here

        "?resource <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?myType . " +
        "FILTER ((?resource) = (<http://example.org/ontology#special>)) " +
        "}";

    Variable resource = new Variable("resource");
    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    selectQuery.addSelection(resource);

    Variable myType = new Variable("myType");
    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(new SimpleTriplePattern(resource,
        new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), myType));

    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(bgp);
    BinaryOperation constraint = new BinaryOperation("=",
        resource, new UriRefExpression(new UriRef("http://example.org/ontology#special")));
    queryPattern.addConstraint(constraint);
    selectQuery.setQueryPattern(queryPattern);

    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here

    final String queryString = "SELECT * WHERE { ?a ?b ?c . } ORDER BY DESC(?c)";

    Variable a = new Variable("a");
    Variable b = new Variable("b");
    Variable c = new Variable("c");
    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    selectQuery.setSelectAll();
    selectQuery.addSelection(a);
    selectQuery.addSelection(b);
    selectQuery.addSelection(c);

    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(new SimpleTriplePattern(a, b, c));
    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(bgp);
    selectQuery.setQueryPattern(queryPattern);
    selectQuery.addOrderCondition(new SimpleOrderCondition(c, false));

    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here

        "OPTIONAL { ?x <http://example.org/ns#price> ?price . } " +
        "}";

    Variable title = new Variable("title");
    Variable price = new Variable("price");
    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    selectQuery.addSelection(title);
    selectQuery.addSelection(price);

    Variable x = new Variable("x");
    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(new SimpleTriplePattern(x,
        new UriRef("http://purl.org/dc/elements/1.1/title"), title));

    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);

    Set<TriplePattern> triplePatternsOpt = new HashSet<TriplePattern>();
    triplePatternsOpt.add(new SimpleTriplePattern(x,
        new UriRef("http://example.org/ns#price"), price));

    SimpleBasicGraphPattern bgpOpt =
        new SimpleBasicGraphPattern(triplePatternsOpt);

    SimpleGroupGraphPattern ggpOpt = new SimpleGroupGraphPattern();
    ggpOpt.addGraphPattern(bgpOpt);

    SimpleOptionalGraphPattern ogp = new SimpleOptionalGraphPattern(bgp, ggpOpt);

    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(ogp);
    selectQuery.setQueryPattern(queryPattern);

    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here

    final String queryString = "SELECT ?p WHERE { " +
        "<http://localhost/testitem> ?p ?x . " +
        "FILTER REGEX(?x,\".*uni.*\"^^<http://www.w3.org/2001/XMLSchema#string>) }";

    Variable p = new Variable("p");
    SimpleSelectQuery selectQuery = new SimpleSelectQuery();
    selectQuery.addSelection(p);

    Variable x = new Variable("x");
    Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
    triplePatterns.add(new SimpleTriplePattern(
        new UriRef("http://localhost/testitem"), p, x));

    SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
    SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
    queryPattern.addGraphPattern(bgp);

    List<Expression> arguments = new ArrayList<Expression>();
    arguments.add(x);
    arguments.add(new LiteralExpression(LiteralFactory.getInstance().
        createTypedLiteral(".*uni.*")));
    BuiltInCall constraint = new BuiltInCall("REGEX", arguments);
    queryPattern.addConstraint(constraint);
    selectQuery.setQueryPattern(queryPattern);
    Assert.assertTrue(selectQuery.toString()
        .replaceAll("( |\n)+", " ").trim().equals(queryString));
  }
View Full Code Here

        final String queryString = "SELECT ?title FROM <http://example.org/library>" +
                " WHERE { <http://example.org/book/book1>" +
                " <http://purl.org/dc/elements/1.1/title> ?title . }";

        SimpleSelectQuery selectQuery = new SimpleSelectQuery();
        Variable variable = new Variable("title");
        selectQuery.addSelection(variable);
        UriRef defaultGraph = new UriRef("http://example.org/library");
        selectQuery.addDefaultGraph(defaultGraph);
        ResourceOrVariable subject = new ResourceOrVariable(
                new UriRef("http://example.org/book/book1"));
        UriRefOrVariable predicate = new UriRefOrVariable(
                new UriRef("http://purl.org/dc/elements/1.1/title"));
        ResourceOrVariable object = new ResourceOrVariable(variable);
        TriplePattern triplePattern = new SimpleTriplePattern(subject, predicate, object);
        Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
        triplePatterns.add(triplePattern);

        SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
        SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
        queryPattern.addGraphPattern(bgp);
        selectQuery.setQueryPattern(queryPattern);

        Assert.assertTrue(selectQuery.toString()
                .replaceAll("( |\n)+", " ").trim().equals(queryString));
    }
View Full Code Here

                "FILTER ((?price) < (\"30.5\"^^<http://www.w3.org/2001/XMLSchema#double>)) " +
                "}";

        Variable price = new Variable("price");
        Variable title = new Variable("title");
        SimpleSelectQuery selectQuery = new SimpleSelectQuery();
        selectQuery.addSelection(title);
        selectQuery.addSelection(price);

        Variable x = new Variable("x");
        Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
        triplePatterns.add(new SimpleTriplePattern(x,
                new UriRef("http://example.org/ns#price"), price));
        triplePatterns.add(new SimpleTriplePattern(x,
                new UriRef("http://purl.org/dc/elements/1.1/title"), title));

        SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
        SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
        queryPattern.addGraphPattern(bgp);
        BinaryOperation constraint = new BinaryOperation("<",
                price, new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(30.5)));
        queryPattern.addConstraint(constraint);
        selectQuery.setQueryPattern(queryPattern);

        Assert.assertTrue(selectQuery.toString()
                .replaceAll("( |\n)+", " ").trim().equals(queryString));
    }
View Full Code Here

                "?resource <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?myType . " +
                "FILTER ((?resource) = (<http://example.org/ontology#special>)) " +
                "}";

        Variable resource = new Variable("resource");
        SimpleSelectQuery selectQuery = new SimpleSelectQuery();
        selectQuery.addSelection(resource);

        Variable myType = new Variable("myType");
        Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
        triplePatterns.add(new SimpleTriplePattern(resource,
                new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), myType));

        SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
        SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
        queryPattern.addGraphPattern(bgp);
        BinaryOperation constraint = new BinaryOperation("=",
                resource, new UriRefExpression(new UriRef("http://example.org/ontology#special")));
        queryPattern.addConstraint(constraint);
        selectQuery.setQueryPattern(queryPattern);

        Assert.assertTrue(selectQuery.toString()
                .replaceAll("( |\n)+", " ").trim().equals(queryString));
    }
View Full Code Here

        final String queryString = "SELECT * WHERE { ?a ?b ?c . } ORDER BY DESC(?c)";

        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        SimpleSelectQuery selectQuery = new SimpleSelectQuery();
        selectQuery.setSelectAll();
        selectQuery.addSelection(a);
        selectQuery.addSelection(b);
        selectQuery.addSelection(c);

        Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
        triplePatterns.add(new SimpleTriplePattern(a, b, c));
        SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
        SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
        queryPattern.addGraphPattern(bgp);
        selectQuery.setQueryPattern(queryPattern);
        selectQuery.addOrderCondition(new SimpleOrderCondition(c, false));

        Assert.assertTrue(selectQuery.toString()
                .replaceAll("( |\n)+", " ").trim().equals(queryString));
    }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSelectQuery

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.