Package net.fortytwo.twitlogic.persistence

Examples of net.fortytwo.twitlogic.persistence.TweetStore


                ((NotifyingSailWrapper) b).setBaseSail(baseSail);
            }
            sail = new WrapperNotifyingSail(b, listener);
            sail.initialize();

            store = new TweetStore(sail);
        }
View Full Code Here


                + "  <URL:http://wiki.github.com/joshsh/twitlogic/configuring-and-running-twitlogic>.");
    }

    private static void runDemo() throws Exception {
        // Create a persistent store.
        TweetStore store = new TweetStore();
        store.initialize();

        try {
            // Create a client for communication with Twitter.
            //TwitterClient client = new Twitter4jClient();
            TwitterClient client = new Twitter4jClient();

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

            Set<User> users = TwitLogic.findFollowList(client);
            Set<String> terms = TwitLogic.findTrackTerms();
            double [][]locations = TwitLogic.findGeoBoxes();

//            GregorianCalendar cal = new GregorianCalendar(2010, GregorianCalendar.MAY, 1);
//            //gatherHistoricalTweets(store, client, users, cal.getTime());

            TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), annotator);
            TweetDeleter d = new TweetDeleter(store);

            ExampleTweetHandler h = new ExampleTweetHandler();
//            client.processFilterStream(users, terms, rLogger, d, 0);
            client.processFilterStream(users, terms, locations, h, d, 0);
            //client.processSampleStream(rLogger, d);
        } finally {
            store.shutDown();
        }
    }
View Full Code Here

                + "  <URL:http://wiki.github.com/joshsh/twitlogic/configuring-and-running-twitlogic>.");
    }

    private static void runDemo() throws Exception {
        // Create a persistent store.
        TweetStore store = new TweetStore();
        store.initialize();

        boolean exitedNormally = false;

        try {
            // Create a client for communication with Twitter.
            TwitterClient client = new Twitter4jClient();
            //TwitterClient client = new CustomTwitterClient();

            // Launch linked data server.
            store.startServer(client);

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

            // Create an agent to listen for commands.
            // Also take the opportunity to memoize users we're following.
            /*
            TwitLogicAgent agent = new TwitLogicAgent(client);
            UserRegistry userRegistry = new UserRegistry(client);
            Handler<Tweet, TweetHandlerException> realtimeStatusHandler
                    = userRegistry.createUserRegistryFilter(
                    new CommandListener(agent, annotator));
            */

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

            GregorianCalendar cal = new GregorianCalendar(2010, GregorianCalendar.MAY, 1);
            //gatherHistoricalTweets(store, client, users, cal.getTime());

            TweetReceivedLogger rLogger = new TweetReceivedLogger(client.getStatistics(), annotator);
            TweetDeleter d = new TweetDeleter(store);
            client.processFilterStream(users, terms, null, rLogger, d, 0);

            exitedNormally = true;
        } finally {
            if (!exitedNormally) {
                LOGGER.warning("exited abnormally");
            }

            store.shutDown();
        }
    }
View Full Code Here

        baseSail.initialize();
        Sail sail = new QueueingSail(baseSail, factory.create());

        try {
            // Create a persistent store.
            TweetStore store = new TweetStore(sail);
            store.setSailConnectionListenerFactory(factory);
            store.doNotRefreshCoreMetadata();
            store.initialize();

            try {
                // Create a client for communication with Twitter.
                CustomTwitterClient client = new CustomTwitterClient();

                Set<User> users = TwitLogic.findFollowList(client);
                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 {
            sail.shutDown();
        }
    }
View Full Code Here

                + "  <URL:http://wiki.github.com/joshsh/twitlogic/configuring-and-running-twitlogic>.");
    }

    private static void runDemo() throws Exception {
        // Create a persistent store.
        TweetStore store = new TweetStore();
        store.initialize();

        try {
            TwitterClient client = new Twitter4jClient();

            //store.dump(System.out);
            //store.dumpToFile(new File("/tmp/twitlogic-tmp-dump.trig"), RDFFormat.TRIG);

            // Launch linked data server.
            store.startServer(client);

            Object mutex = "";
            synchronized (mutex) {
                mutex.wait();
            }
        } finally {
            store.shutDown();
        }
    }
View Full Code Here


    private static final void load() throws TweetStoreException, PropertyException, RepositoryException, IOException, RDFParseException {
        System.out.println("Loading Semantic Web Conference Corpus data");
        // Create a persistent store.
        TweetStore store = new TweetStore();
        store.initialize();
        File dir = TwitLogic.getConfiguration().getFile(SWC_DIR);
        try {
            RepositoryConnection rc = store.getRepository().getConnection();
            try {
                rc.begin();

                rc.clear(SWC_GRAPH);
                rc.commit();
    rc.begin();
                loadFile(dir, rc);
                rc.commit();
    rc.begin();
            } finally {
                rc.rollback();
                rc.close();
            }
        } finally {
            store.shutDown();
        }
        System.out.println("done.");
    }
View Full Code Here

            Properties props = new Properties();
            props.load(new FileInputStream("/Users/josh/projects/fortytwo/twitlogic/config/twitlogic.properties"));
            TwitLogic.setConfiguration(props);

            // Create a persistent store.
            TweetStore store = new TweetStore();
            store.initialize();

            try {
                TweetStoreConnection c = store.createConnection();
                try {
                    URI iswc2009 = new URIImpl("http://twitlogic.fortytwo.net/hashtag/linkeddata");
                    RelatedHashtagsInferencer inf = new RelatedHashtagsInferencer(c.getSailConnection(), iswc2009);

                    int steps = 500;
                    int used = inf.compute(steps);

                    for (WeightedValue<Resource> wv : inf.currentResult().toSortedArray()) {
                        if (wv.value.toString().contains("hashtag")) {
//                            System.out.println("" + wv.weight + "\t" + wv.value);
                            System.out.println(((URI) wv.value).getLocalName());
                        }
                    }


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

                    System.out.println("" + used + " of " + steps + " cycles used.  Results:");
                    for (Resource r : results) {
                        System.out.println("\t" + r);
                    }
                } finally {
                    c.close();
                }
            } finally {
                store.shutDown();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
View Full Code Here

            Properties conf = new Properties();
            conf.load(EarthquakeTweets.class.getResourceAsStream("datascience.properties"));
            TwitLogic.setConfiguration(conf);

            // Create a persistent store.
            TweetStore store = new TweetStore();
            store.initialize();

            try {
                //store.dump(System.out);
                dumpTabSeparatedFile(store, new File("/tmp/earthquaketweets.txt"));

                CustomTwitterClient client = new CustomTwitterClient();
                UserRegistry userRegistry = new UserRegistry(client);

                TweetPersister baseStatusHandler = new TweetPersister(store, client);
                TweetDeleter d = new TweetDeleter(store);

                // Create an agent to listen for commands.
                // Also take the opportunity to memoize users we're following.
                TwitLogicAgent agent = new TwitLogicAgent(client);
                Handler<Tweet> statusHandler
                        = userRegistry.createUserRegistryFilter(
                        new CommandListener(agent, baseStatusHandler));

                Set<User> users = new HashSet<User>();
                Set<String> terms = new HashSet<String>();
                terms.add("earthquake");
                client.processFilterStream(users, terms, null, statusHandler, d, 0);

                System.out.println("Done.");
            } finally {
                store.shutDown();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
View Full Code Here

            Properties props = new Properties();
            props.load(new FileInputStream("/Users/josh/projects/fortytwo/twitlogic/config/twitlogic.properties"));
            TwitLogic.setConfiguration(props);

            // Create a persistent store.
            TweetStore store = new TweetStore();
            store.initialize();

            try {
                TweetStoreConnection c = store.createConnection();
                try {
                    URI iswc2009 = new URIImpl("http://data.semanticweb.org/conference/iswc/2009");
                    ConferenceInferencer inf = new ConferenceInferencer(c.getSailConnection(), iswc2009);

                    int steps = 50;
                    int used = inf.compute(steps);
//                    Collection<Resource> results = inf.currentResult();
                    Collection<Resource> results = inf.currentHashtagResults();

                    System.out.println("" + used + " of " + steps + " cycles used.  Results:");
                    for (Resource r : results) {
                        System.out.println("\t" + r);
                    }
                } finally {
                    c.close();
                }
            } finally {
                store.shutDown();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
View Full Code Here

            Properties props = new Properties();
            props.load(new FileInputStream("/Users/josh/projects/fortytwo/twitlogic/config/twitlogic.properties"));
            TwitLogic.setConfiguration(props);

            // Create a persistent store.
            TweetStore store = new TweetStore();
            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();
                }
            } finally {
                store.shutDown();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of net.fortytwo.twitlogic.persistence.TweetStore

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.