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

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
An open-source NLP library: fast text cleaning and preprocessing.

An open-source NLP library: fast text cleaning and preprocessing

Iaroslav 21 Mar 18, 2022
Unifying Cross-Lingual Semantic Role Labeling with Heterogeneous Linguistic Resources (NAACL-2021).

Unifying Cross-Lingual Semantic Role Labeling with Heterogeneous Linguistic Resources Description This is the repository for the paper Unifying Cross-

Sapienza NLP group 16 Sep 09, 2022
In this workshop we will be exploring NLP state of the art transformers, with SOTA models like T5 and BERT, then build a model using HugginFace transformers framework.

Transformers are all you need In this workshop we will be exploring NLP state of the art transformers, with SOTA models like T5 and BERT, then build a

Aymen Berriche 8 Apr 13, 2022
A simple Streamlit App to classify swahili news into different categories.

Swahili News Classifier Streamlit App A simple app to classify swahili news into different categories. Installation Install all streamlit requirements

Davis David 4 May 01, 2022
Toward Model Interpretability in Medical NLP

Toward Model Interpretability in Medical NLP LING380: Topics in Computational Linguistics Final Project James Cross ( 1 Mar 04, 2022

Training and evaluation codes for the BertGen paper (ACL-IJCNLP 2021)

BERTGEN This repository is the implementation of the paper "BERTGEN: Multi-task Generation through BERT" (https://arxiv.org/abs/2106.03484). The codeb

<a href=[email protected]"> 9 Oct 26, 2022
Words_And_Phrases - Just a repo for useful words and phrases that might come handy in some scenarios. Feel free to add yours

Words_And_Phrases Just a repo for useful words and phrases that might come handy in some scenarios. Feel free to add yours Abbreviations Abbreviation

Subhadeep Mandal 1 Feb 01, 2022
test

Lidar-data-decode In this project, you can decode your lidar data frame(pcap file) and make your own datasets(test dataset) in Windows without any hug

46 Dec 05, 2022
A Python 3.6+ package to run .many files, where many programs written in many languages may exist in one file.

RunMany Intro | Installation | VSCode Extension | Usage | Syntax | Settings | About A tool to run many programs written in many languages from one fil

6 May 22, 2022
Linear programming solver for paper-reviewer matching and mind-matching

Paper-Reviewer Matcher A python package for paper-reviewer matching algorithm based on topic modeling and linear programming. The algorithm is impleme

Titipat Achakulvisut 66 Jul 05, 2022
This repository will contain the code for the CVPR 2021 paper "GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields"

GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields Project Page | Paper | Supplementary | Video | Slides | Blog | Talk If

1.1k Dec 27, 2022
Malware-Related Sentence Classification

Malware-Related Sentence Classification This repo contains the code for the ICTAI 2021 paper "Enrichment of Features for Malware-Related Sentence Clas

Chau Nguyen 1 Mar 26, 2022
RoNER is a Named Entity Recognition model based on a pre-trained BERT transformer model trained on RONECv2

RoNER RoNER is a Named Entity Recognition model based on a pre-trained BERT transformer model trained on RONECv2. It is meant to be an easy to use, hi

Stefan Dumitrescu 9 Nov 07, 2022
This is the source code of RPG (Reward-Randomized Policy Gradient)

RPG (Reward-Randomized Policy Gradient) Zhenggang Tang*, Chao Yu*, Boyuan Chen, Huazhe Xu, Xiaolong Wang, Fei Fang, Simon Shaolei Du, Yu Wang, Yi Wu (

40 Nov 25, 2022
LSTC: Boosting Atomic Action Detection with Long-Short-Term Context

LSTC: Boosting Atomic Action Detection with Long-Short-Term Context This Repository contains the code on AVA of our ACM MM 2021 paper: LSTC: Boosting

Tencent YouTu Research 9 Oct 11, 2022
A paper list of pre-trained language models (PLMs).

Large-scale pre-trained language models (PLMs) such as BERT and GPT have achieved great success and become a milestone in NLP.

RUCAIBox 124 Jan 02, 2023
A PyTorch implementation of the Transformer model in "Attention is All You Need".

Attention is all you need: A Pytorch Implementation This is a PyTorch implementation of the Transformer model in "Attention is All You Need" (Ashish V

Yu-Hsiang Huang 7.1k Jan 05, 2023
Non-Autoregressive Predictive Coding

Non-Autoregressive Predictive Coding This repository contains the implementation of Non-Autoregressive Predictive Coding (NPC) as described in the pre

Alexander H. Liu 43 Nov 15, 2022
Code for paper "Which Training Methods for GANs do actually Converge? (ICML 2018)"

GAN stability This repository contains the experiments in the supplementary material for the paper Which Training Methods for GANs do actually Converg

Lars Mescheder 884 Nov 11, 2022
Pipeline for chemical image-to-text competition

BMS-Molecular-Translation Introduction This is a pipeline for Bristol-Myers Squibb – Molecular Translation by Vadim Timakin and Maksim Zhdanov. We got

Maksim Zhdanov 7 Sep 20, 2022