Sort by Word MatchΒΆ

Example

>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.descriptors import InitializeThesaurus, SortByWordMatch
>>> # Redirecting stderr to avoid messages
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Create the thesaurus
>>> InitializeThesaurus(root_directory="examples/fintech/", quiet=True).run()
>>> # Configure and run the sorter
>>> sorter = (
...     SortByWordMatch(use_colorama=False)
...     .having_pattern("CREDIT")
...     .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/descriptors.the.txt
  Word : CREDIT
  4 matching keys found
  Sorting process completed successfully

Printing thesaurus header
  File : examples/fintech/data/thesaurus/descriptors.the.txt

    ALTERNATIVE_CREDIT_SCORES
      ALTERNATIVE_CREDIT_SCORES
    CREDIT_ACCESS
      CREDIT_ACCESS
    LOWER_PRICED_CREDIT
      LOWER_PRICED_CREDIT
    OTHER_CREDIT_COOPERATIVES
      OTHER_CREDIT_COOPERATIVES
    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