Skip to content

📦 A tool that can recognize and infer data types and semantic meaning from strings.

Notifications You must be signed in to change notification settings

dmf-libs/semantic-data-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Semantic Data Extractor logo

A tool that can recognize and infer data types and semantic meaning from strings

Getting started

Install it with npm:

npm install semantic-data-extractor --save

or yarn:

yarn add semantic-data-extractor

Then import it and use it:

import Recognizer from "semantic-data-extractor";

const recognizer = new Recognizer();
recognizer.recognize("+90.0, -127.554334");

You get as response a list of IRecognizedType with all matching types that fit the data.

For the example above this is the response:

[
  {
    type: "geo-location",
    data: {
      lat: 90,
      lon: -127.554334,
      string: "+90.0, -127.554334"
    }
  }
];

🎉 Congrats, enjoy using Semantic Data Extractor!

Usage

You can use the recognizer to recognize and extract various forms of data from strings:

const recognizer = new Recognizer();

recognizer.recognize("+90.0, -127.554334"); // type: "geo-location"
recognizer.recognize("ISBN 0 93028 923 4"); // type: "isbn"
recognizer.recognize("1080::8:800:200C:417A"); // type: "IPv6"
recognizer.recognize("example@gmail.com"); // type: "email"
recognizer.recognize("#ffc500"); // type: "html-color"
recognizer.recognize('{"a":42}'); // type: "json"
recognizer.recognize("30%"); // type: "percentage"
recognizer.recognize("Denmark"); // type: "country"
recognizer.recognize("A+"); // type: "blood-group"

and many more... (see documentation below)


Specify list of recognizers

You can specifiy list of recognizers to use and ignore all others.

For example we might want to recognize only boolean values and ignore the integer recognizer.

const recognizer = new Recognizer();

recognizer.recognize("1", ["boolean"]);
/*
[
  {
    type: "boolean",
    data: { bool: true }
  }
]
*/

Documentation

View Recognizers Source

View Recognizers tests / usage

This is the initial set of Recognizers:

Contribution

Feel free to add suggestions, PRs, comments and bug reports.

Notes

Add Performance test into `General.test.ts` (test with long string like md5 string)

Authors

Alex Kolarski (aleks.rk@gmail.com)

License

(The MIT License)

Copyright (c) 2019

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.