wordlink
A Word Link Generator that searches for a given term in multiple text files within a specified directory and generates links to the matched occurrences. It provides two output options: an HTML file with clickable links or a console display using a formatted table.
The __main__.py file is located in the /wordlink/ directory.
Prerequisites
- Python 3.x
argparselibraryfuzzysearchlibraryprettytablelibrary
Installation
-
Clone the repository or download the script file.
-
Install the required libraries by running the following command:
pip install wordlink
See INSTALL for instructions to clone from GitHub.
Usage
Run the script using the following command:
python3 wordlink <search_term> <search_directory> [-o OUTPUT_FILE]
<search_term>: The term to search for within the text files.<search_directory>: The directory to search for text files.-o OUTPUT_FILEor--output_file OUTPUT_FILE: (Optional) Specify the output file name to save the results as an HTML file. If not provided, the results will be displayed in the console using a formatted table.
Examples:
Search for the term "example" in the current directory and display the results in the console:
python3 wordlink example .
Search for the term "example" in the directory "documents" and save the results as an HTML file named "output.html":
python3 wordlink example documents -o output.html
See the /examples/readme.md for instructions on running a demo of the wordlink module.
Output
The tool generates two types of output depending on the presence of the output file option:
-
HTML Output File: If an output file is specified using the
-oor--output_fileoption, the tool generates an HTML file with clickable links. Each link represents a matched occurrence in a specific file and line. The output file contains a table with columns for the file name, line number, and corresponding text. -
Console Display: If no output file is provided, the tool displays the results in the console using a formatted table. The console output includes columns for the file name, line number, and corresponding text.
Tests
The tool includes a test suite to ensure its functionality. The main_test.py file contains the unit tests. Here's a description of what each test case in main_test.py is testing:
test_find_word_locations: This test verifies that thefind_word_locationsmethod correctly identifies the locations of the given search term within a test file.test_generate_links_output_file: This test checks if thegenerate_linksmethod generates the expected output file in HTML format when an output file name is provided.test_generate_links_console: This test validates that thegenerate_linksmethod produces the expected console output when no output file name is provided.
To run the tests, navigate to the /tests/ directory and execute the following command:
python3 main_test.py
Limitations
- The tool searches for the specified term within all text files (
.txt) in the given directory and its subdirectories. It does not support searching within other file formats. - The maximum Levenshtein distance for finding near matches is set to 1. This can be adjusted by modifying the
max_l_distparameter in thefind_near_matchesfunction call within thefind_word_locationsmethod.
License
This code is provided under the MIT License. Feel free to modify and use it according to your needs.
Release files for wordlink 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wordlink-1.0.7.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wordlink-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.3 kB
Release files / wordlink-1.0.7.tar.gz
| Download URL | wordlink-1.0.7.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
520dc613e86895ca135c2a9a8037e856ad40218c4fade5d6d6669a8127edf439
|
|
BLAKE2b-256 checksum How to use checksums |
e5d95f5e77062eb3b12d44383c20d2c365bc73470b82a62ad34a948b99d78aae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / wordlink-1.0.7-py3-none-any.whl
| Download URL | wordlink-1.0.7-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7fcc0d39c3e0604b3edce5a70c236d01d83a396a296c6c235baf439bd45e5f71
|
|
BLAKE2b-256 checksum How to use checksums |
80a223d81ce4833ac1c6795fa81e7fc4606d4a843e7780aa77ebfe9c2fa95a2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|