Sort by Word Match¶
Example
>>> # TEST PREPARATION
>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.organizations import InitializeThesaurus, SortByWordMatch
>>> # Redirecting stderr to avoid messages
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Create thesaurus
>>> InitializeThesaurus(root_directory="examples/fintech/", quiet=True).run()
>>> # Create and run the sorter
>>> sorter = (
... SortByWordMatch(use_colorama=False)
... #
... # THESAURUS:
... .having_pattern("Bank")
... #
... # DATABASE:
... .where_root_directory_is("examples/fintech/")
... )
>>> sorter.run()
>>> # Capture and print stderr output
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus by word match...
File : examples/fintech/data/thesaurus/organizations.the.txt
Word : Bank
2 matching keys found
Sorting process completed successfully
Printing thesaurus header
File : examples/fintech/data/thesaurus/organizations.the.txt
Fed Reserv Bank of Chicago (USA)
Federal Reserve Bank of Chicago, Chicago, IL, United States; Federal Rese...
Fed Reserv Bank of Philadelphia (USA)
Federal Reserve Bank of Philadelphia, Philadelphia, PA, United States; Fe...
[UKN] Brussels, Belgium (BEL)
Brussels, Belgium
[UKN] CESifo, Poschingerstr. 5, Munich, 81679, Germany (DEU)
CESifo, Poschingerstr. 5, Munich, 81679, Germany
[UKN] FinTech HK, Hong Kong (HKG)
FinTech HK, Hong Kong
[UKN] Hochschule für Wirtschaft Fribourg, Switzerland (CHE)
Hochschule für Wirtschaft Fribourg, Switzerland
[UKN] Information Technol, Univeril, Germany (DEU)
Information Technology, Univeril, Germany
[UKN] Johns Hopkins SAIS, Washington, DC, United States (USA)
Johns Hopkins SAIS, Washington, DC, United States