def get_entities(content, key, url, language=None): """Get Rosette API named entity results for the given content This method gets results of the "entities" endpoint of the Rosette API. The result is an A(nnotated) D(ata) M(odel) or ADM that is a Python dict representing a document, annotations of the document content, and metadata. content: the textual content of a document for the Rosette API to process key: your Rosette user key url: the URL of the Rosette API language: an optional ISO 639-2 T language code (the Rosette API will automatically detect the language of the content by default) """ api = API(user_key=key, service_url=url) # Request result as Annotated Data Model (ADM) api.setUrlParameter("output", "rosette") parameters = DocumentParameters() parameters['content'] = content parameters['language'] = language adm = api.entities(parameters) return adm
help=( 'Output verbosely (i.e., get the full Annotated Data Model (ADM) ' 'as JSON)' ) ) args = parser.parse_args() # Get the user's Rosette API key key = ( os.environ.get('ROSETTE_USER_KEY') or args.key or getpass(prompt='Enter your Rosette API key: ') ) # Instantiate the Rosette API api = API(user_key=key, service_url=args.api_url) if args.verbose: api.setUrlParameter('output', 'rosette') content = get_content(args.input, args.content_uri) print('Extracting entities via Rosette API ...', file=sys.stderr) adm = request( content, 'entities', api, language=args.language, uri=args.content_uri ) print('Done!', file=sys.stderr) print('Augmenting entities via MediaWiki API ...', file=sys.stderr) augment(adm, args.wikipedia_language, args.verbose) print('Done!', file=sys.stderr) dump(adm)