SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
PHP Source Code Search
with
PHP

柄沢聡太郎 (sotarok)
http://nequal.jp/
twitter.com/sotarok
始める前に




   Copyright © nequal, Creative Commons Attribution-
                 Noncommercial 2.1 @ PHP Study #46.
今⽇はPHP勉強会




     Copyright © nequal, Creative Commons Attribution-
                   Noncommercial 2.1 @ PHP Study #46.
なぜ 9/29 ではないのか




        Copyright © nequal, Creative Commons Attribution-
                      Noncommercial 2.1 @ PHP Study #46.
懇親会はピザだって?




     Copyright © nequal, Creative Commons Attribution-
                   Noncommercial 2.1 @ PHP Study #46.
⾁はどうしたんですか




     Copyright © nequal, Creative Commons Attribution-
                   Noncommercial 2.1 @ PHP Study #46.
本来のPHP勉強会




            Copyright © nequal, Creative Commons Attribution-
                          Noncommercial 2.1 @ PHP Study #46.
PHPerは
⾁の精神を忘れ
 てしまったか
    Copyright © nequal, Creative Commons Attribution-
                  Noncommercial 2.1 @ PHP Study #46.
ごめんなさい冗談です
gusagiさん幹事おつかれさまです




         Copyright © nequal, Creative Commons Attribution-
                       Noncommercial 2.1 @ PHP Study #46.
じこしょうかい
sotarok
•   そうたろう(けー)
•   プリン
•   プリン
•   プリン
•   pudding
•   プリン
•   ⾁
•   ごはん
•   自転⾞
•   写真 – Sony α 300
•   Ethna
•   nequal
                      Copyright © nequal, Creative Commons Attribution-
                                    Noncommercial 2.1 @ PHP Study #46.
宣伝
• WikiHub
  – http://wikihub.org/
  – Git で⽂書管理して,それを Wiki 形式で整形して
    表⽰
  – GitHub の Service Hook で簡単同期
• 制限つきOpenBeta
  – 100⼈まで




                 Copyright © nequal, Creative Commons Attribution-
                               Noncommercial 2.1 @ PHP Study #46.
宣伝2                     なぜか誰も
                        買ってこない
• プリンが好きです




             Copyright © nequal, Creative Commons Attribution-
                           Noncommercial 2.1 @ PHP Study #46.
宣伝2                      yuchimiriさんに
                        RTまでされたのに

• プリンが好きです




             Copyright © nequal, Creative Commons Attribution-
                           Noncommercial 2.1 @ PHP Study #46.
検索エンジンとか
                         つくってるとこ!




 Preferred Infrastructure (PFI)
というところでインターンやってます




 だからか
        だからです
                 Copyright © nequal, Creative Commons Attribution-
                               Noncommercial 2.1 @ PHP Study #46.
Agenda
•   検索エンジン
•   転置インデックス
•   クロールとキーワード抽出
•   スコアリングと並び替え
•   デモ
•   技術的な課題とか




               Copyright © nequal, Creative Commons Attribution-
                             Noncommercial 2.1 @ PHP Study #46.
検索エンジン
• キーワードを⼊⼒
 – → そのキーワードが含まれる(そして探したいと
   思われる)⽂書が探せる

• ソースコード検索
 –   grep
 –   gtags (GNU GLOBAL)
 –   trac + Hyper Estraier (BTS + Plugin)
 –   Google Code Search


                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
grep
• 与えられたキーワードをファイルをたどり,⽂字
  列⼀致で探す
• 前処理が必要ない
• どこにでも⼊ってる


grepのデメリット
• 大量の⽂書から探すのは時間がかかる
  – 同じキーワードで再検索するときもまた同じ処理
• ランキングづけができない

             Copyright © nequal, Creative Commons Attribution-
                           Noncommercial 2.1 @ PHP Study #46.
検索エンジンを作る
• 既存のいろんなソフトウェアを使うのもいいけど
• 「検索エンジン」
 – そんな難しくない
 – PHPでもできる
 – カンタンだよ!

• 今回の目標
 – ローカルのPHPソースファイルからメソッドや関数
   や変数を検索できるようにする
 – ディレクトリを指定して,再帰的にPHPファイルを
   検索
 – grep -rn 'substr' **/*.php

               Copyright © nequal, Creative Commons Attribution-
                             Noncommercial 2.1 @ PHP Study #46.
転置インデックス
転置インデックス
• キーワードから⽂書を逆引きできるようにあらか
  じめつくっておくインデックス

• 焼⾁ =>
  –   ⽜角
  –   Wikipedia – 焼⾁
  –   YAKINIQUEST - ヤキニクエスト
  –   ...




                     Copyright © nequal, Creative Commons Attribution-
                                   Noncommercial 2.1 @ PHP Study #46.
※⽂書はフィクションです

⽂書1
I like Sushi, Yakiniku and pudding !

⽂書2
PHPer like Yakiniku. Maybe not like
Sushi.

⽂書3
Dankogai is an enemy of PHPer.


                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
※⽂書はフィクションです

⽂書1
I like Sushi , Yakiniku and pudding !

⽂書2
PHPer like Yakiniku. Maybe not like
Sushi.

⽂書3
Dankogai is an enemy of PHPer. He
also like Yakiniku.

                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
Sushi          1




             ⽂書1
             I like Sushi, Yakiniku and pudding !
      ⽂書2
    PHPer like Yakiniku. Maybe not like
⽂書3 Sushi.
Dankogai is an enemy of PHPer. He
also like Yakiniku.
                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
Sushi           1
 Yakiniku          1




             ⽂書1
             I like Sushi, Yakiniku and pudding !
      ⽂書2
    PHPer like Yakiniku. Maybe not like
⽂書3 Sushi.
Dankogai is an enemy of PHPer. He
also like Yakiniku.
                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
Sushi           1
 Yakiniku          1
 pudding           1


             ⽂書1
             I like Sushi, Yakiniku and pudding !
      ⽂書2
    PHPer like Yakiniku. Maybe not like
⽂書3 Sushi.
Dankogai is an enemy of PHPer. He
also like Yakiniku.
                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
Sushi           1
 Yakiniku          1              2
 pudding           1


             ⽂書1
             I like Sushi, Yakiniku and pudding !
      ⽂書2
    PHPer like Yakiniku. Maybe not like
⽂書3 Sushi.
Dankogai is an enemy of PHPer. He
also like Yakiniku.
                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
Sushi           1              2
 Yakiniku          1              2
 pudding           1


             ⽂書1
             I like Sushi, Yakiniku and pudding !
      ⽂書2
    PHPer like Yakiniku. Maybe not like
⽂書3 Sushi.
Dankogai is an enemy of PHPer. He
also like Yakiniku.
                           Copyright © nequal, Creative Commons Attribution-
                                         Noncommercial 2.1 @ PHP Study #46.
転置インデックスをPHPで
 • array でしょJK


$inverted_index = array(
    'miyazaki' => array(1, 2, 6, 4 ...),
    'aoi' => array(2, 6, 7, ...),
    'sotarok' => array(...),
    ...
);
    配列のキー:             配列の要素:
      単語              ⽂書IDのリスト
                       Copyright © nequal, Creative Commons Attribution-
                                      Noncommercial 2.1 @ PHP Study #46.
クロールとキーワード抽出
クロールとキーワード抽出

• 対象の⽂書からキーワードを拾い集める
• クローラー -> Google なら Google Bot とか

• キーワード ->
  – 空⽩区切りの⽂字列(英語圏のひと)
  – 形態素解析(明⽇ は あめ だ)
  – n-gram
    • n⽂字区切りでキーワードにする
    • 2-gram(bi-gram)
    • 明⽇ ⽇は はあ あめ めだ

                   Copyright © nequal, Creative Commons Attribution-
                                 Noncommercial 2.1 @ PHP Study #46.
クロールとキーワード抽出をPHPで(1)


•function crawl ($dirname)
   • foreach(glob($dirname . "/*") as $file)
      • if is_dir($file):
         • $files += crawl ($file)
      • else:
         • if $file ~= /.+¥.php$/
             • $files[] = $file
   • return $files

                        Copyright © nequal, Creative Commons Attribution-
                                      Noncommercial 2.1 @ PHP Study #46.
クロールとキーワード抽出をPHPで(2)

• キーワードの抽出
   – 関数名/メソッド名/クラス名/変数名
   – tokenizer を使う

• token_get_all
   • PHP
   •         tokenize
      • http://php.net/tokenizer

• T_STRING
• T_VARIABLE
                       Copyright © nequal, Creative Commons Attribution-
                                     Noncommercial 2.1 @ PHP Study #46.
スコアリングと並び替え
スコアリングと並び替え
• なにかの基準で検索結果を並び替える
• あてはまりの良い⽂書を上に出す

• 普通の検索 なら
 – ページランク (Google のウェブ検索)
 – TF-IDF
     • ⽂書中の単語の出現頻度
     • その単語の⽂書全体での珍しさ
 – ...


                 Copyright © nequal, Creative Commons Attribution-
                               Noncommercial 2.1 @ PHP Study #46.
スコアリングと並び替えをPHPで
• スコアはソースコード中のそのキーワードの出現
  数
• 多い順に並び替え
                                PHP 5.3 なら
                             function($v1, $v2)
uasort(                          でいける!
  $scored,
  create_function(
    '$v1, $v2',
    'return $v1[¥'count¥'] < $v2[¥'count¥'];'
  )
);                      Copyright © nequal, Creative Commons Attribution-
                                      Noncommercial 2.1 @ PHP Study #46.
デモ


Hyper Pudding
http://gist.github.com/192879
技術的な課題
• デモったやつは全部 on memory
  – 大規模⽂書はイケない
    • symfony で 140MB くらい⾷うかな
  – ということで,転置インデックスを外部ファイル
    (Key-Value Store... まぁ,SQLite とかでもいい
    けど) に保持するといい
• 並び替えの基準は出現頻度でいいの?
  – これはまあ難しいですね
  – 属性情報とかいろいろとればさらに
• And/Or 検索

                     Copyright © nequal, Creative Commons Attribution-
                                   Noncommercial 2.1 @ PHP Study #46.
まとめ
• 簡単な検索エンジンはPHPでもつくれる
 – それもお⼿軽に
• インデックスをあらかじめつくっておけば検索は
  瞬時にできる
• 検索技術とか楽しい




             Copyright © nequal, Creative Commons Attribution-
                           Noncommercial 2.1 @ PHP Study #46.
ありがとうございました



Question?

Weitere ähnliche Inhalte

Ähnlich wie PHP Source Code Search with PHP

PHPで並列処理する ライブラリを作った
PHPで並列処理する ライブラリを作ったPHPで並列処理する ライブラリを作った
PHPで並列処理する ライブラリを作ったHironobu Saitoh
 
PEP8を読んでみよう
PEP8を読んでみようPEP8を読んでみよう
PEP8を読んでみよう2bo 2bo
 
Smalltalk との比較で深まる Citrine の理解
Smalltalk との比較で深まる Citrine の理解Smalltalk との比較で深まる Citrine の理解
Smalltalk との比較で深まる Citrine の理解TAKANO Mitsuhiro
 
4時間耐久 PHP on Heroku
4時間耐久 PHP on Heroku4時間耐久 PHP on Heroku
4時間耐久 PHP on HerokuYusuke Ando
 
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介Shoken Fujisaki
 
Oktavia全文検索エンジン - SphinxCon JP 2014
Oktavia全文検索エンジン - SphinxCon JP 2014Oktavia全文検索エンジン - SphinxCon JP 2014
Oktavia全文検索エンジン - SphinxCon JP 2014Yoshiki Shibukawa
 
PSR-3 Logger Interfaceの紹介
PSR-3 Logger Interfaceの紹介PSR-3 Logger Interfaceの紹介
PSR-3 Logger Interfaceの紹介Hiraku Nakano
 
第67回PHP勉強会LT(その2)
第67回PHP勉強会LT(その2)第67回PHP勉強会LT(その2)
第67回PHP勉強会LT(その2)Hideyuki Shimooka
 
anything-php-funcref-perl.el
anything-php-funcref-perl.elanything-php-funcref-perl.el
anything-php-funcref-perl.elKenichirou Oyama
 
FukuokaPHP 3
FukuokaPHP 3FukuokaPHP 3
FukuokaPHP 3ichikaway
 
8時間耐久 PHP構築の教室
8時間耐久 PHP構築の教室8時間耐久 PHP構築の教室
8時間耐久 PHP構築の教室Yusuke Ando
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of PythonTakanori Suzuki
 
composer-scriptsについて
composer-scriptsについてcomposer-scriptsについて
composer-scriptsについてHiraku Nakano
 
PyScriptの紹介
PyScriptの紹介PyScriptの紹介
PyScriptの紹介2bo 2bo
 
私の好きなPython構文 vol.2 #nds46
私の好きなPython構文 vol.2 #nds46私の好きなPython構文 vol.2 #nds46
私の好きなPython構文 vol.2 #nds46civicpg
 
今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築You&I
 
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜Megagon Labs
 
PHP buildpackでhackとphalconが動いた件について
PHP buildpackでhackとphalconが動いた件についてPHP buildpackでhackとphalconが動いた件について
PHP buildpackでhackとphalconが動いた件について健治郎 安井
 

Ähnlich wie PHP Source Code Search with PHP (20)

PHPで並列処理する ライブラリを作った
PHPで並列処理する ライブラリを作ったPHPで並列処理する ライブラリを作った
PHPで並列処理する ライブラリを作った
 
第67回PHP勉強会LT
第67回PHP勉強会LT第67回PHP勉強会LT
第67回PHP勉強会LT
 
PEP8を読んでみよう
PEP8を読んでみようPEP8を読んでみよう
PEP8を読んでみよう
 
社内Chef勉強会
社内Chef勉強会社内Chef勉強会
社内Chef勉強会
 
Smalltalk との比較で深まる Citrine の理解
Smalltalk との比較で深まる Citrine の理解Smalltalk との比較で深まる Citrine の理解
Smalltalk との比較で深まる Citrine の理解
 
4時間耐久 PHP on Heroku
4時間耐久 PHP on Heroku4時間耐久 PHP on Heroku
4時間耐久 PHP on Heroku
 
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介
LLプログラマ向けSwift ExtensionsとテストライブラリQuickの紹介
 
Oktavia全文検索エンジン - SphinxCon JP 2014
Oktavia全文検索エンジン - SphinxCon JP 2014Oktavia全文検索エンジン - SphinxCon JP 2014
Oktavia全文検索エンジン - SphinxCon JP 2014
 
PSR-3 Logger Interfaceの紹介
PSR-3 Logger Interfaceの紹介PSR-3 Logger Interfaceの紹介
PSR-3 Logger Interfaceの紹介
 
第67回PHP勉強会LT(その2)
第67回PHP勉強会LT(その2)第67回PHP勉強会LT(その2)
第67回PHP勉強会LT(その2)
 
anything-php-funcref-perl.el
anything-php-funcref-perl.elanything-php-funcref-perl.el
anything-php-funcref-perl.el
 
FukuokaPHP 3
FukuokaPHP 3FukuokaPHP 3
FukuokaPHP 3
 
8時間耐久 PHP構築の教室
8時間耐久 PHP構築の教室8時間耐久 PHP構築の教室
8時間耐久 PHP構築の教室
 
「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python「Python言語」はじめの一歩 / First step of Python
「Python言語」はじめの一歩 / First step of Python
 
composer-scriptsについて
composer-scriptsについてcomposer-scriptsについて
composer-scriptsについて
 
PyScriptの紹介
PyScriptの紹介PyScriptの紹介
PyScriptの紹介
 
私の好きなPython構文 vol.2 #nds46
私の好きなPython構文 vol.2 #nds46私の好きなPython構文 vol.2 #nds46
私の好きなPython構文 vol.2 #nds46
 
今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築
 
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜
GiNZAで始める日本語依存構造解析 〜CaboCha, UDPipe, Stanford NLPとの比較〜
 
PHP buildpackでhackとphalconが動いた件について
PHP buildpackでhackとphalconが動いた件についてPHP buildpackでhackとphalconが動いた件について
PHP buildpackでhackとphalconが動いた件について
 

Mehr von Sotaro Karasawa

Openpear Project の紹介
Openpear Project の紹介Openpear Project の紹介
Openpear Project の紹介Sotaro Karasawa
 
Modern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI SeminarModern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI SeminarSotaro Karasawa
 
フレームワークxWordPress
フレームワークxWordPressフレームワークxWordPress
フレームワークxWordPressSotaro Karasawa
 
新しくなったOpenpear by nequal
新しくなったOpenpear by nequal新しくなったOpenpear by nequal
新しくなったOpenpear by nequalSotaro Karasawa
 
第42PHP勉強会Ethna 発表資料
第42PHP勉強会Ethna 発表資料第42PHP勉強会Ethna 発表資料
第42PHP勉強会Ethna 発表資料Sotaro Karasawa
 
Introduction of openpear
Introduction of openpearIntroduction of openpear
Introduction of openpearSotaro Karasawa
 
超個人的宣伝と2008年PHPのまとめ
超個人的宣伝と2008年PHPのまとめ超個人的宣伝と2008年PHPのまとめ
超個人的宣伝と2008年PHPのまとめSotaro Karasawa
 
openpearについて@楽天テクノロジーカンファレンス
openpearについて@楽天テクノロジーカンファレンスopenpearについて@楽天テクノロジーカンファレンス
openpearについて@楽天テクノロジーカンファレンスSotaro Karasawa
 
Mockingbirdの紹介LT@PHP勉強会
Mockingbirdの紹介LT@PHP勉強会Mockingbirdの紹介LT@PHP勉強会
Mockingbirdの紹介LT@PHP勉強会Sotaro Karasawa
 
Ethna的ActionとView@設計勉強会
Ethna的ActionとView@設計勉強会Ethna的ActionとView@設計勉強会
Ethna的ActionとView@設計勉強会Sotaro Karasawa
 
Mockingbirdイベントハンドリング@拡張機能勉強会
Mockingbirdイベントハンドリング@拡張機能勉強会Mockingbirdイベントハンドリング@拡張機能勉強会
Mockingbirdイベントハンドリング@拡張機能勉強会Sotaro Karasawa
 
Mockingbirdサーバサイド@拡張機能勉強会
Mockingbirdサーバサイド@拡張機能勉強会Mockingbirdサーバサイド@拡張機能勉強会
Mockingbirdサーバサイド@拡張機能勉強会Sotaro Karasawa
 
Mockingbird@拡張機能勉強会
Mockingbird@拡張機能勉強会Mockingbird@拡張機能勉強会
Mockingbird@拡張機能勉強会Sotaro Karasawa
 
Mockingbirdの実装@拡張機能勉強会
Mockingbirdの実装@拡張機能勉強会Mockingbirdの実装@拡張機能勉強会
Mockingbirdの実装@拡張機能勉強会Sotaro Karasawa
 
Mockingbirdのタブバーの実装@拡張機能勉強会
Mockingbirdのタブバーの実装@拡張機能勉強会Mockingbirdのタブバーの実装@拡張機能勉強会
Mockingbirdのタブバーの実装@拡張機能勉強会Sotaro Karasawa
 
第34回PHP勉強会発表資料 SimpleXML
第34回PHP勉強会発表資料 SimpleXML第34回PHP勉強会発表資料 SimpleXML
第34回PHP勉強会発表資料 SimpleXMLSotaro Karasawa
 

Mehr von Sotaro Karasawa (20)

Ethna Updates
Ethna UpdatesEthna Updates
Ethna Updates
 
Openpear Project の紹介
Openpear Project の紹介Openpear Project の紹介
Openpear Project の紹介
 
Modern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI SeminarModern PHP Programming @ PFI Seminar
Modern PHP Programming @ PFI Seminar
 
Internship at PFI
Internship at PFIInternship at PFI
Internship at PFI
 
フレームワークxWordPress
フレームワークxWordPressフレームワークxWordPress
フレームワークxWordPress
 
新しくなったOpenpear by nequal
新しくなったOpenpear by nequal新しくなったOpenpear by nequal
新しくなったOpenpear by nequal
 
第42PHP勉強会Ethna 発表資料
第42PHP勉強会Ethna 発表資料第42PHP勉強会Ethna 発表資料
第42PHP勉強会Ethna 発表資料
 
Introduction of openpear
Introduction of openpearIntroduction of openpear
Introduction of openpear
 
超個人的宣伝と2008年PHPのまとめ
超個人的宣伝と2008年PHPのまとめ超個人的宣伝と2008年PHPのまとめ
超個人的宣伝と2008年PHPのまとめ
 
openpearについて@楽天テクノロジーカンファレンス
openpearについて@楽天テクノロジーカンファレンスopenpearについて@楽天テクノロジーカンファレンス
openpearについて@楽天テクノロジーカンファレンス
 
LT openpear@LL温泉
LT openpear@LL温泉LT openpear@LL温泉
LT openpear@LL温泉
 
PHP超入門@LL温泉
PHP超入門@LL温泉PHP超入門@LL温泉
PHP超入門@LL温泉
 
Mockingbirdの紹介LT@PHP勉強会
Mockingbirdの紹介LT@PHP勉強会Mockingbirdの紹介LT@PHP勉強会
Mockingbirdの紹介LT@PHP勉強会
 
Ethna的ActionとView@設計勉強会
Ethna的ActionとView@設計勉強会Ethna的ActionとView@設計勉強会
Ethna的ActionとView@設計勉強会
 
Mockingbirdイベントハンドリング@拡張機能勉強会
Mockingbirdイベントハンドリング@拡張機能勉強会Mockingbirdイベントハンドリング@拡張機能勉強会
Mockingbirdイベントハンドリング@拡張機能勉強会
 
Mockingbirdサーバサイド@拡張機能勉強会
Mockingbirdサーバサイド@拡張機能勉強会Mockingbirdサーバサイド@拡張機能勉強会
Mockingbirdサーバサイド@拡張機能勉強会
 
Mockingbird@拡張機能勉強会
Mockingbird@拡張機能勉強会Mockingbird@拡張機能勉強会
Mockingbird@拡張機能勉強会
 
Mockingbirdの実装@拡張機能勉強会
Mockingbirdの実装@拡張機能勉強会Mockingbirdの実装@拡張機能勉強会
Mockingbirdの実装@拡張機能勉強会
 
Mockingbirdのタブバーの実装@拡張機能勉強会
Mockingbirdのタブバーの実装@拡張機能勉強会Mockingbirdのタブバーの実装@拡張機能勉強会
Mockingbirdのタブバーの実装@拡張機能勉強会
 
第34回PHP勉強会発表資料 SimpleXML
第34回PHP勉強会発表資料 SimpleXML第34回PHP勉強会発表資料 SimpleXML
第34回PHP勉強会発表資料 SimpleXML
 

Kürzlich hochgeladen

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Hiroshi Tomioka
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsWSO2
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptxsn679259
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 

Kürzlich hochgeladen (11)

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 

PHP Source Code Search with PHP

  • 1. PHP Source Code Search with PHP 柄沢聡太郎 (sotarok) http://nequal.jp/ twitter.com/sotarok
  • 2. 始める前に Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 3. 今⽇はPHP勉強会 Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 4. なぜ 9/29 ではないのか Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 5. 懇親会はピザだって? Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 6. ⾁はどうしたんですか Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 7. 本来のPHP勉強会 Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 8. PHPerは ⾁の精神を忘れ てしまったか Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 9. ごめんなさい冗談です gusagiさん幹事おつかれさまです Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 11. sotarok • そうたろう(けー) • プリン • プリン • プリン • pudding • プリン • ⾁ • ごはん • 自転⾞ • 写真 – Sony α 300 • Ethna • nequal Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 12. 宣伝 • WikiHub – http://wikihub.org/ – Git で⽂書管理して,それを Wiki 形式で整形して 表⽰ – GitHub の Service Hook で簡単同期 • 制限つきOpenBeta – 100⼈まで Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 13. 宣伝2 なぜか誰も 買ってこない • プリンが好きです Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 14. 宣伝2 yuchimiriさんに RTまでされたのに • プリンが好きです Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 15. 検索エンジンとか つくってるとこ! Preferred Infrastructure (PFI) というところでインターンやってます だからか だからです Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 16. Agenda • 検索エンジン • 転置インデックス • クロールとキーワード抽出 • スコアリングと並び替え • デモ • 技術的な課題とか Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 17. 検索エンジン • キーワードを⼊⼒ – → そのキーワードが含まれる(そして探したいと 思われる)⽂書が探せる • ソースコード検索 – grep – gtags (GNU GLOBAL) – trac + Hyper Estraier (BTS + Plugin) – Google Code Search Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 18. grep • 与えられたキーワードをファイルをたどり,⽂字 列⼀致で探す • 前処理が必要ない • どこにでも⼊ってる grepのデメリット • 大量の⽂書から探すのは時間がかかる – 同じキーワードで再検索するときもまた同じ処理 • ランキングづけができない Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 19. 検索エンジンを作る • 既存のいろんなソフトウェアを使うのもいいけど • 「検索エンジン」 – そんな難しくない – PHPでもできる – カンタンだよ! • 今回の目標 – ローカルのPHPソースファイルからメソッドや関数 や変数を検索できるようにする – ディレクトリを指定して,再帰的にPHPファイルを 検索 – grep -rn 'substr' **/*.php Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 21. 転置インデックス • キーワードから⽂書を逆引きできるようにあらか じめつくっておくインデックス • 焼⾁ => – ⽜角 – Wikipedia – 焼⾁ – YAKINIQUEST - ヤキニクエスト – ... Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 22. ※⽂書はフィクションです ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like Sushi. ⽂書3 Dankogai is an enemy of PHPer. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 23. ※⽂書はフィクションです ⽂書1 I like Sushi , Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like Sushi. ⽂書3 Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 24. Sushi 1 ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like ⽂書3 Sushi. Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 25. Sushi 1 Yakiniku 1 ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like ⽂書3 Sushi. Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 26. Sushi 1 Yakiniku 1 pudding 1 ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like ⽂書3 Sushi. Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 27. Sushi 1 Yakiniku 1 2 pudding 1 ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like ⽂書3 Sushi. Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 28. Sushi 1 2 Yakiniku 1 2 pudding 1 ⽂書1 I like Sushi, Yakiniku and pudding ! ⽂書2 PHPer like Yakiniku. Maybe not like ⽂書3 Sushi. Dankogai is an enemy of PHPer. He also like Yakiniku. Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 29. 転置インデックスをPHPで • array でしょJK $inverted_index = array( 'miyazaki' => array(1, 2, 6, 4 ...), 'aoi' => array(2, 6, 7, ...), 'sotarok' => array(...), ... ); 配列のキー: 配列の要素: 単語 ⽂書IDのリスト Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 31. クロールとキーワード抽出 • 対象の⽂書からキーワードを拾い集める • クローラー -> Google なら Google Bot とか • キーワード -> – 空⽩区切りの⽂字列(英語圏のひと) – 形態素解析(明⽇ は あめ だ) – n-gram • n⽂字区切りでキーワードにする • 2-gram(bi-gram) • 明⽇ ⽇は はあ あめ めだ Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 32. クロールとキーワード抽出をPHPで(1) •function crawl ($dirname) • foreach(glob($dirname . "/*") as $file) • if is_dir($file): • $files += crawl ($file) • else: • if $file ~= /.+¥.php$/ • $files[] = $file • return $files Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 33. クロールとキーワード抽出をPHPで(2) • キーワードの抽出 – 関数名/メソッド名/クラス名/変数名 – tokenizer を使う • token_get_all • PHP • tokenize • http://php.net/tokenizer • T_STRING • T_VARIABLE Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 35. スコアリングと並び替え • なにかの基準で検索結果を並び替える • あてはまりの良い⽂書を上に出す • 普通の検索 なら – ページランク (Google のウェブ検索) – TF-IDF • ⽂書中の単語の出現頻度 • その単語の⽂書全体での珍しさ – ... Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 36. スコアリングと並び替えをPHPで • スコアはソースコード中のそのキーワードの出現 数 • 多い順に並び替え PHP 5.3 なら function($v1, $v2) uasort( でいける! $scored, create_function( '$v1, $v2', 'return $v1[¥'count¥'] < $v2[¥'count¥'];' ) ); Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 38. 技術的な課題 • デモったやつは全部 on memory – 大規模⽂書はイケない • symfony で 140MB くらい⾷うかな – ということで,転置インデックスを外部ファイル (Key-Value Store... まぁ,SQLite とかでもいい けど) に保持するといい • 並び替えの基準は出現頻度でいいの? – これはまあ難しいですね – 属性情報とかいろいろとればさらに • And/Or 検索 Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.
  • 39. まとめ • 簡単な検索エンジンはPHPでもつくれる – それもお⼿軽に • インデックスをあらかじめつくっておけば検索は 瞬時にできる • 検索技術とか楽しい Copyright © nequal, Creative Commons Attribution- Noncommercial 2.1 @ PHP Study #46.