{"id":34103687,"url":"https://github.com/jacksonllee/nskipgrams","last_synced_at":"2026-04-01T23:38:02.564Z","repository":{"id":57447092,"uuid":"290420602","full_name":"jacksonllee/nskipgrams","owner":"jacksonllee","description":"A lightweight Python package to work with ngrams and skipgrams","archived":false,"fork":false,"pushed_at":"2023-03-11T21:43:41.000Z","size":58,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-17T00:41:24.303Z","etag":null,"topics":["computational-linguistics","language","linguistics","natural-language-processing","ngrams","nlp","skipgrams"],"latest_commit_sha":null,"homepage":"https://github.com/jacksonllee/nskipgrams","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacksonllee.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-26T06:58:10.000Z","updated_at":"2025-10-11T18:33:36.000Z","dependencies_parsed_at":"2022-09-07T22:11:59.077Z","dependency_job_id":null,"html_url":"https://github.com/jacksonllee/nskipgrams","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jacksonllee/nskipgrams","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksonllee%2Fnskipgrams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksonllee%2Fnskipgrams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksonllee%2Fnskipgrams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksonllee%2Fnskipgrams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacksonllee","download_url":"https://codeload.github.com/jacksonllee/nskipgrams/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacksonllee%2Fnskipgrams/sbom","scorecard":{"id":500867,"data":{"date":"2025-08-11","repo":{"name":"github.com/jacksonllee/nskipgrams","commit":"7c94066a12094d3f7d97704f7ab1eeb28021f326"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-19T21:48:55.926Z","repository_id":57447092,"created_at":"2025-08-19T21:48:55.926Z","updated_at":"2025-08-19T21:48:55.926Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31292988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-linguistics","language","linguistics","natural-language-processing","ngrams","nlp","skipgrams"],"created_at":"2025-12-14T17:48:33.894Z","updated_at":"2026-04-01T23:38:02.557Z","avatar_url":"https://github.com/jacksonllee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"nskipgrams\n==========\n\n.. image:: https://badge.fury.io/py/nskipgrams.svg\n   :target: https://pypi.python.org/pypi/nskipgrams\n   :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/pyversions/nskipgrams.svg\n   :target: https://pypi.python.org/pypi/nskipgrams\n   :alt: Supported Python versions\n\n.. image:: https://circleci.com/gh/jacksonllee/nskipgrams.svg?style=shield\n   :target: https://circleci.com/gh/jacksonllee/nskipgrams\n   :alt: CircleCI Build\n\n.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4002095.svg\n    :target: https://doi.org/10.5281/zenodo.4002095\n    :alt: DOI\n\n``nskipgrams`` is a lightweight Python package to work with ngrams and skipgrams.\nFields of study using ngrams and skipgrams from sequential data, especially\ncomputational linguistics and natural language processing, will find\nthis package helpful.\n\nHighlights:\n\n* Simple: Store, access, and count ngrams and skipgrams -- that's it!\n* Memory-efficient: Tries are used for internal storage.\n* Hassle-free: No dependencies. Written in pure Python. Today is a great day.\n\nDownload and Install\n--------------------\n\nTo download and install the most recent version::\n\n    $ pip install --upgrade nskipgrams\n\nUsage\n-----\n\nThe following are defined:\n\n- Ngrams\n    - The class ``Ngrams`` handles a collection of ngrams.\n    - The function ``ngrams_from_seq`` yields ngrams for a given sequence.\n- Skipgrams\n    - The class ``Skipgrams`` handles a collection of skipgrams.\n    - The function ``skipgrams_from_seq`` yields skipgrams for a given sequence.\n\nGetting Ngrams from a Sequence\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf you simply need ngrams from a sequence, ``ngrams_from_seq`` is what you're looking for:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from nskipgrams import ngrams_from_seq\n    \u003e\u003e\u003e for ngram in ngrams_from_seq(\"abcdef\", n=2):\n    ...     print(ngram)\n    ('a', 'b')\n    ('b', 'c')\n    ('c', 'd')\n    ('d', 'e')\n    ('e', 'f')\n\nInitializing an Ngram Collection\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from nskipgrams import Ngrams\n    \u003e\u003e\u003e char_ngrams = Ngrams(n=3)  # handles unigrams, bigrams, and trigrams\n\nAdding Ngrams\n^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    \u003e\u003e\u003e char_ngrams.add_from_seq(\"my cats\")\n    \u003e\u003e\u003e char_ngrams.add_from_seq(\"your cat\", count=2)\n\nHere, a sequence is anything that can be iterated over,\nand the corresponding ngrams are extracted from the individual elements\noff of the sequence.\nFor example, if the sequence is a text string like ``\"my cats\"`` above,\nthen the ngrams are character-based (hence the chosen variable name ``char_ngrams``).\n\nTo add a single ngram:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e char_ngrams.add((\"y\", \"o\", \"u\"))\n\nAs a best practice, it is recommended that an ngram be represented as a ``tuple``\nregardless of what the individual elements are,\ne.g., ``(\"y\", \"o\", \"u\")`` for character-based ngrams.\nAs output examples show below, the ``tuple`` data type is also what this package\nuses to represent ngrams.\n\nAccessing Ngrams\n^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    \u003e\u003e\u003e for ngram, count in char_ngrams.ngrams_with_counts(n=1):  # unigrams\n    ...     print(ngram, count)\n    ...\n    ('m',), 1\n    ('y',), 3\n    (' ',), 3\n    ('c',), 3\n    ('a',), 3\n    ('t',), 3\n    ('s',), 1\n    ('o',), 2\n    ('u',), 2\n    ('r',), 2\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e for ngram, count in char_ngrams.ngrams_with_counts(n=2):  # bigrams\n    ...     print(ngram, count)\n    ...\n    ('m', 'y'), 1\n    ('y', ' '), 1\n    ('y', 'o'), 2\n    (' ', 'c'), 3\n    ('c', 'a'), 3\n    ('a', 't'), 3\n    ('t', 's'), 1\n    ('o', 'u'), 2\n    ('u', 'r'), 2\n    ('r', ' '), 2\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e for ngram, count in char_ngrams.ngrams_with_counts(n=3):  # trigrams\n    ...     print(ngram, count)\n    ...\n    ('m', 'y', ' '), 1\n    ('y', ' ', 'c'), 1\n    ('y', 'o', 'u'), 3\n    (' ', 'c', 'a'), 3\n    ('c', 'a', 't'), 3\n    ('a', 't', 's'), 1\n    ('o', 'u', 'r'), 2\n    ('u', 'r', ' '), 2\n    ('r', ' ', 'c'), 2\n\nAccessing Ngrams with a Specific Prefix\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    \u003e\u003e\u003e for ngram, count in char_ngrams.ngrams_with_counts(n=3, prefix=(\"y\",)):\n    ...     print(ngram, count)\n    ...\n    ('y', ' ', 'c'), 1\n    ('y', 'o', 'u'), 3\n\nAccessing the Count of a Specific Ngram\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    \u003e\u003e\u003e char_ngrams.count((\"c\", \"a\", \"t\"))\n    3\n\nChecking Membership\n^^^^^^^^^^^^^^^^^^^\n\nTo check if an ngram has an exact match in the collection so far:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e (\"c\", \"a\", \"t\") in char_ngrams\n    True\n\nCombining Collections of Ngrams\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTo combine collections of ngrams (e.g., when you process data sources in parallel\nand have multiple ``Ngrams`` objects):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e char_ngrams1 = Ngrams(n=2)\n    \u003e\u003e\u003e char_ngrams1.add_from_seq(\"my cat\")\n    \u003e\u003e\u003e set(char_ngrams1.ngrams_with_counts(n=2))\n    {((' ', 'c'), 1),\n     (('a', 't'), 1),\n     (('c', 'a'), 1),\n     (('m', 'y'), 1),\n     (('y', ' '), 1)}\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e char_ngrams2 = Ngrams(n=2)\n    \u003e\u003e\u003e char_ngrams2.add_from_seq(\"your cats\")\n    \u003e\u003e\u003e set(char_ngrams2.ngrams_with_counts(n=2))\n    {((' ', 'c'), 1),\n     (('a', 't'), 1),\n     (('c', 'a'), 1),\n     (('o', 'u'), 1),\n     (('r', ' '), 1),\n     (('t', 's'), 1),\n     (('u', 'r'), 1),\n     (('y', 'o'), 1)}\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e char_ngrams3 = Ngrams(n=2)\n    \u003e\u003e\u003e char_ngrams3.add_from_seq(\"her cats\")\n    \u003e\u003e\u003e set(char_ngrams3.ngrams_with_counts(n=2))\n    {((' ', 'c'), 1),\n     (('a', 't'), 1),\n     (('c', 'a'), 1),\n     (('e', 'r'), 1),\n     (('h', 'e'), 1),\n     (('r', ' '), 1),\n     (('t', 's'), 1)}\n    \u003e\u003e\u003e\n    \u003e\u003e\u003e char_ngrams1.combine(char_ngrams2, char_ngrams3)  # `combine` takes as many Ngrams objects as desired\n    \u003e\u003e\u003e set(char_ngrams1.ngrams_with_counts(n=2))\n    {((' ', 'c'), 3),\n     (('a', 't'), 3),\n     (('c', 'a'), 3),\n     (('e', 'r'), 1),\n     (('h', 'e'), 1),\n     (('m', 'y'), 1),\n     (('o', 'u'), 1),\n     (('r', ' '), 2),\n     (('t', 's'), 2),\n     (('u', 'r'), 1),\n     (('y', ' '), 1),\n     (('y', 'o'), 1)}\n\nIf you don't want to mutate any of the ``Ngrams`` instances\n(the ``combine`` method works in-place and mutates ``these_ngrams``\nwhen ``these_ngrams.combine`` is called),\nthen you can create an empty ngram collection and combine into it\nall of your ngrams:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e collections = [char_ngrams1, char_ngrams2, char_ngrams3]\n    \u003e\u003e\u003e all_ngrams = Ngrams(n=2)  # A new, empty collection of ngrams\n    \u003e\u003e\u003e all_ngrams.combine(*collections)\n\nAny \"Sequences\" and their Corresponding \"Ngrams\" Work\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nWhile the examples above use text strings as sequences and character-based ngrams,\nanother common usage in computational linguistics and NLP is to have\nsegmented phrases/sentences as sequences and word-based ngrams:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from nskipgrams import Ngrams\n    \u003e\u003e\u003e word_ngrams = Ngrams(n=2)\n    \u003e\u003e\u003e word_ngrams.add_from_seq((\"in\", \"the\", \"beginning\"))\n    \u003e\u003e\u003e word_ngrams.add_from_seq((\"in\", \"the\", \"end\"))\n    \u003e\u003e\u003e for ngram, count in word_ngrams.ngrams_with_counts(n=2):\n    ...     print(ngram, count)\n    ...\n    ('in', 'the'), 2\n    ('the', 'beginning'), 1\n    ('the', 'end'), 1\n\nSkipgrams\n^^^^^^^^^\n\nNgrams are a special case of skipgrams, with skip = 0.\nThe class ``Skipgrams`` works the same as ``Ngrams``, with the following differences:\n\n* ``Skipgrams`` has the method ``skipgrams_with_counts`` rather than ``ngrams_with_counts``.\n  ``skipgrams_with_counts`` also has the keyword argument ``skip``\n  (in addition to ``n`` and ``prefix``).\n* For ``Skipgrams``, the methods ``add`` and ``count``, as well as collection instantiation\n  (i.e., ``__init__``), also have a meaningful ``skip`` keyword argument.\n\nThe function ``skipgrams_from_seq`` works the same as ``ngrams_from_seq``, but has\nthe ``skip`` keyword argument (in addition to ``seq`` and ``n``).\n\nCitation\n--------\n\nLee, Jackson L. 2023. nskipgrams: A lightweight Python package to work with ngrams and skipgrams. https://doi.org/10.5281/zenodo.4002095\n\n.. code-block:: latex\n\n    @software{leengrams,\n      author       = {Jackson L. Lee},\n      title        = {nskipgrams: A lightweight Python package to work with ngrams and skipgrams},\n      year         = 2021,\n      doi          = {10.5281/zenodo.4002095},\n      url          = {https://doi.org/10.5281/zenodo.4002095}\n    }\n\nLicense\n-------\n\nMIT License. Please see ``LICENSE.txt`` in the GitHub source code for details.\n\nChangelog\n---------\n\nPlease see ``CHANGELOG.md`` in the GitHub source code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacksonllee%2Fnskipgrams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacksonllee%2Fnskipgrams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacksonllee%2Fnskipgrams/lists"}