Package: wordlink
wordlinkA 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__.pyfile is located in the/wordlink/directory.PrerequisitesPython 3.xargparselibraryfuzzysearchlibraryprettytablelibraryInstallationClone the repository or download the script file.Install the required libraries by running the following command:pipinstallwordlinkSeeINSTALLfor instructions to clone from GitHub.UsageRun the script using the following command:python3wordlink<search_term><search_directory>[-oOUTPUT_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:python3wordlinkexample.Search for the term "example" in the directory "documents" and save the results as an HTML file named "output.html":python3wordlinkexampledocuments-ooutput.htmlSee the/examples/readme.mdfor instructions on running a demo of the wordlink module.OutputThe 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.TestsThe tool includes a test suite to ensure its functionality. Themain_test.pyfile contains the unit tests. Here's a description of what each test case inmain_test.pyis 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:python3main_test.pyLimitationsThe 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 themax_l_distparameter in thefind_near_matchesfunction call within thefind_word_locationsmethod.LicenseThis code is provided under theMIT License. Feel free to modify and use it according to your needs.