https://github.com/vorkytaka/hors
A simple Dart package to extract date and time from natural speech.
https://github.com/vorkytaka/hors
dart datetime natural-speech
Last synced: 11 months ago
JSON representation
A simple Dart package to extract date and time from natural speech.
- Host: GitHub
- URL: https://github.com/vorkytaka/hors
- Owner: Vorkytaka
- License: bsd-3-clause
- Created: 2023-04-23T14:58:52.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T11:07:11.000Z (over 2 years ago)
- Last Synced: 2025-01-01T10:13:58.135Z (about 1 year ago)
- Topics: dart, datetime, natural-speech
- Language: Dart
- Homepage: https://pub.dev/packages/hors
- Size: 6.03 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Hors
### Overview
A simple Dart package to extract date and time from natural speech.
Currently works __only__ with russian language.
### Usage
To use this package you need to create a `Hors` object with list of `TokenParser` and list
of `Recognizer`.
Out of the box there is rich collection of both types, see `Recognizer.all` and `TokenParsers.all`.
Base example looks like this:
```dart
import 'package:hors/hors.dart';
final hors = Hors(
recognizers: Recognizer.all,
tokenParsers: TokenParsers.all,
);
final result = hors.parse('Завтра состоится событие в 11 часов вечера');
```
`parse` method also has optional arguments:
- `DateTime fromDatetime` – the date relative to which the intervals are to be measured.
- `int closestSteps` – the maximum number of words between two dates at which will try to combine
these dates into one, if possible.
### Limitations
- Some recognizers is relate with each-other, so you should know in which order they used or you can
get unpredictable results.
### Examples
```
> Завтра состоится событие в 11 часов
Text: Состоится событие
DateTimeToken, fixed:
2023-04-24 11:00:00.000
> Через 2 дня в 15 часов 30 минут к врачу
Text: К врачу
DateTimeToken, spanForward:
Date: 2023-04-25 15:30:00.000
Span: 63:30:00.000000
> Отправимся на рыбалку с 25 до 28 числа
Text: Отправимся на рыбалку
DateTimeToken, period:
From: 2023-04-25 00:00:00.000
To: 2023-04-28 00:00:00.000
```
### Special thanks
[Original library](https://github.com/DenisNP/Hors) is created
by [DenisNP](https://github.com/DenisNP) with C#.
This is a port of library to the Dart language.
For now this library is backward compatible with the original one.
But this implementation written a little bit different.
For some info how this library works you can
read [this article](https://habr.com/ru/articles/471204/) (ru).