From d9888b5ca497b87df6b61baf4bea22d28f8ee649 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 9 Nov 2022 19:01:24 -0400 Subject: [PATCH 1/4] WS-2589: removing genre from doc & future print_function --- examples/address_similarity.py | 3 +-- examples/categories.py | 3 +-- examples/entities.py | 5 ++--- examples/info.py | 3 +-- examples/language.py | 3 +-- examples/language_multilingual.py | 3 +-- examples/morphology_complete.py | 3 +-- examples/morphology_compound-components.py | 3 +-- examples/morphology_han-readings.py | 3 +-- examples/morphology_lemmas.py | 3 +-- examples/morphology_parts-of-speech.py | 3 +-- examples/name_deduplication.py | 3 +-- examples/name_similarity.py | 1 - examples/name_translation.py | 3 +-- examples/ping.py | 3 +-- examples/relationships.py | 3 +-- examples/semantic_vectors.py | 4 +--- examples/sentences.py | 3 +-- examples/sentiment.py | 4 +--- examples/similar_terms.py | 4 +--- examples/syntax_dependencies.py | 4 +--- examples/tokens.py | 3 +-- examples/topics.py | 3 +-- examples/transliteration.py | 4 +--- 24 files changed, 24 insertions(+), 53 deletions(-) diff --git a/examples/address_similarity.py b/examples/address_similarity.py index 9ffe3a6..a245636 100644 --- a/examples/address_similarity.py +++ b/examples/address_similarity.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get match score (similarity) of two addresses. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/categories.py b/examples/categories.py index 774488a..b032488 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -3,7 +3,6 @@ """ Example code to call Rosette API to get the category of a document (at a given URL). """ -from __future__ import print_function import argparse import json @@ -48,4 +47,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/entities.py b/examples/entities.py index e8191e2..e6e2a50 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get entities from a piece of text. """ -from __future__ import print_function import argparse import json @@ -27,7 +26,7 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country." params = DocumentParameters() params["content"] = entities_text_data - params["genre"] = "social-media" + try: return api.entities(params) except RosetteException as exception: @@ -43,4 +42,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/info.py b/examples/info.py index ab7159f..9684088 100644 --- a/examples/info.py +++ b/examples/info.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get information such as version and build """ -from __future__ import print_function import argparse import json @@ -32,4 +31,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/language.py b/examples/language.py index c8d82d0..fbfc936 100644 --- a/examples/language.py +++ b/examples/language.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to determine the language of a piece of text. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/language_multilingual.py b/examples/language_multilingual.py index 84f5933..c442b76 100644 --- a/examples/language_multilingual.py +++ b/examples/language_multilingual.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to determine the language of a piece of text. """ -from __future__ import print_function import argparse import json @@ -38,4 +37,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index b1781d3..b1c0880 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the complete morphological analysis of a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 3020e60..3332e71 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get de-compounded words from a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index bc1c9ea..b140969 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get Chinese readings of words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -41,4 +40,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index ae6fe57..20921cb 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get lemmas for words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 011b37a..48e3a07 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get part-of-speech tags for words in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/name_deduplication.py b/examples/name_deduplication.py index 0392898..3c56fa9 100644 --- a/examples/name_deduplication.py +++ b/examples/name_deduplication.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to deduplicate a list of names. """ -from __future__ import print_function import argparse import json @@ -37,4 +36,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 0020fae..9f5cd79 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get match score (similarity) of two names. """ -from __future__ import print_function import argparse import json diff --git a/examples/name_translation.py b/examples/name_translation.py index 7f7372d..fd9a753 100644 --- a/examples/name_translation.py +++ b/examples/name_translation.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to translate a name from one language to another. """ -from __future__ import print_function import argparse import json @@ -38,4 +37,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/ping.py b/examples/ping.py index 75aa02b..89d0925 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -2,7 +2,6 @@ """ Example code to send Rosette API a ping to check its reachability. """ -from __future__ import print_function import argparse import json @@ -32,4 +31,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/relationships.py b/examples/relationships.py index c59861d..a04651c 100644 --- a/examples/relationships.py +++ b/examples/relationships.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get entities's relationships from a piece of text. """ -from __future__ import print_function import argparse import json @@ -34,4 +33,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/semantic_vectors.py b/examples/semantic_vectors.py index 066d920..c67e326 100644 --- a/examples/semantic_vectors.py +++ b/examples/semantic_vectors.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get text vectors from a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,5 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/sentences.py b/examples/sentences.py index 44ea8eb..747db2e 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get sentences in a piece of text. """ -from __future__ import print_function import argparse import json @@ -36,4 +35,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/sentiment.py b/examples/sentiment.py index 0b6da36..dd5b52e 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -3,7 +3,6 @@ """ Example code to call Rosette API to get the sentiment of a local file. """ -from __future__ import print_function import argparse import json @@ -57,5 +56,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/similar_terms.py b/examples/similar_terms.py index 9695aa7..88f2940 100644 --- a/examples/similar_terms.py +++ b/examples/similar_terms.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get similar terms for an input. """ -from __future__ import print_function import argparse import json @@ -42,5 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/syntax_dependencies.py b/examples/syntax_dependencies.py index 1790729..38a86b0 100644 --- a/examples/syntax_dependencies.py +++ b/examples/syntax_dependencies.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the syntactic dependencies of a document (at a given URL). """ -from __future__ import print_function import argparse import json @@ -34,5 +33,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/tokens.py b/examples/tokens.py index a1fedd3..a7f47a6 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the tokens (words) in a piece of text. """ -from __future__ import print_function import argparse import json @@ -42,4 +41,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/topics.py b/examples/topics.py index 25d768a..55fa627 100644 --- a/examples/topics.py +++ b/examples/topics.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to get the topics (key phrases and concepts) in a piece of text. """ -from __future__ import print_function import argparse import json @@ -43,4 +42,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) diff --git a/examples/transliteration.py b/examples/transliteration.py index 9fdab66..be9aa82 100644 --- a/examples/transliteration.py +++ b/examples/transliteration.py @@ -2,7 +2,6 @@ """ Example code to call Rosette API to transliterate a piece of text. """ -from __future__ import print_function import argparse import json @@ -44,5 +43,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, - sort_keys=True).encode("utf8")) + print(RESULT) From 6f680a84d0097af1a75de95db66f497b203f1d94 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 15 Nov 2022 12:35:37 -0400 Subject: [PATCH 2/4] WS-2589: fix print for name_similarity.py --- examples/name_similarity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/name_similarity.py b/examples/name_similarity.py index 9f5cd79..1e81ba8 100644 --- a/examples/name_similarity.py +++ b/examples/name_similarity.py @@ -36,4 +36,4 @@ def run(key, alt_url='https://api.rosette.com/rest/v1/'): if __name__ == '__main__': ARGS = PARSER.parse_args() RESULT = run(ARGS.key, ARGS.url) - print(json.dumps(RESULT, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8")) + print(RESULT) From 1c7f34cc893350b7952e0429e49783e26f96978a Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Tue, 15 Nov 2022 18:01:54 -0400 Subject: [PATCH 3/4] WS-2589: removing the genre field --- rosette/api.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rosette/api.py b/rosette/api.py index a85a49f..88bf653 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -153,7 +153,7 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "genre", "profileId")) + self, ("content", "contentUri", "language", "profileId")) self.file_name = "" self.use_multipart = False @@ -236,8 +236,7 @@ def __init__(self): "sourceLanguageOfUse", "sourceScript", "targetScript", - "targetScheme", - "genre")) + "targetScheme")) def validate(self): """Internal. Do not use.""" From 91b2e2b418981369b375fd396057531abe7e9449 Mon Sep 17 00:00:00 2001 From: Yaison <> Date: Wed, 16 Nov 2022 22:10:39 -0400 Subject: [PATCH 4/4] WS-2589: log warning if genre is present --- rosette/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rosette/api.py b/rosette/api.py index 88bf653..e729624 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -153,12 +153,14 @@ class DocumentParameters(_DocumentParamSetBase): def __init__(self): """Create a L{DocumentParameters} object.""" _DocumentParamSetBase.__init__( - self, ("content", "contentUri", "language", "profileId")) + self, ("content", "contentUri", "genre", "language", "profileId")) self.file_name = "" self.use_multipart = False def validate(self): """Internal. Do not use.""" + if self["genre"] is not None: + warnings.warn("genre is deprecated and will be removed in the next release.") if self["content"] is None: if self["contentUri"] is None: raise RosetteException(