Coder Social home page Coder Social logo

octohedron / gemojicountries Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 35 KB

GemojiCountries is a go package to extract country codes and names from UTF-8 strings containing flags, i.e. ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡จ๐Ÿ‡ฆ ๐Ÿ‡ฏ๐Ÿ‡ฒ and get the amount of each

License: MIT License

Go 100.00%
emoji flags golang go utf-8 i18n nlp countries

gemojicountries's Introduction

GemojiCountries

Go package to extract country names and codes from emoji in text

Install

  • Make sure you have your $GOPATH set and install
$ export GOPATH=~/go # Or your gopath location
$ go get -u github.com/octohedron/gemojicountries

Overview

For example, let's say you have the string "Bonjour la france ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ซ๐Ÿ‡ท c'est bon, aussi la chine ๐Ÿ‡จ๐Ÿ‡ณ"

  • GetAmountCountryNamesMatched will return map[china:1 france:2]
  • GetAmountCountryCodesMatched will return map[cn:1 fr:2]

Note that it only matches emoji, not the country names

If you want to get the country codes and you have the country names, i.e. "russia", you can also use the util func

  • GetCountryCodeByCountry will return "ru"

For getting a string with flag emoji with the flags replaced with their string format i.e. "Bonjour la ๐Ÿ‡ซ๐Ÿ‡ท "

  • GetStringReplacedEmoji will return "Bonjour la france"

Example with test

package main

import (
	"testing"

	"github.com/octohedron/gemojicountries"
)

// example with test
func TestCountriesString(t *testing.T) {
	const s = "Bonjour la france ๐Ÿ‡ซ๐Ÿ‡ท  ๐Ÿ‡ซ๐Ÿ‡ท c'est bon aussi ๐Ÿ‡จ๐Ÿ‡ณ la chine"
	t.Logf("%v", gemojicountries.GetAmountCountryCodesMatched(s))
}

Will print

=== RUN   TestCountriesString
--- PASS: TestCountriesString (0.00s)
	../utils_test.go:132: map[china:1 france:2]
PASS
ok 	0.090s
Success: Tests passed.

Contributing? Adding countries and features? Improving performance? Yes. Send PRs ๐Ÿ‘

gemojicountries's People

Contributors

octohedron avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

wade-welles

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.