Word Link Generator
Project description
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
argparse
libraryfuzzysearch
libraryprettytable
library
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_FILE
or--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
-o
or--output_file
option, 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_locations
method correctly identifies the locations of the given search term within a test file.test_generate_links_output_file
: This test checks if thegenerate_links
method generates the expected output file in HTML format when an output file name is provided.test_generate_links_console
: This test validates that thegenerate_links
method 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_dist
parameter in thefind_near_matches
function call within thefind_word_locations
method.
License
This code is provided under the MIT License. Feel free to modify and use it according to your needs.
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
Built Distribution
File details
Details for the file wordlink-1.0.7.tar.gz
.
File metadata
- Download URL: wordlink-1.0.7.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 520dc613e86895ca135c2a9a8037e856ad40218c4fade5d6d6669a8127edf439 |
|
MD5 | f29b618b7bac02c824df3f6f159ab91e |
|
BLAKE2b-256 | e5d95f5e77062eb3b12d44383c20d2c365bc73470b82a62ad34a948b99d78aae |
File details
Details for the file wordlink-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: wordlink-1.0.7-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fcc0d39c3e0604b3edce5a70c236d01d83a396a296c6c235baf439bd45e5f71 |
|
MD5 | 23652e39d185c21ff65fdecd32575240 |
|
BLAKE2b-256 | 80a223d81ce4833ac1c6795fa81e7fc4606d4a843e7780aa77ebfe9c2fa95a2b |