diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index df3bb3e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: python -install: - - pip install tox -script: - - tox diff --git a/examples/README.md b/examples/README.md index 7bbe06f..4434c10 100644 --- a/examples/README.md +++ b/examples/README.md @@ -31,6 +31,7 @@ Each example, when run, prints its output to the console. | morphology_lemmas.py | Gets the lemmas of words from a piece of text | | morphology_parts-of-speech.py | Gets the part-of-speech tags for words in a piece of text | | ping.py | Pings the Rosette API to check for reachability | +| relationships.py | Gets the relationships between entities from a piece of text | | sentences.py | Gets the sentences from a piece of text | | sentiment.py | Gets the sentiment of a local file | | tokens.py | Gets the tokens (words) from a piece of text | diff --git a/examples/categories.py b/examples/categories.py index 65704a6..e70a07f 100644 --- a/examples/categories.py +++ b/examples/categories.py @@ -4,28 +4,20 @@ Example code to call Rosette API to get the category of a document (at a given URL). """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get the category of a piece of a document at a URL") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -parser.add_argument("--url", nargs="?", default="https://en.wikipedia.org/wiki/Basis_Technology_Corp.", help="Optional URL for data") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + url = "https://en.wikipedia.org/wiki/Basis_Technology_Corp." + # Create an API instance + api = API(user_key=key) + params = DocumentParameters() -params = DocumentParameters() + # Use a URL to input data instead of a string + params["contentUri"] = url + result = api.categories(params) -# Use a URL to input data instead of a string -params["contentUri"] = args.url - -result = api.categories(params) - -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/entities.py b/examples/entities.py index 301c794..d1ab80e 100644 --- a/examples/entities.py +++ b/examples/entities.py @@ -4,24 +4,16 @@ Example code to call Rosette API to get entities from a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get the entities from a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) - -params = DocumentParameters() -params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people." -result = api.entities(params) # entity linking is turned off - -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) +def run(key): + # Create an API instance + api = API(user_key=key) + params = DocumentParameters() + params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people." + result = api.entities(params) # entity linking is turned off + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/entities_linked.py b/examples/entities_linked.py index f242bd6..efbf9a2 100644 --- a/examples/entities_linked.py +++ b/examples/entities_linked.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get linked entities from a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people." -result = api.entities(params, True) # entity linking is turned on + params = DocumentParameters() + params["content"] = u"President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill based on Christian faith by July 1st or Washington will become totally dysfunctional, a terrible outcome for American people." + result = api.entities(params, True) # entity linking is turned on -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/info.py b/examples/info.py index 74780bb..62525d6 100644 --- a/examples/info.py +++ b/examples/info.py @@ -4,22 +4,16 @@ Example code to call Rosette API to get information such as version and build """ -import argparse import json -from rosette.api import API +from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get information about Rosette API") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -result = api.info() + result = api.info() -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/language.py b/examples/language.py index c7afafc..a5fe5e1 100644 --- a/examples/language.py +++ b/examples/language.py @@ -4,25 +4,19 @@ Example code to call Rosette API to determine the language of a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Determine the language of a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() + params = DocumentParameters() -params["content"] = u"Por favor Señorita, says the man." -result = api.language(params) + params["content"] = u"Por favor Señorita, says the man." + result = api.language(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/matched-name.py b/examples/matched-name.py index 687725c..5b7a843 100644 --- a/examples/matched-name.py +++ b/examples/matched-name.py @@ -4,25 +4,19 @@ Example code to call Rosette API to get match score (similarity) of two names. """ -import argparse import json from rosette.api import API, NameMatchingParameters -parser = argparse.ArgumentParser(description="Get the similarity score of two names") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = NameMatchingParameters() -params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"} -params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"} -result = api.matched_name(params) + params = NameMatchingParameters() + params["name1"] = {"text": "Michael Jackson", "language": "eng", "entityType": "PERSON"} + params["name2"] = {"text": "迈克尔·杰克逊", "entityType": "PERSON"} + result = api.matched_name(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/morphology_complete.py b/examples/morphology_complete.py index a53e751..a943966 100644 --- a/examples/morphology_complete.py +++ b/examples/morphology_complete.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get the complete morphological analysis of a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get the complete morphological analysis of a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did." -result = api.morphology(params) + params = DocumentParameters() + params["content"] = u"The quick brown fox jumped over the lazy dog. Yes he did." + result = api.morphology(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/morphology_compound-components.py b/examples/morphology_compound-components.py index 628dbc7..52077de 100644 --- a/examples/morphology_compound-components.py +++ b/examples/morphology_compound-components.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get de-compounded words from a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters, MorphologyOutput -parser = argparse.ArgumentParser(description="Get de-compounded words from a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"Rechtsschutzversicherungsgesellschaften" -result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS) + params = DocumentParameters() + params["content"] = u"Rechtsschutzversicherungsgesellschaften" + result = api.morphology(params, MorphologyOutput.COMPOUND_COMPONENTS) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/morphology_han-readings.py b/examples/morphology_han-readings.py index 0652e70..3676935 100644 --- a/examples/morphology_han-readings.py +++ b/examples/morphology_han-readings.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get Chinese readings of words in a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters, MorphologyOutput -parser = argparse.ArgumentParser(description="Get Chinese readings of words in a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"北京大学生物系主任办公室内部会议" -result = api.morphology(params, MorphologyOutput.HAN_READINGS) + params = DocumentParameters() + params["content"] = u"北京大学生物系主任办公室内部会议" + result = api.morphology(params, MorphologyOutput.HAN_READINGS) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/morphology_lemmas.py b/examples/morphology_lemmas.py index d5763bc..87aafc4 100644 --- a/examples/morphology_lemmas.py +++ b/examples/morphology_lemmas.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get lemmas for words in a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters, MorphologyOutput -parser = argparse.ArgumentParser(description="Get lemmas for words in a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon" -result = api.morphology(params, MorphologyOutput.LEMMAS) + params = DocumentParameters() + params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon" + result = api.morphology(params, MorphologyOutput.LEMMAS) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/morphology_parts-of-speech.py b/examples/morphology_parts-of-speech.py index 671a70c..d95c7f0 100644 --- a/examples/morphology_parts-of-speech.py +++ b/examples/morphology_parts-of-speech.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get part-of-speech tags for words in a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters, MorphologyOutput -parser = argparse.ArgumentParser(description="Get part-of-speech tags for words in text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon" -result = api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH) + params = DocumentParameters() + params["content"] = u"The fact is that the geese just went back to get a rest and I'm not banking on their return soon" + result = api.morphology(params, MorphologyOutput.PARTS_OF_SPEECH) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/ping.py b/examples/ping.py index 2c42642..5592b5c 100644 --- a/examples/ping.py +++ b/examples/ping.py @@ -4,22 +4,16 @@ Example code to send Rosette API a ping to check its reachability. """ -import argparse import json from rosette.api import API -parser = argparse.ArgumentParser(description="Send ping to check for reachability of Rosette API") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -result = api.ping() + result = api.ping() -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/relationships.py b/examples/relationships.py new file mode 100644 index 0000000..6a3e12f --- /dev/null +++ b/examples/relationships.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +""" +Example code to call Rosette API to get entities's relationships from a piece of text. +""" + +import json + +from rosette.api import API, RelationshipsParameters + + +def run(key): + # Create an API instance + api = API(user_key=key) + params = RelationshipsParameters() + params["content"] = u"Yesterday in Guatemala, the Supreme Court approved the attorney general's request to impeach President Otto Pérez Molina." + params["options"] = {"accuracyMode": "PRECISION"} + result = api.relationships(params) + + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/sentences.py b/examples/sentences.py index b9e3088..4c3b841 100644 --- a/examples/sentences.py +++ b/examples/sentences.py @@ -4,25 +4,19 @@ Example code to call Rosette API to get sentences in a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get sentences from a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." + params = DocumentParameters() + params["content"] = u"This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." -result = api.sentences(params) + result = api.sentences(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/sentiment.py b/examples/sentiment.py index 7b006a2..1ed1e56 100644 --- a/examples/sentiment.py +++ b/examples/sentiment.py @@ -4,41 +4,33 @@ Example code to call Rosette API to get the sentiment of a local file. """ -import argparse import json import tempfile import os from rosette.api import API, DocumentParameters -# Create default file to read from -# f = tempfile.NamedTemporaryFile(suffix=".html") -f = open("testhtml.html", 'w') -message = "
This article is clean, concise, and very easy to read.
" -f.write(message) -f.seek(0) - -# Collect arguments -parser = argparse.ArgumentParser(description="Get the sentiment of the text in a local file") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -parser.add_argument("--file", nargs="?", default=f.name, help="Optional input file for data") -args = parser.parse_args() - -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) - -params = DocumentParameters() - -# Use an HTML file to load data instead of a string -params.load_document_file(args.file) -result = api.sentiment(params) - -# Clean up the file -f.close() -os.remove("testhtml.html") - -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + +def run(key): + # Create default file to read from + # f = tempfile.NamedTemporaryFile(suffix=".html") + f = open("testhtml.html", 'w') + message = "This article is clean, concise, and very easy to read.
" + f.write(message) + f.seek(0) + + # Create an API instance + api = API(user_key=key) + + params = DocumentParameters() + + # Use an HTML file to load data instead of a string + params.load_document_file(f.name) + result = api.sentiment(params) + + # Clean up the file + f.close() + os.remove("testhtml.html") + + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/tokens.py b/examples/tokens.py index fad71c5..244fb08 100644 --- a/examples/tokens.py +++ b/examples/tokens.py @@ -4,24 +4,18 @@ Example code to call Rosette API to get the tokens (words) in a piece of text. """ -import argparse import json from rosette.api import API, DocumentParameters -parser = argparse.ArgumentParser(description="Get the words in a piece of text") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = DocumentParameters() -params["content"] = u"北京大学生物系主任办公室内部会议" -result = api.tokens(params) + params = DocumentParameters() + params["content"] = u"北京大学生物系主任办公室内部会议" + result = api.tokens(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/examples/translated-name.py b/examples/translated-name.py index a97631f..ef654ba 100644 --- a/examples/translated-name.py +++ b/examples/translated-name.py @@ -4,26 +4,20 @@ Example code to call Rosette API to translate a name from one language to another. """ -import argparse import json from rosette.api import API, NameTranslationParameters -parser = argparse.ArgumentParser(description="Translate a name from one language to another") -parser.add_argument("--key", required=True, help="Rosette API key") -parser.add_argument("--service_url", nargs="?", help="Optional user service URL") -args = parser.parse_args() -# Create an API instance -if args.service_url: - api = API(service_url=args.service_url, user_key=args.key) -else: - api = API(user_key=args.key) +def run(key): + # Create an API instance + api = API(user_key=key) -params = NameTranslationParameters() -params["name"] = u"معمر محمد أبو منيار القذاف" -params["entityType"] = "PERSON" -params["targetLanguage"] = "eng" -result = api.translated_name(params) + params = NameTranslationParameters() + params["name"] = u"معمر محمد أبو منيار القذاف" + params["entityType"] = "PERSON" + params["targetLanguage"] = "eng" + result = api.translated_name(params) -print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + print(json.dumps(result, indent=2, ensure_ascii=False).encode("utf8")) + return json.dumps(result, indent=2, ensure_ascii=False).encode("utf8") diff --git a/rosette/__init__.py b/rosette/__init__.py index 3d1961b..2892268 100644 --- a/rosette/__init__.py +++ b/rosette/__init__.py @@ -16,4 +16,4 @@ limitations under the License. """ -__version__ = '0.5.3' +__version__ = '0.7.1' diff --git a/rosette/api.py b/rosette/api.py index cb5dc0c..51824cb 100644 --- a/rosette/api.py +++ b/rosette/api.py @@ -377,6 +377,17 @@ def load_document_string(self, s, data_type): self["unit"] = InputUnit.DOC +class RelationshipsParameters(DocumentParameters): + + """Parameter object for relationships endpoint. Inherits from L(DocumentParameters), but allows the user + to specify the relationships-unique options parameter.""" + def __init__(self): + """Create a L{RelationshipsParameters} object. Default data format + is L{DataFormat.SIMPLE}, unit is L{InputUnit.DOC}.""" + _DocumentParamSetBase.__init__(self, ("content", "contentUri", "contentType", "unit", "language", "options")) + self["unit"] = InputUnit.DOC # default + + class NameTranslationParameters(_DocumentParamSetBase): """Parameter object for C{translated_name} endpoint. The following values may be set by the indexing (i.e.,C{ parms["name"]}) operator. The values are all @@ -555,7 +566,8 @@ def call(self, parameters): endpoint to which this L{EndpointCaller} object is bound. For all endpoints except C{translated_name} and C{matched_name}, it must be a L{DocumentParameters} object or a string; for C{translated_name}, it must be an L{NameTranslationParameters} object; - for C{matched_name}, it must be an L{NameMatchingParameters} object. + for C{matched_name}, it must be an L{NameMatchingParameters} object. For relationships, + it may be an L(DocumentParameters) or an L(RelationshipsParameters). In all cases, the result is returned as a python dictionary conforming to the JSON object described in the endpoint's entry @@ -742,6 +754,16 @@ def sentiment(self, parameters): of texts to which it is applied.""" return EndpointCaller(self, "sentiment").call(parameters) + def relationships(self, parameters): + """ + Create an L{EndpointCaller} to identify the relationships between entities in the text to + which it is applied and call it. + @param parameters: An object specifying the data, + and possible metadata, to be processed by the relationships identifier. + @type parameters: L{DocumentParameters}, L(RelationshipsParameters), or L{str} + @return: A python dictionary containing the results of relationship extraction.""" + return EndpointCaller(self, "relationships").call(parameters) + def translated_name(self, parameters): """ Create an L{EndpointCaller} to perform name analysis and translation diff --git a/setup.py b/setup.py index eccd1f9..6a76985 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def read(*filenames, **kwargs): buf.append(f.read()) return sep.join(buf) -long_description = read('README.md', 'CHANGES.txt') +long_description = read('README.txt', 'CHANGES.txt') setup(name=NAME, author=AUTHOR, diff --git a/tests/mock-data/request/eng-doc-relationships.json b/tests/mock-data/request/eng-doc-relationships.json new file mode 100644 index 0000000..05f50fb --- /dev/null +++ b/tests/mock-data/request/eng-doc-relationships.json @@ -0,0 +1,5 @@ +{ + "content": "Samsung Can Sell Its Tablet In The U.S. Market\n\n\nThe war between Samsung Electronics and Apple seems to be never ending. The companies have engaged in an international warfare, across continents, with more than 20 cases in 10 countries. The latest news in the Samsung vs. Apple conflict comes from U.S. where a judge decided that Samsung can sell its tablet in the U.S. market.\n\nIn United States, Apple initiated a legal action against Samsung in April, claiming that the South Korean smartphones and tablets “slavishly” copy the iPhone and the iPad. As a result, Apple requested that Samsung will be prohibited from selling the gadgets in the U.S. market. The much expected ruling came late on Friday, as U.S. District Judge Lucy Koh denied Apple’s request for a preliminary injuction against Samsung.\n\nU.S. District Judge Lucy Koh said that “It is not clear than an injuction on Samsung’s accused devices would prevent Apple from being irreparably harmed”. As a result, Koh rejected Apple’s request to bid sales of three Samsung smartphones models and the Samsung Tab 10.1. In the third quarter, Samsung had 23.8 percent of the global smartphone market, nine points higher than Apple.\n\nThe U.S. judge wrote that “Apple has established a likelihood of success on the merits at trial” regarding some of Samsung’s smartphones. Apple would likely prove Samsung infringed one of its tablet patents, but it did not show that it was likely to overcome Samsung’s challenges to the patent’s validity.\n\nAlthough this might be a minor victory for Samsung, as Apple still has high changes of winning the overall lawsuit, Koh’s decision makes it possible for the South Korean company to start Christmas sales.\n\nAnalysts say that global tablet sales are expected to boost to more than 50 million this year, with Apple still the leader of the market. The Silicon Valley based company sold 11.12 million units during the September quarter. So far, Apple sold more than 30 million iPads worldwide.\n\nLast week, a judge in Australia ruled in favor of Apple by extending a ban on Samsung’s iPad sales within the country. Australia is a key market for Samsung Galaxy Tablet and two weeks of banned sales isn’t much, but it can get urgent if Samsung won’t start selling the gadget before Christmas.\n\n\n\nhttp://newsinabox.net/2202/samsung-can-sell-its-tablet-in-the-u-s-market.html\n2011.12.05", + "language": "eng", + "unit": "doc" +} \ No newline at end of file diff --git a/tests/mock-data/request/eng-sentence-relationships.json b/tests/mock-data/request/eng-sentence-relationships.json new file mode 100644 index 0000000..4f6ac83 --- /dev/null +++ b/tests/mock-data/request/eng-sentence-relationships.json @@ -0,0 +1,4 @@ +{ "content": "The first men to reach the moon were Mr. Armstrong and his co-pilot, Col. Edwin E. Aldrin.", + "language": "eng", + "unit": "sentence" +} diff --git a/tests/mock-data/request/eng-url-relationships.json b/tests/mock-data/request/eng-url-relationships.json new file mode 100644 index 0000000..89ec0b0 --- /dev/null +++ b/tests/mock-data/request/eng-url-relationships.json @@ -0,0 +1,3 @@ +{ + "contentUri": "http://news.google.com/news/url?sa=t&fd=R&ct2=us&usg=AFQjCNGOuNpkO_3eDYWh76D8lZDl5jI_pQ&clid=c3a7d30bb8a4878e06b80cf16b898331&cid=52778830388718&ei=bwNNVfDFItjU3AGy-4HQDQ&url=http://www.usatoday.com/story/news/politics/2015/05/08/obama-nike-visit-free-trade-jobs-protests/26974883/" +} diff --git a/tests/mock-data/response/eng-doc-relationships.json b/tests/mock-data/response/eng-doc-relationships.json new file mode 100644 index 0000000..bf6c401 --- /dev/null +++ b/tests/mock-data/response/eng-doc-relationships.json @@ -0,0 +1,185 @@ +{ + "requestId": "f2bd0e5d-f9c8-4525-93fd-816025b291de", + "relationships": [ + { + "predicate": "seems", + "arg1": "The war between Samsung Electronics", + "arg2": "to be never ending" + }, + { + "predicate": "Can Sell", + "arg1": "Samsung", + "arg2": "Its Tablet" + }, + { + "predicate": "decided", + "arg1": "a judge", + "arg2": "that Samsung can sell its tablet in the U.S. market" + }, + { + "predicate": "comes", + "arg1": "Apple conflict", + "locatives": [ + "from U.S." + ] + }, + { + "predicate": "can sell", + "arg1": "Samsung", + "arg2": "its tablet", + "adjuncts": [ + "in the U.S. market" + ] + }, + { + "predicate": "claiming", + "arg1": "Apple", + "arg2": "copy the iPhone" + }, + { + "predicate": "copy", + "arg1": "tablets", + "arg2": "the iPhone" + }, + { + "predicate": "copy", + "arg1": "tablets", + "arg2": "the iPad" + }, + { + "predicate": "copy", + "arg1": "the South Korean smartphones", + "arg2": "the iPhone" + }, + { + "predicate": "initiated", + "arg1": "Apple", + "arg2": "a legal action against Samsung", + "locatives": [ + "In United States" + ], + "adjuncts": [ + "claiming that the South Korean smartphones", + "in April" + ] + }, + { + "predicate": "copy", + "arg1": "the South Korean smartphones", + "arg2": "the iPad" + }, + { + "predicate": "will be prohibited", + "arg1": "Samsung", + "adjuncts": [ + "from selling the gadgets in the U.S. market" + ] + }, + { + "predicate": "requested", + "arg1": "Apple", + "arg2": "that Samsung will be prohibited", + "adjuncts": [ + "As a result" + ] + }, + { + "predicate": "came late", + "arg1": "The much expected ruling", + "adjuncts": [ + "on Friday", + "as U.S. District Judge Lucy Koh denied Apple’s request for a preliminary injuction against Samsung" + ] + }, + { + "predicate": "denied", + "arg1": "U.S. District Judge Lucy Koh", + "arg2": "Apple’s request for a preliminary injuction against Samsung" + }, + { + "predicate": "said", + "arg1": "U.S. District Judge Lucy Koh", + "arg2": "It is not clear than an injuction on Samsung’s accused devices would prevent Apple from being irreparably harmed" + }, + { + "predicate": "rejected", + "arg1": "Koh", + "arg2": "Apple’s request", + "adjuncts": [ + "As a result" + ] + }, + { + "predicate": "had", + "arg1": "Samsung", + "arg2": "23.8 percent of the global smartphone market", + "adjuncts": [ + "In the third quarter" + ] + }, + { + "predicate": "wrote", + "arg1": "The U.S. judge", + "arg2": "Apple has established a likelihood of success on the merits at trial" + }, + { + "predicate": "has established", + "arg1": "Apple", + "arg2": "a likelihood of success on the merits at trial" + }, + { + "predicate": "infringed", + "arg1": "Samsung", + "arg2": "one of its tablet patents" + }, + { + "predicate": "still has", + "arg1": "Apple", + "arg2": "high changes of winning the overall lawsuit" + }, + { + "predicate": "makes", + "arg1": "Koh’s decision", + "arg2": "it possible for the South Korean company to start Christmas sales" + }, + { + "predicate": "are expected", + "arg1": "global tablet sales", + "arg2": "to boost to more than 50 million this year", + "adjuncts": [ + "with Apple still the leader of the market" + ] + }, + { + "predicate": "sold", + "arg1": "Apple", + "arg2": "more than 30 million iPads worldwide" + }, + { + "predicate": "by extending", + "arg1": "a judge in Australia", + "arg2": "a ban on Samsung’s iPad sales within the country" + }, + { + "predicate": "ruled", + "arg1": "a judge in Australia", + "adjuncts": [ + "Last week", + "in favor of Apple", + "by extending a ban on Samsung’s iPad sales within the country" + ] + }, + { + "predicate": "is", + "arg1": "Australia", + "arg2": "a key market for Samsung Galaxy Tablet" + }, + { + "predicate": "is a key market", + "arg1": "Australia", + "adjuncts": [ + "for Samsung Galaxy Tablet" + ] + } + ] +} diff --git a/tests/mock-data/response/eng-doc-relationships.status b/tests/mock-data/response/eng-doc-relationships.status new file mode 100644 index 0000000..08839f6 --- /dev/null +++ b/tests/mock-data/response/eng-doc-relationships.status @@ -0,0 +1 @@ +200 diff --git a/tests/mock-data/response/eng-sentence-relationships.json b/tests/mock-data/response/eng-sentence-relationships.json new file mode 100644 index 0000000..0bd6f36 --- /dev/null +++ b/tests/mock-data/response/eng-sentence-relationships.json @@ -0,0 +1,15 @@ +{ + "requestId": "eaee652e-a6bf-4a32-a159-0a612d2c080a", + "relationships": [ + { + "predicate": "were", + "arg1": "The first men to reach the moon", + "arg2": "Mr. Armstrong" + }, + { + "predicate": "is", + "arg1": "were Mr. Armstrong", + "arg2": "Col. Edwin E. Aldrin" + } + ] +} diff --git a/tests/mock-data/response/eng-sentence-relationships.status b/tests/mock-data/response/eng-sentence-relationships.status new file mode 100644 index 0000000..08839f6 --- /dev/null +++ b/tests/mock-data/response/eng-sentence-relationships.status @@ -0,0 +1 @@ +200 diff --git a/tests/mock-data/response/eng-url-relationships.json b/tests/mock-data/response/eng-url-relationships.json new file mode 100644 index 0000000..69efd03 --- /dev/null +++ b/tests/mock-data/response/eng-url-relationships.json @@ -0,0 +1,943 @@ +{ + "requestId": "8143276a-b6c5-4b5c-957b-f2c12b4378a8", + "relationships": [ + { + "predicate": "makes", + "arg1": "progressive case for trade\nPresident Obama", + "arg2": "took his campaign for a free trade deal to the world headquarters of Nike Friday" + }, + { + "predicate": "makes", + "arg1": "Log out Sign In FAQ\nGet the news\nFacebookEmail Twitter Google", + "arg2": "progressive case for trade\nPresident Obama took his campaign for a free trade deal to the world headquarters of Nike Friday" + }, + { + "predicate": "took", + "arg1": "progressive case for trade\nPresident Obama", + "arg2": "his campaign", + "adjuncts": [ + "for a free trade deal to the world headquarters of Nike", + "where he's extracted a pledge from the world's largest athletic shoe company that it will add 10,000 U.S. jobs" + ] + }, + { + "predicate": "took", + "arg1": "progressive case for trade President Obama", + "arg2": "his campaign", + "adjuncts": [ + "for a free trade deal to the world headquarters of Nike", + "where he's extracted a pledge from the world's largest athletic shoe company that it will add 10,000 U.S. jobs" + ] + }, + { + "predicate": "makes", + "arg1": "progressive case for trade President Obama", + "arg2": "took his campaign for a free trade deal to the world headquarters of Nike Friday" + }, + { + "predicate": "makes", + "arg1": "Post to Facebook Obama", + "arg2": "progressive case for trade President Obama took his campaign for a free trade deal to the world headquarters of Nike Friday" + }, + { + "predicate": "has", + "arg1": "CancelSend\nA link", + "arg2": "been sent to your friend's email address" + }, + { + "predicate": "has been sent", + "arg1": "CancelSend\nA link", + "adjuncts": [ + "to your friend's email address" + ] + }, + { + "predicate": "has", + "arg1": "A link", + "arg2": "been posted to your Facebook feed" + }, + { + "predicate": "has been posted", + "arg1": "A link", + "adjuncts": [ + "to your Facebook feed" + ] + }, + { + "predicate": "makes", + "arg1": "179\nTo find out more about Facebook commenting please read the Conversation Guidelines", + "arg2": "progressive case for trade\nGregory Korte" + }, + { + "predicate": "commenting please read", + "arg1": "more about Facebook", + "arg2": "the Conversation Guidelines" + }, + { + "predicate": "is", + "arg1": "May 8", + "arg2": "2015\nPresident Obama" + }, + { + "predicate": "takes", + "arg1": "trade\nGregory Korte", + "arg2": "USA TODAY", + "arg3": "the stage" + }, + { + "predicate": "takes", + "arg1": "trade\nGregory Korte", + "arg2": "May 8", + "arg3": "the stage" + }, + { + "predicate": "visited", + "arg1": "Obama", + "arg2": "the giant athletic apparel company", + "arg3": "to make his trade policy pitch as he struggles to win over Democrats" + }, + { + "predicate": "dressed", + "arg1": "58 LINKEDIN 179 COMMENTEMAILMORE\nPresident Obama", + "arg2": "his campaign for free trade in the clothing of" + }, + { + "predicate": "would help", + "arg1": "a Pacific trade deal", + "arg2": "American workers" + }, + { + "predicate": "cast", + "arg1": "Obama", + "arg2": "free trade", + "adjuncts": [ + "adopt clean energy", + "in the same terms", + "as his efforts to pass universal health care" + ] + }, + { + "predicate": "cast", + "arg1": "Obama", + "arg2": "free trade", + "adjuncts": [ + "raise the minimum wage", + "in the same terms", + "as his efforts to pass universal health care" + ] + }, + { + "predicate": "visited", + "arg1": "President Barack Obama", + "arg2": "Nike headquarters", + "adjuncts": [ + "to promote his trade agenda" + ] + }, + { + "predicate": "says", + "arg1": "a Trans-Pacific trade deal", + "arg2": "would allow it to benefit from lower tariffs on shoes" + }, + { + "predicate": "is", + "arg1": "notably Vermont Sen. Bernie Sanders", + "arg2": "a presidential candidate" + }, + { + "predicate": "says", + "arg1": "Nike", + "arg2": "a Trans-Pacific trade deal would allow it to benefit from lower tariffs on shoes" + }, + { + "predicate": "see", + "arg1": "many liberals", + "adjuncts": [ + "as a symbol of failed trade policies" + ] + }, + { + "predicate": "is", + "arg1": "the minimum wage", + "arg2": "56 cents an hour" + }, + { + "predicate": "make", + "arg1": "330,000 workers", + "arg2": "Nike shoes" + }, + { + "predicate": "said", + "arg1": "Obama", + "arg2": "would have to increase the minimum wage" + }, + { + "predicate": "seemed", + "arg1": "Nike", + "adjuncts": [ + "like an unlikely venue for a speech" + ] + }, + { + "predicate": "approves", + "arg1": "USA TODAY\nSenate panel", + "arg2": "trade bill", + "adjuncts": [ + "At first" + ] + }, + { + "predicate": "announced", + "arg1": "Nike", + "arg2": "it would hire 10,000 workers in the United States over the next decade" + }, + { + "predicate": "passes", + "arg1": "a Pacific trade agreement", + "arg2": "Congress" + }, + { + "predicate": "was made", + "arg1": "Nike's fast-growth success story", + "arg2": "possible", + "adjuncts": [ + "because of the power of trade" + ] + }, + { + "predicate": "said", + "arg1": "Nike President Mark Parker", + "arg2": "was made possible because of the power of trade" + }, + { + "predicate": "said", + "arg1": "Introducing Obama", + "arg2": "was made possible because of the power of trade" + }, + { + "predicate": "should see", + "arg1": "companies", + "arg2": "that kind of success" + }, + { + "predicate": "wants", + "arg1": "Nike", + "arg2": "to hire American workers" + }, + { + "predicate": "said", + "arg1": "Labor groups", + "arg2": "if Nike wants to hire American workers, it shouldn't be contingent on a trade deal" + }, + { + "predicate": "is", + "arg1": "this time", + "arg2": "different" + }, + { + "predicate": "has met", + "arg1": "Obama's free trade push", + "arg2": "resistance from within his own Democratic party" + }, + { + "predicate": "hit", + "arg1": "USA TODAY\nFree trade critics", + "arg2": "Obama", + "adjuncts": [ + "over Nike visit\nLike President Clinton", + "before him" + ] + }, + { + "predicate": "will have", + "arg1": "the Trans-Pacific Partnership", + "arg2": "more labor" + }, + { + "predicate": "has argued", + "arg1": "The White House", + "arg2": "that the Trans-Pacific Partnership will have more labor" + }, + { + "predicate": "to insist", + "arg1": "Congress", + "adjuncts": [ + "on stronger provisions before an up-or-down vote on passage" + ] + }, + { + "predicate": "acknowledged", + "arg1": "Obama", + "arg2": "that intra-party debate Friday" + }, + { + "predicate": "announced", + "arg1": "the White House", + "arg2": "have questioned the appearances" + }, + { + "predicate": "have questioned", + "arg1": "the Nike visit", + "arg2": "the appearances of using a company" + }, + { + "predicate": "was built", + "arg1": "the Nike brand", + "adjuncts": [ + "by outsourcing manufacturing to sweatshops in Asia" + ] + }, + { + "predicate": "is", + "arg1": "The symbolism of his speech", + "arg2": "staggering" + }, + { + "predicate": "gather", + "arg1": "Demonstrators", + "locatives": [ + "near the Sentinel Hotel" + ] + }, + { + "predicate": "spoke", + "arg1": "President Obama", + "adjuncts": [ + "at a Democratic fundraiser" + ] + }, + { + "predicate": "is", + "arg1": "Thomas Boyd", + "arg2": "VIDEO" + }, + { + "predicate": "based", + "arg1": "valuable states in America", + "adjuncts": [ + "on value of land per acre" + ] + }, + { + "predicate": "is", + "arg1": "Aziz Hamzaogullari", + "arg2": "portfolio manager for the Loomis Sayles Growth Fund" + }, + { + "predicate": "are wired", + "arg1": "THE DAY IN MONEYAmazon", + "arg2": "to keep growing market share" + }, + { + "predicate": "is", + "arg1": "00:59\nUnity Stoakes", + "arg2": "co-founder of StartUp Health" + }, + { + "predicate": "|", + "arg1": "THE DAY IN MONEYHealth care technology booms", + "arg2": "00:59\nUnity Stoakes" + }, + { + "predicate": "added", + "arg1": "Hamzaogullari", + "arg2": "that the anti-trust suit against Newslook\n2 of 42\nVIDEO" + }, + { + "predicate": "is", + "arg1": "Trisha Thadani", + "arg2": "Collin Brennan\n3 of 42\nVIDEO" + }, + { + "predicate": "share", + "arg1": "Buzz60's Leigh Scheps", + "arg2": "some tops" + }, + { + "predicate": "is", + "arg1": "Buzz60's Leigh Scheps", + "arg2": "@LeighTVReporters" + }, + { + "predicate": "introduced", + "arg1": "THE DAY IN MONEYAmazon launches", + "arg2": "free shipping for small" + }, + { + "predicate": "|", + "arg1": "free shipping on small items", + "arg2": "00:40\nAmazon", + "adjuncts": [ + "on Tuesday" + ] + }, + { + "predicate": "has stabilized", + "arg1": "04:40\nThe high yield bond market", + "arg2": "since worries about falling energy prices dragged it down last winter" + }, + { + "predicate": "says", + "arg1": "Morgan Stanley", + "arg2": "| 04:40\nThe high yield bond market has stabilized since worries about falling energy prices dragged it down last winter" + }, + { + "predicate": "|", + "arg1": "Morgan Stanley", + "arg2": "04:40\nThe high yield bond market has stabilized since worries about falling energy prices dragged it down last winter" + }, + { + "predicate": "says", + "arg1": "Richard Lindquist", + "arg2": "the good times will continue" + }, + { + "predicate": "says", + "arg1": "the good times", + "arg2": "will continue" + }, + { + "predicate": "is", + "arg1": "Richard Lindquist", + "arg2": "head of high yield at Morgan Stanley Investment Management" + }, + { + "predicate": "ended", + "arg1": "00:55\nShares of PVH Corp.", + "arg2": "making it TheStreet's Move of the Day", + "adjuncts": [ + "up 7 percent" + ] + }, + { + "predicate": "came", + "arg1": "Earnings per share", + "adjuncts": [ + "in at $0.71", + "were looking for" + ] + }, + { + "predicate": "polled", + "arg1": "the $0.59 analysts", + "adjuncts": [ + "by Thomson Reuters" + ] + }, + { + "predicate": "is keeping", + "arg1": "FireEye | 01:00\nTheStreet's Jim Cramer", + "arg2": "an eye on shares of FireEye" + }, + { + "predicate": "says", + "arg1": "one of his favorite themes for 2015", + "arg2": "is cyber security" + }, + { + "predicate": "says", + "arg1": "Cramer", + "arg2": "is cyber security" + }, + { + "predicate": "is", + "arg1": "one of his favorite themes for 2015", + "arg2": "cyber security" + }, + { + "predicate": "quashes", + "arg1": "THE DAY IN MONEYNintendo", + "arg2": "rumors of future deal with android | 02:00\nRumors of a Nintendo Android deal" + }, + { + "predicate": "were dismissed", + "arg1": "THE DAY IN MONEYNintendo quashes rumors of future deal with android | 02:00\nRumors of a Nintendo Android deal", + "adjuncts": [ + "by the big N", + "on Tuesday" + ] + }, + { + "predicate": "provided", + "arg1": "Video", + "adjuncts": [ + "by Newsy Newslook\n11 of 42\nVIDEO" + ] + }, + { + "predicate": "are under pressure", + "arg1": "U.S.-bred poultry suppliers", + "adjuncts": [ + "with the U.S. Department of Agriculture" + ] + }, + { + "predicate": "explains", + "arg1": "RealMoney Pro contributor", + "arg2": "how to cut your exposure to stocks" + }, + { + "predicate": "|", + "arg1": "Avoid companies with egg dependencies", + "arg2": "01:45" + }, + { + "predicate": "|", + "arg1": "earnings estimates", + "arg2": "stocks are" + }, + { + "predicate": "reported", + "arg1": "the company", + "arg2": "earnings on Tuesday" + }, + { + "predicate": "beats", + "arg1": "THE DAY IN MONEYCracker Barrel", + "arg2": "earnings estimates | 00:49\nCracker Barrel" + }, + { + "predicate": "beats", + "arg1": "earnings estimates", + "arg2": "| 00:49\nCracker Barrel" + }, + { + "predicate": "buys", + "arg1": "THE DAY IN MONEYBoot Barn", + "arg2": "western lifestyle retailer Sheplers", + "adjuncts": [ + "for $147M | 01:29\nBoot Barn Holdings Inc. said June 1 it has agreed to buy fellow western lifestyle retailer Sheplers Inc. for $147 million in cash" + ] + }, + { + "predicate": "said", + "arg1": "Boot Barn Holdings Inc.", + "arg2": "it has agreed to buy fellow western lifestyle retailer Sheplers Inc. for $147 million in cash" + }, + { + "predicate": "is", + "arg1": "The seller", + "arg2": "San Francisco-based private equity firm Gryphon Investors" + }, + { + "predicate": "slip", + "arg1": "factory orders", + "arg2": "shares" + }, + { + "predicate": "told", + "arg1": "A source", + "arg2": "The Deal's Richard Collings tha Newslook\n15 of 42\nVIDEO", + "adjuncts": [ + "THE DAY IN MONEYGM" + ] + }, + { + "predicate": "reported", + "arg1": "the automaker", + "arg2": "a 3 percent increase in domestic sales in May" + }, + { + "predicate": "beat", + "arg1": "Ford", + "arg2": "monthly sales forecasts" + }, + { + "predicate": "also beat", + "arg1": "Ford", + "arg2": "estimates", + "adjuncts": [ + "falling at a slower-than-expected pace in May" + ] + }, + { + "predicate": "announced", + "arg1": "the company", + "arg2": "a new camera" + }, + { + "predicate": "jumped", + "arg1": "Touchscreen", + "arg2": "as much as 7%", + "adjuncts": [ + "on Monday", + "after the company announced a new camera" + ] + }, + { + "predicate": "announced", + "arg1": "THE DAY IN MONEYGoPro", + "arg2": "a new camera with Touchscreen, Stock skyrockets | 01:01\nGoPro (GPRO) shares jumped as much as 7% on Monday" + }, + { + "predicate": "according to", + "arg1": "that features a built-in screen", + "arg2": "CNET" + }, + { + "predicate": "is", + "arg1": "The GoPro Hero", + "arg2": "a touchscreen camera that's only its second offering" + }, + { + "predicate": "|", + "arg1": "| America's Markets", + "arg2": "01:37\nUSA" + }, + { + "predicate": "might outsmart", + "arg1": "investors", + "arg2": "the usual June gloom", + "adjuncts": [ + "in this edition of America's Markets" + ] + }, + { + "predicate": "has", + "arg1": "Krystin Goodwin", + "arg2": "five things airlines don't want you to know" + }, + { + "predicate": "is", + "arg1": "Krystin Goodwin", + "arg2": "@Krystingoodwin" + }, + { + "predicate": "has", + "arg1": "five things airlines", + "arg2": "don't want you to know" + }, + { + "predicate": "drops", + "arg1": "THE DAY IN MONEYMacau's casino revenue", + "arg2": "37%", + "adjuncts": [ + "in twelve month" + ] + }, + { + "predicate": "has dropped", + "arg1": "casino revenue for the Chinese peninsula", + "arg2": "37.1 percent", + "adjuncts": [ + "in May", + "from last year's numbers" + ] + }, + { + "predicate": "opens", + "arg1": "THE DAY IN MONEYDenver", + "arg2": "its first marijuana-friendly hotel | 01:03\nThe Nativ is Colorado's first openly pot-friendly hotel" + }, + { + "predicate": "is", + "arg1": "The Nativ", + "arg2": "Colorado's first openly pot-friendly hotel" + }, + { + "predicate": "has", + "arg1": "TC Newman", + "arg2": "the details" + }, + { + "predicate": "Find out", + "arg1": "01:24", + "adjuncts": [ + "from a Halstead Property executive" + ] + }, + { + "predicate": "sits down", + "arg1": "Brian Lewis", + "arg2": "to discuss this exclusive market", + "adjuncts": [ + "with Fortune's Leigh Gallagher" + ] + }, + { + "predicate": "is", + "arg1": "Brian Lewis", + "arg2": "Executive VP of Halstead Property" + }, + { + "predicate": "may endorse", + "arg1": "the AFL CIO", + "adjuncts": [ + "in 2016" + ] + }, + { + "predicate": "is", + "arg1": "| 04:42\nMichael Lin", + "arg2": "president of the Taiwan Stock Exchange" + }, + { + "predicate": "talks", + "arg1": "more links", + "arg2": "| 04:42\nMichael Lin", + "adjuncts": [ + "about the planned trading link with Singapore" + ] + }, + { + "predicate": "seeks", + "arg1": "THE DAY IN MONEYTaiwan Exchange Chief", + "arg2": "more links with Singapore | 04:42\nMichael Lin, president of the Taiwan Stock Exchange, talks about the planned trading link with Singapore" + }, + { + "predicate": "are using", + "arg1": "THE DAY IN MONEYThe central bankers", + "arg2": "tomatoes", + "arg3": "to fight inflation" + }, + { + "predicate": "is struggling", + "arg1": "02:19\nIndonesia", + "arg2": "to fight its highest rate of inflation" + }, + { + "predicate": "makes", + "arg1": "Netflix", + "arg2": "a good graduation gift | 01:59\nTheStreet's Jim Cramer answers your Twitter questions about Blackstone (BX" + }, + { + "predicate": "says", + "arg1": "Netflix", + "arg2": "makes a good graduation gift" + }, + { + "predicate": "says", + "arg1": "THE DAY IN MONEYJim Cramer", + "arg2": "Netflix makes a good graduation gift" + }, + { + "predicate": "answers", + "arg1": "your Twitter", + "arg2": "questions about Blackstone" + }, + { + "predicate": "answers", + "arg1": "a good graduation gift", + "arg2": "| 01:59\nTheStreet's Jim Cramer", + "arg3": "your Twitter questions about Blackstone" + }, + { + "predicate": "said", + "arg1": "the Commerce Department", + "adjuncts": [ + "on Friday" + ] + }, + { + "predicate": "fell", + "arg1": "First-quarter gross domestic product", + "arg2": "0.7 percent" + }, + { + "predicate": "have", + "arg1": "Nebraska", + "arg2": "the lowest unemployment rates" + }, + { + "predicate": "have", + "arg1": "Utah", + "arg2": "the lowest unemployment rates" + }, + { + "predicate": "have", + "arg1": "North Dakota", + "arg2": "the lowest unemployment rates" + }, + { + "predicate": "has", + "arg1": "Douglas McIntyre of 24/7 Wall Street", + "arg2": "the details" + }, + { + "predicate": "are demanding", + "arg1": "action | 01:29\nWorried that their reputations will be tarnished by their links to FIFA", + "adjuncts": [ + "even warning it is prepared to jump ship", + "with Visa" + ] + }, + { + "predicate": "will be tarnished", + "arg1": "their reputations", + "adjuncts": [ + "by their links to FIFA" + ] + }, + { + "predicate": "just sped", + "arg1": "shuttle people between Los Angeles", + "arg2": "a bit closer to reality" + }, + { + "predicate": "is Getting", + "arg1": "THE DAY IN MONEYHyperloop", + "arg2": "a Test Track in California | 00:52\nThe" + }, + { + "predicate": "is returning", + "arg1": "THE DAY IN MONEYSkyMall", + "arg2": "online" + }, + { + "predicate": "found", + "arg1": "the quirky items", + "adjuncts": [ + "in the catalog returning to an airplane seat pocket near you" + ] + }, + { + "predicate": "shows", + "arg1": "TC Newman", + "arg2": "you some of the quirky items" + }, + { + "predicate": "was the next development", + "arg1": "The buzz at Google I/O", + "adjuncts": [ + "Google's partnership with GoPro" + ] + }, + { + "predicate": "is coming", + "arg1": "THE DAY IN MONEYVirtual reality", + "adjuncts": [ + "to YouTube | 00:44" + ] + }, + { + "predicate": "was the next development", + "arg1": "The buzz at Google I/O", + "adjuncts": [ + "of its Cardboard VR viewing device" + ] + }, + { + "predicate": "was", + "arg1": "The buzz at Google I/O", + "arg2": "the next development of its Cardboard VR viewing device" + }, + { + "predicate": "will record", + "arg1": "GoPro", + "arg2": "whose camera sets", + "arg3": "VR-ready videos" + }, + { + "predicate": "is offering", + "arg1": "| 00:50\nAmazon", + "arg2": "free same-day shipping for its Prime subscribers", + "adjuncts": [ + "in some of its key markets" + ] + }, + { + "predicate": "plans", + "arg1": "no one", + "arg2": "to slow oil production" + }, + { + "predicate": "shows", + "arg1": "OPEC", + "arg2": "thinks no one plans to slow oil production" + }, + { + "predicate": "announced", + "arg1": "Google's upgrades to Android", + "adjuncts": [ + "at Google I/O" + ] + }, + { + "predicate": "is", + "arg1": "05:25\nJuan Benitez", + "arg2": "chief technology officer at Braintree" + }, + { + "predicate": "will end", + "arg1": "oil glut", + "adjuncts": [ + "until at least 2017 | 01:50\nThe 12-nation conglomerate's long-term strategy report" + ] + }, + { + "predicate": "thinks", + "arg1": "OPEC", + "arg2": "no one plans to slow oil production" + }, + { + "predicate": "is", + "arg1": "Bloomberg's Cory Johnson", + "arg2": "chief technology officer at Braintree" + }, + { + "predicate": "thinks", + "arg1": "no one", + "arg2": "plans to slow oil production" + }, + { + "predicate": "ended", + "arg1": "| 00:49\nShares of data storage company Western Digital", + "adjuncts": [ + "following Goldman Sachs upgrade" + ] + }, + { + "predicate": "upgraded", + "arg1": "Goldman Sachs", + "arg2": "the stock", + "adjuncts": [ + "to BUY from NEUTRAL" + ] + }, + { + "predicate": "says", + "arg1": "North America's bandwidth", + "arg2": "| 01:21\nA new study", + "arg3": "Netflix accounts for about 37 percent of North American Internet traffic during peak hours" + }, + { + "predicate": "is apparently hogging", + "arg1": "THE DAY IN MONEYNetflix", + "arg2": "North America's bandwidth" + }, + { + "predicate": "is", + "arg1": "| 04:34\nSuccess", + "arg2": "life on your own terms" + }, + { + "predicate": "is", + "arg1": "The Dealmaker’s Ten Commandments", + "arg2": "a methodology for figuring out what the terms are for yourself" + }, + { + "predicate": "provided", + "arg1": "Video", + "adjuncts": [ + "by Newsy Newslook\n41 of 42\nVIDEO" + ] + }, + { + "predicate": "says", + "arg1": "The Dealmaker’s Ten Commandments", + "arg2": "is a methodology for figuring out what the terms are for yourself" + }, + { + "predicate": "is life", + "arg1": "| 04:34\nSuccess", + "adjuncts": [ + "on your own terms" + ] + }, + { + "predicate": "says", + "arg1": "THE DAY IN MONEYThe Hollywood Dealmaker’s Guide", + "arg2": "his book The Dealmaker’s Ten Commandments is a methodology for figuring out what the terms are for yourself" + } + ] +} diff --git a/tests/mock-data/response/eng-url-relationships.status b/tests/mock-data/response/eng-url-relationships.status new file mode 100644 index 0000000..08839f6 --- /dev/null +++ b/tests/mock-data/response/eng-url-relationships.status @@ -0,0 +1 @@ +200 diff --git a/tests/test_rosette_api.py b/tests/test_rosette_api.py index e85a3d0..f0fc3d5 100644 --- a/tests/test_rosette_api.py +++ b/tests/test_rosette_api.py @@ -30,7 +30,7 @@ except ImportError: from io import BytesIO as streamIO import gzip -from rosette.api import API, DocumentParameters, NameTranslationParameters, NameMatchingParameters, RosetteException +from rosette.api import API, DocumentParameters, NameTranslationParameters, NameMatchingParameters, RelationshipsParameters, RosetteException _IsPy3 = sys.version_info[0] == 3 @@ -88,6 +88,9 @@ def __init__(self, filename=None): # Name translation requires NameTranslationParameters elif "translated-name" in filename: self.params = NameTranslationParameters() + # Relationships requires RelationshipParameters if user wants to specify options + elif "relationships" in filename: + self.params = RelationshipsParameters() # Find and load contents of request file into parameters with open(request_file_dir + filename + ".json", "r") as inp_file: params_dict = json.loads(inp_file.read()) @@ -190,6 +193,7 @@ def call_endpoint(input_filename, expected_status_filename, expected_output_file "/language": test.api.language, "/matched-name": test.api.matched_name, "/morphology/complete": test.api.morphology, + "/relationships": test.api.relationships, "/sentiment": test.api.sentiment, "/translated-name": test.api.translated_name} @@ -226,7 +230,7 @@ def test_all(input_filename, expected_status_filename, expected_output_filename, def test_debug(): # Doesn't really matter what it returns for this test, so just making sure it catches all of them endpoints = ["categories", "entities", "entities/linked", "language", "matched-name", "morphology-complete", - "sentiment", "translated-name"] + "sentiment", "translated-name", "relationships"] expected_status_filename = response_file_dir + "eng-sentence-entities.status" expected_output_filename = response_file_dir + "eng-sentence-entities.json" for rest_endpoint in endpoints: @@ -264,7 +268,7 @@ def test_debug(): @httpretty.activate def test_just_text(): endpoints = ["categories", "entities", "entities/linked", "language", "matched-name", "morphology-complete", - "sentiment", "translated-name"] + "sentiment", "translated-name", "relationships"] expected_status_filename = response_file_dir + "eng-sentence-entities.status" expected_output_filename = response_file_dir + "eng-sentence-entities.json" for rest_endpoint in endpoints: