{"id":18490386,"url":"https://github.com/axsaucedo/wcpy","last_synced_at":"2025-05-13T23:35:47.270Z","repository":{"id":62588363,"uuid":"95299201","full_name":"axsaucedo/wcpy","owner":"axsaucedo","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-25T18:52:05.000Z","size":58254,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T17:17:07.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/axsaucedo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-24T13:28:04.000Z","updated_at":"2017-06-24T13:33:18.000Z","dependencies_parsed_at":"2022-11-03T17:48:12.335Z","dependency_job_id":null,"html_url":"https://github.com/axsaucedo/wcpy","commit_stats":null,"previous_names":["axsauze/wcpy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axsaucedo%2Fwcpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axsaucedo%2Fwcpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axsaucedo%2Fwcpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axsaucedo%2Fwcpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axsaucedo","download_url":"https://codeload.github.com/axsaucedo/wcpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043218,"owners_count":22004912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-06T12:59:32.234Z","updated_at":"2025-05-13T23:35:47.248Z","avatar_url":"https://github.com/axsaucedo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# WordCount Python - [ wc.py ]\n\nUtility tool to count the occurrences of words in text using an NLP tokenizer.\n\n## Overview\n\nThis repository contains the CLI and SDK for the WordCount Python [ wc.py ].\n\n`wc.py` provides a set of tools to analyse the number of occurences of words across a single or multiple documents. It can be accessed through the CLI, or directly through the SDK provided by the `WCExtractor` and the `WCCore` classes in the `wcpy` module.\n\nFor the **CLI interface quickstart** please refer to the **User Guide below**.\n\nFor the **SDK interface quickstart** please refer to the **SDK Interface below**.\n\nFor more advanced documnetation please refer to the official [WCPY documentation](https://axsauze.github.io/wcpy/).\n\n### WCPY Interface\n\nThe word count python interface also has an external interface that can be used to interact with.\n\n![Image of wcpy API](https://github.com/axsauze/wcpy-api/blob/master/assets/wcpy-api.jpg)\n\nThis interface can be found at [https://github.com/axsauze/wcpy-api](https://github.com/axsauze/wcpy-api)\n\n# Installation\n\nYou can install it from pip by running:\n\n```\npip install wc.py\n```\n\nThis will install the script in your computer so you'll be able to call it directly with `wc.py`.\n\n# CLI User Guide\n\n## Usage\n\nAfter installing it you can view the usage and options with `wc.py -h`:\n\n```\nusage: wc.py [-h] [-v] [--limit LIMIT] [--reverse]\n             [--filter-words FILTER_WORDS [FILTER_WORDS ...]]\n             [--file-ext FILE_EXT] [--truncate TRUNCATE]\n             [--columns COLUMNS [COLUMNS ...]] [--output-file OUTPUT_FILE]\n             paths [paths ...]\n\nCount the number of words in the files on a folder\n\npositional arguments:\n  paths                 (REQUIRED) Path(s) to folders and/or files to count words from\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -v, --version         show program's version number and exit\n  --limit LIMIT         (Optional) Limit the number of results that you would like to display.\n  --reverse             (Optional) List is sorted in ascending order by default, use this flag to reverse sorting to descending order.\n  --filter-words FILTER_WORDS [FILTER_WORDS ...]\n                        (Optional) You can get results filtered to only the list of words provided.\n  --file-ext FILE_EXT   (Optional) This is the default file extention for the files being used\n  --truncate TRUNCATE   (Optional) Output is often quite large, you can truncate the output by passing a number greater than 5\n  --columns COLUMNS [COLUMNS ...]\n                        (Optional) This argument allows you to choose the columns to be displayed in the output. Options are: word, count, files and sentences.\n  --output-file OUTPUT_FILE\n                        (Optional) Define an output file to save the output\n\nEXAMPLE USAGE:\n                wc.py ./\n                wc.py ./ --limit 10\n                wc.py doc1.txt doc2.txt --filter-words tool awesome an\n                wc.py docs/ tests/ --truncate 100 --columns word count\n                wc.py ./ --filter-words tool awesome an --truncate 50 --output output.txt\n```\n\n## Examples\n\n#### Counts of word occurences in documents in this folder recusively\n\n```\nwc.py ./\n```\n\n#### Word occurrences in this folder docs with limit of the top 10\n\n```\nwc.py ./ --limit 10\n```\n\n#### Word occurences in multiple files showing only specific words\n\n```\nwc.py doc2.txt doc1.txt --filter-words tool awesome an\n```\n\n#### Word occurences in folder with output truncated and only 2 columns\n\n```\nwc.py tests/test_data/ --truncate 20 --columns word count\n```\n\n#### Saving output to file\n\n```\nwc.py ./ --filter-words tool awesome an --truncate 50 --output output.txt\n```\n\n#### Get the current version\n\n```\nwc.py -v\n```\n\n# SDK Interface\n\nIt is possible to interact with the SDK in multiple levels, the two most common usecases will be:\n\n* WCCore class - Interact with filepaths\n* WCExtractor class - Interact with files and text\n\n## WCCore class\n\n### generate_wc_dict(self, paths)\n\nThis function finds all the files in a given set of paths, and builds a dictionary with the following structure:\n\n\n### generate_wc_list(self, paths)\n\nThis function finds all the files in a given set of paths, and builds a sorted list (by word count) of the following structure\n\n\n## WCExtractor class\n\n### extract_wc_from_file\n\nThis function extracts all the text from a file and builds a wc_dict object\n\n### extract_wc_from_line\n\nThis function extracts all the words from a line and adds it to a wc_dict object\n\n## WCExtractorProcessor class\n\nThis class does all the processing to convert a WC Dict into a sorted WCList object.\n\n### process_dict_wc_to_list\n\nAs function name suggest, this function converts a WCDict object into a sorted WCList object.\n\n## Core WC Types\n\n### WCDict\n\n```\n{\n    \u003cWORD_1:: STR\u003e: {\n        word_count: \u003cWORD_COUNT:: INT\u003e,\n        files: {\n            \u003cFILE_PATH:: STR\u003e: [\n                \u003cLINE_1:: STR\u003e,\n                \u003cLINE_2:: STR\u003e,\n                …\n            ]\n        },\n        {\n            …\n        }\n    },\n    \u003cWORD_2:: STR\u003e: ...\n}\n```\n\n### WCList\n\n```\n[\n    {\n        \"word\": \u003cWORD_1:: STR\u003e,\n\n        word_count: \u003cWORD_COUNT:: INT\u003e,\n        files: {\n            \u003cFILE_PATH:: STR\u003e: [\n                \u003cLINE_1:: STR\u003e,\n                \u003cLINE_2:: STR\u003e,\n                …\n            ]\n        }\n    },\n    {\n        \"word\": \u003cWORD_2:: STR\u003e,\n        ...\n\n    }\n]\n```\n\n# Contributing\n\nIf you'd like to contribute, feel free to submit a pull request, open bugs/issues and join the discussion.\n\n## Install VirtualEnv and Requirements\n\nPython 3.X is used, and it's strongly recommended to set up the project in a virtual environment:\n\n```\nvirtualenv --no-site-packages -p python3 venv\n```\n\nThen install it using the setup.py command\n\n```\npython setup.py install_data\n```\n\nYou can also install the requirements directly by running\n\n```\npython -r requirements.txt\n```\n\n## NLTK\n\nThis package uses the NLTK `english.pickle` dataset. The dataset includes in both, the repository and the PyPi package, however if you want to donwload more of the languages you can do so with the following command:\n\n```\npython -c \"import nltk; nltk.download('punkt')\"\n```\n\n## Testing\n\n`py.test` is used to run the tests, in order to run it simply run:\n\n```\npython setup.py test\n```\n\n## Cleaning\n\nTo clean all the files generated during runtime simply run:\n\n```\npython setup.py clean\n```\n\n# Roadmap\n\n* Support multiple types of documents\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxsaucedo%2Fwcpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxsaucedo%2Fwcpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxsaucedo%2Fwcpy/lists"}