Skip to main content

A dictionary-based tokenizer.

Project description

DicTok

A dictionary-based tokenizer. It tokenizes a text based on known tokens.

Installation

pip install dictok

Usage

  1. Create your dic-file with a list of tokens e.g. tokens.dic:
super
man
note
book
store
...
  1. Import dictok and pass it the dictionary file as main parameter:
>>> import dictok
>>> dt = dictok.DicTok('tokens.dic')
  1. 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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictok-0.0.5-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

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

Hashes for dictok-0.0.5.tar.gz
Algorithm Hash digest
SHA256 34364ec7edd0ba66291f47e32c0d8a776ff1dab8368d757f35bf7a14a49fd89c
MD5 9633cb2e800014c305364be8dac9397c
BLAKE2b-256 4eca69299906ca025b23cd6ecce7953f165ee6070741ff648a405d26fbf7fc0a

See more details on using hashes here.

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

Hashes for dictok-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9b9a66c089d382ace195633566c7bb5bdcd2bd1e55ea3b0261d1d1f2bcd2289e
MD5 1f09f752084f05355d5cd10391d2a404
BLAKE2b-256 57f96c90b15346921abbc569ddf17943e26329641f05ebf31abda65dbaabf940

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page