コード例 #1
0
ファイル: test_rosette_api.py プロジェクト: yuxideng/python
def test_the_name_similarity_endpoint(api, json_response):
    """Test the name similarity endpoint"""
    httpretty.enable()
    httpretty.register_uri(httpretty.POST,
                           "https://api.rosette.com/rest/v1/info",
                           body=json_response,
                           status=200,
                           content_type="application/json")
    httpretty.register_uri(httpretty.POST,
                           "https://api.rosette.com/rest/v1/name-similarity",
                           body=json_response,
                           status=200,
                           content_type="application/json")

    matched_name_data1 = "Michael Jackson"
    matched_name_data2 = "迈克尔·杰克逊"
    params = NameSimilarityParameters()
    params["name1"] = {
        "text": matched_name_data1,
        "language": "eng",
        "entityType": "PERSON"
    }
    params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}

    result = api.name_similarity(params)
    assert result["name"] == "Rosette API"
    httpretty.disable()
    httpretty.reset()
コード例 #2
0
def test_for_name_similarity_required_parameters(api, json_response):
    httpretty.enable()
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                           body=json_response, status=200, content_type="application/json")
    httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/name-similarity",
                           body=json_response, status=200, content_type="application/json")

    matched_name_data1 = "Michael Jackson"
    matched_name_data2 = "迈克尔·杰克逊"
    params = NameSimilarityParameters()

    with pytest.raises(RosetteException) as e_rosette:
        result = api.name_similarity(params)

    assert e_rosette.value.status == 'missingParameter'
    assert e_rosette.value.message == 'Required Name Similarity parameter not supplied'

    params["name1"] = {
        "text": matched_name_data1,
        "language": "eng",
        "entityType": "PERSON"}
    with pytest.raises(RosetteException) as e_rosette:
        result = api.name_similarity(params)

    assert e_rosette.value.status == 'missingParameter'
    assert e_rosette.value.message == 'Required Name Similarity parameter not supplied'

    params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}

    result = api.name_similarity(params)
    assert result["name"] == "Rosette API"
    httpretty.disable()
    httpretty.reset()
コード例 #3
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)

    matched_name_data1 = "Michael Jackson"
    matched_name_data2 = "迈克尔·杰克逊"
    params = NameSimilarityParameters()
    params["name1"] = {
        "text": matched_name_data1,
        "language": "eng",
        "entityType": "PERSON"
    }
    params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}
    return api.name_similarity(params)
コード例 #4
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)

    matched_name_data1 = "Michael Jackson"
    matched_name_data2 = "迈克尔·杰克逊"
    params = NameSimilarityParameters()
    params["name1"] = {
        "text": matched_name_data1,
        "language": "eng",
        "entityType": "PERSON"
    }
    params["name2"] = {"text": matched_name_data2, "entityType": "PERSON"}
    try:
        return api.name_similarity(params)
    except RosetteException as exception:
        print(exception)