Sort by Key Order¶
Example
>>> # TEST PREPARATION
>>> import sys
>>> from io import StringIO
>>> from techminer2.thesaurus.organizations import CreateThesaurus, SortByKeyOrder
>>> # Redirecting stderr to avoid messages
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # Create thesaurus
>>> CreateThesaurus(root_directory="example/", quiet=True).run()
>>> # Create and run the sorter
>>> sorter = (
... SortByKeyOrder()
... #
... # THESAURUS:
... .having_keys_ordered_by("alphabetical")
... #
... # DATABASE:
... .where_root_directory_is("example/")
... )
>>> sorter.run()
>>> # Capture and print stderr output
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus alphabetically
File : example/thesaurus/organizations.the.txt
Thesaurus sorting completed successfully
Printing thesaurus header
File : example/thesaurus/organizations.the.txt
Anhui Univ of Finan and Econ (CHN)
School of Finance, Anhui University of Finance and Economics, Bengbu, 233...
Baekseok Univ (KOR)
Division of Tourism, Baekseok University, South Korea
Baewha Women’s Univ (KOR)
Department of Information Security, Baewha Women’s University, Seoul, Sou...
Baylor Univ (USA)
Baylor University, United States; Hankamer School of Business, Baylor Uni...
Beihang Univ (CHN)
School of Economics and Management, Beihang University, China
Brussels, Belgium (BEL)
Brussels, Belgium
CESifo, Poschingerstr. 5, Munich, 81679, Germany (DEU)
CESifo, Poschingerstr. 5, Munich, 81679, Germany
Cent for Law, Markets & Regulation, UNSW Australia, Australia (AUS)
Centre for Law, Markets & Regulation, UNSW Australia, Australia
>>> # Capture and print stderr output
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # with_keys_order_by: "alphabetical", "key_length", "word_length"
>>> from techminer2.thesaurus.organizations import SortByKeyOrder
>>> (
... SortByKeyOrder()
... #
... # THESAURUS:
... .having_keys_ordered_by("key_length")
... #
... # DATABASE:
... .where_root_directory_is("example/")
... #
... .run()
... )
>>> # Capture and print stderr output
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus by key length
File : example/thesaurus/organizations.the.txt
Thesaurus sorting completed successfully
Printing thesaurus header
File : example/thesaurus/organizations.the.txt
The Res center of information technology & economic and social development of...
The Research center of information technology & economic and social devel...
Cent for Law, Markets & Regulation, UNSW Australia, Australia (AUS)
Centre for Law, Markets & Regulation, UNSW Australia, Australia
Stanford GSB and the Hoover Institution, United States (USA)
Stanford GSB and the Hoover Institution, United States
Johns Hopkins SAIS, Washington, DC, United States (USA)
Johns Hopkins SAIS, Washington, DC, United States
CESifo, Poschingerstr. 5, Munich, 81679, Germany (DEU)
CESifo, Poschingerstr. 5, Munich, 81679, Germany
Univ of the Free State and Univ of Ghana Bus Sch (GHA)
University of the Free State and University of Ghana Business School, Uni...
Hochschule für Wirtschaft Fribourg, Switzerland (CHE)
Hochschule für Wirtschaft Fribourg, Switzerland
Max Planck Inst for Innovation and Competition (DEU)
Max Planck Institute for Innovation and Competition, Marstallplatz 1, Mun...
>>> # TEST PREPARATION
>>> original_stderr = sys.stderr
>>> sys.stderr = StringIO()
>>> # with_keys_order_by: "alphabetical", "key_length", "word_length"
>>> from techminer2.thesaurus.organizations import SortByKeyOrder
>>> (
... SortByKeyOrder()
... #
... # THESAURUS:
... .having_keys_ordered_by("word_length")
... #
... # DATABASE:
... .where_root_directory_is("example/")
... #
... .run()
... )
>>> # Capture and print stderr output
>>> output = sys.stderr.getvalue()
>>> sys.stderr = original_stderr
>>> print(output)
Sorting thesaurus by word length
File : example/thesaurus/organizations.the.txt
Thesaurus sorting completed successfully
Printing thesaurus header
File : example/thesaurus/organizations.the.txt
Transport and Telecomunication Inst (LVA)
Transport and Telecomunication Institute, Latvia
Fraunhofer-Inst for Soft and Syst Eng ISST (DEU)
Fraunhofer-Institute for Software and Systems Engineering ISST, Dortmund,...
CESifo, Poschingerstr. 5, Munich, 81679, Germany (DEU)
CESifo, Poschingerstr. 5, Munich, 81679, Germany
Univ Koblenz-Landau (DEU)
Institute for Software Technology IST, Universität Koblenz-Landau, Koblen...
Fed Reserv Bank of Philadelphia (USA)
Federal Reserve Bank of Philadelphia, Philadelphia, PA, United States; Fe...
Pennsylvania State Univ (USA)
Department of Supply Chain and Information Systems, Smeal College of Busi...
Stanford GSB and the Hoover Institution, United States (USA)
Stanford GSB and the Hoover Institution, United States
Sungkyunkwan Univ (KOR)
Software College, Sungkyunkwan University, Suwon, South Korea; Sungkyunkw...