Sort By MatchΒΆ
Example
>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.user import InitializeThesaurus, SortByMatch
>>> # Redirecting stderr to avoid messages during doctests
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Reset the thesaurus to initial state
>>> InitializeThesaurus(thesaurus_file="demo.the.txt", field="raw_descriptors",
... root_directory="examples/fintech/", quiet=True).run()
>>> # Creates, configures, an run the sorter
>>> sorter = (
... SortByMatch(use_colorama=False)
... .with_thesaurus_file("demo.the.txt")
... .having_pattern("BUSINESS")
... .having_case_sensitive(False)
... .having_regex_flags(0)
... .having_regex_search(False)
... .where_root_directory_is("examples/fintech/")
... )
>>> sorter.run()
>>> # Capture and print stderr output to test the code using doctest
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus by match...
File : examples/fintech/data/thesaurus/demo.the.txt
Pattern : BUSINESS
Case sensitive : False
Regex Flags : 0
Regex Search : False
21 matching keys found
Sorting process completed successfully
Printing thesaurus header
File : examples/fintech/data/thesaurus/demo.the.txt
AGRIBUSINESS
AGRIBUSINESS
BUSINESS
BUSINESS; BUSINESSES
BUSINESS_DEVELOPMENT
BUSINESS_DEVELOPMENT
BUSINESS_GERMANY
BUSINESS_GERMANY
BUSINESS_INFRASTRUCTURE
BUSINESS_INFRASTRUCTURE; BUSINESS_INFRASTRUCTURES
BUSINESS_MODEL
BUSINESS_MODEL; BUSINESS_MODELS
BUSINESS_OPPORTUNITIES
BUSINESS_OPPORTUNITIES
BUSINESS_PROCESS
BUSINESS_PROCESS