Package org.openrdf.sail

Examples of org.openrdf.sail.SailConnection


                Set<String> terms = TwitLogic.findTrackTerms();

                final Handler<Tweet> annotator
                        = createAnnotator(store, client);

                final SailConnection c = sail.getConnection();
                //c.addConnectionListener(listener);

                try {
                    Handler<Tweet> adder = new Handler<Tweet>() {
                        public boolean isOpen() {
                            return !closed && annotator.isOpen();
                        }

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

                            annotator.handle(tweet);
                        }
                    };

                    // Can't use a deleter here.
                    NullHandler<Tweet> d = new NullHandler<Tweet>();

                    // TODO: optionally gather historical tweets

                    TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), adder);

                    if (0 < users.size() || 0 < terms.size()) {
                        client.processFilterStream(users, terms, null, rLogger, d, 0);
                    } else {
                        client.processSampleStream(rLogger, d);
                    }
                } finally {
                    c.close();
                }
            } finally {
                store.shutDown();
            }
        } finally {
View Full Code Here


                ? ((MappingSail) sail).getBaseSail()
                : sail;

        Collection<Resource> results;

        SailConnection sc = baseSail.getConnection();
        try {
            sc.begin();
            //System.out.println("resource (really): " + resource);
            RelatedHashtagsInferencer inf = new RelatedHashtagsInferencer(sc, resource);
            int used = inf.compute(steps);

            results = inf.currentHashtagResults(limit);

        } finally {
            sc.rollback();
            sc.close();
        }
        /*
        System.out.println("" + used + " of " + steps + " cycles used.  Results:");
        for (Resource r : results) {
            System.out.println("\t" + r);
View Full Code Here

        Sail baseSail = sail instanceof MappingSail
                ? ((MappingSail) sail).getBaseSail()
                : sail;

        //SailConnection sc = sail.getConnection();
        SailConnection sc = baseSail.getConnection();
        try {
            sc.begin();
            //System.out.println("resource (really): " + resource);
            ConferenceInferencer inf = new ConferenceInferencer(sc, resource);
            int steps = 150;
            int used = inf.compute(steps);

            Collection<Resource> results = inf.currentHashtagResults();

            /*
            System.out.println("" + used + " of " + steps + " cycles used.  Results:");
            for (Resource r : results) {
                System.out.println("\t" + r);
            }//*/

            StringBuilder sb = new StringBuilder();
            boolean first = true;
            for (Resource r : results) {
                if (first) {
                    first = false;
                } else {
                    sb.append("    UNION\n");
                }

                sb.append("  { ?post sioc:topic <").append(r).append("> }\n");
            }

            return TWEETS_WITH_ALTERNATIVE_TOPICS_QUERY
                    .replace(ALTERNATIVE_TOPICS_PLACEHOLDER, sb.toString())
                    .replace(MIN_TIMESTAMP_PLACEHOLDER, after);
        } finally {
            sc.rollback();
            sc.close();
        }
    }
View Full Code Here

        try {
            TweetStoreConnection c = store.createConnection();
            try {
                ParsedQuery q = parseQuery(SELECT_DUMP_FIELDS);
                BindingSet bs = new MapBindingSet();
                SailConnection sc = c.getSailConnection();
                try {
                    sc.begin();
                    CloseableIteration<? extends BindingSet, QueryEvaluationException> results
                            = sc.evaluate(q.getTupleExpr(), q.getDataset(), bs, false);
                    try {
                        while (results.hasNext()) {
                            BindingSet r = results.next();
                            String timestamp = ((Literal) r.getBinding(TIMESTAMP).getValue()).getLabel().replaceAll("\t", " ");
                            String location = ((Literal) r.getBinding(LOCATION).getValue()).getLabel().replaceAll("\t", " ");
                            String text = ((Literal) r.getBinding(TEXT).getValue()).getLabel()
                                    .replaceAll("\t", " ")
                                    .replaceAll("\n", " ")
                                    .replaceAll("\r", " ");

                            ps.println(timestamp + "\t" + location + "\t" + text);
                        }
                    } finally {
                        results.close();
                    }
                } finally {
                    sc.rollback();
                    sc.close();
                }
            } finally {
                c.close();
            }
        } finally {
View Full Code Here

            try {
                store.initialize();

                TweetStoreConnection c = store.createConnection();
                try {
                    SailConnection sc = c.getSailConnection();
                    try {
                        sc.begin();
                        SparqlTools.executeQuery(GOLD_TWEETS_QUERY, sc, System.out, 100, SparqlTools.SparqlResultFormat.JSON);
                    } finally {
                        sc.rollback();
                        sc.close();
                    }
                    //queryAndWriteJSON(ISWC_STATEMENTS_QUERY, sc, System.out);
                } finally {
                    c.close();
                }
View Full Code Here

                store.doNotRefreshCoreMetadata();
                store.initialize();

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

                    try {
                        c.begin();
                        // Offline persister
                        final TweetPersister persister = new TweetPersister(store, null);

                        try {
                            CustomTwitterClient client = new CustomTwitterClient();

                            TweetPersistedLogger pLogger = new TweetPersistedLogger(client.getStatistics(), persister);

                            // Add a "topic sniffer".
                            TopicSniffer topicSniffer = new TopicSniffer(pLogger);

                            // Add a tweet annotator.
                            Matcher matcher = new MultiMatcher(
                                    new DemoAfterthoughtMatcher());

                            final Handler<Tweet> annotator
                                    = new TweetAnnotator(matcher, topicSniffer);

                            Handler<Tweet> adder = new Handler<Tweet>() {
                                public boolean isOpen() {
                                    return annotator.isOpen();
                                }

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

                                     annotator.handle(tweet);
                                }
                            };
                            Handler<Tweet> deleter = new TweetDeleter(store);

                            TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), adder);

                            client.processSampleStream(rLogger, deleter);
                        } finally {
                            persister.close();
                        }
                    } finally {
                        c.rollback();
                        c.close();
                    }
                } finally {
                    store.shutDown();
                }
            } finally {
View Full Code Here

        File dump = conf.getFile("dump", null);
        if (null != dump) {
            LOGGER.info("loading from dump file: " + dump);

            try {
                SailConnection sc = sail.getConnection();
                try {
                    sc.begin();
                    RDFParser parser = Rio.createParser(RDFFormat.NQUADS);
                    parser.setRDFHandler(new StatementAdder(sc));
                    InputStream is = new FileInputStream(dump);
                    try {
                        parser.parse(is, "");
                    } finally {
                        is.close();
                    }
                    sc.commit();
    sc.begin();
                } finally {
                    sc.rollback();
                    sc.close();
                }
            } catch (Throwable t) {
                LOGGER.severe("exception occurred while loading: " + t);
                t.printStackTrace(System.err);
                System.exit(1);
View Full Code Here

    public static void dumpTripleStore(final Sail sail,
                                       final OutputStream out) throws SailException, IOException {
        Writer w = new PrintWriter(out);
        try {
            SailConnection sc = sail.getConnection();
            try {
                sc.begin();
                // TODO: one insert statement per statement is a bit verbose (when many statements share the same graph)
                CloseableIteration<? extends Statement, SailException> iter
                        = sc.getStatements(null, null, null, false);
                try {
                    while (iter.hasNext()) {
                        w.append(createSparqlInsertStatement(iter.next()));
                    }
                } finally {
                    iter.close();
                }
            } finally {
                sc.rollback();
                sc.close();
            }
        } finally {
            w.close();
        }
    }
View Full Code Here

                store.doNotRefreshCoreMetadata();
                store.initialize();

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

                    try {
                        c.begin();

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

                        try {
                            CustomTwitterClient client = new CustomTwitterClient();

                            // Note: this is only for serving local files.
                            store.startServer(client);

                            TweetPersistedLogger pLogger = new TweetPersistedLogger(client.getStatistics(), persister);
                            TweetFilterCriterion crit = new TweetFilterCriterion(TwitLogic.getConfiguration());
                            Filter<Tweet> f = new Filter<Tweet>(crit, pLogger);

                            // Add a "topic sniffer".
                            TopicSniffer topicSniffer = new TopicSniffer(f);

                            // Add a tweet annotator.
                            Matcher matcher = new MultiMatcher(
                                    new DemoAfterthoughtMatcher());

                            final Handler<Tweet> annotator
                                    = new TweetAnnotator(matcher, topicSniffer);

                            Handler<Tweet> adder = new Handler<Tweet>() {
                                public boolean isOpen() {
                                    return annotator.isOpen();
                                }

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

                                     annotator.handle(tweet);
                                }
                            };
                            Handler<Tweet> deleter = new TweetDeleter(store);

                            TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), adder);

                            Set<User> users = TwitLogic.findFollowList(client);
                            Set<String> terms = TwitLogic.findTrackTerms();

                            if (0 < users.size() || 0 < terms.size()) {
                                client.processFilterStream(users, terms, null, rLogger, deleter, 0);
                            } else {
                                client.processSampleStream(rLogger, deleter);
                            }
                        } finally {
                            persister.close();
                        }
                    } finally {
                        c.rollback();
                        c.close();
                    }
                } finally {
                    store.shutDown();
                }
            } finally {
View Full Code Here

            public void handleTransaction(final List<TransactionOperation> operations) throws SailException {
                System.out.println(new String(createTransactionEntity(operations)));
            }
        };

        SailConnection sc = sail.getConnection();
        try {
            sc.removeStatements(RDF.TYPE, null, null, (URI) null);
            sc.commit();
        } finally {
            sc.rollback();
            sc.close();
        }

        sail.shutDown();
        baseSail.shutDown();
    }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.SailConnection

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.