示例#1
0
def fetchConceptsForUserConcept(institution, token, cutoff=0.5):
	"""
	Given a user-defined concept name and an access token this function returns the dictionary model for the given raw concept.
	This method is called as a part of processing on user input during registration.
	The top-scoring result of a call to annotateText *should*, in ordinary cases, correspond with the article-name of the concept.
	This result is then run through event_insight_lib.fetchRelatedConcepts().
	"""
	# Fetch the precise name of the node (article title) associated with the institution.
	_concept_node = event_insight_lib.annotateText(institution, token)
	# If the correction call is successful, keep going.
	if 'annotations' in _concept_node.keys() and len(_concept_node['annotations']) != 0:
		_concept_node_title = _concept_node['annotations'][0]['concept']['label']
		_related_concepts = event_insight_lib.fetchRelatedConcepts(_concept_node_title, token)
		return parseRawConceptCall(_related_concepts, cutoff)
	# Otherwise, if the call was not successful, return a None flag.
	else:
		return None
	def addUserInputToConceptModel(self, user_input, cutoff=0.2):
		"""
		This method attempts to resolve user input (`input`) into a list of related concepts.
		At issue is the fact that user input has to be resolved somehow to the name of the nearest Wikipedia article, not always easy.
		In cases where this is not possible, this method will return a False flag.
		In cases where this happens as desired, this method will return a True flag.
		"""
		# Fetch the precise name of the node (article title) associated with the institution.
		concept_node = event_insight_lib.annotateText(user_input, backend.getToken())
		# If the correction call is successful, keep going.
		if 'annotations' in concept_node.keys() and len(concept_node['annotations']) != 0:
			concept_node_title = concept_node['annotations'][0]['concept']['label']
			related_concepts = event_insight_lib.fetchRelatedConcepts(concept_node_title, backend.getToken())
			model = backend.parseRawConceptCall(related_concepts, cutoff)
			new_concept_model = ConceptModel(model=model, maturity=1)
			self.iterateModel(new_concept_model)
			return True
		# Otherwise, if the call was not successful, return a False flag.
		else:
			return None