A dictionary-based tokenizer.
Project description
DicTok
A dictionary-based tokenizer. It tokenizes a text based on known tokens.
Installation
pip install dictok
Usage
- Create your dic-file with a list of tokens e.g.
tokens.dic:
super
man
note
book
store
...
- Import
dictokand pass it the dictionary file as main parameter:
>>> import dictok
>>> dt = dictok.DicTok('tokens.dic')
- You are ready to use it:
>>> sent = "Superman bought a notebook in the bookstore."
>>> dt.tokenize(sent)
['Super', 'man', 'bought', 'a', 'note', 'book', 'in', 'the', 'book', 'store', '.']
Options
You can also ignore single characters or unknown tokens:
>>> dt.tokenize(sent, include_unknown = False, include_single_chars = False)
['Super', 'man', 'note', 'book', 'book', 'store']
If you want to rewrite words or, for example, recognize and correct words with typing errors, you can do so by specifying them as pair in the dictionary:
super
man
bought,buy
note
book
buok,book
store
stohre,store
...
>>> dt = dictok.DicTok('tokens.dic')
>>> sent = "Superman bought a notebuok in the bookstohre."
>>> dt.tokenize(sent, include_unknown = False, include_single_chars = False)
['Super', 'man', 'buy', 'note', 'book', 'book', 'store']
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dictok-0.0.5.tar.gz
(3.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dictok-0.0.5.tar.gz.
File metadata
- Download URL: dictok-0.0.5.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34364ec7edd0ba66291f47e32c0d8a776ff1dab8368d757f35bf7a14a49fd89c
|
|
| MD5 |
9633cb2e800014c305364be8dac9397c
|
|
| BLAKE2b-256 |
4eca69299906ca025b23cd6ecce7953f165ee6070741ff648a405d26fbf7fc0a
|
File details
Details for the file dictok-0.0.5-py3-none-any.whl.
File metadata
- Download URL: dictok-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9a66c089d382ace195633566c7bb5bdcd2bd1e55ea3b0261d1d1f2bcd2289e
|
|
| MD5 |
1f09f752084f05355d5cd10391d2a404
|
|
| BLAKE2b-256 |
57f96c90b15346921abbc569ddf17943e26329641f05ebf31abda65dbaabf940
|