Replace Ends With WordΒΆ
Example
>>> # TEST PREPARATION
>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.user import CreateThesaurus, ReplaceEndsWithWord
>>> # Redirecting stderr to avoid messages during doctests
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Reset the thesaurus to initial state
>>> CreateThesaurus(thesaurus_file="demo.the.txt", field="raw_descriptors",
... root_directory="example/", quiet=True).run()
>>> # Creates, configures, and run the replacer
>>> replacer = (
... ReplaceEndsWithWord()
... .with_thesaurus_file("demo.the.txt")
... .having_word("BUSINESS")
... .having_replacement("business")
... .where_root_directory_is("example/")
... )
>>> replacer.run()
>>> # Capture and print stderr output to test the code using doctest
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Replacing ending word in keys
File : example/thesaurus/demo.the.txt
Word : BUSINESS
Replacement : business
2 replacements made successfully
Word replacing completed successfully
Printing thesaurus header
File : example/thesaurus/demo.the.txt
business
BUSINESS; BUSINESSES
THE_BANKING_business
THE_BANKING_BUSINESS
A_A_)_THEORY
A_A_)_THEORY
A_A_THEORY
A_A_THEORY
A_BASIC_RANDOM_SAMPLING_STRATEGY
A_BASIC_RANDOM_SAMPLING_STRATEGY
A_BEHAVIOURAL_PERSPECTIVE
A_BEHAVIOURAL_PERSPECTIVE
A_BETTER_UNDERSTANDING
A_BETTER_UNDERSTANDING
A_BLOCKCHAIN_IMPLEMENTATION_STUDY
A_BLOCKCHAIN_IMPLEMENTATION_STUDY