Ejemplo n.º 1
0
def determine_matching_similarity(question_word, candidate, is_question_entity=False):
	if is_question_entity:
		matching_similarity = question_word['link_probability']
		return matching_similarity
	else:
		matching_similarity = spacy.similarity_word2vec(question_word, candidate['label'])
		return matching_similarity
Ejemplo n.º 2
0
def determine_matching_similarity(question_word, candidate, is_question_entity=False):
	if is_question_entity:
		matching_similarity = question_word['link_probability']
		return matching_similarity
	else:
		if not candidate['label']:
			return 0
		label = wd.wikidata_id_to_label(candidate['label'])

		matching_similarity = spacy.similarity_word2vec(question_word, label)
		return matching_similarity
Ejemplo n.º 3
0
def answer_complete_question(question, tagmeToken):
	entities = tagme_get_all_entities(question, tagmeToken) 
	highest_matching_similarity = -1
	for entity in entities:
		shortened_question = string.shorten_question_for_predicate_similarity(question, entity['spot'])
		statements = wd.get_all_statements_of_entity(entity['wikidata_id'])
		for statement in statements:
			# no identifier predicates
			if statement['predicate']['id'] in identifier_predicates:
				continue
			predicate_label 	= wd.wikidata_id_to_label(statement['predicate']['id'])
			matching_similarity = spacy.similarity_word2vec(predicate_label, shortened_question) * entity['link_probability']
			if highest_matching_similarity == -1 or matching_similarity > highest_matching_similarity:
				answer 		= statement['entity']['id'] if statement['object']['id'] == entity['wikidata_id'] else statement['object']['id']
				context 	= {'entity': {'id': entity['wikidata_id']}, 'predicate': {'id': statement['predicate']['id']}, 'object': {'id': answer}}
				result 		= {'context': context, 'answers': [{'answer': answer, 'rank': 1}] }
				highest_matching_similarity = matching_similarity
	return result