def ontology_words_mapping(sentence):
	# simple preprocessing of utterance substitution of key words, phrases and compound words
	G = kb_services.load_semantic_network()
	language_info = kb_services.language_info()
	sentence = sentence.lower()
	# substitutes pronoun me for speaker (later should use contextual info of robot, who is talking?)
	sentence = re.sub(' me ', ' speaker ', sentence)
	sentence = re.sub('\?', ' ?', sentence)
	sentence = re.sub('pick up ', 'take ', sentence)

	sentence = re.sub('  ', ' ', sentence)
	sentence = re.sub('\.', '', sentence)
	sentence = re.sub(', ', ' ', sentence)

	sentence = re.sub(' $', '', sentence)

	sentence = re.sub(' one ', ' 1 ', sentence)
	sentence = re.sub(' two ', ' 2 ', sentence)
	sentence = re.sub(' three ', ' 3 ', sentence)
	sentence = re.sub(' four ', ' 4 ', sentence)
	sentence = re.sub(' five ', ' 5 ', sentence)

	sentence = re.sub(' other ', ' ', sentence)


	sentence = re.sub(' that is ', ' that_is ', sentence)
	sentence = re.sub(' from ', ' that_is above ', sentence)
	sentence = re.sub(' from top of ', ' that_is above ', sentence)
	sentence = re.sub(' placed on ', ' that_is above ', sentence)
	sentence = re.sub(' off ', ' that_is above ', sentence)
	
	sentence = re.sub(' which is ', ' that_is ', sentence)

	sentence = re.sub(' exactly down', ' down', sentence)

	sentence = re.sub(' most left ', ' leftmost ', sentence)

	# declaration of classes and objects
	sentence = re.sub('((is)|(are)) ((an object of)|(an instance of)|(an adjetive of))( a)? ', 'is is_object_of ', sentence)
	sentence = re.sub('((is)|(are)) ((a kind of)|(a sort of)) ', 'is is_kind_of ', sentence)
	# simple from of verbs
	sentence = re.sub(' ((is)|(are)) ', ' is ', sentence)
	# transform plural into singular
	#for each in language_info['noun']:
	#	plural = derive_plural(each)
	#	sentence = re.sub(plural, each, sentence)
	# unite compound words
	compound_words = kb_services.compound_words(G)
	for each in compound_words:
		test = re.sub('_', ' ', each)
		sentence = re.sub(test, each, sentence)

	#print "de aqui debo sustituir aka: ", sentence
	words = sentence.split(' ')
	new_sentence = []
	for each in words:
		new_sentence.append(kb_services.find_original_aka(G, each))

	new_sentence = " ".join(new_sentence)
	return new_sentence
示例#2
0
def pos_tagger(G, sentence):
	# loads dictionary with language information given in ontologies
	language_info = kb_services.language_info()
	# brake sentence into words
	words = sentence.split(' ')
	tags = []
	# for each word look for all pos tags it has
	for w in words:
		tags.append(look_tags(language_info, w))
	
	ranked_disambiguated_tags = disambiguate_pos(G, words, tags)
	print "pos tags: ", ranked_disambiguated_tags
	return words, ranked_disambiguated_tags
示例#3
0
def pos_tagger(G, sentence):
    # loads dictionary with language information given in ontologies
    language_info = kb_services.language_info()
    # brake sentence into words
    words = sentence.split(' ')
    tags = []
    # for each word look for all pos tags it has
    for w in words:
        tags.append(look_tags(language_info, w))

    ranked_disambiguated_tags = disambiguate_pos(G, words, tags)
    #print ranked_disambiguated_tags
    return words, ranked_disambiguated_tags
示例#4
0
def ontology_words_mapping(sentence):
    # simple preprocessing of utterance substitution of key words, phrases and compound words
    G = kb_services.load_semantic_network()
    language_info = kb_services.language_info()
    sentence = sentence.lower()
    # substitutes pronoun me for speaker (later should use contextual info of robot, who is talking?)
    sentence = re.sub(' me ', ' speaker ', sentence)
    sentence = re.sub('\?', ' ?', sentence)
    sentence = re.sub('pick up ', 'take ', sentence)

    sentence = re.sub('  ', ' ', sentence)
    sentence = re.sub('\.', '', sentence)
    sentence = re.sub(', ', ' ', sentence)

    sentence = re.sub(' $', '', sentence)

    sentence = re.sub(' one ', ' 1 ', sentence)
    sentence = re.sub(' two ', ' 2 ', sentence)
    sentence = re.sub(' three ', ' 3 ', sentence)
    sentence = re.sub(' four ', ' 4 ', sentence)
    sentence = re.sub(' five ', ' 5 ', sentence)

    sentence = re.sub(' other ', ' ', sentence)

    sentence = re.sub(' that is ', ' that_is ', sentence)
    sentence = re.sub(' from ', ' that_is above ', sentence)
    sentence = re.sub(' from top of ', ' that_is above ', sentence)
    sentence = re.sub(' placed on ', ' that_is above ', sentence)
    sentence = re.sub(' off ', ' that_is above ', sentence)

    sentence = re.sub(' which is ', ' that_is ', sentence)

    sentence = re.sub(' exactly down', ' down', sentence)

    sentence = re.sub(' most left ', ' leftmost ', sentence)

    # declaration of classes and objects
    sentence = re.sub(
        '((is)|(are)) ((an object of)|(an instance of)|(an adjetive of))( a)? ',
        'is is_object_of ', sentence)
    sentence = re.sub('((is)|(are)) ((a kind of)|(a sort of)) ',
                      'is is_kind_of ', sentence)
    # simple from of verbs
    sentence = re.sub(' ((is)|(are)) ', ' is ', sentence)
    # transform plural into singular
    #for each in language_info['noun']:
    #	plural = derive_plural(each)
    #	sentence = re.sub(plural, each, sentence)
    # unite compound words
    compound_words = kb_services.compound_words(G)
    for each in compound_words:
        test = re.sub('_', ' ', each)
        sentence = re.sub(test, each, sentence)

    #print "de aqui debo sustituir aka: ", sentence
    words = sentence.split(' ')
    new_sentence = []
    for each in words:
        new_sentence.append(kb_services.find_original_aka(G, each))

    new_sentence = " ".join(new_sentence)
    return new_sentence
def ontology_words_mapping(sentence):
	# simple preprocessing of utterance substitution of key words, phrases and compound words
	G = kb_services.load_semantic_network()
	language_info = kb_services.language_info()
	sentence = sentence.lower()
	# substitutes pronoun me for speaker (later should use contextual info of robot, who is talking?)
	#sentence = re.sub(' me ', ' speaker ', sentence)
	sentence = re.sub('\?', ' ?', sentence)
	sentence = re.sub('pick up ', 'take ', sentence)
        sentence = re.sub('-', '_', sentence)

	sentence = re.sub('  ', ' ', sentence)
	sentence = re.sub('\.', '', sentence)
	sentence = re.sub(', ', ' ', sentence)

	sentence = re.sub(' $', '', sentence)
        sentence = re.sub("'", ' ', sentence)


	sentence = re.sub(' one ', ' 1 ', sentence)
	sentence = re.sub(' two ', ' 2 ', sentence)
	sentence = re.sub(' three ', ' 3 ', sentence)
	sentence = re.sub(' four ', ' 4 ', sentence)
	sentence = re.sub(' five ', ' 5 ', sentence)

	sentence = re.sub(' other ', ' ', sentence)

	sentence = re.sub(' person ', ' man ', sentence)

	sentence = re.sub(' which is ', ' that_is ', sentence)

	sentence = re.sub(' exactly down', ' down', sentence)

	sentence = re.sub('search for ', 'search_for ', sentence)

	sentence = re.sub('look for', 'look_for', sentence)
	sentence = re.sub('middle bottom', 'middle_bottom', sentence)

        #Montral special objects names
        sentence = re.sub('bathroom s cabinet', 'bathroom_s_cabinet', sentence)


	
	sentence = re.sub('(could|can|would) you (please )?(robot )?', '', sentence)
	sentence = re.sub('please (robot )?', '', sentence)
	
	# declaration of classes and objects
	sentence = re.sub('((is)|(are)) ((an object of)|(an instance of)|(an adjetive of))( a)? ', 'is is_object_of ', sentence)
	sentence = re.sub('((is)|(are)) ((a kind of)|(a sort of)) ', 'is is_kind_of ', sentence)
	# simple from of verbs
	sentence = re.sub(' ((is)|(are)) ', ' is ', sentence)
	# transform plural into singular
	#for each in language_info['noun']:
	#	plural = derive_plural(each)
	#	sentence = re.sub(plural, each, sentence)
	# unite compound words
	compound_words = kb_services.compound_words(G)
	#print "compound nons :  ", compound_words
	for each in compound_words:
		test = re.sub('_', ' ', each)
		sentence = re.sub(test, each, sentence)

	#print "de aqui debo sustituir aka: ", sentence
	words = sentence.split(' ')
	new_sentence = []
	for each in words:
		new_sentence.append(kb_services.find_original_aka(G, each))
		#print "palabra: ",each, " se sustituye por:  ", kb_services.find_original_aka(G, each)

	new_sentence = " ".join(new_sentence)
	return new_sentence
def ontology_words_mapping(sentence):
	# simple preprocessing of utterance substitution of key words, phrases and compound words
	G = kb_services.load_semantic_network()
	language_info = kb_services.language_info()
	sentence = sentence.lower()
	# substitutes pronoun me for speaker (later should use contextual info of robot, who is talking?)
	#sentence = re.sub(' me ', ' speaker ', sentence)
	sentence = re.sub('\?', ' ?', sentence)
	sentence = re.sub('pick up ', 'take ', sentence)
	sentence = re.sub('robot ', '', sentence)


	sentence = re.sub('  ', ' ', sentence)
	sentence = re.sub('\.', '', sentence)
	sentence = re.sub(', ', ' ', sentence)

	sentence = re.sub(' $', '', sentence)


	sentence = re.sub(' one ', ' 1 ', sentence)
	sentence = re.sub(' two ', ' 2 ', sentence)
	sentence = re.sub(' three ', ' 3 ', sentence)
	sentence = re.sub(' four ', ' 4 ', sentence)
	sentence = re.sub(' five ', ' 5 ', sentence)

	sentence = re.sub(' other ', ' ', sentence)

	sentence = re.sub(' person ', ' man ', sentence)

	sentence = re.sub(' which is ', ' that_is ', sentence)

	sentence = re.sub(' exactly down', ' down', sentence)

	sentence = re.sub('search for', 'search_for', sentence)

	sentence = re.sub('look for', 'look_for', sentence)

	sentence = re.sub('go out', 'go_out', sentence)

	sentence = re.sub('get into', "get_into", sentence)

	sentence = re.sub("searches for", "searches_for", sentence)
	sentence = re.sub("pick up", "pick_up", sentence)
	sentence = re.sub("right of", "right_of", sentence)
	sentence = re.sub("left of", "left_of", sentence)
	sentence = re.sub("bring up", "bring_up", sentence)

	sentence = re.sub("right of", "right_of", sentence)
	sentence = re.sub("right of the", "right_of", sentence)
	sentence = re.sub("near of", "near_of", sentence)
	sentence = re.sub("near of the", "near_of", sentence)
	sentence = re.sub("left of", "left_of", sentence)
	sentence = re.sub("left of the", "left_of", sentence)
	sentence = re.sub("in front of", "in_front_of", sentence)
	sentence = re.sub("in front of the", "in_front_of", sentence)
	sentence = re.sub("in front", "in_front", sentence)
	sentence = re.sub("to the front of", "in_front_of", sentence)
	sentence = re.sub("to the front of the", "in_front_of", sentence)
	sentence = re.sub("behind of", "behind_of", sentence)
	sentence = re.sub("behind of the", "behind_of", sentence)
	sentence = re.sub("next to", "next_to", sentence)
	sentence = re.sub("next to the", "next_to", sentence)

	sentence = re.sub("i want", "next_to", sentence)
	sentence = re.sub("i need", "next_to", sentence)
	sentence = re.sub("next to the", "next_to", sentence)

	sentence = re.sub("bottle of", "bottle", sentence)
	#sentence = re.sub("follow me", "follow_me", sentence)

	sentence = re.sub("at corner", "at_corner", sentence)
	sentence = re.sub("at corner of", "at_corner_of", sentence)
	sentence = re.sub("at end", "at_end", sentence)
	sentence = re.sub("at end of", "at_end_of", sentence)
	
	sentence = re.sub('(could|can|would) you (please )?(robot )?', '', sentence)
	#sentence = re.sub('', '', sentence)

	sentence = re.sub('please (robot )?', '', sentence)
	
	# declaration of classes and objects
	sentence = re.sub('((is)|(are)) ((an object of)|(an instance of)|(an adjetive of))( a)? ', 'is is_object_of ', sentence)
	sentence = re.sub('((is)|(are)) ((a kind of)|(a sort of)) ', 'is is_kind_of ', sentence)
	# simple from of verbs
	sentence = re.sub(' ((is)|(are)) ', ' is ', sentence)
	# transform plural into singular
	#for each in language_info['noun']:
	#	plural = derive_plural(each)
	#	sentence = re.sub(plural, each, sentence)
	# unite compound words
	compound_words = kb_services.compound_words(G)
	#print "compound nons :  ", compound_words
	for each in compound_words:
		test = re.sub('_', ' ', each)
		sentence = re.sub(test, each, sentence)

	#print "de aqui debo sustituir aka: ", sentence
	words = sentence.split(' ')
	new_sentence = []
	for each in words:
		new_sentence.append(kb_services.find_original_aka(G, each))
		#print "palabra: ",each, " se sustituye por:  ", kb_services.find_original_aka(G, each)

	new_sentence = " ".join(new_sentence)
	return new_sentence
def ontology_words_mapping(sentence):
    # simple preprocessing of utterance substitution of key words, phrases and compound words
    G = kb_services.load_semantic_network()
    language_info = kb_services.language_info()
    sentence = sentence.lower()
    # substitutes pronoun me for speaker (later should use contextual info of robot, who is talking?)
    #sentence = re.sub(' me ', ' speaker ', sentence)
    sentence = re.sub('\?', ' ?', sentence)
    sentence = re.sub('pick up ', 'take ', sentence)
    sentence = re.sub('robot ', '', sentence)

    sentence = re.sub('  ', ' ', sentence)
    sentence = re.sub('\.', '', sentence)
    sentence = re.sub(', ', ' ', sentence)

    sentence = re.sub(' $', '', sentence)

    sentence = re.sub(' one ', ' 1 ', sentence)
    sentence = re.sub(' two ', ' 2 ', sentence)
    sentence = re.sub(' three ', ' 3 ', sentence)
    sentence = re.sub(' four ', ' 4 ', sentence)
    sentence = re.sub(' five ', ' 5 ', sentence)

    sentence = re.sub(' other ', ' ', sentence)

    sentence = re.sub(' person ', ' man ', sentence)

    sentence = re.sub(' which is ', ' that_is ', sentence)

    sentence = re.sub(' exactly down', ' down', sentence)

    sentence = re.sub('search for', 'search_for', sentence)

    sentence = re.sub('look for', 'look_for', sentence)

    sentence = re.sub('go out', 'go_out', sentence)

    sentence = re.sub('get into', "get_into", sentence)

    sentence = re.sub("searches for", "searches_for", sentence)
    sentence = re.sub("pick up", "pick_up", sentence)
    sentence = re.sub("right of", "right_of", sentence)
    sentence = re.sub("left of", "left_of", sentence)
    sentence = re.sub("bring up", "bring_up", sentence)

    sentence = re.sub("right of", "right_of", sentence)
    sentence = re.sub("right of the", "right_of", sentence)
    sentence = re.sub("near of", "near_of", sentence)
    sentence = re.sub("near of the", "near_of", sentence)
    sentence = re.sub("left of", "left_of", sentence)
    sentence = re.sub("left of the", "left_of", sentence)
    sentence = re.sub("in front of", "in_front_of", sentence)
    sentence = re.sub("in front of the", "in_front_of", sentence)
    sentence = re.sub("in front", "in_front", sentence)
    sentence = re.sub("to the front of", "in_front_of", sentence)
    sentence = re.sub("to the front of the", "in_front_of", sentence)
    sentence = re.sub("behind of", "behind_of", sentence)
    sentence = re.sub("behind of the", "behind_of", sentence)
    sentence = re.sub("next to", "next_to", sentence)
    sentence = re.sub("next to the", "next_to", sentence)

    sentence = re.sub("i want", "next_to", sentence)
    sentence = re.sub("i need", "next_to", sentence)
    sentence = re.sub("next to the", "next_to", sentence)

    sentence = re.sub("bottle of", "bottle", sentence)
    #sentence = re.sub("follow me", "follow_me", sentence)

    sentence = re.sub("at corner", "at_corner", sentence)
    sentence = re.sub("at corner of", "at_corner_of", sentence)
    sentence = re.sub("at end", "at_end", sentence)
    sentence = re.sub("at end of", "at_end_of", sentence)

    sentence = re.sub('(could|can|would) you (please )?(robot )?', '',
                      sentence)
    #sentence = re.sub('', '', sentence)

    sentence = re.sub('please (robot )?', '', sentence)

    # declaration of classes and objects
    sentence = re.sub(
        '((is)|(are)) ((an object of)|(an instance of)|(an adjetive of))( a)? ',
        'is is_object_of ', sentence)
    sentence = re.sub('((is)|(are)) ((a kind of)|(a sort of)) ',
                      'is is_kind_of ', sentence)
    # simple from of verbs
    sentence = re.sub(' ((is)|(are)) ', ' is ', sentence)
    # transform plural into singular
    #for each in language_info['noun']:
    #	plural = derive_plural(each)
    #	sentence = re.sub(plural, each, sentence)
    # unite compound words
    compound_words = kb_services.compound_words(G)
    #print "compound nons :  ", compound_words
    for each in compound_words:
        test = re.sub('_', ' ', each)
        sentence = re.sub(test, each, sentence)

    #print "de aqui debo sustituir aka: ", sentence
    words = sentence.split(' ')
    new_sentence = []
    for each in words:
        new_sentence.append(kb_services.find_original_aka(G, each))
        #print "palabra: ",each, " se sustituye por:  ", kb_services.find_original_aka(G, each)

    new_sentence = " ".join(new_sentence)
    return new_sentence