mcpField
T
text-summarizer

text-summarizer

github.com/dkyazzentwatwaドキュメント124693 回インストール29 週間前に更新
リポジトリ

text-summarizer について

text-summarizer は、文書の抽出型要約を行う Python ツールおよびコマンドラインツールです。複数のアルゴリズムを備え、要約の長さや要点抽出、バッチ処理を指定できます。

主な機能

  1. 01抽出型要約
  2. 02TextRank、LSA、頻度ベースの手法
  3. 03比率・文数・単語数による長さ指定
  4. 04要点の抽出
  5. 05テキストとファイルの一括処理

活用シーン

  1. 01ニュース記事を指定した文数に要約
  2. 02研究論文をアブストラクト相当の長さに要約
  3. 03会議メモから要点を抽出

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill text-summarizer

インストール後、Claude Code で/text-summarizerを入力して読み込まれたか確認します。

同梱ファイルscripts/requirements.txtscripts/text_summarizer.py

詳細

テキスト要約

抽出型要約を使って、長いテキスト文書から簡潔な要約を作成します。意味を保ちながら、最も重要な文を特定して抽出します。

クイックスタート

from scripts.text_summarizer import TextSummarizer

# Summarize text
summarizer = TextSummarizer()
summary = summarizer.summarize(long_text, ratio=0.2)  # 20% of original
print(summary)

# Summarize file
summary = summarizer.summarize_file("article.txt", num_sentences=5)

機能

  • 抽出型要約:元のテキストから重要な文を選択します
  • 長さの調整:比率、文数、または単語数で指定できます
  • 複数のアルゴリズム:TextRank、LSA、頻度ベース
  • 要点:箇条書き形式の要約を抽出します
  • バッチ処理:複数の文書を要約します
  • 構造の維持:文の順序を維持するオプションがあります

API リファレンス

初期化
summarizer = TextSummarizer(
    method="textrank",    # textrank, lsa, frequency
    language="english"
)
要約
# By ratio (20% of original length)
summary = summarizer.summarize(text, ratio=0.2)

# By sentence count
summary = summarizer.summarize(text, num_sentences=5)

# By word count
summary = summarizer.summarize(text, max_words=100)
要点の抽出
# Get bullet points
points = summarizer.extract_key_points(text, num_points=5)
for point in points:
    print(f"• {point}")
バッチ処理
# Summarize multiple texts
texts = [text1, text2, text3]
summaries = summarizer.summarize_batch(texts, ratio=0.2)

# Summarize files in directory
summaries = summarizer.summarize_directory("./articles/", ratio=0.3)
オプション
# Preserve original sentence order
summary = summarizer.summarize(text, preserve_order=True)

# Include title/first sentence
summary = summarizer.summarize(text, include_first=True)

# Minimum sentence length filter
summarizer.min_sentence_length = 10

CLI の使用方法

# Summarize text file
python text_summarizer.py --input article.txt --ratio 0.2

# Specific sentence count
python text_summarizer.py --input article.txt --sentences 5

# Extract key points
python text_summarizer.py --input article.txt --points 5

# Batch process
python text_summarizer.py --input-dir ./docs --output-dir ./summaries --ratio 0.3

# Output to file
python text_summarizer.py --input article.txt --output summary.txt --ratio 0.2
CLI 引数
引数説明デフォルト
--input入力ファイルのパス必須
--output出力ファイルのパスstdout
--input-dirファイルのディレクトリ-
--output-dir出力ディレクトリ-
--ratio要約の比率(0.0-1.0)0.2
--sentences文の数-
--words単語数の上限-
--pointsN 個の要点を抽出-
--method使用するアルゴリズムtextrank
--preserve-order文の順序を維持False

使用例

ニュース記事の要約
summarizer = TextSummarizer()

article = """
[Long news article text...]
"""

# Get a 3-sentence summary
summary = summarizer.summarize(article, num_sentences=3)
print("Summary:")
print(summary)

# Get key points
points = summarizer.extract_key_points(article, num_points=5)
print("\nKey Points:")
for i, point in enumerate(points, 1):
    print(f"{i}. {point}")
研究論文の要旨
summarizer = TextSummarizer(method="lsa")

paper = open("research_paper.txt").read()

# Create abstract-length summary
abstract = summarizer.summarize(paper, max_words=250)
print(abstract)
会議メモの要約
summarizer = TextSummarizer()

notes = """
Meeting started at 2pm. John presented Q3 results showing 15% growth.
Sarah raised concerns about supply chain delays affecting Q4 projections.
The team discussed mitigation strategies including dual-sourcing.
Budget allocation for marketing was approved at $50k.
Next steps include vendor outreach by Friday.
Follow-up meeting scheduled for next Tuesday.
"""

summary = summarizer.summarize(notes, num_sentences=3)
points = summarizer.extract_key_points(notes, num_points=4)

print("Summary:", summary)
print("\nAction Items:")
for point in points:
    print(f"• {point}")
文書のバッチ要約
summarizer = TextSummarizer()

import os
for filename in os.listdir("./documents"):
    if filename.endswith(".txt"):
        text = open(f"./documents/{filename}").read()
        summary = summarizer.summarize(text, ratio=0.2)

        with open(f"./summaries/{filename}", "w") as f:
            f.write(summary)

        print(f"Summarized: {filename}")

アルゴリズムの比較

アルゴリズム速度品質最適な用途
TextRank中高一般的なテキスト
LSA高速良好技術文書
Frequency高速中素早い要約

依存関係

nltk>=3.8.0
numpy>=1.24.0
scikit-learn>=1.2.0

制限事項

  • 抽出型のみ(言い換えや新しいテキストの生成は行いません)
  • 構造の整ったテキスト(段落や明確な文)で最も効果を発揮します
  • 非常に短いテキストは、うまく要約できない場合があります
  • 文脈を深く理解するわけではないため、ニュアンスを見落とすことがあります

コメント