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

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
Few-shot Natural Language Generation for Task-Oriented Dialog

Few-shot Natural Language Generation for Task-Oriented Dialog This repository contains the dataset, source code and trained model for the following pa

172 Dec 13, 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
A machine learning model for analyzing text for user sentiment and determine whether its a positive, neutral, or negative review.

Sentiment Analysis on Yelp's Dataset Author: Roberto Sanchez, Talent Path: D1 Group Docker Deployment: Deployment of this application can be found her

Roberto Sanchez 0 Aug 04, 2021
IEEEXtreme15.0 Questions And Answers

IEEEXtreme15.0 Questions And Answers IEEEXtreme is a global challenge in which teams of IEEE Student members – advised and proctored by an IEEE member

Dilan Perera 15 Oct 24, 2022
NLTK Source

Natural Language Toolkit (NLTK) NLTK -- the Natural Language Toolkit -- is a suite of open source Python modules, data sets, and tutorials supporting

Natural Language Toolkit 11.4k Jan 04, 2023
[KBS] Aspect-based sentiment analysis via affective knowledge enhanced graph convolutional networks

#Sentic GCN Introduction This repository was used in our paper: Aspect-Based Sentiment Analysis via Affective Knowledge Enhanced Graph Convolutional N

Akuchi 35 Nov 16, 2022
中文医疗信息处理基准CBLUE: A Chinese Biomedical LanguageUnderstanding Evaluation Benchmark

English | 中文说明 CBLUE AI (Artificial Intelligence) is playing an indispensabe role in the biomedical field, helping improve medical technology. For fur

452 Dec 30, 2022
Toolkit for Machine Learning, Natural Language Processing, and Text Generation, in TensorFlow. This is part of the CASL project: http://casl-project.ai/

Texar is a toolkit aiming to support a broad set of machine learning, especially natural language processing and text generation tasks. Texar provides

ASYML 2.3k Jan 07, 2023
Sentiment-Analysis and EDA on the IMDB Movie Review Dataset

Sentiment-Analysis and EDA on the IMDB Movie Review Dataset The main part of the work focuses on the exploration and study of different approaches whi

Nikolas Petrou 1 Jan 12, 2022
Universal Adversarial Triggers for Attacking and Analyzing NLP (EMNLP 2019)

Universal Adversarial Triggers for Attacking and Analyzing NLP This is the official code for the EMNLP 2019 paper, Universal Adversarial Triggers for

Eric Wallace 248 Dec 17, 2022
A crowdsourced dataset of dialogues grounded in social contexts involving utilization of commonsense.

A crowdsourced dataset of dialogues grounded in social contexts involving utilization of commonsense.

Alexa 62 Dec 20, 2022
This Project is based on NLTK It generates a RANDOM WORD from a predefined list of words, From that random word it read out the word, its meaning with parts of speech , its antonyms, its synonyms

This Project is based on NLTK(Natural Language Toolkit) It generates a RANDOM WORD from a predefined list of words, From that random word it read out the word, its meaning with parts of speech , its

SaiVenkatDhulipudi 2 Nov 17, 2021
Code examples for my Write Better Python Code series on YouTube.

Write Better Python Code This repository contains the code examples used in my Write Better Python Code series published on YouTube: https:/

858 Dec 29, 2022
Officile code repository for "A Game-Theoretic Perspective on Risk-Sensitive Reinforcement Learning"

CvarAdversarialRL Official code repository for "A Game-Theoretic Perspective on Risk-Sensitive Reinforcement Learning". Initial setup Create a virtual

Mathieu Godbout 1 Nov 19, 2021
⛵️The official PyTorch implementation for "BERT-of-Theseus: Compressing BERT by Progressive Module Replacing" (EMNLP 2020).

BERT-of-Theseus Code for paper "BERT-of-Theseus: Compressing BERT by Progressive Module Replacing". BERT-of-Theseus is a new compressed BERT by progre

Kevin Canwen Xu 284 Nov 25, 2022
构建一个多源(公众号、RSS)、干净、个性化的阅读环境

2C 构建一个多源(公众号、RSS)、干净、个性化的阅读环境 作为一名微信公众号的重度用户,公众号一直被我设为汲取知识的地方。随着使用程度的增加,相信大家或多或少会有一个比较头疼的问题——广告问题。 假设你关注的公众号有十来个,若一个公众号两周接一次广告,理论上你会面临二十多次广告,实际上会更多,运

howie.hu 678 Dec 28, 2022
NLP Overview

NLP-Overview Introduction The field of NPL encompasses a variety of topics which involve the computational processing and understanding of human langu

PeterPham 1 Jan 13, 2022
Simplified diarization pipeline using some pretrained models - audio file to diarized segments in a few lines of code

simple_diarizer Simplified diarization pipeline using some pretrained models. Made to be a simple as possible to go from an input audio file to diariz

Chau 65 Dec 30, 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
Search Git commits in natural language

NaLCoS - NAtural Language COmmit Search Search commit messages in your repository in natural language. NaLCoS (NAtural Language COmmit Search) is a co

Pushkar Patel 50 Mar 22, 2022