Takes a full name and splits it into individual name parts

Overview

gonameparts

gonameparts splits a human name into individual parts. This is useful when dealing with external data sources that provide names as a single value, but you need to store the discrete parts in a database for example.

GoDoc Build Status

Author

James Polera [email protected]

Dependencies

No external dependencies. Uses Go's standard packages

Example

package main

import (
	"encoding/json"
	"fmt"

	"github.com/polera/gonameparts"
)

func main() {

	// Parsing a name and printing its parts
	nameString := gonameparts.Parse("Thurston Howell III")
	fmt.Println("FirstName:", nameString.FirstName)
	fmt.Println("LastName:", nameString.LastName)
	fmt.Println("Generation:", nameString.Generation)
	// Output:
	// FirstName: Thurston
	// LastName: Howell
	// Generation: III

    // Parse a name with multiple "also known as" aliases, output JSON
	multipleAKA := gonameparts.Parse("Tony Stark a/k/a Ironman a/k/a Stark, Anthony a/k/a Anthony Edward \"Tony\" Stark")
	jsonParts, _ := json.Marshal(multipleAKA)
	fmt.Printf("%v\n", string(jsonParts))
	/* Output:
		{
	    "aliases": [
	        {
	            "aliases": null,
	            "first_name": "Ironman",
	            "full_name": "Ironman",
	            "generation": "",
	            "last_name": "",
	            "middle_name": "",
	            "nickname": "",
	            "provided_name": " Ironman ",
	            "salutation": "",
	            "suffix": ""
	        },
	        {
	            "aliases": null,
	            "first_name": "Anthony",
	            "full_name": "Anthony Stark",
	            "generation": "",
	            "last_name": "Stark",
	            "middle_name": "",
	            "nickname": "",
	            "provided_name": " Stark, Anthony ",
	            "salutation": "",
	            "suffix": ""
	        },
	        {
	            "aliases": null,
	            "first_name": "Anthony",
	            "full_name": "Anthony Edward Stark",
	            "generation": "",
	            "last_name": "Stark",
	            "middle_name": "Edward",
	            "nickname": "\"Tony\"",
	            "provided_name": " Anthony Edward \"Tony\" Stark",
	            "salutation": "",
	            "suffix": ""
	        }
	    ],
	    "first_name": "Tony",
	    "full_name": "Tony Stark",
	    "generation": "",
	    "last_name": "Stark",
	    "middle_name": "",
	    "nickname": "",
	    "provided_name": "Tony Stark a/k/a Ironman a/k/a Stark, Anthony a/k/a Anthony Edward \"Tony\" Stark",
	    "salutation": "",
	    "suffix": ""
		}*/

}
You might also like...
Build "Dictionary of the Old Norwegian Language" into easier-to-use data formats

Old Norwegian Dictionary Builder Build "Dictionary of the Old Norwegian Language" into easier-to-use data formats. Available formats: JSON DSL XML Usa

Script to inject Aliucord into a Discord ipa.

Aliucord-Patcher Script to patch Discord's ipa with a custom build of hermes, apply a custom icon and apply changes to Info.plist. Usage: go run cmds/

Decode / encode XML to/from map[string]interface{} (or JSON); extract values with dot-notation paths and wildcards. Replaces x2j and j2x packages.

mxj - to/from maps, XML and JSON Decode/encode XML to/from map[string]interface{} (or JSON) values, and extract/modify values from maps by key or key-

Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler

Pagser Pagser inspired by page parser。 Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and str

[Go] Package of validators and sanitizers for strings, numerics, slices and structs

govalidator A package of validators and sanitizers for strings, structs and collections. Based on validator.js. Installation Make sure that Go is inst

Take screenshots of websites and create PDF from HTML pages using chromium and docker

gochro is a small docker image with chromium installed and a golang based webserver to interact wit it. It can be used to take screenshots of w

Parse data and test fixtures from markdown files, and patch them programmatically, too.

go-testmark Do you need test fixtures and example data for your project, in a language agnostic way? Do you want it to be easy to combine with documen

Watches container registries for new and changed tags and creates an RSS feed for detected changes.

Tagwatch Watches container registries for new and changed tags and creates an RSS feed for detected changes. Configuration Tagwatch is configured thro

A general purpose application and library for aligning text.

align A general purpose application that aligns text The focus of this application is to provide a fast, efficient, and useful tool for aligning text.

Comments
  • Slice Range Out of Bounds on Invalid Name

    Slice Range Out of Bounds on Invalid Name

    I noticed I started getting a runtime exception when a fed in an invalid name. If you try to Parse "I am a Popsicle" as a name, you will be able to reproduce the exception. It seems that line 135 (https://github.com/polera/gonameparts/blob/master/nameparts.go#L135) of nameparts.go needs to perform a simple validation to make sure the lnEnd isn't less than partmap["lnprefix"]. I have a PR that will reference this issue.

    opened by husobee 3
  • Names ending with an apostrophe causes a panic.

    Names ending with an apostrophe causes a panic.

    Not sure if a name would ever end with an apostrophe, but if you tried to parse "John Smith'", go name parts will panic with the following:

        /go_workspace/src/github.com/polera/gonameparts/namestring.go:93` +0x795
    github.com/polera/gonameparts.(*nameString).normalize(0x82025daf0, 0x0, 0x0, 0x0)
        /go_workspace/src/github.com/polera/gonameparts/namestring.go:159 +0x16d
    github.com/polera/gonameparts.Parse(0x7fff5fbff943, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
            /go_workspace/src/github.com/polera/gonameparts/nameparts.go:98 +0x7f
    
    bug 
    opened by TomDeVito 0
  • Invalid Name causes panic

    Invalid Name causes panic

    slice range out of bounds check performed in the event 'generation' or 'suffix' is in a position before lnprefix

    Referencing: https://github.com/polera/gonameparts/issues/2

    opened by husobee 0
  • Names with comma are not always inverted

    Names with comma are not always inverted

    Hi, nice library. I was running a few test cases... In general most are looking pretty good, however there is one issue I spotted:

    name := gonameparts.Parse("John A. Smith, Jr.")
    fmt.Printf("%s %s\n", name.FirstName, name.LastName)
    #=> Jr. Smith
    

    If there is a comma and its followed by any of the salutations then the name should not be flipped.

    bug good first issue 
    opened by harlow 0
Owner
James Polera
James Polera
A full-featured regex engine in pure Go based on the .NET engine

regexp2 - full featured regular expressions for Go Regexp2 is a feature-rich RegExp engine for Go. It doesn't have constant time guarantees like the b

Doug Clark 670 Jan 9, 2023
In-memory, full-text search engine built in Go. For no particular reason.

Motivation I just wanted to learn how to write a search engine from scratch without any prior experience. Features Index content Search content Index

Michele Riva 27 Sep 1, 2022
In-memory, full-text search engine built in Go. For no particular reason.

Motivation I just wanted to learn how to write a search engine from scratch without any prior experience. Features Index content Search content Index

Michele Riva 27 Sep 1, 2022
This package provides Go (golang) types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most famously used by app.diagrams.net, the new name of draw.io.

Go Draw - Golang MX This package provides types and helper functions to do some basic but useful things with mxGraph diagrams in XML, which is most fa

null 2 Aug 30, 2022
Match regex group into go struct using struct tags and automatic parsing

regroup Simple library to match regex expression named groups into go struct using struct tags and automatic parsing Installing go get github.com/oris

Ori Seri 126 Nov 5, 2022
A fast, easy-of-use and dependency free custom mapping from .csv data into Golang structs

csvparser This package provides a fast and easy-of-use custom mapping from .csv data into Golang structs. Index Pre-requisites Installation Examples C

João Duarte 22 Nov 14, 2022
Preventing 3rd Party DLLs from Injecting into your Malware

Doge-BlockDLLs Preventing 3rd Party DLLs from Injecting into your Malware ACG(Arbitrary Code Guard)的方式等大佬来实现 Ref https://www.ired.team/offensive-secur

TimWhite 20 Dec 7, 2022
network .md into .html with plaintext files

plain network markdown files into html with plaintext files plain is a static-site generator operating on plaintext files containing a small set of co

Alexander Cobleigh 69 Dec 10, 2022
Turns any junk text into a usable wordlist for brute-forcing.

haklistgen Turns any junk text into a usable wordlist for brute-forcing. Installation go get -u github.com/hakluke/haklistgen Usage Examples Scrape a

Luke Stephens (hakluke) 147 Dec 22, 2022
golang program that simpily converts html into markdown

Simpily converts html to markdown Just a simple project I wrote in golang to convert html to markdown, surprisingly works decent for a lot of websites

null 1 Oct 23, 2021