python - Load local resources with NLTK -


i'm using nltk python 3. i'd load custom pickle file knowing file name.

i have pickle in directory like:

/path/to/project/nltk/tokenizers/punkt/english.pickle 

i load , use so:

import nltk sent_tokenizer = nltk.data.load('file:/path/to/project/nltk/tokenizers/punkt/english.pickle') tokens = sent_tokenizer('a big hunk of text.') 

however, seems nltk infers don't have python 3 version of resource , adds in py3 desired path:

lookuperror:  **********************************************************************   resource '/path/to/project/nltk/tokenizers/punkt/py3/english.pickle   ' not found.  please use nltk downloader   obtain resource:  >>> nltk.download()   searched in:     - '' ********************************************************************** 

i able use real path file, instead of leaving out py3 folder , expecting nltk insert it. there way directly import resource without nltk modifying path?

thanks! j

since they're resources, load them without going through nltk's data.load api. pickled resources can unpickled:

with open("/path/to/english.pickle", "rb") resource:     sent_tokenizer = pickle.load(resource) 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -