Name parsing
People's names split into title, given, middle and family name and suffix, Last, First and ALL CAPS read too, and duplicates like J. Smith and John Smith found.
Version 1.0.0 · 3 functions · 1 crate
Functions
What use name_parse.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use name_parse, name_same_person from name_parse (Quillo 0.6).
name_parse(name: str) → anyor an errorThe parts of a full name: { title, given, middle, family, suffix, honorifics, initials, first_last, full }, those missing null. It reads "Last, First" too, and fixes ALL CAPS and all lower case ("mcdonald" is "McDonald"). Western names: a name in another order (Chinese, Hungarian) is read given name first. An error when it is not a name.
name_same_person(a: str, b: str) → boolor an errorWhether two written names may be the same person: "J. Smith" and "John Smith" may, "Jane Smith" and "John Smith" may not. For finding duplicate contacts.
name_short(name: str) → stror an errorThe name as "J. Smith": the first initial and the family name, for bylines and compact lists.
Get it
$ quillo install name_parse # name_parse.qwer into this folder$ quillo install name_parse --example # and its example, name_parse.qweOr with curl:
$ curl -O https://quillolang.org/plugins/files/name_parse.qwer$ curl -O https://quillolang.org/plugins/files/name_parse.qweThen, in your program, all of it or only what you call:
use name_parse.qweruse name_parse, name_same_person from name_parse // Quillo 0.6: only theseIt uses this crate, which cargo fetches the first time the plugin is built:
human_name = "2"Example
// Contacts imported from a spreadsheet: one "name" column split into parts, and duplicates found.//// quillo run name_parse.qwe then open http://localhost:8080/contactsuse "name_parse.qwer"let column = ["Dr. Martin Luther King, Jr.", "KING, MARTIN L", "ada lovelace", "Mr. John Ronald Reuel Tolkien CBE", "Juan de la Cruz"]route GET /contacts = column | map((c) => { written: c, parts: name_parse(c)? })route GET /duplicates = { j_smith: name_same_person("J. Smith", "John Smith")?, jane_john: name_same_person("Jane Smith", "John Smith")?, king: name_same_person("Dr. Martin Luther King, Jr.", "KING, MARTIN L")?, byline: name_short("Mr. John Ronald Reuel Tolkien CBE")?,}route GET /parse ? { name: str } = name_parse(name)?$ quillo run name_parse.qwe$ curl 'localhost:8080/contacts'$ curl 'localhost:8080/duplicates'Source
//! People's names split into their parts, for forms, CRMs and mail merges: title, given name, middle names, family name and suffix, from "Dr. Martin Luther King, Jr." or "KING, MARTIN L".//! version: 1.0.0//!//! [dependencies]//! human_name = "2"use human_name::Name;use serde_json::{json, Value};fn parse(name: &str) -> Result<Name, String> { if name.len() > 1000 { return Err("names up to 1,000 characters".into()); } Name::parse(name).ok_or_else(|| format!("{:?} does not read as a person's name", name))}/// The parts of a full name: `{ title, given, middle, family, suffix, honorifics, initials, first_last, full }`, those missing null. It reads "Last, First" too, and fixes ALL CAPS and all lower case ("mcdonald" is "McDonald"). Western names: a name in another order (Chinese, Hungarian) is read given name first. An error when it is not a name.pub fn name_parse(name: &str) -> Result<Value, String> { let n = parse(name)?; Ok(json!({ "title": n.honorific_prefix(), "given": n.given_name(), "middle": n.middle_name().map(|m| m.into_owned()), "family": n.surname(), "suffix": n.generational_suffix(), "honorifics": n.honorific_suffix(), "initials": n.initials(), "first_last": n.display_first_last().into_owned(), "full": n.display_full_with_honorifics().into_owned(), }))}/// Whether two written names may be the same person: "J. Smith" and "John Smith" may, "Jane Smith" and "John Smith" may not. For finding duplicate contacts.pub fn name_same_person(a: &str, b: &str) -> Result<bool, String> { Ok(parse(a)?.consistent_with(&parse(b)?))}/// The name as "J. Smith": the first initial and the family name, for bylines and compact lists.pub fn name_short(name: &str) -> Result<String, String> { Ok(parse(name)?.display_initial_surname().into_owned())}Related
vcard.qwer · 1.0.0vCards read and written: contacts from phones, Outlook and Google Contacts imported, and save-contact files made.8 views · 9 downloadsCase case.qwer · 1.0.0Text in snake_case, camelCase, PascalCase, kebab-case, CONSTANT_CASE, Title Case and Sentence case: column names as API keys and labels.7 views · 8 downloadsHTML to Markdown html_markdown.qwer · 1.0.0HTML turned into clean Markdown as Turndown does: headings, lists, links, images, code blocks, quotes and tables kept, scripts and the parts you name dropped; for importing old posts, editor output, and pages for an LLM.7 views · 6 downloadsHumanize humanize.qwer · 1.0.0Durations, file sizes and relative times as people write them and back: 2h 30m, 1.5 GB, 2 GiB, 3 days ago, in 2 hours.7 views · 11 downloadsInflection inflect.qwer · 1.0.0English words in the right form for counts and labels: plurals and singulars, 3 items, ordinals such as 1st and 22nd, and a or an by how a word sounds.6 views · 7 downloadsJapanese kana kana.qwer · 1.0.0Japanese kana: romaji typed as hiragana or katakana, kana written in Hepburn romaji, hiragana and katakana each to the other, half-width katakana from bank and till systems made full-width, and which scripts a text uses.6 views · 10 downloadsThread 0 posts
On Name parsing: questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.