All Projects → sshaw → Normalize_country

sshaw / Normalize_country

Convert country names and codes to a standard.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Normalize country

bitsnpicas
Bits'N'Picas - Bitmap & Emoji Font Creation & Conversion Tools
Stars: ✭ 171 (+185%)
Mutual labels:  emoji, conversion
Emoji Art Generator
Use a genetic algorithm to evolve an image by putting emojies on a canvas
Stars: ✭ 53 (-11.67%)
Mutual labels:  emoji
Emotion Ratings
😠 😞 😑 😊 😍 This plugin allows you to create ratings using emojis
Stars: ✭ 37 (-38.33%)
Mutual labels:  emoji
Ut4x Converter
Helps converting old Unreal Tournament maps to new Unreal Tournament 4 game.
Stars: ✭ 46 (-23.33%)
Mutual labels:  conversion
Unicode Tr51
Emoji data extracted from Unicode Technical Report #51.
Stars: ✭ 38 (-36.67%)
Mutual labels:  emoji
Emotecollector
Collects emotes from other servers for use by people who don't have Nitro
Stars: ✭ 51 (-15%)
Mutual labels:  emoji
Polarity
Detect the polarity (sentiment) of text
Stars: ✭ 33 (-45%)
Mutual labels:  emoji
Gitmoji Commit Hook
Start the commit message with an applicable emoji
Stars: ✭ 58 (-3.33%)
Mutual labels:  emoji
Weird Json
A collection of strange encoded JSONs. For connoisseurs.
Stars: ✭ 53 (-11.67%)
Mutual labels:  emoji
Darknet2caffe
Convert Darknet model to Caffe's
Stars: ✭ 46 (-23.33%)
Mutual labels:  conversion
0xc
Easy base conversion in emacs
Stars: ✭ 42 (-30%)
Mutual labels:  conversion
Vue Emoji
An emoji component for vue2.0
Stars: ✭ 39 (-35%)
Mutual labels:  emoji
Emojitaco
Alfred Emoji Script with Taco and other unicode 9 emoji
Stars: ✭ 51 (-15%)
Mutual labels:  emoji
Vchsm
C++ 11 algorithm implementation for voice conversion using harmonic plus stochastic models
Stars: ✭ 38 (-36.67%)
Mutual labels:  conversion
Awesome Emoji Picker
Add-on/WebExtension that provides a modern emoji picker that you can use to find and copy/insert emoji into the active web page.
Stars: ✭ 54 (-10%)
Mutual labels:  emoji
Cryptii
Web app and framework offering modular conversion, encoding and encryption
Stars: ✭ 971 (+1518.33%)
Mutual labels:  conversion
Twemoji Color Font
Twitter Unicode 13 emoji color OpenType-SVG font for Linux/MacOS/Windows
Stars: ✭ 1,006 (+1576.67%)
Mutual labels:  emoji
Superbadges
Emoji Tab Bar button badges ✨
Stars: ✭ 47 (-21.67%)
Mutual labels:  emoji
Mojilist
🛍 Create shopping lists with emojis!
Stars: ✭ 60 (+0%)
Mutual labels:  emoji
Unicode Proposals
Proposals for new characters to encode and canonic character sequences to register
Stars: ✭ 55 (-8.33%)
Mutual labels:  emoji

= NormalizeCountry

Convert country names and codes to a standard.

{Build Status}[https://travis-ci.org/sshaw/normalize_country] {}[https://codeclimate.com/github/sshaw/normalize_country]

=== Overview

require "normalize_country"

NormalizeCountry("America") # "United States" NormalizeCountry("United States of America") # "United States" NormalizeCountry("USA", :to => :official) # "United States of America" NormalizeCountry("Iran", :to => :official) # "Islamic Republic of Iran" NormalizeCountry("U.S.", :to => :alpha2) # "US" NormalizeCountry("U.S.", :to => :numeric) # "840" NormalizeCountry("US", :to => :fifa) # "USA" NormalizeCountry("US", :to => :emoji) # "🇺🇸" NormalizeCountry("US", :to => :shortcode) # ":flag-us:" NormalizeCountry("Iran", :to => :alpha3) # "IRN" NormalizeCountry("Iran", :to => :ioc) # "IRI" NormalizeCountry("DPRK", :to => :short) # "North Korea" NormalizeCountry("North Korea", :to => :iso_name) # "Korea, Democratic People's Republic Of"

Or

NormalizeCountry.convert("U.S.", :to => :alpha2) # "US"

Set the default

NormalizeCountry.to = :alpha3 NormalizeCountry.convert("Mexico") # "MEX" NormalizeCountry.convert("United Mexican States") # "MEX"

=== Installation

Rubygems ({part of Ruby}[https://www.ruby-lang.org]):

gem install normalize_country

{Bundler}[http://bundler.io]:

gem "normalize_country"

=== Supported Conversions

In addition to trying to convert from common, non-standardized names and abbrivations, +NormalizeCountry+ will convert to/from the following:

[:alpha2] ISO 3166-1 alpha-2 [:alpha3] ISO 3166-1 alpha-3 [:emoji] The country's emoji [:fifa] FIFA (International Federation of Association Football) [:ioc] International Olympic Committee [:iso_name] Country name used by ISO 3166-1 [:numeric] ISO 3166-1 numeric code [:official] The country's official name [:short] A shortned version of the country's name, commonly used when speaking and/or writing (US English) [:shortcode:] Emoji shortcode

A list of valid formats can be obtained by calling +NormalizeCountry.formats+.

=== Obtaining an Array or Hash

NormalizeCountry.to_a # Defaults to NormalizeCountry.to NormalizeCountry.to_a(:ioc) # Array of IOC codes in ascending order NormalizeCountry.to_h(:ioc) # :ioc => NormalizeCountry.to NormalizeCountry.to_h(:ioc, :to => :numeric) # :ioc => :numeric

=== Conversion Utility

A small script is included that can convert country names contained in a DB table or a set of XML or CSV files

shell > normalize_country -h usage: normalize_country [options] SOURCE -h, --help Show this message -f, --format FORMAT The format of SOURCE -t, --to CONVERSION Convert country names to this format (see docs for valid formats) -l, --location LOCATION The location of the conversion

Some examples

normalize_country -t alpha2 -l 'Country Name' -f csv data.csv normalize_country -t numeric -l countries.code -f db postgres://usr:[email protected]/conquests normalize_country -t fifa -l //teams[@sport = 'fútbol americano']//country -f xml data.xml

If the format is +xml+ or +csv+ you can spefify a directory instead of a filename

normalize_country -t alpha2 -l 'Country Name' -f csv /home/sshaw/capital-losses/2008

With a format of +csv+ it will read all files with an extension of +csv+ or +tsv+. For +csv+ and +xml+ the original file(s) will be overwritten with new file(s) containing the converted country names.

To convert an XML file with namespaces just include the namespace prefix defined in the file in the XPath query (+LOCATION+).

The +db+ format's +SOURCE+ argument must be a {Sequel connection string}[http://sequel.jeremyevans.net/rdoc/classes/Sequel.html#method-c-connect]. Here +LOCATION+ is in the format +table.column+, which will be updated with the converted name.

=== Random Country Data for Your Tests

Random data generating gems like {Faker}[http://rubygems.org/gems/faker] and {RandomData}[http://rubygems.org/gems/random_data] don't generate much country data. If you'd like to use this gem to do so I suggest checking out this gist: https://gist.github.com/sshaw/6068404

=== Faulty/Missing/Erroneous Country Names

Please submit a patch or {open an issue}[https://github.com/sshaw/normalize_country/issues].

=== Why?

This code was -to some extent- part of a larger project that allowed users to perform a free-text search by country. Country names were stored in the DB by their ISO names.

Several years later at work we had to extract country names from a web service that didn't standardize them. Sometimes they used UK, other times U.K. It then occured to me that this code could be useful outside of the original project. The web service was fixed but, nevertheless...

=== Somewhat Similar Gems

Upon further investigation I've found the following:

  • {Carmen}[https://github.com/jim/carmen]: ISO country names and states/subdivisions
  • {countries}[https://github.com/hexorx/countries] ISO country names, states/subdivisions, currency, E.164 phone numbers and language translations
  • {country_codes}[https://github.com/SunDawg/country_codes] ISO country names and currency data
  • {i18n_data}[https://github.com/grosser/i18n_data]: ISO country names in different languages, includes alpha codes
  • {ModelUN}[https://github.com/uhhuhyeah/model_un]: Similar to this gem but with less support for conversion, it does include US states

=== See Also

  • {National Colors}[https://github.com/sshaw/national_colors]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].