Git Product home page Git Product logo

lexed's Introduction

Lexed

English word and sentence tokenizer, for natural language processing.

Installation

Install it on your node project via NPM.

npm i --save lexed

Usage

This lexer can be used for both:

  • Splitting string into an array of multiple sentences.
  • Splitting a string into arrays of sentences and further into arrays of tokens

Sentence Level

const Lexed = require("lexed").Lexed;
// or ES6 imports
import Lexed from "lexed";

const result = new Lexed('Sentence one. Sentence two! sentence 3? sentence "four." Sentence Five. Microsoft Co. released windows 10').sentenceLevel();
console.log(result);
// would give the following array:
[
	'Sentence one.',
	'Sentence two!',
	'sentence 3?',
	'sentence "four."',
	'Sentence Five.',
	'Microsoft Co. released windows 10'
];

Sentence and token level

const Lexed = require("lexed").Lexed;
// or ES6 imports
import Lexed from "lexed";

const result = new Lexed('Microsoft Co. released windows 10').lexer().tokens;
console.log(result);
// would give the following object:
[
	[
		'Microsoft',
		'Co.'
		'released',
		'windows',
		'10'
	],
];

Extensibility

Currently there's not much to extend in the lexer. Except the abbreviations list.

The abbreviations list is used to detect dots . that are not really a full stop for a sentence.

For example the following sentence: Mr. Andrews went to the office, if Mr isn't registered as an abbreviation, then it the string would be considered two sentences:

  • Mr.
  • Andrews went to the office

Which is obviously inaccurate. However, since Mr. is actually registered as an abbreviation, then we'll get one sentence: Mr. Andrews went to the office.

Now if you want to extend the abbreviations list you should import the abbreviations from Lexed library and add/remove values as you wish.

const abbreviations = require("lexed").abbreviations;
// or ES6 imports
import {abbreviations} from "lexed";

// push new abbreviation
abbreviations.push("Mmm"); // french for madam

Contributing

Perquisites:

  • Mocha (testing framework) installed globally
  • TypeScript (language compiler) installed globally
  • ts-node (typescript) runtime installed globally

Contributing

  • Clone the repository: git clone https://github.com/alexcorvi/lexed.git
  • Install dependencies: cd lexed && npm install
  • ...
  • Test penn-treebank compliance: npm run penn
  • Test the library: npm run test
  • Build the library: npm run build

License

The MIT License (MIT) - Copyright (c) 2017 Alex Corvi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lexed's People

Contributors

alexcorvi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lexed's Issues

Abbreviations test comments need updating?

Or something does. The test seems to be testing "ADA" not "M." or "Mme.": https://github.com/FinNLP/lexed/blob/master/test/extending.abbreviations.ts#L10-L14. It's unclear why "m" is included in the abbreviations list, though.

I haven't tried this out myself yet, but is it correct that the initial result would have been ["M. et Mme.","Pierre Dubois sont allés à la tribune hier soir."]? Would "M." not be a sentence by itself without the abbreviations list?

Less of a contradiction is https://github.com/FinNLP/lexed/blob/master/test/extending.abbreviations.ts#L4, which says, "which means Monsieur. and Madame. respectively in French." and should say, "which means Monsieur and Madame respectively in French." without the periods.

Feature Request: Preserve paragraphs

It would be really ud]seful to be able to preserve a paragraph.

For example:

This is the first paragraph. It has two sentences.

This is the second paragraph, it is separated from the first by two (or more) newline characters.

Would it be possible to give the user control of that as an API parameter?

(I've looked into your regex to see if submitting a PR was doable, but it looks figuring it out would probably fry my grey matter in a matter of seconds. If it was an easy change, I'd be open to knowing how much change to the code something like that would require, and where I might try to begin.)

Online demo

It'd be great if there were an online demo with just a field where users could input a sentence or paragraph and see what the current functionality and output of lexed looks like.

Readme links need updating

The links to examples of extending the module go to 404. From what I can tell, instead of ".js", they now need to be ".ts".

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.