Skip to content

Commit e49d71c

Browse files
authored
Merge pull request #40 from vunb/dev
expose api get vntk logger
2 parents 4254239 + 74066b3 commit e49d71c

3 files changed

Lines changed: 77 additions & 37 deletions

File tree

README.md

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,57 @@ If you are interested in contributing to **vntk**, or just hacking on it, then f
1818

1919
Jump to guide: [How to build an NLP API Server using Vntk](#nlp-api-server).
2020

21+
# Documentation
22+
23+
* [**CLI Utilities**](#cli-utilities)
24+
* [1. Installation](#1-installation)
25+
* [2. Usage Example](#2-usage-example)
26+
* [**API Usage**](#api-usage)
27+
* [1. Tokenizer](#1-tokenizer)
28+
* [2. Word Segmentation](#2-word-segmentation)
29+
* [3. POS Tagging](#3-pos-tagging)
30+
* [4. Chunking](#4-chunking)
31+
* [5. Named Entity Recognition](#5-named-entity-recognition)
32+
* [PER LOC ORG](#ner-per-loc-org)
33+
* [Date time](#ner-date-time)
34+
* [Custom NER](#ner-custom)
35+
* [6. Utility](#6-utility)
36+
* [Dictionary](#dictionary)
37+
* [Clean html](#clean-html)
38+
* [7. TF-IDF](#7-tf-idf)
39+
* [8. Classifiers](#8-classifiers)
40+
* [Naive Bayes](#bayes-classifier)
41+
* [fastText](#fasttext-classifier)
42+
* [9. Language identification](#9-language-identification)
43+
* [10. CRFSuite](#10-crfsuite)
44+
* [**NLP API Server**](#nlp-api-server)
45+
* [**Contributing**](#contributing)
46+
* [**License**](#license)
47+
2148
# CLI Utilities
2249

50+
## 1. Installation
51+
2352
Vntk cli will install nice and easy with:
2453

2554
> npm install -g @vntk/cli
2655
27-
Then you need to pay attention how to use these cli utilities to preprocess text from files, especially vietnamese that describe at the end of each apis usage. If you wish to improve the tool, please fork and make it better [here](https://github.com/vntk/vntk-cli).
56+
Then you need to pay attention to how to use these cli utilities to preprocess text from files, especially vietnamese that **describe at the end of each apis usage**. If you wish to improve the tool, please fork and make it better [here](https://github.com/vntk/vntk-cli).
2857

29-
# API Usage
58+
## 2. Usage Example
3059

31-
* [1. Tokenizer](#1-tokenizer)
32-
* [2. Word Segmentation](#2-word-segmentation)
33-
* [3. POS Tagging](#3-pos-tagging)
34-
* [4. Chunking](#4-chunking)
35-
* [5. Named Entity Recognition](#5-named-entity-recognition)
36-
* [PER LOC ORG](#ner-per-loc-org)
37-
* [Date time](#ner-date-time)
38-
* [Custom NER](#ner-custom)
39-
* [6. Utility](#6-utility)
40-
* [Dictionary](#dictionary)
41-
* [Clean html](#clean-html)
42-
* [7. TF-IDF](#7-tf-idf)
43-
* [8. Classifiers](#8-classifiers)
44-
* [Naive Bayes](#bayes-classifier)
45-
* [fastText](#fasttext-classifier)
46-
* [9. Language identification](#9-language-identification)
47-
* [10. CRFSuite](#10-crfsuite)
60+
After the CLI has installed, you need to open your `Terminal` (or Command Prompt on Windows) and type command you need to use.
61+
62+
For instance, the following command will open a file and process it by using Word Tokenizer to tokenize each lines in the file.
63+
64+
```bash
65+
# Process a text file or a folder
66+
$ vntk ws input.txt --output output.txt
67+
68+
# Output file will contain lines which have tokenized.
69+
```
70+
71+
# API Usage
4872

4973
## 1. Tokenizer
5074

@@ -68,8 +92,8 @@ Command line: `vntk tok <file_name.txt>`
6892

6993
## 2. Word Segmentation
7094

71-
> Vietnamese Word Segmentation using Conditional Random Fields, called: `WordTokenizer`.
72-
> WordTokenizer helps break text into arrays of words!
95+
> Vietnamese Word Segmentation using Conditional Random Fields, called: `Word Tokenizer`.
96+
> Word Tokenizer helps break text into arrays of words!
7397
7498
```js
7599
var vntk = require('vntk');
@@ -256,7 +280,7 @@ vntk clean <file_name1.txt>
256280
[Term Frequency–Inverse Document Frequency (tf-idf)](http://en.wikipedia.org/wiki/Tf%E2%80%93idf) is implemented to determine how important a word (or words) is to a document relative to a corpus. See following example.
257281

258282
```js
259-
var vntk = require('./lib/vntk');
283+
var vntk = require('vntk');
260284
var tfidf = new vntk.TfIdf();
261285

262286
tfidf.addDocument('Đại tướng Trần Đại Quang - Ủy viên Bộ Chính trị, Bí thư Đảng ủy Công an Trung ương, Bộ trưởng Bộ Công an.');

lib/vntk.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ const fs = require('fs')
1111
const util = require('util')
1212
// singleton instance
1313

14-
exports.util = () => require('./util');
14+
/**
15+
* Regex Tokenizer
16+
*/
1517
exports.tokenizer = () => require('./tokenizer');
1618

1719
/**
1820
* Word Segmentation
21+
* It also is a Word Tokenizer which use a CRF model
1922
* @param {String} modelFileName new custom model
2023
*/
2124
exports.wordTokenizer = (modelFileName) => {
22-
if(modelFileName && fs.existsSync(modelFileName)) {
25+
if (modelFileName && fs.existsSync(modelFileName)) {
2326
return require('./word_tokenizer').newModel(modelFileName)
24-
} else {
27+
} else {
2528
return require('./word_tokenizer')
2629
}
2730
}
@@ -31,9 +34,9 @@ exports.wordTokenizer = (modelFileName) => {
3134
* @param {String} modelFileName new custom model
3235
*/
3336
exports.posTag = (modelFileName) => {
34-
if(modelFileName && fs.existsSync(modelFileName)) {
37+
if (modelFileName && fs.existsSync(modelFileName)) {
3538
return require('./pos_tag').newModel(modelFileName)
36-
} else {
39+
} else {
3740
return require('./pos_tag')
3841
}
3942
}
@@ -43,9 +46,9 @@ exports.posTag = (modelFileName) => {
4346
* @param {String} modelFileName new custom model
4447
*/
4548
exports.chunking = (modelFileName) => {
46-
if(modelFileName && fs.existsSync(modelFileName)) {
49+
if (modelFileName && fs.existsSync(modelFileName)) {
4750
return require('./chunking').newModel(modelFileName)
48-
} else {
51+
} else {
4952
return require('./chunking')
5053
}
5154
};
@@ -55,9 +58,9 @@ exports.chunking = (modelFileName) => {
5558
* @param {String} modelFileName new custom model
5659
*/
5760
exports.ner = (modelFileName) => {
58-
if(modelFileName && fs.existsSync(modelFileName)) {
61+
if (modelFileName && fs.existsSync(modelFileName)) {
5962
return require('./ner').newModel(modelFileName)
60-
} else {
63+
} else {
6164
return require('./ner')
6265
}
6366
};
@@ -67,9 +70,9 @@ exports.ner = (modelFileName) => {
6770
* @param {String} modelFileName new custom model
6871
*/
6972
exports.langid = (modelFileName) => {
70-
if(modelFileName && fs.existsSync(modelFileName)) {
73+
if (modelFileName && fs.existsSync(modelFileName)) {
7174
return require('./langid').newModel(modelFileName)
72-
} else {
75+
} else {
7376
return require('./langid')
7477
}
7578
};
@@ -79,9 +82,9 @@ exports.langid = (modelFileName) => {
7982
* @param {String} modelFileName path to new updated dictionary
8083
*/
8184
exports.dictionary = (modelFileName) => {
82-
if(modelFileName && fs.existsSync(modelFileName)) {
85+
if (modelFileName && fs.existsSync(modelFileName)) {
8386
return new require('@vntk/dictionary').Dictionary(modelFileName)
84-
} else {
87+
} else {
8588
return require('@vntk/dictionary')
8689
}
8790
}
@@ -100,10 +103,23 @@ exports.BayesClassifier = require('./classifiers').BayesClassifier;
100103
exports.LogisticRegressionClassifier = require('./classifiers').LogisticRegressionClassifier;
101104
exports.FastTextClassifier = require('./classifiers').FastTextClassifier;
102105

106+
/**
107+
* Utilities
108+
*/
109+
exports.util = () => require('./util');
110+
111+
/**
112+
* Get a new logger
113+
* @param {String} name
114+
*/
115+
exports.logger = (name) => {
116+
return require('./logger')(name);
117+
}
118+
103119
/**
104120
* Depreciated
105121
* Please use lower camelCase api with custom model.
106122
*/
107123
exports.Langid = util.deprecate(exports.langid, '`vntk.Langid()` is depreciated, please use `vntk.langid([custom_model])` instead.')
108124
exports.getDictionary = util.deprecate(exports.dictionary, '`vntk.getDictionary()` is depreciated, please use `vntk.dictionary([custom_model])` instead.')
109-
exports.wordSent = util.deprecate(exports.wordTokenizer, '`vntk.wordSent()` is depreciated, please use `vntk.wordTokenizer([custom_model])` instead.')
125+
exports.wordSent = util.deprecate(exports.wordTokenizer, '`vntk.wordSent()` is depreciated, please use `vntk.wordTokenizer([custom_model])` instead.')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vntk",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Vietnamese NLP Toolkit for Node",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)