GithubHelp home page GithubHelp logo

johncmunson / kontractions Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 112 KB

A small javascript library for converting to and fro' contractions.

License: MIT License

JavaScript 100.00%
contractions contraction natural language processing nlp javascript-library

kontractions's Introduction

    __                    __                           __     _                        
   / /__  ____    ____   / /_   _____  ____ _  _____  / /_   (_)  ____    ____    _____
  / //_/ / __ \  / __ \ / __/  / ___/ / __ `/ / ___/ / __/  / /  / __ \  / __ \  / ___/
 / ,<   / /_/ / / / / // /_   / /    / /_/ / / /__  / /_   / /  / /_/ / / / / / (__  )
/_/|_|  \____/ /_/ /_/ \__/  /_/     \__,_/  \___/  \__/  /_/   \____/ /_/ /_/ /____/  

A small javascript library for converting to and fro' contractions.

Install

npm i --save kontractions or yarn add kontractions

Basic Usage

ES6

import kontractions from 'kontractions'

Node Modules

const kontractions = require('kontractions')

API

  • kontractions.contract(string): Converts a string containing longforms to a string containing contractions.
  • kontractions.expand(string): Converts a string containing contractions to a string containing longforms, or the various possible longforms.
  • kontractions.expandToList(string): Converts a string containing contractions to a list of strings containing all possible longforms.
  • kontractions.updateContractions(object): Accepts an object and can be used for extending, modifying, or disabling the built-in default contractions.
  • kontractions.updateLongforms(object): Accepts an object and can be used for extending, modifying, or disabling the built-in default longforms.

Examples

  • kontractions.contract("I did not do it.") //=> i didn't do it.
  • kontractions.expand("I didn't do it.") //=> i did not do it.
  • kontractions.expand("I hope there's more food.") //=> i hope (( there has || there is )) more food.
  • kontractions.expandToList("I didn't do it.") //=> [ 'i did not do it.' ]
  • kontractions.expandToList("I hope there's more food.") //=> [ 'i hope there has more food.', 'i hope there is more food.' ]
  • kontractions.updateContractions({"they'd've": ['they would have']}) //=> The contraction they'd've will now be recognized when using the contract method.
  • kontractions.updateLongforms({"they would have": "they'd've"}) //=> The longform they would have will now be recognized when using the expand method.
  • kontractions.updateContractions({"they'd've": ['they would have']}) //=> Pass a falsy value to disable a contraction.
  • kontractions.updateLongforms({"they would have": false}) //=> Pass a falsy value to disable a longform.

Defaults

Philosophy

This library aims to do one thing and do it well. With regards to the expand method, while it would be possible to examine the context in which contractions are used to determine the proper expansion, that will likely remain beyond the scope of this package. Therefore, consumers will need to implement their own logic to examine the output and pick the correct expansion.

Contributions

All contributors will receive proper attribution, as outlined in the awesome All-Contributors specification developed by open-source superstar Kent C. Dodds.

Development Setup

This project was bootstrapped with Babel Starter Kit. To get started with development, fork this repo and make edits to the src directory. Install dependencies with npm install or yarn. Run tests with npm test.

License

kontractions is available under MIT. See LICENSE for more details.

To-do

  • Add option to enable 3-word+ contractions

kontractions's People

Contributors

haueck avatar johncmunson avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.