Sort by Word MatchΒΆ

Example

>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.descriptors import CreateThesaurus, SortByWordMatch
>>> # Redirecting stderr to avoid messages
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Create the thesaurus
>>> CreateThesaurus(root_directory="example/", quiet=True).run()
>>> # Configure and run the sorter
>>> sorter = (
...     SortByWordMatch()
...     .having_pattern("CREDIT")
...     .where_root_directory_is("example/")
... )
>>> sorter.run()
>>> # Capture and print stderr output
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus file by word match
  File : example/thesaurus/descriptors.the.txt
  Word : CREDIT
  4 matching keys found
  Thesaurus sorting by word match completed successfully

Printing thesaurus header
  File : example/thesaurus/descriptors.the.txt

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