Sort by Word MatchΒΆ

Example

>>> # TEST PREPARATION
>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.user import CreateThesaurus, SortByWordMatch
>>> # Redirecting stderr to avoid messages during doctests
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Reset the thesaurus to initial state
>>> CreateThesaurus(thesaurus_file="demo.the.txt", field="raw_descriptors",
...     root_directory="example/", quiet=True).run()
>>> # Creates, configures, an run the sorter
>>> sorter = (
...     SortByWordMatch()
...     .with_thesaurus_file("demo.the.txt")
...     .having_pattern("BUSINESS")
...     .where_root_directory_is("example/")
... )
>>> sorter.run()
>>> # Capture and print stderr output to test the code using doctest
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus file by word match
  File : example/thesaurus/demo.the.txt
  Word : BUSINESS
  19 matching keys found
  Thesaurus sorting by word match completed successfully

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

    BUSINESS
      BUSINESS; BUSINESSES
    BUSINESS_DEVELOPMENT
      BUSINESS_DEVELOPMENT
    BUSINESS_GERMANY
      BUSINESS_GERMANY
    BUSINESS_INFRASTRUCTURE
      BUSINESS_INFRASTRUCTURE; BUSINESS_INFRASTRUCTURES
    BUSINESS_MODEL
      BUSINESS_MODEL; BUSINESS_MODELS
    BUSINESS_OPPORTUNITIES
      BUSINESS_OPPORTUNITIES
    BUSINESS_PROCESS
      BUSINESS_PROCESS
    FUNDAMENTALLY_NEW_BUSINESS_OPPORTUNITIES
      FUNDAMENTALLY_NEW_BUSINESS_OPPORTUNITIES