Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jack-r-warren/best_effort_parser
Dart best-effort parsing for names with unknown formats (like unstructured user input)
https://github.com/jack-r-warren/best_effort_parser
dart flutter parsing
Last synced: 3 days ago
JSON representation
Dart best-effort parsing for names with unknown formats (like unstructured user input)
- Host: GitHub
- URL: https://github.com/jack-r-warren/best_effort_parser
- Owner: jack-r-warren
- License: bsd-3-clause
- Created: 2019-05-10T03:25:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-25T03:16:22.000Z (over 5 years ago)
- Last Synced: 2023-10-11T10:17:01.907Z (about 1 year ago)
- Topics: dart, flutter, parsing
- Language: Dart
- Homepage: https://pub.dev/packages/best_effort_parser
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Best Effort Parser
> Author: [Jack Warren][author site]
[![Build Status](https://travis-ci.com/jack-r-warren/best_effort_parser.svg?branch=master)](https://travis-ci.com/jack-r-warren/best_effort_parser) [![Coverage Status](https://coveralls.io/repos/github/jack-r-warren/best_effort_parser/badge.svg?branch=master)](https://coveralls.io/github/jack-r-warren/best_effort_parser?branch=master) [![Pub](https://img.shields.io/pub/v/best_effort_parser.svg)](https://pub.dartlang.org/packages/best_effort_parser)
Parse unstructured user input, with customizable behavior and output types. Parsing is currently available for [names](#name-parsing) and [dates](#date-parsing).
## Name Parsing
#### `best_effort_parser/name.dart`Provides parsing of names by categorizing different parts:
- **family**: A person's last name(s)
- **given**: A person's first and middle name(s)
- **dropping particle**: particle(s) before the person's last name that are ignored if only the last name is shown
- **non-dropping particle**: particles(s) before the person's last name that are *not* ignored if only the last name is shown
- **suffix**: abbreviations after a person's last nameFeatures handling of a wide range of formats: beyond just "first last" and "last, first", particles and suffixes are parsed from any reasonably correct position a user may place them.
### Example:
#### `name_example.dart````dart
import 'package:best_effort_parser/name.dart';void main(List arguments) =>
print(NameParser.basic().parse(arguments.join(' ')).diagnosticString());
```Demo:
```bash
λ dart name_example.dart 'Jack Warren'
[Given]: Jack [Family]: Warrenλ dart name_example.dart 'La Fontaine, Jean de'
[Given]: Jean [Dropping Particle]: de [Non-dropping Particle]: La [Family]: Fontaineλ dart name_example.dart 'Gates, Bill III'
[Given]: Bill [Family]: Gates [Suffix]: IIIλ dart name_example.dart 'Willem de Kooning'
[Given]: Willem [Dropping Particle]: de [Family]: Kooning
```Customization of both parsing and output type is available.
## Date Parsing
#### `best_effort_parser/date.dart`Provides parsing of dates by collecting years, months, and days and assembling those parts into a list. Each entry in that output list represents a singular date, so a string containing multiple dates or a range will have multiple entries in its output.
### Example:
#### `date_example.dart````dart
import 'package:best_effort_parser/date.dart';void main(List arguments) =>
DateParser.basic().parse(arguments.join(' ')).forEach(print);
```Demo:
```bash
λ dart date_example.dart 'January 1st, 2019'
[Day]: 1 [Month]: 1 [Year]: 2019λ dart date_example.dart '1/2/3'
[Day]: 2 [Month]: 1 [Year]: 2003λ dart date_example.dart '10/10/90 - 3/13/18'
[Day]: 10 [Month]: 10 [Year]: 1990
[Day]: 13 [Month]: 3 [Year]: 2018λ dart date_example.dart 'Spring-Summer 2010'
[Month]: 3 [Year]: 2010
[Month]: 6 [Year]: 2010λ dart date_example.dart '1999-6-15'
[Day]: 15 [Month]: 6 [Year]: 1999λ dart date_example.dart '40 20 10'
[Day]: 20 [Month]: 10 [Year]: 1940
```As seen in the last example especially, the parser will do its best even in the face of _very_ odd input. In that example, 40 can't be a day or month, and 20 can't be a month, so a year-day-month format will be used for that date only.
Customization of both parsing and output type is available.
## Feature requests and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[author site]: https://jackwarren.info
[tracker]: https://github.com/jack-r-warren/best_effort_parser/issues