Sort By MatchΒΆ

Example

>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.descriptors import InitializeThesaurus, SortByMatch
>>> # 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 = (
...     SortByMatch(use_colorama=False)
...     .having_pattern("BLOCK")
...     .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
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output) 
Sorting thesaurus by match...
            File : examples/fintech/data/thesaurus/descriptors.the.txt
         Pattern : BLOCK
  Case sensitive : False
     Regex Flags : 0
    Regex Search : False
  3 matching keys found
  Sorting process completed successfully

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

    A_BLOCKCHAIN_IMPLEMENTATION_STUDY
      A_BLOCKCHAIN_IMPLEMENTATION_STUDY
    BLOCKCHAIN
      BLOCKCHAIN
    BLOCKCHAIN_IMPLEMENTATION
      BLOCKCHAIN_IMPLEMENTATION
    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_CASE_STUDY
      A_CASE_STUDY