def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) params = RelationshipsParameters() params["content"] = u"Bill Murray is in the new Ghostbusters film!" params["options"] = {"accuracyMode": "PRECISION"} return api.relationships(params)
def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." params = DocumentParameters() params["content"] = relationships_text_data api.setOption('accuracyMode', 'PRECISION') return api.relationships(params)
def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) relationships_text_data = "The Ghostbusters movie was filmed in Boston." params = DocumentParameters() params["content"] = relationships_text_data api.setOption('accuracyMode', 'PRECISION') return api.relationships(params)
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) relationships_text_data = "FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC’s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR’s security cameras to the same government officials. At the time, Timms was the head of FLIR’s Middle East office in Dubai." params = DocumentParameters() params["content"] = relationships_text_data try: return api.relationships(params) except RosetteException as exception: print(exception)
def run(key, altUrl='https://api.rosette.com/rest/v1/'): # Create an API instance api = API(user_key=key, service_url=altUrl) relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." params = DocumentParameters() params["content"] = relationships_text_data api.setOption('accuracyMode', 'PRECISION') try: return api.relationships(params) except RosetteException as e: print(e)
def Analyse(self, message, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key="89350904c7392a44f0f9019563be727a", 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#morphological-analysis-introduction # Opening the ID Dictionary # load_dict() # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only params = DocumentParameters() relationships_text_data = message params["content"] = relationships_text_data rel = [] first_entity = None first_entity_id = None try: RESULT = api.relationships(params) try: #print(RESULT['relationships'][0]) first_entity = RESULT['relationships'][0]['arg1'] if message.find(RESULT['relationships'][0]['arg1']) < message.find(RESULT['relationships'][0]['arg2']) else RESULT['relationships'][0]['arg2'] first_entity_id = self.get_id(first_entity) first_entity = first_entity.split(" ") except: first_entity_id = -1 for r in RESULT['relationships']: arg2_split = r['arg2'].split(" ") confidence = '?' if "confidence" in r: confidence = str(round(r["confidence"],2)) if first_entity: if any(s in arg2_split for s in first_entity): if self.get_id(r['arg2']) == first_entity_id: rel.append({'Relationship':r['predicate']+'^-1', 'Subject':r['arg2'], 'Object':r['arg1'], 'Confidence': confidence}) rel.append({'Relationship':r['predicate'],'Subject':r['arg1'],'Object':r['arg2'], 'Confidence': confidence}) ## Closing the ID Dict self.save_dict() return rel, first_entity_id except RosetteException as exception: print(exception)
def Analyse(self, message, doc=None, lock=None, alt_url='https://api.rosette.com/rest/v1/'): """ Run the example """ # Create an API instance api = API(user_key="969b3593686184bb42803d8da453f119", 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#morphological-analysis-introduction # api.set_option('modelType','perceptron') #Valid for Chinese and Japanese only # Opening the ID Dictionary # load_dict() ### Will Close after Analysis of the document is completed if lock == None: lock = Lock() params = DocumentParameters() if doc: relationships_text_data = doc[:20000] else: relationships_text_data = wikipedia.page(message).content[:20000] params["content"] = relationships_text_data rel = [] message_id = self.get_id(message) message_split = message.split(" ") try: with lock: RESULT = api.relationships(params) for r in RESULT['relationships']: arg2_split = r['arg2'].split(" ") confidence = '?' if "confidence" in r: confidence = str(round(r["confidence"],2)) if any(s in arg2_split for s in message_split): if self.get_id(r['arg2']) == message_id: rel.append({'Relationship':r['predicate']+'^-1', 'Subject':r['arg2'], 'Object':r['arg1'], 'Confidence': confidence}) rel.append({'Relationship':r['predicate'],'Subject':r['arg1'],'Object':r['arg2'], 'Confidence': confidence}) ## Closing the ID Dict self.save_dict() ## return rel, message_id except RosetteException as exception: print(exception)
def Analyse(self): """ Run the example """ # Create an API instance api = API(user_key="969b3593686184bb42803d8da453f119", service_url='https://api.rosette.com/rest/v1/') # u = Utils() params = DocumentParameters() relationships_text_data = [] while True: try: relationships_text_data = wikipedia.page( self.message).content[:20000] break except wikipedia.DisambiguationError as e: print(self.eid, self.message) nameclash = True for n in e.options: if self.u.get_id(n) == self.eid: if n == self.message: pass else: self.message = n nameclash = False break if nameclash: self.message = " " except wikipedia.exceptions.PageError as e: self.error = self.u.id_to_name(self.eid) + " " + str(e) print(self.error) break try: params["content"] = relationships_text_data rel = [] message_id = self.u.get_id(self.message) message_split = self.message.split(" ") pred_list = [] RESULT = [] with self.lock: RESULT = api.relationships(params) args = ['arg1', 'arg2'] arg_to_split = 'arg2' if self.inverse else 'arg1' args.remove(arg_to_split) other_arg = args[0] rel_to_compare = self.relation.split("^-1")[0] for r in RESULT['relationships']: if r['predicate'] == rel_to_compare: arg_split = r[arg_to_split].split(" ") # Subject Split if any(s in arg_split for s in message_split): # Searching for alias names if self.u.get_id(r[arg_to_split]) == message_id: pred_list.append(r[other_arg]) self.q1.put(set(pred_list)) except RosetteException as exception: print(exception) self.error = exception self.q1.put(set(pred_list)) except Exception as e: print(e, self.message) self.error = e self.q1.put(set(pred_list))