best_effort_parser 1.1.0

Best Effort Parser #

Author: Jack Warren

Build Status Coverage Status Pub

Parse unstructured user input, with customizable behavior and output types. Parsing is currently available for names and dates.

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 name

Features 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 #

import 'package:best_effort_parser/name.dart';

void main(List<String> arguments) =>
    print(NameParser.basic().parse(arguments.join(' ')).diagnosticString());

Demo:

λ  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 #

import 'package:best_effort_parser/date.dart';

void main(List<String> arguments) => 
    DateParser.basic().parse(arguments.join(' ')).forEach(print);

Demo:

λ  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.

1.1.0 #

  • Improve handling of unambiguous compact dates
    • Technically a slight breaking change, in that dates are compact dates are handled more consistently. For example, given a date like "10/20/2000", the month will always be 10 because it can't be 20, regardless of any compact date format set in the constructor.

1.0.2 #

  • Update README.md title (package name already at the top of the page on pub)

1.0.1 #

  • Fix README.md typo

1.0.0 #

  • Documentation fixes
  • Fix version constraint; require dart 2.3

0.3.1 #

  • Standardize formatting and documentation

0.3.0 #

  • Add date parsing

0.2.8 #

  • Make the deployment script executable

0.2.7 #

  • Manual Travis deployment because "deploy:" doesn't appear to work

0.2.6 #

  • Skip cleanup

0.2.5 #

  • Yet more Travis fixes

0.2.4 #

  • More Travis fixes

0.2.3 #

  • Configure deployment script deploy.sh

0.2.2 #

  • Configure Travis and Coveralls

0.2.1 #

  • Updated README.md
  • Name parsing example (name_example.dart)

0.2.0 #

  • Name parsing with documentation, testing, and diagnostics

0.1.0 #

  • Name parsing functional
    • TODO: better documentation, testing, diagnostics

0.0.1 #

  • Add project configuration files
  • Initial version, created by Stagehand

example/README.md

Examples #

Sample behavior of these examples is available in the top-level README.md file

name_example.dart #

A command-line utility demoing the capabilities of package:best_effort_parser/name.dart.

import 'package:best_effort_parser/name.dart';

/// Bare-bones example of using [NameParser] as a command-line program. All arguments are
/// concatenated with spaces and then run through the parser with default settings.
///
/// Example usage:
/// ```text
/// λ  dart name_example.dart 'Jack Warren'
/// [Given]: Jack [Family]: Warren
/// ```
void main(List<String> arguments) =>
    print(NameParser.basic().parse(arguments.join(' ')).diagnosticString());

Provided dart is on your path, the script may be run from the example/ directory with dart name_exaple.dart followed by strings of your choice.

date_example.dart #

A command-line utility demoing the capabilities of package:best_effort_parser/date.dart.

import 'package:best_effort_parser/date.dart';

/// Bare-bones example of using [DateParser] as a command-line program. All arguments are
/// concatenated with spaces and then run through the parser with default settings.
///
/// Example usage:
/// ```text
/// λ  dart date_example.dart 'January 1st, 2019'
/// [Day]: 1 [Month]: 1 [Year]: 2019
/// ```
void main(List<String> arguments) =>
    DateParser.basic().parse(arguments.join(' ')).forEach(print);

Provided dart is on your path, the script may be run from the example/ directory with dart date_example.dart followed by strings of your choice.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  best_effort_parser: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:best_effort_parser/date.dart';
import 'package:best_effort_parser/name.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0
test_coverage ^0.2.0