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

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
A framework for implementing federated learning

This is partly the reproduction of the paper of [Privacy-Preserving Federated Learning in Fog Computing](DOI: 10.1109/JIOT.2020.2987958. 2020)

DavidChen 46 Sep 23, 2022
NeurIPS'21: Probabilistic Margins for Instance Reweighting in Adversarial Training (Pytorch implementation).

source code for NeurIPS21 paper robabilistic Margins for Instance Reweighting in Adversarial Training

9 Dec 20, 2022
a chinese segment base on crf

Genius Genius是一个开源的python中文分词组件,采用 CRF(Conditional Random Field)条件随机场算法。 Feature 支持python2.x、python3.x以及pypy2.x。 支持简单的pinyin分词 支持用户自定义break 支持用户自定义合并词

duanhongyi 237 Nov 04, 2022
PyTorch implementation of the NIPS-17 paper "Poincaré Embeddings for Learning Hierarchical Representations"

Poincaré Embeddings for Learning Hierarchical Representations PyTorch implementation of Poincaré Embeddings for Learning Hierarchical Representations

Facebook Research 1.6k Dec 29, 2022
NumPy String-Indexed is a NumPy extension that allows arrays to be indexed using descriptive string labels

NumPy String-Indexed NumPy String-Indexed is a NumPy extension that allows arrays to be indexed using descriptive string labels, rather than conventio

Aitan Grossman 1 Jan 08, 2022
Use Tensorflow2.7.0 Build OpenAI'GPT-2

TF2_GPT-2 Use Tensorflow2.7.0 Build OpenAI'GPT-2 使用最新tensorflow2.7.0构建openai官方的GPT-2 NLP模型 优点 使用无监督技术 拥有大量词汇量 可实现续写(堪比“xx梦续写”) 实现对话后续将应用于FloatTech的Bot

Watermelon 9 Sep 13, 2022
Uses Google's gTTS module to easily create robo text readin' on command.

Tool to convert text to speech, creating files for later use. TTRS uses Google's gTTS module to easily create robo text readin' on command.

0 Jun 20, 2021
Utility for Google Text-To-Speech batch audio files generator. Ideal for prompt files creation with Google voices for application in offline IVRs

Google Text-To-Speech Batch Prompt File Maker Are you in the need of IVR prompts, but you have no voice actors? Let Google talk your prompts like a pr

Ponchotitlán 1 Aug 19, 2021
Simple python code to fix your combo list by removing any text after a separator or removing duplicate combos

Combo List Fixer A simple python code to fix your combo list by removing any text after a separator or removing duplicate combos Removing any text aft

Hamidreza Dehghan 3 Dec 05, 2022
This is the offline-training-pipeline for our project.

offline-training-pipeline This is the offline-training-pipeline for our project. We adopt the offline training and online prediction Machine Learning

0 Apr 22, 2022
CVSS: A Massively Multilingual Speech-to-Speech Translation Corpus

CVSS: A Massively Multilingual Speech-to-Speech Translation Corpus CVSS is a massively multilingual-to-English speech-to-speech translation corpus, co

Google Research Datasets 118 Jan 06, 2023
CCQA A New Web-Scale Question Answering Dataset for Model Pre-Training

CCQA: A New Web-Scale Question Answering Dataset for Model Pre-Training This is the official repository for the code and models of the paper CCQA: A N

Meta Research 29 Nov 30, 2022
LOT: A Benchmark for Evaluating Chinese Long Text Understanding and Generation

LOT: A Benchmark for Evaluating Chinese Long Text Understanding and Generation Tasks | Datasets | LongLM | Baselines | Paper Introduction LOT is a ben

46 Dec 28, 2022
This repository contains the code for running the character-level Sandwich Transformers from our ACL 2020 paper on Improving Transformer Models by Reordering their Sublayers.

Improving Transformer Models by Reordering their Sublayers This repository contains the code for running the character-level Sandwich Transformers fro

Ofir Press 53 Sep 26, 2022
Simple program that translates the name of files into English

Simple program that translates the name of files into English. Useful for when editing/inspecting programs that were developed in a foreign language.

0 Dec 22, 2021
Longformer: The Long-Document Transformer

Longformer Longformer and LongformerEncoderDecoder (LED) are pretrained transformer models for long documents. ***** New December 1st, 2020: Longforme

AI2 1.6k Dec 29, 2022
Datasets of Automatic Keyphrase Extraction

This repository contains 20 annotated datasets of Automatic Keyphrase Extraction made available by the research community. Following are the datasets and the original papers that proposed them. If yo

LIAAD - Laboratory of Artificial Intelligence and Decision Support 163 Dec 23, 2022
Mednlp - Medical natural language parsing and utility library

Medical natural language parsing and utility library A natural language medical

Paul Landes 3 Aug 24, 2022
Simple and efficient RevNet-Library with DeepSpeed support

RevLib Simple and efficient RevNet-Library with DeepSpeed support Features Half the constant memory usage and faster than RevNet libraries Less memory

Lucas Nestler 112 Dec 05, 2022