Git Product home page Git Product logo

extract-content-javascript's Introduction

ExtractContentJS

本文抽出 JavaScript ライブラリ

やれること

  • 本文抽出

  • タグおすすめ

ファイル

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

lib/lib.js

共通するもの

lib/extract-content.js

本文抽出

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

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

sketch/extract-content.test.js

本文抽出テスト

lib/scoring-words.js

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

使い方

本文抽出インタフェース

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

ExtractContentJS.LayeredExtractor

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からの深さ

AUTHOR

INA Lintaro

Copryright

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

Copyright of the original implementation

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

LICENCE

MIT License

extract-content-javascript's People

Contributors

hotchpotch avatar nanto avatar tarao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.