Là một dự án mã nguồn mở, mailgun/talon đã đạt 1.3k sao trên GitHub, ngôn ngữ Python.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Mailgun library to extract message quotations and signatures.
Plain-text quotation headers are recognized in several languages, including
Ukrainian reply headers produced by localized mail clients.
If you ever tried to parse message quotations or signatures you know that absence of any formatting standards in this area could make this task a nightmare. Hopefully this library will make your life much easier. The name of the project is inspired by TALON - multipurpose robot designed to perform missions ranging from reconnaissance to combat and operate in a number of hostile environments. That’s what a good quotations and signature parser should be like :smile:
Installation
Talon supports Python 3.7 and newer.
Quotations and brute-force signature extraction:
.. code:: sh
pip install talon
Machine-learning signature extraction needs numpy, scipy, scikit-learn, and
joblib. Install those extras with:
.. code:: sh
pip install "talon[ml]"
Talon includes inline type annotations (PEP 561_), so type checkers such as
mypy pick them up automatically.
.. _PEP 561: https://peps.python.org/pep-0561/
Usage
Here’s how you initialize the library and extract a reply from a text
message:
.. code:: python
import talon
from talon import quotations
talon.init()
text = """Reply
-----Original Message-----
Quote"""
reply = quotations.extract_from(text, 'text/plain')
# -- OR --
reply = quotations.extract_from_plain(text)
# reply == "Reply"
A signature can follow the quote. extract_from keeps that signature
with the reply. extract_quotation returns the quoted span between them,
including the splitter line:
.. code:: python
text = """Reply
On 11-Apr-2011, at 6:54 PM, Bob <[email protected]> wrote:
> Quote
--
Bob Smith"""
reply = quotations.extract_from_plain(text)
# reply == "Reply\n\n--\nBob Smith"
quotation = quotations.extract_quotation(text, 'text/plain')
# -- OR --
quotation = quotations.extract_quotation_plain(text)
# quotation == "On 11-Apr-2011, at 6:54 PM, Bob <[email protected]> wrote:\n\n> Quote"
To extract a reply from html:
.. code:: python
html = """Reply
<blockquote>
<div>
On 11-Apr-2011, at 6:54 PM, Bob <[email protected]> wrote:
</div>
<div>
Quote
</div>
</blockquote>"""
reply = quotations.extract_from(html, 'text/html')
# -- OR --
reply = quotations.extract_from_html(html)
# reply == "<html><body><p>Reply</p></body></html>"
quotation = quotations.extract_quotation_html(html)
# quotation is the removed <blockquote>, including "Quote"
Often the best way is the easiest one. Here’s how you can extract
signature from email message without any
machine learning fancy stuff:
.. code:: python
from talon.signature.bruteforce import extract_signature
message = """Wow. Awesome!
--
Bob Smith"""
text, signature = extract_signature(message)
# text == "Wow. Awesome!"
# signature == "--\nBob Smith"
Quick and works like a charm 90% of the time. For other 10% you can use
the power of machine learning algorithms (requires talon[ml]):
.. code:: python
import talon
# don't forget to init the library first
# it loads machine learning classifiers
talon.init()
from talon import signature
message = """Thanks Sasha, I can't go any higher and is why I limited it to the
homepage.
John Doe
via mobile"""
text, signature = signature.extract(message, sender='[email protected]')
# text == "Thanks Sasha, I can't go any higher and is why I limited it to the\nhomepage."
# signature == "John Doe\nvia mobile"
For machine learning talon currently uses the scikit-learn_ library to build SVM
classifiers. The core of machine learning algorithm lays in
talon.signature.learning package. It defines a set of features to
apply to a message (featurespace.py), how data sets are built
(dataset.py), classifier’s interface (classifier.py).
Currently the data used for training is taken from our personal email
conversations and from ENRON_ dataset. As a result of applying our set
of features to the dataset we provide files classifier and
train.data that don’t have any personal information but could be
used to load trained classifier. Those files should be regenerated every
time the feature/data set is changed.
To regenerate the model files, you can run
.. code:: sh
python train.py
or
.. code:: python
from talon.signature import EXTRACTOR_FILENAME, EXTRACTOR_DATA
from talon.signature.learning.classifier import train, init
train(init(), EXTRACTOR_DATA, EXTRACTOR_FILENAME)
Open-source Dataset
Recently we started a forge_ project to create an open-source, annotated dataset of raw emails. In the project we
used a subset of ENRON_ data, cleansed of private, health and financial information by EDRM_. At the moment over 190
emails are annotated. Any contribution and collaboration on the project are welcome. Once the dataset is ready we plan to
start using it for talon.
talon comes with a pre-processed dataset and a pre-trained classifier. To retrain the classifier on your own dataset of raw emails, structure and annotate them in the same way the forge_ project does. Then do:
.. code:: python
from talon.signature.learning.dataset import build_extraction_dataset
from talon.signature.learning import classifier as c
build_extraction_dataset("/path/to/your/P/folder", "/path/to/talon/signature/data/train.data")
c.train(c.init(), "/path/to/talon/signature/data/train.data", "/path/to/talon/signature/data/classifier")
Note that for signature extraction you need just the folder with the positive samples with annotated signature lines (P folder).
.. _forge: https://github.com/mailgun/forge
Research
The library is inspired by the following research papers and projects:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mailgun/talon là nguồn chính thức.
mailgun/talon có phải mã nguồn mở không?
Có — mailgun/talon phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/mailgun/talon.
mailgun/talon có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho mailgun/talon. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
mailgun/talon dùng license gì?
mailgun/talon phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
mailgun/talon là gì?
mailgun/talon (mailgun/talon) là dự án Python TopGit theo dõi. Tính tới lần đồng bộ gần nhất, repo có 1.3k sao.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc talon có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về talon.