Sort by Starts With Key MatchΒΆ

Example

>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.descriptors import CreateThesaurus, SortByStartsWithKeyMatch
>>> # 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 = (
...     SortByStartsWithKeyMatch()
...     .having_pattern("COMM")
...     .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 key match
     File : example/thesaurus/descriptors.the.txt
  Pattern : COMM
  2 matching keys found
  Thesaurus sorting by key match completed successfully

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

    COMMERCE
      COMMERCE
    COMMERCIAL_BANKS
      COMMERCIAL_BANKS
    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