A tool that can recognize and infer data types and semantic meaning from strings
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!
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)
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 }
}
]
*/
View Recognizers tests / usage
This is the initial set of Recognizers:
- Boolean
- URL
- DateTime
- Time
- Integer number
- Float number
- Mac Address
- Binary string
- File Path
- IPv4
- IPv4 Socket
- IPv6
- Top Level Domain (TLD)
- Country
- Geo Location
- Percentage
- ISBN
- Credit Card
- HTML Colors
- Programming comment
- EU VAT Number
- JSON
- MD5
- Blood Group
- CIDR
- YouTube video URL
- Musical Chords
- JWT Token
- Image URL
- US States
- City
- Person Name
- Person Title
- Currency
- BG phone number
- BG Address
- GUID - http://www.regexlib.com/REDetails.aspx?regexp_id=3851, http://www.regexlib.com/REDetails.aspx?regexp_id=4918
- TCP Port - http://www.regexlib.com/REDetails.aspx?regexp_id=1236
- UK Postal codes - http://www.regexlib.com/REDetails.aspx?regexp_id=1047
- Apache common log format - http://www.regexlib.com/REDetails.aspx?regexp_id=1085
- Social Security Number - All Rules Enforced - http://www.regexlib.com/REDetails.aspx?regexp_id=2850
- DMS Coordinate - http://www.regexlib.com/REDetails.aspx?regexp_id=3219
Feel free to add suggestions, PRs, comments and bug reports.
Add Performance test into `General.test.ts` (test with long string like md5 string)
Alex Kolarski (aleks.rk@gmail.com)
(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.