とりあえず,TwitterストリーミングAPIでデータをもっと欲しいので,
gardenhoseに申し込んでみた.
http://twitter.com/help/request_streaming
にアクセスして,名前,所属,E-Mail,URL,申請理由を書くだけ.
登録したら速攻使えるようになりました.
というか,sampleの性能があがって,gardenhoseになりました.
申請理由とか真面目に書いたのに,あんまり意味がない.
で,どのくらいとれるようになったかを確認.
sampleではIDの下一桁が0-4のTweetがとれていたけど,gardenhoseだと下2桁が0-14のTweetが取得出来ていた.およそ3倍の性能と言ったところ.
それでも,全体の15%しかとれない.これが多いか少ないかは難しいところだ.
sampleでは日本語のTweetが秒間6.5個くらいとれたのに対して,
gardenhoseでは日本語のTweetが秒間20個くらいとれた.
ちなみに,計測時間は19:30くらい.
昼間は秒間10Tweetくらいだった.だいぶ差があるなあ.
2010年4月28日水曜日
2010年4月27日火曜日
日本語が含まれるかどうかの判定
TwitterのストリーミングAPIから日本語が使われているTweetだけ取得したいので,
日本語マッチングをやってみた.
日本語マッチングをやってみた.
Matcher m = Pattern.compile("([\\p{InHiragana}\\p{InKatakana}])").matcher(text); boolean isJapanese = m.find();\p{InCJKUnifiedIdeographs}で漢字もとれるけど,漢字オンリーのつぶやきは中国系の人の物が多いみたいなので,ひらがなかカタカナが含まれるもののみにした.
2010年4月26日月曜日
Twitter Streaming APIをJavaで試してみる
2011年10月05日追記:
Streaming APIがHTTPS対応となったので,若干変更が必要です.
詳しくは,こちらのバージョンをご覧ください.
2010年12月24日追記:
Twitter4jを使ったバージョンを作ったので,そちらを使った方が良いと思われます.
TwitterのStreamingAPIにがぜん興味が出てきたので,Javaで実装してみた.
package twitter; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.Authenticator; import java.net.HttpURLConnection; import java.net.PasswordAuthentication; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * StreamAPIから送られてくるStreamデータをひたすら取得し続けるクラス * @author tori * */ public class TwitterStreamReader { /** * 使い方の例 * @param args * @throws UnsupportedEncodingException */ public static void main(String[] args) throws UnsupportedEncodingException { TwitterStreamReader tsr = new TwitterStreamReader("Twitter-UserName", "Password"); tsr.start(); while(true){ List<String> tweetList = tsr.readStoredList(); List<String> errList = tsr.readErrLogList(); for(String text:tweetList){ System.out.println(text); } for(String err:errList){ System.err.println(err); } } } /** * sampleのタイムライン取得のためのURL */ private static final String DEFAULT_API_URL = "http://stream.twitter.com/1/statuses/sample.json"; String userName; String password; /** * 強制終了させられたかどうか */ boolean isForceStop; /** * 取得しているかどうか */ boolean isRunning; /** * Synchlonizedされたリスト */ List<String> dataList; /** * Synchlonizedされたリスト */ List<String> errLogList; /** * apiのURL */ String apiUrl = DEFAULT_API_URL; /** * ストリームを読み続けるためのスレッド */ private Thread streamReadThread; public TwitterStreamReader(String userName, String password) { super(); this.userName = userName; this.password = password; dataList = Collections.synchronizedList(new ArrayList<String>()); errLogList = Collections.synchronizedList(new ArrayList<String>()); } /** * 読み込みを開始する */ public void start(){ StreamReader streamReader = new StreamReader(); streamReadThread = new Thread(streamReader); streamReadThread.start(); } /** * 取得を停止する<br> */ public void stop() { this.isForceStop = true; } /** * データ取得中かどうかを返す * @return */ public boolean isRunning(){ return streamReadThread.isAlive(); } /** * 取得済みのTweetデータのリストを取得する<br> * これまでに読み込んだデータは削除される * @return 是までに読み込んだデータ */ public List<String> readStoredList(){ List<String> storedList; synchronized (dataList) { storedList = new ArrayList<String>(dataList); dataList.clear(); } return storedList; } /** * エラーログのリストを取得する<br> * これまでに読み込んだデータは削除される * @return 是までに読み込んだデータ */ public List<String> readErrLogList(){ List<String> storedList; synchronized (errLogList) { storedList = new ArrayList<String>(errLogList); errLogList.clear(); } return storedList; } /** * 強制停止信号を送ったかどうか * @return the isForceStop */ public boolean isForceStop() { return isForceStop; } /** * データ読み込み用クラス * @author tori * */ class StreamReader implements Runnable{ @Override public void run() { isForceStop = false; while(!isForceStop){ InputStreamReader isr = null; BufferedReader br = null; try{ URL connectUrl = new URL(apiUrl); HttpURLConnection con = (HttpURLConnection)connectUrl.openConnection(); con.setRequestMethod("GET"); con.setDoOutput(true); con.setInstanceFollowRedirects(true); Authenticator auth = new Authenticator(){ public PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(userName, password.toCharArray()); } }; Authenticator.setDefault(auth); isr = new InputStreamReader(con.getInputStream(), "UTF8"); br = new BufferedReader(isr); while(!isForceStop){ String tweet = br.readLine(); synchronized (dataList) { dataList.add(tweet); } } }catch(Exception e){ StringBuffer buf = new StringBuffer(); buf.append(e.getClass().getName()+"\n"); for(StackTraceElement ste:e.getStackTrace()){ buf.append(String.format("\tat %s.%s(%s:%d)\n", ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber())); } synchronized (errLogList) { errLogList.add(buf.toString()); } }finally{ try{ br.close(); }catch(Exception e){ } try{ isr.close(); }catch(Exception e){ } } } } } }
参考にしたのは,
この辺.
どんどん取ってくるためにThread化したけど,使いたい人は好きに作り直せばいいと思う.
2010年4月25日日曜日
App Engine覚書
Localhostで接続したときのDataScoreViewなど。
http://localhost:8888/_ah/admin
忘れっぽいエンジニアのJakarta Strutsリファレンス
http://struts.wasureppoi.com/
http://d.hatena.ne.jp/y_koh/20090531/1243766131
とりあえず、datanucleus-appengine-1.0.4.1.final.jarをビルドパスからはずせばいいみたい。
http://localhost:8888/_ah/admin
忘れっぽいエンジニアのJakarta Strutsリファレンス
http://struts.wasureppoi.com/
The class "com.appspot.****.className" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
org.datanucleus.exceptions.ClassNotPersistableException: The class "com.appspot.****.className" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
ってな謎のエラーが発生してJSPをうまく処理できないとき。org.datanucleus.exceptions.ClassNotPersistableException: The class "com.appspot.****.className" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
http://d.hatena.ne.jp/y_koh/20090531/1243766131
とりあえず、datanucleus-appengine-1.0.4.1.final.jarをビルドパスからはずせばいいみたい。
2010年4月23日金曜日
2010年4月9日金曜日
2010年4月2日金曜日
SNS関連論文サーベイ
SNS関連の論文をサーベイしてみよう.
とりあえず,列挙する.
とりあえず,列挙する.
- 松尾豊, 安田雪:SNSにおける関係形成原理–mixiのデータ分析–, 人工知能学会論文誌, Vol. 22, No. 5 (2007)
http://www.jstage.jst.go.jp/article/tjsai/22/5/22_531/_article/-char/ja
mixiの分析
- Adamic, L., Buyukkokten, O., and Adar, E.: A social
network caught in theWeb, First Monday, Vol. 8, No. 6, p. 29 (2003)
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.106.620&rep=rep1&type=pdf
- Ahn, Y., Han, S., Kwak, H., Moon, S., and Jeong, H.: Analysis of topological characteristics of huge online social networking services, Proceedings of the 16th international conference on World Wide Web, pp. 835–844 (2007)
http://www2007.org/papers/paper676.pdf
Cyworldの分析
- Ishida, K., Toriumi, F., and Ishii, K.: Proposal for Growth Model of Social Network Services, IEEE/WIC/ACM International Conference on Web Intelligence and Intelligent Agent Technology, 2008. WI-IAT '08 1, 91-97
- Yuta, K., Ono, N., and Fujiwara, Y.:A Gap in the Community-Size Distribution of a Large-Scale Social Networking Site, Arxiv preprint physics/0701168 (2007)
- Ellen Spertus , Mehran Sahami , Orkut Buyukkokten, Evaluating similarity measures: a large-scale study in the orkut social network, Proceeding of the eleventh ACM SIGKDD international conference on Knowledge discovery in data mining, August 21-24, 2005, Chicago, Illinois, USA
http://portal.acm.org/citation.cfm?id=1081956
- Mislove, A., Koppula, H. S., Gummadi, K. P., Druschel, P., and Bhattacharjee, B. 2008. Growth of the flickr social network. In Proceedings of the First Workshop on online Social Networks (Seattle, WA, USA, August 18 - 18, 2008). WOSP '08. ACM, New York, NY, 25-30.
http://portal.acm.org/citation.cfm?id=1397735.1397742/#
- Mislove, A., Marcon, M., Gummadi, K. P., Druschel, P., and Bhattacharjee, B. 2007. Measurement and analysis of online social networks. In Proceedings of the 7th ACM SIGCOMM Conference on internet Measurement (San Diego, California, USA, October 24 - 26, 2007). IMC '07. ACM, New York, NY, 29-42
http://www.google.co.jp/url?sa=t&source=web&ct=res&cd=1&ved=0CAYQFjAA&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.109.4432%26rep%3Drep1%26type%3Dpdf&ei=wkS1S_KPBc-GkAXYsaWNDQ&usg=AFQjCNGjH9MsDjXYFK82nkMnAqeZEdjRtg&sig2=CUOTckYLCnz2LVgpVND_Og
- 内田誠, 白山晋:SNS のネットワーク構造の分析とモデル推定, 情報処理学会論文誌,vol47,No.9 (2006)
http://ci.nii.ac.jp/naid/110004782185
- 湯田聴夫、小野直亮、藤原義久:ソーシャルネットワーキングサービスにおける人的ネットワーク構造、情報処理学会論文誌、47(3), 865-874.(2006)
http://ci.nii.ac.jp/naid/110004708844#cit
- 鳥海不二夫, 山本仁志, 諏訪博彦,岡田勇, 和泉潔, 橋本康弘: 大量SNSサイトの比較分析 人工知能学会論文誌 Vol. 25 (2010) , No. 1 pp.78-89 (01/2010)
http://ci.nii.ac.jp/naid/130000151239
- Brown, J., Broderick, A.J. and Lee, N. (2007). Word of Mouth Communication Within Online Communities: Conceptualizing the Online Social Network. Journal of Interactive Marketing, 21(3), 2-20.
http://apgsweden.typepad.com/apgsweden/files/viralzzz.pdf
- 高井一輝, 河口信夫:ACS: 多様な人間関係を表現可能なソーシャルネットワーキングシステム, 情報処理学会論文誌,Vol. 48, No. 7, pp. 2328–2339 (2007)
http://ci.nii.ac.jp/naid/110006345319
- 鳥海不二夫,石田健,石井健一郎: 小規模SNSのモデル化と活性化シミュレーション 電子情報通信学会論文誌 B Vol.J91-B No.4 pp.397-406 (04/2008)
http://ci.nii.ac.jp/naid/110007379141
- Fujio TORIUMI, Ken ISHIDA, and Kenichiro ISHII: Activation Methods for Small Social Network Services The 2008 IEEE/WIC/ACM International Conference on Web Intelligence(12/2008)