Beispiel #1
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)

    params = DocumentParameters()

    params["content"] = u"Por favor Señorita, says the man."
    return api.language(params)
Beispiel #2
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)

    language_data = "Por favor Señorita, says the man."
    params = DocumentParameters()
    params["content"] = language_data
    api.setCustomHeaders("X-RosetteAPI-App", "python-app")
    return api.language(params)
Beispiel #3
0
def run(key, alt_url='https://api.rosette.com/rest/v1/'):
    """ Run the example """
    # Create an API instance
    api = API(user_key=key, service_url=alt_url)

    language_data = "Por favor Señorita, says the man."
    params = DocumentParameters()
    params["content"] = language_data
    api.set_custom_headers("X-RosetteAPI-App", "python-app")
    try:
        return api.language(params)
    except RosetteException as exception:
        print(exception)
Beispiel #4
0
def test_the_max_pool_size(json_response, doc_params):
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language",
                           body=json_response, status=200, content_type="application/json",
                           adding_headers={
                               'x-rosetteapi-concurrency': 5
                           })
    api = API('bogus_key')
    assert api.getPoolSize() == 1
    result = api.language(doc_params)
    assert result["name"] == "Rosette API"
    assert api.getPoolSize() == 5
    httpretty.disable()
    httpretty.reset()
Beispiel #5
0
def test_the_max_pool_size(json_response, doc_params):
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/language",
                           body=json_response, status=200, content_type="application/json",
                           adding_headers={
                               'x-rosetteapi-concurrency': 5
                           })
    api = API('bogus_key')
    assert api.getPoolSize() == 1
    result = api.language(doc_params)
    assert result["name"] == "Rosette API"
    assert api.getPoolSize() == 5
    httpretty.disable()
    httpretty.reset()
def run(key, alt_url='https://api.rosette.com/rest/v1/'):
    """ Run the example """
    # Create an API instance
    api = API(user_key=key, service_url=alt_url)

    language_multilingual_data = "On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times.  Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays.  ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان."
    params = DocumentParameters()
    params["content"] = language_multilingual_data
    api.set_custom_headers("X-RosetteAPI-App", "python-app")
    api.set_option('multilingual', True)

    try:
        return api.language(params)
    except RosetteException as exception:
        print(exception)
Beispiel #7
0
def get_rosette_predictions(X):
    pred = []
    api = API(user_key="b65b38189be361e200bc5c36e6522cf2")
    params = DocumentParameters()
    print('Request started')
    i = 0
    for textstr in X:
        try:
            i = i + 1
            params["content"] = textstr
            result = api.language(params)
            #result = json.loads(result)
            lang = result['languageDetections'][0]['language']
            pred.append(lang)
            #sleep(0.05)
            if (i%50 == 0):
                print(i)
        except Exception as inst:
            print('Exception', i,inst, result)

    print('Request ended')
    return pred
Beispiel #8
0
# -*- coding: utf-8 -*-

"""
Example code to call Rosette API to determine the language of a piece of text.
"""

import argparse
import pprint

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)

params = DocumentParameters()

# Use an HTML file to load data instead of a string
params["content"] = u"Por favor Señorita, says the man."
result = api.language(params)

pprint.pprint(result)