├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── lib ├── client.js └── server.py └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Dan Kaplun 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-nltk 2 | ========= 3 | 4 | NodeJS bindings for Python's NLTK 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/client'); 2 | -------------------------------------------------------------------------------- /lib/client.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var child_process = require('child_process'); 3 | var zerorpc = require('zerorpc'); 4 | var Promise = require('bluebird'); 5 | 6 | var cp = child_process.spawn(path.join(__dirname, 'server.py')); 7 | 8 | var client = new zerorpc.Client(); 9 | client.connect('tcp://127.0.0.1:4242'); 10 | client.invokeP = Promise.promisify(client.invoke); 11 | 12 | process.on('exit', function () { 13 | cp.kill(); 14 | }); 15 | 16 | module.exports = client; 17 | -------------------------------------------------------------------------------- /lib/server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import zerorpc 4 | import nltk 5 | 6 | from types import ModuleType 7 | 8 | def rpcize(module, join='_'): 9 | result = {} 10 | 11 | for name, value in module.__dict__.items(): 12 | if name.startswith('_'): continue 13 | 14 | if callable(value): 15 | result[name] = value 16 | elif isinstance(value, ModuleType) and (value.__package__ or '').startswith(module.__package__ + '.'): 17 | result.update(dict( 18 | (name + join + subname, subvalue) 19 | for subname, subvalue in rpcize(value, join).items())) 20 | else: 21 | result[name] = lambda: value 22 | 23 | return result 24 | 25 | s = zerorpc.Server(rpcize(nltk)) 26 | s.bind("tcp://127.0.0.1:4242") 27 | s.run() 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-nltk", 3 | "version": "0.0.0", 4 | "description": "NodeJS bindings for Python's NLTK", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/dbkaplun/node-nltk.git" 12 | }, 13 | "author": "Dan Kaplun ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/dbkaplun/node-nltk/issues" 17 | }, 18 | "homepage": "https://github.com/dbkaplun/node-nltk", 19 | "dependencies": { 20 | "zerorpc": "^0.9.3", 21 | "bluebird": "^1.2.2" 22 | } 23 | } 24 | --------------------------------------------------------------------------------