Package net.fortytwo.ripple.model

Examples of net.fortytwo.ripple.model.ModelConnection


        //base.shutDown();
    }

    @Override
    public SailConnection getConnection() throws SailException {
        ModelConnection mc;
        try {
            mc = model.createConnection();
        } catch (RippleException e) {
            throw new SailException(e);
        }
View Full Code Here


    public SesameModel(final Sail sail) throws RippleException {
        logger.fine("instantiating SesameModel");

        this.sail = sail;

        ModelConnection mc = createConnection();

        try {
            // TODO: eliminate this temporary value map
            specialValues = new SpecialValueMap();
            specialValues = new LibraryLoader().load(mc);

            // At the moment, op needs to be a special value for the sake of the
            // evaluator.  This has the side-effect of making "op" a keyword.
            specialValues.add(Operator.OP, mc);

            // The nil list also needs to be special, so "nil" is also incidentally a keyword.
            specialValues.add(mc.list(), mc);

            mc.commit();
        } finally {
            mc.close();
        }
    }
View Full Code Here

        RDFValue v = modelConnection.valueOf(u);
        assertEquals(s, v.sesameValue().stringValue());
    }

    public void testGrahamKlyneCases() throws Exception {
        ModelConnection mc = getTestModel().createConnection();

        // See: http://lists.w3.org/Archives/Public/uri/2006Feb/0003.html
        InputStream is = URITest.class.getResourceAsStream("UriTest.n3");

        RDFImporter importer = new RDFImporter(mc);
        SesameInputAdapter.parse(is, importer, "", RDFFormat.N3);
        mc.commit();

        Collector<RippleValue> cases = new Collector<RippleValue>();
        StatementPatternQuery query = new StatementPatternQuery(null, TYPE, URITEST);
        mc.query(query, cases, false);

        for (Object aCase : cases) {
            RippleValue caseValue = (RippleValue) aCase;
            (new UriTestCase(caseValue, mc)).test(mc);
        }

        is.close();
        mc.close();
    }
View Full Code Here

        assertEquals(nsCreated, ns);
        assertEquals(localNameCreated, localName);
    }

    public void testURINamespace() throws Exception {
        ModelConnection mc = getTestModel().createConnection();

        InputStream is = URITest.class.getResourceAsStream("UriNamespaceTest.txt");

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));
        int lineno = 0;

        // Break out when end of stream is reached.
        while (true) {
            String line = reader.readLine();
            lineno++;

            if (null == line)
                break;

            line = line.trim();

            if (!line.startsWith("#") && !line.equals("")) {
                String[] args = line.split("\t");
                if (args.length != 3)
                    throw new RippleException("wrong number of aguments on line " + lineno);
                namespaceTest(args[0], args[1], args[2], mc);
            }
        }

        is.close();
        mc.close();
    }
View Full Code Here

        assertReducesTo( "(1 2 3) rdf:type >>", "rdf:List" );
        */
    }

    public void testFromRDF() throws Exception {
        final ModelConnection mc = getTestModel().createConnection();

        InputStream is = RippleListTest.class.getResourceAsStream("listTest.ttl");
        RDFImporter importer = new RDFImporter(mc);
        SesameInputAdapter.parse(is, importer, "", RDFFormat.TURTLE);
        mc.commit();
        is.close();

        RDFValue head;
        Collector<RippleList> created = new Collector<RippleList>();
        final Collector<RippleList> allowed = new Collector<RippleList>();

        Sink<RippleList> verifySink = new Sink<RippleList>() {
            public void put(final RippleList list) throws RippleException {
                boolean found = false;

                for (Iterator<RippleList> iter = allowed.iterator(); iter.hasNext(); ) {
                    if (0 == mc.getComparator().compare(iter.next(), list)) {
                        found = true;
                        break;
                    }
                }

                assertTrue(found);
            }
        };

        RippleValue l1 = mc.valueOf("1", XMLSchema.STRING);
        RippleValue l2 = mc.valueOf("2", XMLSchema.STRING);
        RippleValue l1a = mc.valueOf("1a", XMLSchema.STRING);
        RippleValue l1b = mc.valueOf("1b", XMLSchema.STRING);
        RippleValue l2a = mc.valueOf("2a", XMLSchema.STRING);
        RippleValue l2b = mc.valueOf("2b", XMLSchema.STRING);

        head = new RDFValue(createURI("urn:test.RippleListTest.FromRdfTest#simpleList", mc));
        created.clear();
        mc.toList(head, created);
        assertEquals(1, created.size());
        allowed.clear();
        allowed.put(mc.list().push(l2).push(l1));
        created.writeTo(verifySink);

        head = new RDFValue(createURI("urn:test.RippleListTest.FromRdfTest#firstBranchingList", mc));
        created.clear();
        mc.toList(head, created);
        assertEquals(2, created.size());
        allowed.clear();
        allowed.put(mc.list().push(l2).push(l1a));
        allowed.put(mc.list().push(l2).push(l1b));
        created.writeTo(verifySink);

        head = new RDFValue(createURI("urn:test.RippleListTest.FromRdfTest#restBranchingList", mc));
        created.clear();
        mc.toList(head, created);
        assertEquals(2, created.size());
        allowed.clear();
        allowed.put(mc.list().push(l2a).push(l1));
        allowed.put(mc.list().push(l2b).push(l1));
        created.writeTo(verifySink);

        head = new RDFValue(createURI("urn:test.RippleListTest.FromRdfTest#firstAndRestBranchingList", mc));
        created.clear();
        mc.toList(head, created);
        assertEquals(4, created.size());
        allowed.clear();
        allowed.put(mc.list().push(l2a).push(l1a));
        allowed.put(mc.list().push(l2a).push(l1b));
        allowed.put(mc.list().push(l2b).push(l1a));
        allowed.put(mc.list().push(l2b).push(l1b));
        created.writeTo(verifySink);

        // Note: the circular list is not tested.

        mc.close();
    }
View Full Code Here

public class DatatypeSyntaxTest extends RippleTestCase {
    public void testBoolean() throws Exception {
        Collection<RippleList> results;
        RippleList stack;
        Literal l;
        ModelConnection mc = getTestModel().createConnection();

        results = reduce("true");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("true", l.getLabel());
        assertEquals(XMLSchema.BOOLEAN, l.getDatatype());

        results = reduce("false");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("false", l.getLabel());
        assertEquals(XMLSchema.BOOLEAN, l.getDatatype());

        mc.close();
    }
View Full Code Here

    public void testInteger() throws Exception {
        Collection<RippleList> results;
        RippleList stack;
        Literal l;
        ModelConnection mc = getTestModel().createConnection();

        results = reduce("0");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0", l.getLabel());
        assertEquals(XMLSchema.INTEGER, l.getDatatype());

        results = reduce("10");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("10", l.getLabel());
        assertEquals(XMLSchema.INTEGER, l.getDatatype());

        // Leading "-" sign
        results = reduce("-5");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("-5", l.getLabel());
        assertEquals(XMLSchema.INTEGER, l.getDatatype());

        // Leading "+" sign
        results = reduce("+1");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("1", l.getLabel());
        assertEquals(XMLSchema.INTEGER, l.getDatatype());

        // Leading zeroes
        results = reduce("042");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("42", l.getLabel());
        assertEquals(XMLSchema.INTEGER, l.getDatatype());

        mc.close();
    }
View Full Code Here

    public void testDouble() throws Exception {
        Collection<RippleList> results;
        RippleList stack;
        Literal l;
        ModelConnection mc = getTestModel().createConnection();

        results = reduce("0.0e0");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0.0", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Leading '-' on exponent.
        results = reduce("10E-02");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0.1", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Leading '+' on exponent.
        results = reduce("10.1E+2");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("1010.0", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Extra trailing zeroes are preserved (although according to the XML
        // Schema specification, they don't need to be).
        results = reduce("0.00e0");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0.0", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Leading "-" on mantissa
        results = reduce("-5e11");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("-5.0E11", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Leading "+" on mantissa
        results = reduce("+1.2e1");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("12.0", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        // Leading zeroes
        results = reduce("00042E99");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("4.2E100", l.getLabel());
        assertEquals(XMLSchema.DOUBLE, l.getDatatype());

        mc.close();
    }
View Full Code Here

    public void testDecimal() throws Exception {
        Collection<RippleList> results;
        RippleList stack;
        Literal l;
        ModelConnection mc = getTestModel().createConnection();

        results = reduce("0.0");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0.0", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        results = reduce("10.1");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("10.1", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        // Extra trailing zeroes are preserved (although according to the XML
        // Schema specification, they don't need to be).
        results = reduce("0.00");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("0.00", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        // Leading "-" sign
        results = reduce("-5.1");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("-5.1", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        // Leading "+" sign
        results = reduce("+1.2");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("1.2", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        // Leading zeroes
        results = reduce("00042.09");
        assertEquals(1, results.size());
        stack = results.iterator().next();
        assertEquals(1, stack.length());
        l = (Literal) stack.getFirst().toRDF(mc).sesameValue();
        assertEquals("42.09", l.getLabel());
        assertEquals(XMLSchema.DECIMAL, l.getDatatype());

        mc.close();
    }
View Full Code Here

        mc.close();
    }

    public void testListConcatenation() throws Exception {
        ModelConnection mc = getTestModel().createConnection();
        RippleValue
                a0 = mc.valueOf(42),
                a1 = mc.valueOf(137),
                a2 = mc.valueOf(23),
                b0 = mc.valueOf(216);
        mc.close();

        RippleList
                listA = mc.list().push(a2).push(a1).push(a0),
                listB = mc.list().push(b0);

        assertEquals(listA.length(), 3);
        assertEquals(listA.get(0), a0);
        assertEquals(listA.get(1), a1);
        assertEquals(listA.get(2), a2);
        assertEquals(listB.length(), 1);
        assertEquals(listB.get(0), b0);
        assertEquals(mc.list().length(), 0);

        RippleList lresult;

        lresult = listA.concat(listB);
        assertEquals(lresult.length(), 4);
        assertEquals(lresult.get(0), a0);
        assertEquals(lresult.get(1), a1);
        assertEquals(lresult.get(2), a2);
        assertEquals(lresult.get(3), b0);
        lresult = listB.concat(listA);
        assertEquals(lresult.length(), 4);
        assertEquals(lresult.get(0), b0);
        assertEquals(lresult.get(1), a0);
        assertEquals(lresult.get(2), a1);
        assertEquals(lresult.get(3), a2);

        lresult = listA.concat(mc.list());
        assertEquals(lresult.length(), 3);
        assertEquals(lresult.get(0), a0);
        assertEquals(lresult.get(1), a1);
        assertEquals(lresult.get(2), a2);

        lresult = mc.list().concat(listB);
        assertEquals(lresult.length(), 1);
        assertEquals(lresult.get(0), b0);

        lresult = mc.list().concat(mc.list());
        assertEquals(lresult.length(), 0);
        assertEquals(lresult, mc.list());
    }
View Full Code Here

TOP

Related Classes of net.fortytwo.ripple.model.ModelConnection

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.