コード例 #1
0
def test_chunker():
	G = kb_services.load_semantic_network()
	#print G.nodes()
	sentence = "find the door on the right"
	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)

	words, ranked_tags = pos_tagger(G, sentence)	


	print words
	print ranked_tags[0]

	pp_interpretation = constituent_chunker(grammar_np_simple, words, ranked_tags[0])

	print "chunked words: ", pp_interpretation[1]

	print "noun phrases: ", pp_interpretation[2]

#test_ontology_word_mapping()
#test_pos()
#test_disambiguity()
#test_cyk()
#test_chunker()
コード例 #2
0
ファイル: parsing.py プロジェクト: rmartella/JUSTINA
def test_chunker():
    G = kb_services.load_semantic_network()
    #print G.nodes()
    sentence = "find the door on the right"
    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)

    words, ranked_tags = pos_tagger(G, sentence)

    print words
    print ranked_tags[0]

    pp_interpretation = constituent_chunker(grammar_np_simple, words,
                                            ranked_tags[0])

    print "chunked words: ", pp_interpretation[1]

    print "noun phrases: ", pp_interpretation[2]


#test_ontology_word_mapping()
#test_pos()
#test_disambiguity()
#test_cyk()
#test_chunker()
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
コード例 #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
コード例 #5
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(' $', '', 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
コード例 #6
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('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
コード例 #7
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('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