Exemple #1
0
def get_vector(folder, file):
    f = open(folder + file, "r")
    embeddings_data = f.read()

    api = API(user_key="", service_url="http://localhost:8181/rest/v1/")
    params = DocumentParameters()
    params["content"] = embeddings_data

    try:
        vector = api.text_embedding(params)
        save_vector(file, vector, "doc", "")
    except RosetteException as exception:
        print(exception)
    except:
        print('unkown error in get vector')

    try:
        sentences = api.sentences(params)
        sentences = sentences.get('sentences')
        for x in sentences:
            params["content"] = x
            sentence_vector = api.text_embedding(params)
            save_vector(file, sentence_vector, "sen", x)
    except RosetteException as exception:
        print(exception)
    except:
        print('unkown sentence error')
Exemple #2
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"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."

    return api.sentences(params)
Exemple #3
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)

    sentences_data = "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"] = sentences_data

    return api.sentences(params)
Exemple #4
0
def sen_tagging(tokens_data, key='c573c91d6f074690b5bb6af453fed596'):
    # create an API instance
    print "sen_tagging"
    api = API(user_key=key)
    params = DocumentParameters()
    params["content"] = tokens_data
    results = api.sentences(params)
    ans = json.dumps(results, indent=2, ensure_ascii=False,
                     sort_keys=True).encode('utf-8')
    ans_json = json.loads(ans)
    print "sen_tagging finished"
    return ans_json['sentences']
Exemple #5
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)

    sentences_data = "This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me."
    params = DocumentParameters()
    params["content"] = sentences_data

    try:
        return api.sentences(params)
    except RosetteException as exception:
        print(exception)
Exemple #6
0
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)

params = DocumentParameters()
params["content"] = u"""
This land is your land This land is my land
From California to the New York island;
From the red wood forest to the Gulf Stream waters

This land was made for you and Me.

As I was walking that ribbon of highway,
I saw above me that endless skyway:
I saw below me that golden valley:
This land was made for you and me."""

result = api.sentences(params)

pprint.pprint(result)