douban linguist
DESCRIPTION
Douban LinguistTRANSCRIPT
• 遍历⺫⽬目录下所有⽂文件
• 忽略以 . 开头的⺫⽬目录, 忽略⼆二进制⽂文件/⽣生成⽂文件(如 coffeescript ⽣生成的 js)/压缩⽂文件(如 jquery.min.js)/通⽤用的第三⽅方类库(如 bootstrap)
• 对余下的⽂文件进⾏行分析并汇总
当输⼊入路径是⺫⽬目录时
当输⼊入路径是⽂文件时
• 根据⽂文件扩展名查找(数据源⾃自samples.json, languages.yml)
• 未匹配到时返回空(None)
• 匹配到⼀一个结果时将其返回
• 匹配到多个结果时分析⽂文件内容
算法: statistical classifier (之前⽂文档中写的是 Bayesian classifier)
分析内容
• 使⽤用 Tokenizer 将内容转为 tokens
• 拿 tokens 分别与所有(根据扩展名)匹配到的编程语⾔言的 Tokens 进⾏行⽐比较, 将概率最⼤大编程语⾔言判定为结果
Ruby Python 替代 #
pygments.rb pygments !前者是后者的 Ruby 封装实现
mime-types mimetypes Python 内置
escap_utils urllib 毫⽆无鸭梨
charlock_holmes ? 先⾛走着
计划时对依赖处理是这样想的
Code 来需求了!!!
• 移动组: PR diff 中不需要显⽰示 .pbxproj, .mobileprovision
• 前端组: 统计时不计⼊入压缩版本以及 coffeescript ⽣生成⽂文件
判断是否⽣生成⽂文件
Scanner 带来的性能提升
Travis-ci 中使⽤用 Scanner 前后对⽐比
github-linguist 与使⽤用 Scanner 后的douban-linguist 对⽐比
注: 减少的 22 个 test case ⻅见 https://github.com/douban/linguist/blob/eba200742c9f7ebd433b7aa73774381b80ddb0fa/tests/test_strscan.py
2013 Drinkup@北京
• 咨询 Linguist 与 Github 交互实现 !
!
• 问我 Python 版有没⽐比 Ruby 快 !
• 告诉他提了个 pull request
PUSH > HOOK > QUEUE > (PULL) > CALCULATE > CALLBACK
相关链接
• https://github.com/douban/linguist
• https://github.com/douban/PyCharlockHolmes
• https://github.com/liluo/mime
• https://github.com/liluo/pygments-github-lexers
• https://github.com/cuteio/scanner
• https://github.com/github/linguist