Package org.openrdf.sail

Examples of org.openrdf.sail.Sail


            transientSail.shutDown();
        }
    }

    private void testSocketBasedLoggingTransientMemoryPersister() throws Exception {
        Sail baseSail = new MemoryStore();
        baseSail.initialize();

        DatagramSocket s = new DatagramSocket();

        String msg = "15663\tADD_STATEMENT\t<http://twitlogic.fortytwo.net/post/twitter/-1129589402>\t<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\t<http://rdfs.org/sioc/types#MicroblogPost>\t{}";
        byte[] buf = msg.getBytes();
View Full Code Here


        File dir = new File("/tmp/twitlogic-stresstest-ns");
        if (dir.exists()) {
            deleteDirectory(dir);
        }

        Sail sail = new NativeStore(dir);
        sail.initialize();

        try {
            TweetStore store = new TweetStore(sail);
            store.initialize();
            try {
                TweetPersister p = new TweetPersister(store, null);

                stressTest(p, 1000);
            } finally {
                store.shutDown();
            }
        } finally {
            sail.shutDown();
        }
    }
View Full Code Here

    // Over the LAN: 6 t/s
    // Locally: 7 t/s
    private void testAllegroGraphPersister() throws Exception {
        SailFactory f = new AGRepositorySailFactory(TwitLogic.getConfiguration(), false);
        Sail sail = f.makeSail();
        sail.initialize();

        try {
            TweetStore store = new TweetStore(sail);
            store.initialize();
            try {
                TweetPersister p = new TweetPersister(store, null);

                stressTest(p, 10);
            } finally {
                store.shutDown();
            }
        } finally {
            sail.shutDown();
        }
    }
View Full Code Here

        int udpOutputPorts[] = {9992};//{9990, 9991, 9992, 9993, 9994, 9995};//, 9996, 9997};

//            InetAddress address = InetAddress.getByName("foray");
        //int port = 9999;

        Sail workingSail = new MemoryStore();
        workingSail.initialize();

        try {
            Sail streamingSail = new UdpTransactionSail(workingSail, address, udpOutputPorts);

            try {
                TweetStore store = new TweetStore(streamingSail);
                store.doNotRefreshCoreMetadata();
                store.initialize();

                try {
                    // A connection with which to repeatedly clear the working store
                    final SailConnection c = workingSail.getConnection();

                    try {
                        // Offline persister
                        final TweetPersister p = new TweetPersister(store, null);

                        try {
                            Handler<Tweet> h = new Handler<Tweet>() {
                                public boolean isOpen() {
                                    return p.isOpen();
                                }

                                public void handle(final Tweet tweet) throws HandlerException {
                                    try {
                                        c.clear();
                                        c.commit();
                                        c.begin();
                                    } catch (SailException e) {
                                        throw new HandlerException(e);
                                    }

                                    p.handle(tweet);
                                }
                            };

                            stressTest(h, 1000);
                        } finally {
                            p.close();
                        }
                    } finally {
                        c.close();
                    }
                } finally {
                    store.shutDown();
                }
            } finally {
                streamingSail.shutDown();
            }
        } finally {
            workingSail.shutDown();
        }
    }
View Full Code Here

        OutputStream os;

        String[] names = new String[]{"tweet", "screenName", "replyTo", "createdAt", "text"};

        File dir = new File("/tmp/sparqljdbc/nativestore");
        Sail sail = new NativeStore(dir);
        sail.initialize();
        try {
            Repository repo = new SailRepository(sail);
            RepositoryConnection rc = repo.getConnection();
            try {
                rc.begin();
                rc.clear();
                rc.commit();
                rc.begin();

                rc.add(new File("/tmp/twitlogic-dump.nq"), "", RDFFormat.NQUADS);
                rc.commit();
                rc.begin();

                ////////////////////////////////////////////////////////////////

                query = "PREFIX dc: <http://purl.org/dc/terms/>\n" +
                        "PREFIX sioc: <http://rdfs.org/sioc/ns#>\n" +
                        "SELECT DISTINCT ?tweet1 ?tweet2 ?time1 ?time2 WHERE {\n" +
                        "    ?tweet1 dc:created ?time1 .\n" +
                        "    ?tweet2 dc:created ?time2 .\n" +
                        "    ?tweet2 sioc:reply_of ?tweet1 .\n" +
                        "}";

                os = new FileOutputStream("/tmp/replies.csv");
                try {
                    doQuery(query, rc, new PrintStream(os), new CSVOutputter() {
                        public void output(final BindingSet b,
                                           final StringBuilder sb) {
                            sb.append(esc(((URI) b.getValue("tweet1")).getLocalName()));
                            sb.append(", ");
                            long l1 = ((Literal) b.getValue("time1")).calendarValue().toGregorianCalendar().getTime().getTime();
                            sb.append(esc("" + l1));

                            sb.append(", ");

                            sb.append(esc(((URI) b.getValue("tweet2")).getLocalName()));
                            sb.append(", ");
                            long l2 = ((Literal) b.getValue("time2")).calendarValue().toGregorianCalendar().getTime().getTime();
                            sb.append(esc("" + l2));
                        }
                    });
                } finally {
                    os.close();
                }

                ////////////////////////////////////////////////////////////////

                query = "PREFIX dc: <http://purl.org/dc/terms/>\n" +
                        "PREFIX sioc: <http://rdfs.org/sioc/ns#>\n" +
                        "SELECT DISTINCT ?tweet ?account ?replyTo ?createdAt ?text WHERE {\n" +
                        "    ?tweet dc:created ?createdAt .\n" +
                        "    ?tweet sioc:content ?text .\n" +
                        "    ?tweet sioc:has_creator ?account .\n" +
                        // "    ?account sioc:id ?screenName .\n" +
                        "    OPTIONAL { ?tweet sioc:reply_of ?replyTo . } .\n" +
                        "}";

                os = new FileOutputStream("/tmp/tweets.csv");
                try {
                    doQuery(query, rc, new PrintStream(os), new CSVOutputter() {
                        public void output(final BindingSet b,
                                           final StringBuilder sb) {
                            sb.append(esc(((URI) b.getValue("tweet")).getLocalName()));
                            sb.append(", ");
                            sb.append(esc(((URI) b.getValue("account")).getLocalName()));
                            //  sb.append(esc(((Literal) b.getValue("screenName")).getLabel()));
                            sb.append(", ");
                            Value v = b.getValue("replyTo");
                            if (null == v) {
                                sb.append("\"\"");
                            } else {
                                sb.append(esc(((URI) v).getLocalName()));
                            }
                            sb.append(", ");
                            sb.append(esc(((Literal) b.getValue("createdAt")).getLabel()));
                            sb.append(", ");
                            sb.append(esc(((Literal) b.getValue("text")).getLabel()));
                        }
                    });
                } finally {
                    os.close();
                }

                ////////////////////////////////////////////////////////////////

                query = "PREFIX sioc: <http://rdfs.org/sioc/ns#>\n" +
                        "PREFIX sioct: <http://rdfs.org/sioc/types#>\n" +
                        "SELECT DISTINCT ?tweet ?topic WHERE {\n" +
                        "    ?tweet a sioct:MicroblogPost .\n" +
                        "    ?tweet sioc:topic ?topic .\n" +
                        "}";

                os = new FileOutputStream("/tmp/tweet_topics.csv");
                try {
                    doQuery(query, rc, new PrintStream(os), new CSVOutputter() {
                        public void output(final BindingSet b,
                                           final StringBuilder sb) {
                            sb.append(esc(((URI) b.getValue("tweet")).getLocalName()));
                            sb.append(", ");
                            sb.append(esc(((URI) b.getValue("topic")).getLocalName()));
                        }
                    });
                } finally {
                    os.close();
                }

                ////////////////////////////////////////////////////////////////

                query = "PREFIX sioc: <http://rdfs.org/sioc/ns#>\n" +
                        "PREFIX sioct: <http://rdfs.org/sioc/types#>\n" +
                        "SELECT DISTINCT ?tweet ?url WHERE {\n" +
                        "    ?tweet a sioct:MicroblogPost .\n" +
                        "    ?tweet sioc:links_to ?url .\n" +
                        "}";

                os = new FileOutputStream("/tmp/tweet_links.csv");
                try {
                    doQuery(query, rc, new PrintStream(os), new CSVOutputter() {
                        public void output(final BindingSet b,
                                           final StringBuilder sb) {
                            sb.append(esc(((URI) b.getValue("tweet")).getLocalName()));
                            sb.append(", ");
                            sb.append(esc(((URI) b.getValue("url")).stringValue()));
                        }
                    });
                } finally {
                    os.close();
                }

                ////////////////////////////////////////////////////////////////

            } finally {
                rc.rollback();
                rc.close();
            }
        } finally {
            sail.shutDown();
        }
    }
View Full Code Here

                log.info("- notifying plugin: {} (DISABLED)", provider.getName());
            }
        }

        // wrap all standard sails
        Sail standardSail = notifyingSail;
        for(StandardSailProvider provider : standardSailProviders) {
            if(provider.isEnabled()) {
                log.info("- standard plugin: {}",provider.getName());
                standardSail = provider.createSail(standardSail);
            } else {
View Full Code Here

                            final PrintStream err)
            throws RippleException {
        // Create a Sesame triple store.
        URIMap uriMap = new URIMap();
        SailConfiguration sailConfig = new SailConfiguration(uriMap);
        Sail sail = sailConfig.getSail();

        // Attach a Ripple model to the repository.
        Model model = new SesameModel(sail);

        // Attach a query engine to the model.
View Full Code Here

public class RippleSailDemo {
    private RippleSailDemo() {
    }

    private static void runDemo() throws Exception {
        Sail storage = new MemoryStore();
        storage.initialize();
        Sail linkedData = new LinkedDataSail(storage);
        linkedData.initialize();

        RippleSail ripple = new RippleSail(linkedData);
        ripple.initialize();

        Repository repo = new SailRepository(ripple);
        RepositoryConnection rc = repo.getConnection();

        // Constructing literal subjects
        String query1 = "PREFIX math: <http://fortytwo.net/2011/04/ripple/math#>\n" +
                "PREFIX stack: <http://fortytwo.net/2011/04/ripple/stack#>\n" +
                "SELECT ?result WHERE {\n" +
                "   ?x stack:self 42 .\n" +
                "   ?x math:sqrt ?result .\n" +
                "}";

        // Constructing literal predicates
        String query2 = "PREFIX graph: <http://fortytwo.net/2011/04/ripple/graph#>\n" +
                "PREFIX stack: <http://fortytwo.net/2011/04/ripple/stack#>\n" +
                "PREFIX s: <urn:string:>\n" +
                "SELECT ?result WHERE {\n" +
                "   ?x stack:self \"{\\\"foo\\\": true, \\\"bar\\\": [6, 9, 42]}\" .\n" +
                "   ?x graph:to-json/s:foo ?result .\n" +
                "}";

        // Loading externally-defined programs
        String query3 = "PREFIX : <http://ripple.fortytwo.net/code/2011/06/rippleSailExamples#>\n" +
                "SELECT ?name WHERE {" +
                "    () :embarcadero/:parent-place*/s:name ?name ." +
                "}";

        TupleQueryResult r = rc.prepareTupleQuery(QueryLanguage.SPARQL, query2).evaluate();
        while (r.hasNext()) {
            System.out.println("result: " + r.next());
        }

        rc.close();
        repo.shutDown();
        ripple.shutDown();
        linkedData.shutDown();
        storage.shutDown();
    }
View Full Code Here

        return count;
    }

    public void testRecoverFromParseError() throws Exception {
        Sail sail = new MemoryStore();
        sail.initialize();

        String bad = "bad";

        String good = "@prefix foo:  <http://example.org/foo#>.\n"
                + "foo:a foo:b foo:c.";

        InputStream is = null;

        try {
            is = new ByteArrayInputStream(bad.getBytes());
            add(sail, is, "", RDFFormat.TURTLE);
        } catch (Exception e) {
        } finally {
            is.close();
        }

        try {
            is = new ByteArrayInputStream(good.getBytes());
            add(sail, is, "", RDFFormat.TURTLE);
        } catch (Exception e) {
        }
        is.close();

        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            int count = countStatements(sc, null);
            assertEquals(1, count);
        } finally {
View Full Code Here

            sc.close();
        }
    }

    public void testAddFromInputStream() throws Exception {
        Sail sail = new MemoryStore();
        sail.initialize();
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();

            URI ctxA = sail.getValueFactory().createURI("urn:test.AddFromInputStreamTest.ctxA#");

            String s = "@prefix foo:  <http://example.org/foo#>.\n"
                    + "foo:a foo:b foo:c.";
            InputStream is = new ByteArrayInputStream(s.getBytes());
            try {
                add(sail, is, ctxA.toString(), RDFFormat.TURTLE, ctxA);
            } finally {
                is.close();
            }

            assertEquals(1, countStatements(sc, null));
/* 60 */
            assertEquals(1, countStatements(sc, ctxA));
        } finally {
            sc.close();
        }
        sail.shutDown();
    }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.Sail

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.