-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from vunb/dev
Add an example to build an NLP API Server
Showing
10 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extensionsLocationCache": true, | ||
"httpPort": 3000, | ||
"logger": { | ||
"console": { | ||
"transport": "console", | ||
"level": "info" | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# NLP API Server | ||
|
||
You can easily create a NLP API Server using `Vntk`. What you need to do is decide where to deploy server. Here are some helpful ways to do this. | ||
|
||
|
||
## NPM Script | ||
|
||
At the project directory, run: | ||
|
||
* `$ npm start` | ||
|
||
Then open your browser or `Postman` to test apis. | ||
|
||
* http://localhost:3000/api/tok/xin%20chào%20các%20bạn | ||
* http://localhost:3000/api/pos/xin%20chào%20các%20bạn | ||
* http://localhost:3000/api/chunking/xin%20chào%20các%20bạn | ||
* http://localhost:3000/api/ner/xin%20chào%20các%20bạn | ||
|
||
## Docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
const vntk = require('../lib/vntk'); | ||
|
||
const tokenizer = vntk.wordTokenizer(); | ||
const posTag = vntk.posTag(); | ||
const chunking = vntk.chunking(); | ||
const ner = vntk.ner(); | ||
|
||
// kites extension definition | ||
module.exports = function (kites) { | ||
kites.on('expressConfigure', (app) => { | ||
|
||
/** | ||
* API Homepage | ||
*/ | ||
app.get('/', (req, res) => { | ||
res.send('This is an example Vntk Server!') | ||
}) | ||
|
||
/** | ||
* Word Tokenizer | ||
*/ | ||
app.get('/api/tok/:text', (req, res) => { | ||
var text = req.param('text') | ||
var format = req.param('format') | ||
var result = tokenizer.tag(text, format) | ||
res.ok(result) | ||
}); | ||
|
||
/** | ||
* POS Tagging | ||
*/ | ||
app.get('/api/pos/:text', (req, res) => { | ||
var text = req.param('text') | ||
var format = req.param('format') | ||
var result = posTag.tag(text, format) | ||
res.ok(result) | ||
}) | ||
|
||
/** | ||
* Chunking | ||
*/ | ||
app.get('/api/chunking/:text', (req, res) => { | ||
var text = req.param('text') | ||
var format = req.param('format') | ||
var result = chunking.tag(text, format) | ||
res.ok(result) | ||
}) | ||
|
||
/** | ||
* Named Entity Recognition | ||
*/ | ||
app.get('/api/ner/:text', (req, res) => { | ||
var text = req.param('text') | ||
var format = req.param('format') | ||
var result = ner.tag(text, format) | ||
res.ok(result) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
const engine = require('@kites/engine'); | ||
const apiRoutes = require('./api') | ||
|
||
engine({ | ||
loadConfig: true, | ||
discover: true | ||
}) | ||
.use(apiRoutes) | ||
.init() | ||
.then(function (kites) { | ||
kites.logger.info('VNTK API Server has initialized!'); | ||
}) | ||
.catch(function (e) { | ||
console.error(e.stack); | ||
process.exit(1); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
var test = require('tape'), | ||
path = require('path'), | ||
vntk = require('../../lib/vntk'), | ||
crfsuite = vntk.crfsuite(); | ||
|
||
test('crfsuite load trained model', function (t) { | ||
t.plan(1); | ||
|
||
var tagger = crfsuite.Tagger(); | ||
var modelFilename = path.resolve(__dirname, './models/model.bin'); | ||
var result = tagger.open(modelFilename); | ||
|
||
t.true(result, 'Open model file should be ok!'); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters