Code Monkey home page Code Monkey logo

words's Introduction

Words Test Status codecov Go Reference

Go package words provides capabilities for extracting words from a string, by a collection of rules.

Rules

  1. Invalid UTF8-strings will not be split
  2. Hyphenated words will be treated as individual words unless disabled. E.g. "small-town" => []{"small", "town"}
  3. If the character is a space, punctuation or symbol, it will be voided, unless disabled. E.g. "my_string here" => []{"my", "string", "here"}
  4. Characters of same type in sequence, will be put together.
  5. If the current character is a lowercase, and the last character of the previous word was uppercase, the uppercase letter will be moved to the lowercase string. E.g. "YAMLParser" => []{"YAML", "Parser"}

Installation

$ go get github.com/imbue11235/words

Usage

Basic usage

words.Extract("Do you prefer camelCase to snake_case?") 
// => []string{"Do", "you", "prefer", "camel", "case", "to", "snake", "case")

words.Extract("YAMLParser")
// => []string{"YAML", "Parser"}

words.Extract("Bose QC35")
// => []string{"Bose", "QC", "35"}

With options

To further customize the extraction, options can be passed to the extract-method.

Punctuation

To include punctuation

words.Extract("So, now punctuation will be included.", words.IncludePunctuation())
// => []string{"So", ",", "now", "punctuation", "will", "be", "included", "."}

Spaces

To include spaces

words.Extract("So   many   spaces", words.IncludeSpaces())
// => []string{"So", "   ", "many", "   ", "spaces"}

Symbols

To include symbols

words.Extract("Some>String", words.IncludeSymbols())
// => []string{"Some", ">", "String"}

Hyphenated words

To allow hyphenated words

words.Extract("An anti-clockwise direction", words.AllowHyphenatedWords())
// => []string{"An", "anti-clockwise", "direction"}

Multiple options

To use multiple options at the same time

words.Extract("Using multiple options!" words.IncludeSpaces(), words.IncludePunctuation())
// => []string{"Using", " ", "multiple", " ", "options", "!"}

License

This project is licensed under the MIT license.

words's People

Contributors

imbue11235 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.