Skip to content

hatena/extract-content-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

本文抽出 JavaScript ライブラリ

  • 本文抽出

  • タグおすすめ

基本的には以下をこの順に読み込めば動く:

lib/lib.js

共通するもの

lib/extract-content.js

本文抽出

リポジトリのルートでmake packageするとこれらを連結した extract-content-all.js が生成される.

実際の使い方を詳しく見たくなったら:

sketch/extract-content.test.js

本文抽出テスト

lib/scoring-words.js

タグのスコアリング(サンプル)

本文抽出だけしたい/ハンドラを指定したい場合に使う.

var ex = new ExtractContentJS.LayeredExtractor();
//ex.addHandler( ex.factory.getHandler('Description') );
//ex.addHandler( ex.factory.getHandler('Scraper'));
//ex.addHandler( ex.factory.getHandler('GoogleAdsence') );
ex.addHandler( ex.factory.getHandler('Heuristics') );
var res = ex.extract(document);

if (res.isSuccess) {
    res.url;   // URL string
    res.title; // title string
    res.engine; // 抽出に用いたハンドラそのもの
    res.content; // コンテンツクラスのインスタンス(後述)
}

ハンドラはいまのところHeuristicsのみ実装済み.

content.asLeaves(); // 本文だと判定された葉ノードを含む葉クラスインスタンス(後述)の配列を返す
content.asNode(); // すべての葉ノードの共通の祖先のうち最深のものを返す
content.asTextFragment(); // asLeaves()に含まれるノードのテキストを連結したものを返す
content.toString(); // asNode()のtextContentを返す
leaf.node; // 葉ノード
leaf.depth; // ノードのbodyからの深さ

INA Lintaro

Copyright © 2009 INA Lintaro / Hatena. All rights reserved.

Copyright © 2007/2008 Nakatani Shuyo / Cybozu Labs Inc. All rights reserved.

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •