自然言語で書かれた時間情報表現を抽出/規格化するルールベースの解析器

Overview

ja-timex

自然言語で書かれた時間情報表現を抽出/規格化するルールベースの解析器

概要

ja-timex は、現代日本語で書かれた自然文に含まれる時間情報表現を抽出しTIMEX3と呼ばれるアノテーション仕様に変換することで、プログラムが利用できるような形に規格化するルールベースの解析器です。

以下の機能を持っています。

  • ルールベースによる日本語テキストからの日付や時刻、期間や頻度といった時間情報表現を抽出
  • アラビア数字/漢数字、西暦/和暦などの多彩なフォーマットに対応
  • 時間表現のdatetime/timedelta形式への変換サポート

入力

from ja_timex import TimexParser

timexes = TimexParser().parse("彼は2008年4月から週に3回ジョギングを1時間行ってきた")

出力

[<TIMEX3 tid="t0" type="DATE" value="2008-04-XX" text="2008年4月">,
 <TIMEX3 tid="t1" type="SET" value="P1W" freq="3X" text="週に3回">,
 <TIMEX3 tid="t2" type="DURATION" value="PT1H" text="1時間">]

datetime/timedeltaへの変換

# <TIMEX3 tid="t0" type="DATE" value="2008-04-XX" text="2008年4月">
In []: timexes[0].to_datetime()
Out[]: DateTime(2008, 4, 1, 0, 0, 0, tzinfo=Timezone('Asia/Tokyo'))
# <TIMEX3 tid="t2" type="DURATION" value="PT1H" text="1時間">
In []: timexes[2].to_duration()
Out[]: Duration(hours=1)

インストール

pip install ja-timex

ドキュメント

ja-timex documentation

参考仕様

本パッケージは、以下の論文で提案されている時間情報アノテーションの枠組みを元に作成しています。

Comments
  • [Feature Request] 漢数字からアラビア数字への変換を無効にするオプションの追加

    [Feature Request] 漢数字からアラビア数字への変換を無効にするオプションの追加

    🚀 機能提案

    漢数字からアラビア数字への変換を無効にするオプションの追加

    モチベーション

    • 漢数字からアラビア数字に変換する際に「一時はどうなることかと」「十分なインターバル」といった表現を誤検出してしまう問題がある
    • 日付が漢数字で書かれないドキュメントであることが分かっている場合には、こうした変換を無効にすることで抽出精度を上げることができる

    解決策や課題解決の方針

    以下のように引数を渡す。

    timex_parser = TimexParser(ignroe_kansuji=True)
    

    追加/補足情報

    enhancement 
    opened by yagays 3
  • [Modify Rules] 夜9時・今夜9時のような表現のサポート

    [Modify Rules] 夜9時・今夜9時のような表現のサポート

    📝 時間情報表現のルール

    今夜9時今日の夜9時からのような表現を21時として解釈する

    用例

    告知などでよく使われる表現。 https://twitter.com/telebee_tnc/status/1420572285157613574

    時間表現への変換

    >>> timexes = TimexParser().parse("今夜9時スタートです。")
    >>> timexes
    [<TIMEX3 tid="t0" type="TIME" value="T21-XX-XX" text="夜9時">]
    

    早速使わせていただいています。是非ご検討のほどお願いします。

    opened by harokki 3
  • [Bug] 日付表現で半を含む際のto_datetime()の動作

    [Bug] 日付表現で半を含む際のto_datetime()の動作

    🐛 Bug

    説明

    日付表現に半や午後(PM)を含むとき、to_datetime()を実行すると、TIMEX3タグのvalueには反映されているようですが、日付型/時間型に半や午後の時刻が反映されません。 仕様でしょうか?? 初issueなので何か間違えていたら申し訳ありません。よろしくお願いします。

    現状挙動

    timex_parser = TimexParser(reference=pendulum.now()) # 2022/8/27 18:00:00 
    print(timex_parser.parse("20時半"))
    print(timex_parser.parse("20時半")[0].to_datetime())
    print()
    print(timex_parser.parse("午後11時"))
    print(timex_parser.parse("午後11時")[0].to_datetime())
    

    出力

    [<TIMEX3 tid="t0" type="TIME" value="T20-30-XX" text="20時半">]
    2022-08-27T20:00:00+09:00
    
    [<TIMEX3 tid="t0" type="TIME" value="T23-XX-XX" text="午後11時">]
    2022-08-27T11:00:00+09:00
    

    理想の挙動

    出力

    [<TIMEX3 tid="t0" type="TIME" value="T20-30-XX" text="20時半">]
    2022-08-27T20:30:00+09:00
    
    [<TIMEX3 tid="t0" type="TIME" value="T23-XX-XX" text="午後11時">]
    2022-08-27T23:00:00+09:00
    

    実行環境

    • ja-timexのバージョン : 0.2.6
    • Pythonのバージョン : 3.10.5
    • OSの情報: Windows10
    bug 
    opened by qwertyroiro 2
  • [Bug] 漢数字の時刻表現のspanがずれる

    [Bug] 漢数字の時刻表現のspanがずれる

    🐛 Bug

    説明

    入力した文章から抽出したtimexがもっているspanの長さが想定していた長さとちがう。

    現状挙動

    text = "平成三十一年に起きた出来事はなんですか?"
    timex = TimexParser().parse(text)
    print(timex[0].span)
    # (0,5)
    

    理想の挙動

    text = "平成三十一年に起きた出来事はなんですか?"
    timex = TimexParser().parse(text)
    print(timex[0].span)
    # (0,6)
    

    再現方法やエラー内容

    実行環境

    • ja-timexのバージョン : 0.2.0
    • Pythonのバージョン : 3.8.10
    • OSの情報: MacOS Bigsur

    追加/補足情報

    もしかしてbugではなく、一度漢数字をアラビア数字にしたあと、spanをとっているのでしょうか?そういう仕様なのでしょうか? もしそうでしたら、変更前の文字列のspan情報が欲しいというfeatureを投げたいです。

    bug 
    opened by reonyanarticle 2
  • [Feature Request] 期間を含む表現が数字を含まない場合にも range_start (range_end) が取得できる

    [Feature Request] 期間を含む表現が数字を含まない場合にも range_start (range_end) が取得できる

    🚀 機能提案

    現在 TimexParser.parse は期間を表す表現(例えば「15日から16日」)のときには、range_startrange_end) がTrueとなります。一方数字を含まない表現「昨日から今日」の場合には range_start は機能していません。

    スクリーンショット 2022-01-31 10 44 51

    そこで数字を含まない期間表現が入力に含まれている場合にも range_start (end) が True となる挙動になってほしいと考えています 🙏

    モチベーション

    • 本パッケージのユーザが期間表現が数字を含まない場合に特殊なフローを追加しなくても良くなる。

    解決策や課題解決の方針

    追加/補足情報

    enhancement 
    opened by takahi-i 1
  • [Modify Rules] 複数の日付間の範囲指定のrangeStartとrangeEndが対応しない

    [Modify Rules] 複数の日付間の範囲指定のrangeStartとrangeEndが対応しない

    📝 時間情報表現のルール

    「2012年5月30日(水)〜6月10日(日)」といった表現の際に、中間の2つに対してrangeStartとrangeEndが付与され、外側の2つには付与されない。

    [<TIMEX3 tid="t0" type="DATE" value="2012-05-30" text="2012年5月30日">,
     <TIMEX3 tid="t1" type="DATE" value="XXXX-WXX-3" range_start="True" text="(水)">,
     <TIMEX3 tid="t2" type="DATE" value="XXXX-06-10" range_end="True" text="6月10日">,
     <TIMEX3 tid="t3" type="DATE" value="XXXX-WXX-7" text="(日)">]
    

    用例

    「2012年5月30日(水)〜6月10日(日)」

    時間表現への変換

    仕様を検討

    追加/補足情報

    rule 
    opened by yagays 1
Releases(v0.2.7)
  • v0.2.7(Sep 14, 2022)

  • v0.2.6(Jun 11, 2022)

  • v0.2.5(Apr 17, 2022)

    Changes

    🐛 Bug Fixes

    • 文字列正規化により文字列長が長くなる場合にspanが補正されない問題を修正 (#82) @yagays

    📖 Documentation and examples

    • ドキュメントを更新 (#81) @yagays
    • update docs (#78) @yagays
    • ドキュメントを更新 (#77) @yagays

    🚧 Maintenance

    • release-drafterが対象とするデフォルトブランチ名を変更 (#80) @yagays
    • ブランチ名がfeatureかfixの場合のみCIでtoxを実行 (#79) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.2.4(Feb 23, 2022)

  • v0.2.3(Feb 4, 2022)

    Changes

    🚀 Features

    • 今世紀という表現をサポート (#74) @yagays
    • 範囲表現でも期間を表す場合に対応 (#73) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.2.2(Jan 29, 2022)

    Changes

    🐛 Bug Fixes

    • 漢数字やコンマなどの正規化前の時刻表現の文字列とスパンをTIMEXタグに含める (#70) @yagays

    📖 Documentation and examples

    • ドキュメントに時刻表現の数値の正規化の追加 (#71) @yagays

    🚧 Maintenance

    • dev-dependenciesのバージョンを一括で上げる (#69) @yagays
    • 現在の年を補完するテストを修正 (#68) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(Oct 17, 2021)

    Changes

    🚀 Features

    • Xから翌Yという表現を範囲表現として取得する (#65) @yagays
    • 12:00〜17:30といった時間表現の抽出ミスを修正 (#64) @yagays

    🐛 Bug Fixes

    • 年表記で数字が小さいときもDATEとして抽出される問題を修正 (#66) @yagays

    📖 Documentation and examples

    • ドキュメントを修正 (#59) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Sep 5, 2021)

    Changes

    TIMEXクラスに、範囲表現と起点と終点を表すrange_startrange_endというクラス変数を追加しました。

    🚀 Features

    • TIMEXタグの__repr__にrangeStart, rangeEndを追加 (#57) @yagays
    • "1,2ヶ月"や"1~2分"といった複数の日付表現が列挙された場合に対応 (#56) @yagays
    • TIMEXタグのrangeStartとrangeEndを追加し、抽出ルールを実装 (#55) @yagays

    📖 Documentation and examples

    • rangeStartとrangeEndに対応 (#58) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.1.9(Aug 29, 2021)

    Changes

    🚀 Features

    • 数字正規化済みのテキストを利用できるように変更 (#52) @yagays

    🐛 Bug Fixes

    • 複数の漢数字を処理できない問題を修正 (#53) @yagays

    📖 Documentation and examples

    • ユーザが独自にルールを指定できるCustomTaggerのテストとドキュメントを追加 (#54) @yagays

    🚧 Maintenance

    • ユーザが独自にルールを指定できるCustomTaggerのテストとドキュメントを追加 (#54) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.1.8(Aug 22, 2021)

    Changes

    🚀 Features

    • Filterの導入により対象外の表現を除外 (#49) @yagays

    🐛 Bug Fixes

    • 0.5ヶ月や3.5年前といった表現の取得ミスを修正 (#50) @yagays
    • 数字の途中を日付と誤認識する問題を修正 (#48) @yagays

    📖 Documentation and examples

    • 抽出例の具体例および既存研究との差異を追加 (#47) @yagays

    🚧 Maintenance

    • stop poetry install before running tox (#51) @yagays
    • Fix typos (#46) @shirayu
    Source code(tar.gz)
    Source code(zip)
  • v0.1.7(Aug 14, 2021)

    Changes

    🚀 Features

    • 漢数字を変換しないignore_kansujiパラメータを追加 (#44) @yagays
    • 末日という表現をサポート (#42) @yagays
    • 16世紀頃, 紀元前2世紀近くといった表現をサポート (#40) @yagays
    • 早朝6時や10時半といった表現をサポート (#36) @yagays
    • 深夜0時や深夜25時といった表現をサポート (#35) @yagays
    • 3日ぶりや10年ぶりといった表現をサポート (#32) @yagays
    • 8日目や30年もの間といった表現をサポート (#30) @yagays

    🐛 Bug Fixes

    • 一時代を時間として取得してしまう問題を修正 (#45) @yagays
    • 翌週28日が週28日と取得される問題を修正 (#39) @yagays
    • remove JUST mod (#38) @yagays
    • 数字が複数含まれるときに桁数のコンマ処理がされない問題を修正 (#37) @yagays
    • 12:30といった全角コロンの時間表記を取得できるように修正 (#34) @yagays
    • 時刻表現の後にスペースがある際にTimex.textに含まれないように修正 (#33) @yagays
    • 東京・千代田区や千春,千夏,千秋,千冬といった表現を取得してしまうバグを修正 (#31) @yagays
    • 全角括弧の囲みを取得するように修正 (#29) @yagays

    📖 Documentation and examples

    • update docs (#41) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.1.6(Aug 9, 2021)

    Changes

    🚀 Features

    • to_datetime()でデフォルトのtimezoneを設定可能にする (#27) @yagays
    • 1年半後や1時間半前、半年といった表現をサポート (#23) @yagays
    • "半"という表現をサポート (#22) @yagays

    🐛 Bug Fixes

    • 先月や半年前などの数字を伴わない表現でto_duration()の計算を修正 (#25) @yagays
    • "世紀"の前に数字が無いとエラーが出る問題を修正 (#24) @yagays

    📖 Documentation and examples

    • 日付型/時間型への変換方法の説明を追加 (#28) @yagays
    • typoを修正 (#18) @yagays

    🚧 Maintenance

    • テストを追加 (#26) @yagays
    • enable to trigger with release drafter (#17) @yagays
    Source code(tar.gz)
    Source code(zip)
  • v0.1.5(Aug 6, 2021)

    Changes

    🚀 Features

    • 基準日を設定できるようにする (#14) @yagays
    • 夜9時・今夜9時のような表現をサポート (#13) @yagays (thanks @harokki)

    📖 Documentation and examples

    • 基準日時の説明を追加 (#16) @yagays

    🚧 Maintenance

    • streamlitのアプリでto_datetime/to_durationに対応 (#15) @yagays
    • add release-drafter (#12) @yagays
    Source code(tar.gz)
    Source code(zip)
  • 0.1.4(Aug 5, 2021)

    🐛 Bug fixes

    • "毎年6月"が"年6月"と判定されるバグを修正 #4
    • Windows環境でテストが通らないエラーを修正 #8

    🚧 Maintenance

    • CIを整備 #6 #10
    Source code(tar.gz)
    Source code(zip)
  • 0.1.3(Aug 1, 2021)

  • 0.1.0(Aug 1, 2021)

Owner
Yuki Okuda
Yuki Okuda
Multispeaker & Emotional TTS based on Tacotron 2 and Waveglow

This Repository contains a sample code for Tacotron 2, WaveGlow with multi-speaker, emotion embeddings together with a script for data preprocessing.

Ivan Didur 106 Jan 01, 2023
A Python script that compares files in directories

compare-files A Python script that compares files in different directories, this is similar to the command filecmp.cmp(f1, f2). I made this script in

Colvin 1 Oct 15, 2021
A Python wrapper for simple offline real-time dictation (speech-to-text) and speaker-recognition using Vosk.

Simple-Vosk A Python wrapper for simple offline real-time dictation (speech-to-text) and speaker-recognition using Vosk. Check out the official Vosk G

2 Jun 19, 2022
DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference

DeeBERT This is the code base for the paper DeeBERT: Dynamic Early Exiting for Accelerating BERT Inference. Code in this repository is also available

Castorini 132 Nov 14, 2022
A tool helps build a talk preview image by combining the given background image and talk event description

talk-preview-img-builder A tool helps build a talk preview image by combining the given background image and talk event description Installation and U

PyCon Taiwan 4 Aug 20, 2022
A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. X-Ray supports 18 languages.

WordDumb A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. Languages X-Ray supp

172 Dec 29, 2022
An evaluation toolkit for voice conversion models.

Voice-conversion-evaluation An evaluation toolkit for voice conversion models. Sample test pair Generate the metadata for evaluating models. The direc

30 Aug 29, 2022
BERN2: an advanced neural biomedical namedentity recognition and normalization tool

BERN2 We present BERN2 (Advanced Biomedical Entity Recognition and Normalization), a tool that improves the previous neural network-based NER tool by

DMIS Laboratory - Korea University 99 Jan 06, 2023
Collection of scripts to pinpoint obfuscated code

Obfuscation Detection (v1.0) Author: Tim Blazytko Automatically detect control-flow flattening and other state machines Description: Scripts and binar

Tim Blazytko 230 Nov 26, 2022
Disfl-QA: A Benchmark Dataset for Understanding Disfluencies in Question Answering

Disfl-QA is a targeted dataset for contextual disfluencies in an information seeking setting, namely question answering over Wikipedia passages. Disfl-QA builds upon the SQuAD-v2 (Rajpurkar et al., 2

Google Research Datasets 52 Jun 21, 2022
NLP techniques such as named entity recognition, sentiment analysis, topic modeling, text classification with Python to predict sentiment and rating of drug from user reviews.

This file contains the following documents sumbited for Baruch CIS9665 group 9 fall 2021. 1. Dataset: drug_reviews.csv 2. python codes for text classi

Aarif Munwar Jahan 2 Jan 04, 2023
Chinese real time voice cloning (VC) and Chinese text to speech (TTS).

Chinese real time voice cloning (VC) and Chinese text to speech (TTS). 好用的中文语音克隆兼中文语音合成系统,包含语音编码器、语音合成器、声码器和可视化模块。

Kuang Dada 6 Nov 08, 2022
This repository serves as a place to document a toy attempt on how to create a generative text model in Catalan, based on GPT-2

GPT-2 Catalan playground and scripts to train a GPT-2 model either from scrath or from another pretrained model.

Laura 1 Jan 28, 2022
Chinese NER(Named Entity Recognition) using BERT(Softmax, CRF, Span)

Chinese NER(Named Entity Recognition) using BERT(Softmax, CRF, Span)

Weitang Liu 1.6k Jan 03, 2023
🚀Clone a voice in 5 seconds to generate arbitrary speech in real-time

English | 中文 Features 🌍 Chinese supported mandarin and tested with multiple datasets: aidatatang_200zh, magicdata, aishell3, data_aishell, and etc. ?

Vega 25.6k Dec 31, 2022
⚖️ A Statutory Article Retrieval Dataset in French.

A Statutory Article Retrieval Dataset in French This repository contains the Belgian Statutory Article Retrieval Dataset (BSARD), as well as the code

Maastricht Law & Tech Lab 19 Nov 17, 2022
:mag: Transformers at scale for question answering & neural search. Using NLP via a modular Retriever-Reader-Pipeline. Supporting DPR, Elasticsearch, HuggingFace's Modelhub...

Haystack is an end-to-end framework that enables you to build powerful and production-ready pipelines for different search use cases. Whether you want

deepset 6.4k Jan 09, 2023
Simple, Fast, Powerful and Easily extensible python package for extracting patterns from text, with over than 60 predefined Regular Expressions.

patterns-finder Simple, Fast, Powerful and Easily extensible python package for extracting patterns from text, with over than 60 predefined Regular Ex

22 Dec 19, 2022
Exploration of BERT-based models on twitter sentiment classifications

twitter-sentiment-analysis Explore the relationship between twitter sentiment of Tesla and its stock price/return. Explore the effect of different BER

Sammy Cui 2 Oct 02, 2022
⚡ boost inference speed of T5 models by 5x & reduce the model size by 3x using fastT5.

Reduce T5 model size by 3X and increase the inference speed up to 5X. Install Usage Details Functionalities Benchmarks Onnx model Quantized onnx model

Kiran R 399 Jan 05, 2023