Skip to content

Commit 20b5ca3

Browse files
author
Hannah
committed
entities/linked deprecation
1 parent cb21f95 commit 20b5ca3

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

examples/entities_linked.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text.
5+
"""
6+
7+
import argparse
8+
import json
9+
import os
10+
11+
from rosette.api import API, DocumentParameters
12+
13+
14+
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
15+
# Create an API instance
16+
api = API(user_key=key, service_url=altUrl)
17+
18+
entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon."
19+
params = DocumentParameters()
20+
params["content"] = entities_linked_text_data
21+
params["genre"] = "social-media"
22+
return api.entities(params, True) # entity linking is turned on
23+
24+
25+
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Calls the ' + os.path.splitext(os.path.basename(__file__))[0] + ' endpoint')
26+
parser.add_argument('-k', '--key', help='Rosette API Key', required=True)
27+
parser.add_argument('-u', '--url', help="Alternative API URL", default='https://api.rosette.com/rest/v1/')
28+
29+
if __name__ == '__main__':
30+
args = parser.parse_args()
31+
result = run(args.key, args.url)
32+
print(json.dumps(result, indent=2, ensure_ascii=False, sort_keys=True).encode("utf8"))

rosette/api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,24 @@ def morphology(self, parameters, facet=MorphologyOutput.COMPLETE):
752752
@return: A python dictionary containing the results of morphological analysis."""
753753
return EndpointCaller(self, "morphology/" + facet).call(parameters)
754754

755-
def entities(self, parameters):
755+
def entities(self, parameters, resolve_entities=False):
756756
"""
757757
Create an L{EndpointCaller} to identify named entities found in the texts
758758
to which it is applied and call it. Linked entity information is optional, and
759759
its need must be specified at the time the operator is created.
760760
@param parameters: An object specifying the data,
761761
and possible metadata, to be processed by the entity identifier.
762762
@type parameters: L{DocumentParameters} or L{str}
763+
@param resolve_entities: Specifies whether or not linked entity information will
764+
be wanted.
765+
@type resolve_entities: Boolean
763766
@return: A python dictionary containing the results of entity extraction."""
764-
return EndpointCaller(self, "entities").call(parameters)
767+
if resolve_entities:
768+
warnings.warn_explicit("the /entities/linked endpoint is replaced by /entities.", DeprecationWarning)
769+
return EndpointCaller(self, "entities/linked").call(parameters)
770+
else:
771+
return EndpointCaller(self, "entities").call(parameters)
772+
765773

766774
def categories(self, parameters):
767775
"""

0 commit comments

Comments
 (0)