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

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


                .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

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

        ResourceOrVariable s = new ResourceOrVariable(
                new UriRef("http://example.org/person#Alice"));
        UriRefOrVariable p = new UriRefOrVariable(
                new UriRef("http://www.w3.org/2001/vcard-rdf/3.0#FN"));
        ResourceOrVariable o = new ResourceOrVariable(new Variable("name"));
        Set<TriplePattern> constructTriplePatterns = new HashSet<TriplePattern>();
        constructTriplePatterns.add(new SimpleTriplePattern(s, p, o));
        SimpleConstructQuery constructQuery = new SimpleConstructQuery(constructTriplePatterns);

        s = new ResourceOrVariable(new Variable("x"));
        p = new UriRefOrVariable(new UriRef("http://xmlns.com/foaf/0.1/name"));
        Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
        triplePatterns.add(new SimpleTriplePattern(s, p, o));

        SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
View Full Code Here

    public void testAskQuery() {

        final String queryString = "ASK WHERE { ?x <http://xmlns.com/foaf/0.1/name> " +
                "\"Alice\"^^<http://www.w3.org/2001/XMLSchema#string> . }";

        ResourceOrVariable s = new ResourceOrVariable(new Variable("x"));
        UriRefOrVariable p = new UriRefOrVariable(
                new UriRef("http://xmlns.com/foaf/0.1/name"));
        ResourceOrVariable o = new ResourceOrVariable(
                LiteralFactory.getInstance().createTypedLiteral("Alice"));
View Full Code Here

                "?x <http://purl.org/dc/elements/1.1/title> ?title . " +
                "?x <http://example.org/ns#price> ?price . " +
                "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));
View Full Code Here

        final String queryString = "SELECT ?resource WHERE { " +
                "?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);
View Full Code Here

    @Test
    public void testOrderBy() {

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