Knwl.js is a Javascript library that parses through text for dates, times, phone numbers, emails, places, and more.

Related tags

Utilities Knwl.js
Overview

Knwl.js

Knwl.js is a Javascript library that parses through text for dates, times, phone numbers, emails, places, and more.


Project Future

The future of the Knwl.js project: https://github.com/loadfive/Knwl.js/issues/97


Parser plugins are what make Knwl.js tick and give it new parsing abilities. There are many already available under ./default_plugins for a number of tasks. If you're interested in developing plugins for Knwl.js, ./plugin_development.md is a great place to start.

Installation

Installation instructions are specific to whether you want to run Knwl.js in the browser, or on the server with Node.js.

For Node.js

Install using npm:

	npm install knwl.js
  1. Load the knwl module using require() and create a new Instance.

    	var Knwl = require("./knwl.js");
    	
    	var knwlInstance = new Knwl('english');

    You can optionally specify a language in the first parameter. This helps plugins identify and better suit particular languages.

  2. Load a parser plugin.

    	knwlInstance.register('dates', require('./default_plugins/dates'));

    The first parameter is the desired label for the plugin. The second parameter is a require() call to load the plugin.

    Note: The plugins in the ./default_plugins directory will be loaded automatically.

For the Browser

Note: A packaged version of Knwl.js for the browser with default plugins is available in the ./dist directory.

These steps require the npm package.

  1. Run npm install to install dependencies.

  2. browserify may be used to build a Knwl.js project from Node.js for the browser.

    Use the following syntax in the terminal:

    	./node_modules/.bin/browserify script.js knwl.js > output.js

    The script.js file is the Node.js file you wish to package for the browser.

Usage Guide

These steps are the same regardless of whether Knwl.js is running on the server or client.

  1. Initiate Knwl.js on a String.

    knwlInstance.init("This is a string. This was written on the 2nd of June, of 2015.");

    This line runs the initial parser functions that prepare the String for plugins to use. Plugins will not function without this method first being called on the String.

  2. Initiate a plugin to parse the String.

    var dates = knwlInstance.get('dates');

    The first parameter of knwl.get() is the name of the parser plugin you're trying to access (make sure you've added the plugin's .js file to the header of the page). The names of all default parser plugins are provided towards the end of this document. If you're using plugins other than the defaults, see their respective documentation.

    Anyways, if the parser plugin is found, knwl.get() will return an array of this format:

    var results = [
    	{ //result
    		//plugin-specific properties
    		"preview": "This was written on the 2nd of June of 2015.", //the sentence of rough location of the data from the String
    		"found": integer //the position (in words) of the result in the String
    	}
    ]

    For example, here's what is returned from knwl.get('dates') when called on the previously mentioned String:

    [
    	{
    		"year": 2015,
    		"month": 6,
    		"day": 2,
    		"preview": "This was written on the 2nd of June of 2015.",
    		"found": 5
    	}
    ]

Default Plugins

These are automatically loaded by default.

dates.js

knwl.get('dates');
	
	//Returns any dates found in the String.

times.js

knwl.get('times');
	
	//Returns any times found in the String.
	

phones.js

knwl.get('phones')

	//Returns any phone numbers found in the String.

links.js

knwl.get('links')

	//Returns any links found in the String.

emails.js

knwl.get('emails')
	
	//Returns any email addresses found in the String.

places.js

knwl.get('places')

	//Returns any places found in the String.

Experimental Plugins

Notice: These plugins have not been upgraded to the new syntax.

These parser plugins are not as accurate as the default plugins. However, they should be stable (they shouldn't crash the page) to use if you are willing to use them. They are considerably more static and rigid than default plugins.

In the future, some of these plugins may reach a level of accuracy that promotes them from experimental status to the default plugins. However, some will merely stay as experiments.

english.js

knwl.get('english')

	//Returns the simple parts (verb, subject, etc.) of basic sentences found in the String.
	//WARNING: this is a rigid and simplistic plugin, thus it is merely an experiment.

units.js

knwl.get('units')
	
	//Returns any units (grams, pounds, etc.) found in the String.

Developing Parser Plugins

What's awesome about the new version of Knwl.js is that it makes it much easier for anyone with a little knowledge of JS to build plugins. These plugins offer new parsing abilities for Knwl.js that otherwise wouldn't exist.

If you want to try your hand at building plugins for Knwl.js, there's documentation available in plugin_development.md.

Comments
  • Node.js Support

    Node.js Support

    Sorry for the massive PR, but it was difficult to break this up into small pieces.

    Changes

    • Refactored each plugin into it's own module (no longer modifies globals)
    • Added test and build scripts (use npm test and npm run build respectively)
    • Added Node.js support while maintaining browser support (using browserify)
      • Running npm run build writes the browser bundle to ./dist/knwl.js
    • Running tests no longer requires globally installed npm packages
    • Plugins are now registered explicitly using knwl.register(name, definition)
      • All default plugins are automatically registered for you
    • Renamed knwl.parserList to knwl.plugins

    Todo

    • Update docs to reflect these changes.
    • Make sure everything in the demo still works as expected.

    Let me know if you have any issues with what I've done here. I'm happy to update this PR.

    opened by marshall007 14
  • Add tests along with a travis-ci config

    Add tests along with a travis-ci config

    You will need to enable travis-ci and put the status image in your self.

    -- edited out. tests now pass -- I will add more tests as I go along but this seems like a good place to start off with.

    opened by benjojo 10
  • Recognition of common TLDs

    Recognition of common TLDs

    Parsed mozilla’s list of tld names to recognize links written without http:// or www. http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat

    This should solve #33 Apparently the JS-file is now crowded. :(

    opened by kitten 5
  • Code cleanup

    Code cleanup

    This is a major source update Pinging @loadfive @gprasant for feedback.

    While working on knwl.js I noticed a great deal of the tabbing was all over the place. I have gone though and enforced everything is 4 spaces for a tab. This means alot of the code is now much more readable on how "deep" you are.

    I also replaced all uses of alert with console.error so that if/when we move to a node module or so mething that could be compatible with node. It will be a lot smoother.

    I also made sure that all the multidimensional array's are spaced out more, making appending to them a great deal more easy.

    rksupft

    Overall I think this will greatly improve the code readability of the whole project!

    Have a great xmas :christmas_tree:

    as a major side note, it is worth merging this one last before anyone else's PR's to avoid death by merge conflicts

    opened by benjojo 5
  • Added the dependencies to package.json

    Added the dependencies to package.json

    Now after cloning the project, they only need to run npm install -g from the base project directory to globally and recursively install all required node modules (keep in mind if someone just runs npm install the node_modules folder will appear in the base project directory. Should consider adding a .gitignore if you do not want the node_modules folder appearing in the project).

    This will create an easier way for all contributors to manage/install dependencies for the project.

    opened by derek-meulmeester 4
  • Really picky JS Optimisation

    Really picky JS Optimisation

    Hey,

    I was just looking through the source code - Nice work! I just noticed a really small JS tweak you could do that would make it a little tidier. At the moment you do this a few times:

    var words = []; //make a copy of the rawWords array (otherwise, changes will be mirrored to knwl.words prop)
            for (var i = 0; i < rawWords.length; i++) {
                words[i] = rawWords[i];
            }
    

    When you could do either: var words = rawWords.concat([]); or var words = rawWords.slice(0);

    As I say, it really doesn't matter too much... but clean code is happy code :smile: and I doubt the performance impact (if any) is significant.

    opened by MentalAtom 3
  • RFE: multiiple parser instances

    RFE: multiiple parser instances

    Presently all functionality stems from data stored on the rootmost require('knwl') object. This makes it impossible to have more than one parse running at a time. I would like to see the ability to instantiate individual parser instances each parsing different strings.

    opened by rektide 3
  • Test suite removed just prior to 1.0 release?

    Test suite removed just prior to 1.0 release?

    It appears that all the tests were removed in 7fd3637, was there a reason behind this? It would be much easier to write plugins if we had example test cases for the existing default ones.

    opened by marshall007 3
  • Ratios

    Ratios

    The code should be quite clean. Let me know if there are any issues. This is currently an experimental plugin because:

    • 12:30 is usually not a ratio but some time of the day. Yet still it gets recognized as a ratio.
    • context is not tested and unstable.

    I will implement a matcher for financial values in the following days. Not sure if a new release makes sense before both plugins are merged.

    opened by janwirth 2
  • Link Analysis

    Link Analysis

    Using the knwl.js for analysis some links are very good too! Maybe detect the type of the link like, article, video, picture and other stuffs are a good improve.

    opened by thebergamo 2
  • Multi-lingual setup

    Multi-lingual setup

    I know it's early days, but it'd be cool to start it now, to make things easier in the future. Being able to set what language the text is using, and then running any of the plugins with that specific language will make for more detailed analysis of processed text.

    opened by NoelDavies 2
  • Trying to get in touch regarding a security issue

    Trying to get in touch regarding a security issue

    Hey there!

    I'd like to report a security issue but cannot find contact instructions on your repository.

    If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

    Thank you for your consideration, and I look forward to hearing from you!

    (cc @huntr-helper)

    opened by JamieSlome 0
  • Security Issue: Request for contact

    Security Issue: Request for contact

    Hello,

    The GitHub Security Lab team has found a potential vulnerability in your project. Please create a Security Advisory and invite me in to further disclose and discuss the vulnerability details and potential fix. Alternatively, please add a Security Policy containing a security email address to send the details to.

    Kind regards, A

    opened by pwntester 0
  • TypeError: str.toLowerCase is not a function

    TypeError: str.toLowerCase is not a function

    I am trying to detect a phone number as a Number and it seems that Knwl.js accepts only strings and the following TypeError occurs.

    TypeError: str.toLowerCase is not a function
        at Knwl.init (/path/knwl.js:1154:23)
    

    Here is a test case that reproduces the problem.

    var knwl = new Knwl();
    var phone = 5555555555;
    knwl.init(phone);
    console.log(knwl.get('phones'));
    

    To fix the problem, we may change line 1154 to the following

    var lowercase = String(str).toLowerCase();
    
    opened by waitingcheung 0
  • Project Future

    Project Future

    Hello, everyone. First off, I would like to express my gratitude to all who have contributed to Knwl.js; this project wouldn't be the same without you. Looking ahead, however, a few things need to be addressed.

    I wrote the base framework for this project many years ago, and I did so while also in the midst of becoming comfortable with Javascript, and, as such, the initial design of the program was sporadic; it was more of an experiment in personal interests than a project with a definitive usecase. Since then, and through many refinements and evolutions, Knwl.js has developed into a program that functions decently on a restricted number of datapoints. For certain use cases, these limitations are not an issue; however, in more cases than not, the inflexible methods by which Knwl.js functions inhibit the potential uses of the program.

    Knwl.js works by referencing a limited dictionary of terms and combinations of terms, which, when found in a body of text, trigger certain methods to run a hard-coded, systematic scan through the text for related information. This static, unchanging nature lends itself to Knwl.js' inability to adapt and evolve independently. In order to combat this issue, a new version of Knwl.js was developed to support plugins. The update allowed developers to create parsers for specialized tasks as needed and somewhat mitigated the rigidity of Knwl.js. Unfortunately, when a foundation is faulty, anything built atop will achieve nothing more than instability, and I am afraid this is the case with Knwl.js.

    The framework that Knwl.js has been built upon serves its purpose adequately; the project was built to be a simple, plug and play parser built in javascript; however, for the reasons stated prior, I do not believe there is potential for further growth in its current implementation. For this reason, I see little reason to continue attempting without facing the original problem: a static, pre-defined dictionary-dependant parser.

    Knwl.js has a special place in my heart as a project I conceived very early on. If you use this project, do not worry: it will not be going away; however, though I will monitor pull-requests and merge as the community suggests, I will no longer be actively writing for the project.

    In a word, I am giving this project back to you, the people who made it so great in the first place. I am open to any suggestions or comments you may have. I would like to do what is best for all of you.

    Thank you, Ben

    opened by benhmoore 0
  • Change a little bit the file structure to support multiple cultures

    Change a little bit the file structure to support multiple cultures

    Hi @loadfive,

    Thanks for this cool tool, I'm using it to parse some dates in English and that's quite good :)

    However I want to help you to increase the translation range but the structure of the project doesn't seem to be adequate to the extensibility required for contributions.

    As I see, we have a lot of translatable strings mixed with the functionality... It would be so much better to separate functionality/feature from the string searched/used. Basically making a small dictionary for the functions.

    I saw you have - on the experimental_plugins - an english.js which contains some words already.

    That'd be nice if you hadn't mixed some functionality (like 'findSentences' and alike).

    Last but not least, consider doing a language identification based on the culture, not on the language itself. E.g:

    pt_PT !== pt_BR

    en_US !== en_UK

    and so on.

    If you want I can help out, just tell me if you'd like some help on that ;) And thanks for your time!

    One thing that would be interesting to check is the possibility to integrate either with a tool/library like FormatJS or with the Unicode Group, more exactly the ICU sub-group ( http://site.icu-project.org/ ).

    opened by mAiNiNfEcTiOn 0
Releases(v1.0.2)
Owner
Ben Moore
Ben Moore
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.

KeyboardJS KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to s

Robert Hurst 2k Dec 30, 2022
Pretty diff to html javascript library (diff2html)

diff2html diff2html generates pretty HTML diffs from git diff or unified diff output. Table of Contents Features Online Example Distributions Usage Di

Rodrigo Fernandes 2.3k Dec 29, 2022
Node.js object hash library with properties/arrays sorting to provide constant hashes. It also provides a method that returns sorted object strings that can be used for object comparison without hashes.

node-object-hash Tiny and fast node.js object hash library with properties/arrays sorting to provide constant hashes. It also provides a method that r

Alexander 73 Oct 7, 2022
JavaScript parser for FIGlet fonts

_______ _________ _______ _ _______ _________ _________ _______ ( ____ \\__ __/( ____ \( \ ( ____ \\__ __/ \__ _/(

Scott González 114 Oct 15, 2022
Clock and task scheduler for node.js applications, providing extensive control of time and callback scheduling in prod and test code

#zeit A node.js clock and scheduler, intended to take place of the global V8 object for manipulation of time and task scheduling which would be handle

David Denton 12 Dec 21, 2021
front.phone is a Javascript library that identifies, validates and formats phone numbers.

front.phone front.phone is a Javascript library that identifies, validates and formats phone numbers. Demo The main goal of this project is to create

VTEX 55 Oct 27, 2022
Say goodbye to bots looking for emails and phone numbers.

Hidden From BotsSay goodbye to bots looking for emails and phone numbers Normally on the internet there are bots, crawlers or spiders, they are all th

Erik Giovani 14 Oct 17, 2022
⏱ A library for working with dates and times in JS

Luxon Luxon is a library for working with dates and times in JavaScript. DateTime.now().setZone("America/New_York").minus({ weeks: 1 }).endOf("day").t

Moment.js 13.4k Jan 9, 2023
🌐 Text Input Component for validating and formatting international phone numbers.

React Native Intl Phone Field Try the Expo Snack ?? ??️ Demo It's a javascript-only (no native code) component that can run in iOS, Android, Expo & Re

Ivanka Todorova 24 Jul 8, 2022
Projeto individual, um site para cobertura de partidas de vôlei, times onde você pode saber onde, quando acontecerá as partidas, e dados sobre os times.

?? Volleyball Esports Coverage Um portal de vôlei para as pessoas se conectarem ou divulgarem suas partidas, conhecimentos e uma maneira de conhecerem

PedroJsn 4 Jun 6, 2022
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
jquery-input-mask-phone-number.js - A simple, easy jquery format phone number mask library

jquery-input-mask-phone-number A jQuery Plugin to make masks on input field to US phone format. Quick start 1. Add latest jQuery and jquery-input-mask

Raja Rama Mohan Thavalam 12 Aug 25, 2022
Project to manage multiple emails at once with lots of customization. You can send and receive emails. Desktop notifications can be modified.

Technologies Used React Redux Tailwind CSS Features Admin dashboard User settings and or user dashboard send emails recive emails Connections through

Multi Email 9 Dec 17, 2022
null 147 Dec 8, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript

Ping.js Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript! This is useful for whe

Alfred Gutierrez 353 Dec 27, 2022
A simple bot for twitch, which has a silly AI in places. The library "cleverbot-free" is used for AI.

AITwitchChat A simple bot for twitch, which has a silly AI in places. The library "cleverbot-free" is used for AI. Requiments tmi.js Node.js 16.6.0 or

DesConnet 4 Dec 7, 2022