Sort by Word MatchΒΆ

Example

>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.countries import CreateThesaurus, SortByWordMatch
>>> # Redirect stderr to capture output
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Create the thesaurus
>>> CreateThesaurus(root_directory="example/", quiet=True).run()
>>> # Sort the thesaurus by word match
>>> sorter = (
...     SortByWordMatch()
...     .having_pattern("Germany")
...     .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/countries.the.txt
  Word : Germany
  1 matching keys found
  Thesaurus sorting by word match completed successfully

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

    Germany
      CESifo, Poschingerstr. 5, Munich, 81679, Germany; Chair of e-Finance, Goe...
    Australia
      Centre for Law, Markets & Regulation, UNSW Australia, Australia; Charles ...
    Belgium
      Brussels, Belgium
    Brunei Darussalam
      Universiti Brunei Darussalam, School of Business and Economics, Jln Tungk...
    China
      Cheung Kong Graduate School of Business, and Institute of Internet Financ...
    Denmark
      Copenhagen Business School, Department of IT Management, Howitzvej 60, Fr...
    France
      SKEMA Business School, Lille, France; University of Lille Nord de France,...
    Ghana
      University of the Free State and University of Ghana Business School, Uni...