Пример #1
0
def test_debug():
    # Doesn't really matter what it returns for this test, so just making sure it catches all of them
    endpoints = ["categories", "entities", "entities/linked", "language", "matched-name", "morphology-complete",
                 "sentiment", "translated-name", "relationships"]
    expected_status_filename = response_file_dir + "eng-sentence-entities.status"
    expected_output_filename = response_file_dir + "eng-sentence-entities.json"
    for rest_endpoint in endpoints:
        httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/" + rest_endpoint,
                               status=get_file_content(expected_status_filename),
                               body=get_file_content(expected_output_filename),
                               content_type="application/json")

    with open(expected_output_filename, "r") as expected_file:
        expected_result = json.loads(expected_file.read())

    # need to mock /info call too because the api will call it implicitly
    with open(response_file_dir + "info.json", "r") as info_file:
        body = info_file.read()
        httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info",
                               body=body, status=200, content_type="application/json")
        httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                               body=body, status=200, content_type="application/json")

    api = API("0123456789", debug=True)

    content = "He also acknowledged the ongoing U.S. conflicts in Iraq and Afghanistan, noting that he is the \"commander in chief of a country that is responsible for ending a war and working in another theater to confront a ruthless adversary that directly threatens the American people\" and U.S. allies."

    params = DocumentParameters()
    params.__setitem__("content", content)
    api.entities(params)

    # Check that the most recent querystring had debug=true
    assert httpretty.last_request().querystring == {'debug': ['true']}
Пример #2
0
def main(argv):
       
    parser = argparse.ArgumentParser(description='Template for storing/analyzing responses from Rosette APIs')
    parser.add_argument('-k', '--key', required=True, help="rosette api key")
    args = parser.parse_args()

    # initialize
    rosette = ""
    
    print "trytext.py: starting up..."
    
    ##########
    # extract text from the file
    sText = "\"Gigli\" -- which spawned the phenomenon the gossip pages and celebrity magazines so lovingly refer to as \"Bennifer\" -- is every bit as unwatchable as the deafening negative chatter would suggest. The dialogue from writer-/sdirector Martin Brest is clunky, the film has serious tonal inconsistencies and at more than two hours, it drags on way longer than it should. Even making a little game of it, and trying to pinpoint the exact moment when Ben Affleck and Jennifer Lopez fell in love, stops being fun after a while. Perhaps it\'s when he says, in an attempt to seduce her, \"I\'m the bull, you\'re the cow.\" Or when she beckons him into foreplay by lying back in bed and purring, \"Gobble, gobble\" -- which could forever change the way you view your Thanksgiving turkey. But as pop-star vehicles go, \"Gigli\" isn\'t as insufferable as, say, last year\'s Madonna-Guy Ritchie debacle, \"Swept Away.\" It\'s more on par with Mariah Carey\'s \"Glitter\" and Britney Spears\' \"Crossroads.\" If this were a movie starring two B-list actors, or two complete unknowns, it probably would have gone straight to video. After curious masochists and J.Lo fans check it out the first weekend, \"Gigli\" probably will have a drop-off in audience that rivals \"The Hulk\" -- 70 percent -- then go to video. And with the release next spring of Kevin Smith\'s \"Jersey Girl,\" in which they also co-star, we can have this little conversation all over again. For now, we have Affleck starring as incompetent mob thug Larry Gigli. (That\'s pronounced JEE-lee, which rhymes with really, a running joke that isn\'t particularly funny the first time.) Gigli is asked to kidnap Brian (Justin Bartha), the mentally disabled younger brother of a/sfederal prosecutor who\'s going after a New York mobster (Al Pacino). His boss, however, thinks he\'s incapable of handling the assignment alone and sends in Ricki (Lopez), another contractor, to help him. Gigli is an anti-social lout who lives in a seedy apartment. Ricki is beautiful, grounded, enlightened. She quotes Sun Tzu -- who could blame Gigli for falling for her? (And whether you like her or not, Lopez does have an undeniable presence.) But Ricki is also a lesbian -- so it makes absolutely no sense when she falls for him, too, although they have all the obligatory banter and alleged sexual tension required of a romantic comedy. (And it\'s only a romantic comedy sometimes. Other times, it aims to be an edgy action-crime movie; still other times, it aspires for gag-inducing poignancy.) Apparently, the only force that binds them is the fact that they both feel squeamish about cutting off Brian\'s thumb and mailing it to his prosecutor brother. Instead, they break into a morgue and saw the thumb off a corpse using a plastic knife, while Brian -- who has an unexplained penchant for old-school rap -- sings Sir Mix-a-Lot\'s \"Baby Got Back.\" It\'s also incredibly misinformed to suggest that Ricki can be \"converted\" to heterosexuality -- that a man\'s love is all she really needed to allay any confusion about all that silly lesbian stuff. So what you have here is \"Rain Man\" meets \"Chasing Amy\" -- which is apropos, since the latter is a 1997 Kevin Smith movie in which Affleck also starred as a guy who falls for a lesbian. Instead of counting matches and obsessing about \"The People\'s Court\" like Dustin Hoffman\'s \"Rain Man\" character, Brian counts sunflower seeds and obsesses over going to \"the Baywatch.\" Cameos from Pacino, Christopher Walken as a detective and Lainie Kazan as Gigli\'s mother don\'t help, either. Did they owe someone a favor? What are they doing here? Pacino won his one and only Oscar with Brest for 1992\'s \"Scent of a Woman,\" but couldn\'t he have just thanked the director instead? Instead, we get to see Pacino shoot someone in the head, then watch as fish in a nearby aquarium snack on splattered drops of the victim\'s blood."
    ##########
    # to do: strip ascii etc?
    # connect to rosette 
    if not rosette:
        rosette = API(user_key=args.key)
        params = DocumentParameters()
    # send the text
    params['content'] = sText
    jResponse = rosette.entities(params)  # entity linking is turned off
    print json.dumps(jResponse, sort_keys=True, indent=4, separators=(',', ': '))
    jResponse = rosette.sentiment(params)  # entity linking is turned off
    print json.dumps(jResponse, sort_keys=True, indent=4, separators=(',', ': '))
     
    print "trytext.py: done"
Пример #3
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"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."
    return api.entities(params, True)  # entity linking is turned on
Пример #4
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)
    entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS"
    params = DocumentParameters()
    params["content"] = entities_text_data
    return api.entities(params)  # entity linking is turned off
Пример #5
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)
    entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS"
    params = DocumentParameters()
    params["content"] = entities_text_data
    params["genre"] = "social-media"
    return api.entities(params)
Пример #6
0
class RosetteWrapper(generic_vendor.VendorWrapper):
    def __init__(self, settings):
        self.client = API(user_key=settings['api_key'])

    def call_api(self, content):
        params = DocumentParameters()
        params["content"] = content[0:49999]  # truncate to first 50000 chars
        res = {}
        try:
            res = self.client.entities(params)
        except RosetteException as exception:
            print(exception)
            res = {"rosette_exception": str(exception)}
        return json.dumps(res, sort_keys=True, indent=4)

    def report(self, response_file_name, metadata):
        response = self.load_response_json(response_file_name)
        response_with_confidence = {
            'entities': [
                entity for entity in response['entities']
                if 'confidence' in entity
            ]
        }
        response_with_confidence['entities'].sort(
            key=lambda x: x['confidence'], reverse=True)
        response_without_confidence = {
            'entities': [
                entity for entity in response['entities']
                if 'confidence' not in entity
            ]
        }
        response_without_confidence['entities'].sort(key=lambda x: x['count'],
                                                     reverse=True)

        report = self.base_report(response_file_name)
        report['entities'] = self.feature_report(
            response_with_confidence, 'entities',
            lambda e: e['normalized'] + ' (' + e['type'] + ')', metadata,
            lambda e: e['normalized'])
        report[
            'entities_without_confidence_information'] = self.feature_report(
                response_with_confidence, 'entities',
                lambda e: e['normalized'] + ' (' + e['type'] + ')')

        entity_types_of_interest = [
            'LOCATION', 'PERSON', 'TEMPORAL:DATE', 'ORGANIZATION'
        ]
        for entity_type in entity_types_of_interest:
            entities = [
                entity for entity in response['entities']
                if entity['type'] == entity_type
            ]
            report['entities'][entity_type + ' examples'] = [
                e['normalized'] for e in entities
            ][0:19]

        return report
Пример #7
0
def run(key, altUrl='https://api.rosette.com/rest/v1/'):
    # Create an API instance
    api = API(user_key=key, service_url=altUrl)

    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."
    params = DocumentParameters()
    params["content"] = entities_linked_text_data
    params["genre"] = "social-media"
    # This syntax is deprecated, call api.entities(params)
    return api.entities(params, True)
Пример #8
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)
    entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit.  Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel.  In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."
    params = DocumentParameters()
    params["content"] = entities_text_data
    params["genre"] = "social-media"
    try:
        return api.entities(params)
    except RosetteException as exception:
        print(exception)
Пример #9
0
def entities(text, alt_url='https://api.rosette.com/rest/v1/'):
    """ Run the example """
    # Create an API instance
    key = 'Your rosette api key'  # Create your api key though url https://www.rosette.com/
    api = API(user_key=key, service_url=alt_url)

    params = DocumentParameters()
    params["content"] = text
    params["genre"] = "social-media"
    try:
        return api.entities(params)
    except RosetteException as exception:
        print(exception)
Пример #10
0
def run(url,
        key="ec7cdb76e8130367aa00c17cc2bcc3d7",
        alt_url='https://api.rosette.com/rest/v1/'):
    """ Run the example """
    #categories_url_data = "https://www.nytimes.com/2018/06/26/business/trump-harley-davidson-tariffs.html?smtyp=cur&smid=tw-nytimes"
    #url = categories_url_data
    # Create an API instance
    api = API(user_key=key, service_url=alt_url)
    params = DocumentParameters()

    # Use a URL to input data instead of a string
    params["contentUri"] = url
    try:
        return api.entities(params)
    except RosetteException as exception:
        print(exception)
Пример #11
0
def get_wol(wol, key=user_key, alt_url=ros_url):
    lst = wol.split("|")
    lst.sort(key=lambda a: len(a))
    api = API(user_key=user_key, service_url=alt_url)
    params = DocumentParameters()
    params["language"] = "eng"
    rtotal = []
    for line in lst:
        params["content"] = line
        json_obj = json.loads(json.dumps(api.entities(params, True), indent=2, ensure_ascii=False))
        if json_obj["entities"] and len(rtotal) < 4:
            rtotal.append(line)
    result = "<ul> "
    for x in lst:
        result += "<li>" + x + "</li>"
    result += "</ul>"
    return result
Пример #12
0
Файл: tt.py Проект: OmkarB/pecan
def proper_key_words(key_word, key=user_key, alt_url=ros_url):
    # Create an API instance
    api = API(user_key=key, service_url=alt_url)

    params = NameMatchingParameters()
    params['name1'] = key_word
    max = ['error', 0]
    for x in wikipedia.search(key_word):
        params["name2"] = x
        val = json.loads(json.dumps(api.matched_name(params), indent=2,
                                    ensure_ascii=False))['result']['score'] > max[1]
        if val > max[1]:
            max = [x, val]
    params = DocumentParameters()
    params['content'] = wikipedia.summary(max[0])
    json_obj = json.loads(json.dumps(api.entities(params), indent=2, ensure_ascii=False,
                                     sort_keys=True))
    return parse_with_queue(json_obj, key_word)
Пример #13
0
def test_just_text():
    endpoints = ["categories", "entities", "entities/linked", "language", "matched-name", "morphology-complete",
                 "sentiment", "translated-name", "relationships"]
    expected_status_filename = response_file_dir + "eng-sentence-entities.status"
    expected_output_filename = response_file_dir + "eng-sentence-entities.json"
    for rest_endpoint in endpoints:
        httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/" + rest_endpoint,
                               status=get_file_content(expected_status_filename),
                               body=get_file_content(expected_output_filename),
                               content_type="application/json")

    with open(expected_output_filename, "r") as expected_file:
        expected_result = json.loads(expected_file.read())

    # need to mock /info call too because the api will call it implicitly
    with open(response_file_dir + "info.json", "r") as info_file:
        body = info_file.read()
        httpretty.register_uri(httpretty.GET, "https://api.rosette.com/rest/v1/info",
                               body=body, status=200, content_type="application/json")
        httpretty.register_uri(httpretty.POST, "https://api.rosette.com/rest/v1/info",
                               body=body, status=200, content_type="application/json")

    api = API("0123456789")

    content = "He also acknowledged the ongoing U.S. conflicts in Iraq and Afghanistan, noting that he is the \"commander in chief of a country that is responsible for ending a war and working in another theater to confront a ruthless adversary that directly threatens the American people\" and U.S. allies."

    result = api.entities(content)
    # Check that it work for entities
    assert result == expected_result

    # Check that it throws the correct error for matched-name
    try:
        api.matched_name(content)
        assert False
    except RosetteException as e:
        assert e.status == "incompatible"

    # Check that it throws the correct error for translated-name
    try:
        api.translated_name(content)
        assert False
    except RosetteException as e:
        assert e.status == "incompatible"
Пример #14
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)

    # Set selected API options.
    # For more information on the functionality of these
    # and other available options, see Rosette Features & Functions
    # https://developer.rosette.com/features-and-functions#entity-extraction-and-linking

    # api.set_option('calculateSalience','true')
    # api.set_option('linkEntities','false')

    entities_text_data = "The Securities and Exchange Commission today announced the leadership of the agency’s trial unit.  Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency’s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel.  In that role, they were jointly responsible for supervising the trial unit at the agency’s Washington D.C. headquarters as well as coordinating with litigators in the SEC’s 11 regional offices around the country."
    params = DocumentParameters()
    params["content"] = entities_text_data
    params["genre"] = "social-media"
    try:
        return api.entities(params)
    except RosetteException as exception:
        print(exception)
Пример #15
0
    def run(self, txtfile, alt_url='https://api.rosette.com/rest/v1/'):
        """
        Set up connection to the API and receives the founded entities.
        :param txtfile: Name of the file with scraped text.
        :return: entities in JSON format.
        """
        # Create an API instance
        print self.key
        api = API(user_key=self.key, service_url=alt_url)

        lines = ""
        f = open(txtfile)
        for x, y in enumerate(f):
            if y.__contains__("."):
                lines = lines + str(y)
        f.close()
        params = DocumentParameters()
        params["content"] = lines
        try:
            return api.entities(params)
        except RosetteException as exception:
            print(exception)
Пример #16
0
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
Пример #17
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)

    # Set selected API options.
    # For more information on the functionality of these
    # and other available options, see Rosette Features & Functions
    # https://developer.rosette.com/features-and-functions#entity-extraction-and-linking

    # api.set_option('calculateSalience','true')
    # api.set_option('linkEntities','false')

    entities_text_data = (
        "Charlene and Bruce Olson\[email protected]\[email protected]\n11004 Territorial Dr, Burnsville, MN 55337, "
        "USA\n612-501-6937\n\n8-10 am arrival time\n\n$160 plus tax for the interior and exterior panes of glass as well as the "
        "screens and sills\n\n------\n$160 plus tax = $172.44\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWindow Cleaning\nFri, "
        "Mar 10 at 09:00 AM (4 hours)\n<A href='http://maps.google.com/?q=11004%20Territorial%20Drive%0ABurnsville,mn%2055337' "
        "target='_blank'>Appointment will be held at: 11004 Territorial Drive\nBurnsville,mn 55337</A>\nNotes\t\t\t\tYou did a "
        "fantastic job last time!  We are putting our house on the market on Monday the 13th so would really appreciate clean "
        "windows!\n\n\nTo make changes to the appointment, please follow this link: "
        "https://www.vcita.com/engagements/haq8bbncx10tsxr8?meeting_action=view&meeting_id=4029aac71f39f3ab&email_token"
        "=37348fc469f7a82fe17b&from_email=true&owner=true&flow=Email_Action&flow_origin=accepted_notification&flow_action"
        "=view_appointment\n\n\nFull details on Charlene Olson, Click Here: https://www.vcita.com/clients/?client=o2pun84hy2c31eb8&flow"
        "=Email_Action&flow_origin=accepted_notification&flow_action=view_contact_details#/o2pun84hy2c31eb8\nEmail\t"
        "\t\t\[email protected], Click Here: mailto:[email protected]\nPhone\t\t\t\t612-501-6937\nAddress\t\t\t\t<A "
        "href='http://maps.google.com/?q=11004%20Territorial%20Drive%0ABurnsville,mn%2055337' target='_blank'>"
        "11004 Territorial Drive\nBurnsville,mn 55337</A>\nGender\t\t\t\tFemale\nSource\t\t\t\tLiveSite Widget\n"
        "Facebook Profile, Click Here: https://www.facebook.com/charlene.olson.35\n|"
    )
    params = DocumentParameters()
    params["content"] = entities_text_data
    params["genre"] = "social-media"
    try:
        return api.entities(params)
    except RosetteException as exception:
        print(exception)
Пример #18
0
def main(argv):

    parser = argparse.ArgumentParser(
        description='Template for storing/analyzing responses from Rosette APIs'
    )
    parser.add_argument('-k', '--key', required=True, help="rosette api key")
    args = parser.parse_args()

    # initialize
    rosette = ""

    print "trytext.py: starting up..."

    ##########
    # extract text from the file
    sText = "\"Gigli\" -- which spawned the phenomenon the gossip pages and celebrity magazines so lovingly refer to as \"Bennifer\" -- is every bit as unwatchable as the deafening negative chatter would suggest. The dialogue from writer-/sdirector Martin Brest is clunky, the film has serious tonal inconsistencies and at more than two hours, it drags on way longer than it should. Even making a little game of it, and trying to pinpoint the exact moment when Ben Affleck and Jennifer Lopez fell in love, stops being fun after a while. Perhaps it\'s when he says, in an attempt to seduce her, \"I\'m the bull, you\'re the cow.\" Or when she beckons him into foreplay by lying back in bed and purring, \"Gobble, gobble\" -- which could forever change the way you view your Thanksgiving turkey. But as pop-star vehicles go, \"Gigli\" isn\'t as insufferable as, say, last year\'s Madonna-Guy Ritchie debacle, \"Swept Away.\" It\'s more on par with Mariah Carey\'s \"Glitter\" and Britney Spears\' \"Crossroads.\" If this were a movie starring two B-list actors, or two complete unknowns, it probably would have gone straight to video. After curious masochists and J.Lo fans check it out the first weekend, \"Gigli\" probably will have a drop-off in audience that rivals \"The Hulk\" -- 70 percent -- then go to video. And with the release next spring of Kevin Smith\'s \"Jersey Girl,\" in which they also co-star, we can have this little conversation all over again. For now, we have Affleck starring as incompetent mob thug Larry Gigli. (That\'s pronounced JEE-lee, which rhymes with really, a running joke that isn\'t particularly funny the first time.) Gigli is asked to kidnap Brian (Justin Bartha), the mentally disabled younger brother of a/sfederal prosecutor who\'s going after a New York mobster (Al Pacino). His boss, however, thinks he\'s incapable of handling the assignment alone and sends in Ricki (Lopez), another contractor, to help him. Gigli is an anti-social lout who lives in a seedy apartment. Ricki is beautiful, grounded, enlightened. She quotes Sun Tzu -- who could blame Gigli for falling for her? (And whether you like her or not, Lopez does have an undeniable presence.) But Ricki is also a lesbian -- so it makes absolutely no sense when she falls for him, too, although they have all the obligatory banter and alleged sexual tension required of a romantic comedy. (And it\'s only a romantic comedy sometimes. Other times, it aims to be an edgy action-crime movie; still other times, it aspires for gag-inducing poignancy.) Apparently, the only force that binds them is the fact that they both feel squeamish about cutting off Brian\'s thumb and mailing it to his prosecutor brother. Instead, they break into a morgue and saw the thumb off a corpse using a plastic knife, while Brian -- who has an unexplained penchant for old-school rap -- sings Sir Mix-a-Lot\'s \"Baby Got Back.\" It\'s also incredibly misinformed to suggest that Ricki can be \"converted\" to heterosexuality -- that a man\'s love is all she really needed to allay any confusion about all that silly lesbian stuff. So what you have here is \"Rain Man\" meets \"Chasing Amy\" -- which is apropos, since the latter is a 1997 Kevin Smith movie in which Affleck also starred as a guy who falls for a lesbian. Instead of counting matches and obsessing about \"The People\'s Court\" like Dustin Hoffman\'s \"Rain Man\" character, Brian counts sunflower seeds and obsesses over going to \"the Baywatch.\" Cameos from Pacino, Christopher Walken as a detective and Lainie Kazan as Gigli\'s mother don\'t help, either. Did they owe someone a favor? What are they doing here? Pacino won his one and only Oscar with Brest for 1992\'s \"Scent of a Woman,\" but couldn\'t he have just thanked the director instead? Instead, we get to see Pacino shoot someone in the head, then watch as fish in a nearby aquarium snack on splattered drops of the victim\'s blood."
    ##########
    # to do: strip ascii etc?
    # connect to rosette
    if not rosette:
        rosette = API(user_key=args.key)
        params = DocumentParameters()
    # send the text
    params['content'] = sText
    jResponse = rosette.entities(params)  # entity linking is turned off
    print json.dumps(jResponse,
                     sort_keys=True,
                     indent=4,
                     separators=(',', ': '))
    jResponse = rosette.sentiment(params)  # entity linking is turned off
    print json.dumps(jResponse,
                     sort_keys=True,
                     indent=4,
                     separators=(',', ': '))

    print "trytext.py: done"
Пример #19
0
# -*- coding: utf-8 -*-

"""
Example code to call Rosette API to get entities from a piece of text.
"""

import argparse
import pprint

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get the entities 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"""President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill
based on Christian faith by July 1st or Washington will become totally dysfunctional,
a terrible outcome for American people."""
result = api.entities(params)  # entity linking is turned off

pprint.pprint(result)
Пример #20
0
# -*- coding: utf-8 -*-

"""
Example code to call Rosette API to get linked (against Wikipedia) entities from a piece of text.
"""

import argparse
import pprint

from rosette.api import API, DocumentParameters

parser = argparse.ArgumentParser(description="Get linked entities 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"""President Obama urges the Congress and Speaker Boehner to pass the $50 billion spending bill
        based on Christian faith by July 1st or Washington will become totally dysfunctional,
        a terrible outcome for American people."""
result = api.entities(params, True)  # entity linking is turned on

pprint.pprint(result)
Пример #21
0
 # if no existing response file...
 if not os.path.isfile(sResponseFile):
     # send to Rosette...
     print "enrich.py: sending text to Rosette API..."
     # extract text from the file
     sText = ""
     for field in args.fieldlist:
         sText = sText + jInput[field] + ' '
     # to do: strip ascii etc?
     # connect to rosette
     if not rosette:
         rosette = API(user_key=args.key)
         params = DocumentParameters()
     # send the text
     params['content'] = sText
     jResponse = rosette.entities(
         params)  # entity linking is turned off
     # write out the response
     print "enrich.py: writing response:", sResponseFile
     try:
         fr = open(sResponseFile, 'w')
     except Exception, e:
         print "enrich.py: error creating:", e
         f.close()
         continue
     try:
         json.dump(jResponse,
                   fr,
                   sort_keys=True,
                   indent=4,
                   separators=(',', ': '))
     except Exception, e:
Пример #22
0
 # if no existing response file...
 if not os.path.isfile(sResponseFile):
     # send to Rosette...
     print "enrich.py: sending text to Rosette API..."
     # extract text from the file
     sText = ""
     for field in args.fieldlist:
         sText = sText + jInput[field] + ' '
     # to do: strip ascii etc?
     # connect to rosette 
     if not rosette:
         rosette = API(user_key=args.key)
         params = DocumentParameters()
     # send the text
     params['content'] = sText
     jResponse = rosette.entities(params)  # entity linking is turned off
     # write out the response
     print "enrich.py: writing response:", sResponseFile
     try:
         fr = open(sResponseFile, 'w')
     except Exception, e:
         print "enrich.py: error creating:", e
         f.close()
         continue
     try:
         json.dump(jResponse,fr, sort_keys=True, indent=4, separators=(',', ': '))
     except Exception, e:
         print "enrich.py: error writing:", e
         fr.close()
         f.close()
         continue