def process_set(data): '''''' word=data["word"] pronunciation=data["pronunciation"] if pronunciation=="": pronunciation=None word_info=data["word_info"] #missingno import natlink result=0 if pronunciation==None: result=natlink.addWord(word, word_info) if result==0 and data["force"]==1: process_delete(data) result=natlink.addWord(word, word_info) else: result=natlink.addWord(word, word_info, str(pronunciation)) if result==0 and data["force"]==1: process_delete(data) result=natlink.addWord(word, word_info, str(pronunciation)) if result==1: utilities.report("word added successfully: "+word, False) else: utilities.report("word add failed: "+word, False)
def process_set(data): '''''' word = data["word"] pronunciation = data["pronunciation"] if pronunciation == "": pronunciation = None word_info = data["word_info"] #missingno import natlink result = 0 if pronunciation == None: result = natlink.addWord(word, word_info) if result == 0 and data["force"] == 1: process_delete(data) result = natlink.addWord(word, word_info) else: result = natlink.addWord(word, word_info, str(pronunciation)) if result == 0 and data["force"] == 1: process_delete(data) result = natlink.addWord(word, word_info, str(pronunciation)) if result == 1: utilities.report("word added successfully: " + word, False) else: utilities.report("word add failed: " + word, False)
def make_active_word(name, default_word_flags): flags = natlink.getWordInfo(name, 0) if flags != None: return # already an active word flags = natlink.getWordInfo(name, 1) if flags != None: default_word_flags = flags # currently in backup dictionary print "promoting '%s' from backup to active dictionary" % name else: default_word_flags |= USER_ADDED # new word, added by user print "adding new user word '%s'" % name if natlink.addWord(name, default_word_flags) == 1: return currentProns = natlink.getWordProns(name) natlink.addWord(name, default_word_flags, currentProns[0])
def make_active_word(name, default_word_flags): flags = natlink.getWordInfo(name, 0) if flags != None: return # already an active word flags = natlink.getWordInfo(name, 3) if flags != None: default_word_flags = flags # currently in backup dictionary print "promoting '%s' from backup to active dictionary" % name else: default_word_flags |= USER_ADDED # new word, added by user print "adding new user word '%s'" % name try: if natlink.addWord(name, default_word_flags) == 1: return except Exception, e: print " FAILED: " + type(e).__name__ + ": " + str(e) return
def addWord(word, *rest): """Add a word to NatSpeak's vocabulary. We only add the word if it doesn't already exist in the vocabulary. Returns *TRUE* iif the word was successfully added. """ global word_info_flag # # First, fix the written form of the word # # DCF: no, this is stupid. Let the caller do this if desired, but allow # the caller to add a word with the desired spoken form. # spoken, written = spoken_written_form(word) # word = vocabulary_entry(spoken, written, clean_written=1) # # Make sure we are connected to SR system # #ignore requests to add single letters - they should already exist if word in string.ascii_letters: return 1 if word == 'g' or word == 'g\\g': raise RuntimeError('I thought we agreed not to add single letters') origWord = word if len(word.split('\\')[0]) == 1 and word.split('\\')[0] and word.split( '\\')[0][0] in string.letters: trace('sr_interface.addWord', 'single letter word, should not be added! "%s"' % word) return trace('sr_interface.addWord', 'normalizing word for Dragon: "%s"' % word) word = normalize_word_for_Dragon(word) trace('sr_interface.addWord', 'after normalize word for Dragon: "%s"' % word) if word in stringsOfNumbers: if word in numberstringToSpoken: word = numberstringToSpoken[word] #print 'addWord, take spoken form for number: %s'% word else: print 'addWord, no numbers without spoken form are accepted: "%s"' % word return if word is None: pass return if getWordInfo(word) is None: #trace('sr_interface.addWord', 'this word is new to NatSpeak: %s'% word) #trace_call_stack('sr_interface.addWord', '**') if word.startswith('.'): pass if word != origWord: trace( 'sr_interface.addWord', 'this word (to be added) is changed by normalize_word_for_Dragon: "%s" to "%s"' % (origWord, word)) if len(rest) == 0: flag = word_info_flag elif len(rest) == 1: flag = rest[0] else: return None try: natlink.addWord(word, flag) sr_user_needs_saving = 1 except: # In case the word's spoken form is rejected by # NatSpeak return None # # Note: Need to add redundant entry without special # characters (e.g. {Spacebar}}) in the written form, # because Select XYZ will not work if XYZ has some spaces # in its written form. This means that there will be two # vocabulary entries in the vocabulary. The entry without # spaces will always be used by Select XYZ, but # unfortunately, the dictation grammar may chose the one # without spaces over the one with spaces. Hopefully, # user correction will address that # word_no_special_chars = re.sub('{Spacebar}', '', word) if word_no_special_chars != word: trace( 'sr_interface.addWord', 'adding redundant form with no spaces \'%s\'' % word_no_special_chars) natlink.addWord(word_no_special_chars, flag) return 1
def addWord(word, *rest): """Add a word to NatSpeak's vocabulary. We only add the word if it doesn't already exist in the vocabulary. Returns *TRUE* iif the word was successfully added. """ global word_info_flag # trace('sr_interface.addWord', 'adding \'%s\'' % word) # # First, fix the written form of the word # # DCF: no, this is stupid. Let the caller do this if desired, but allow # the caller to add a word with the desired spoken form. # spoken, written = spoken_written_form(word) # word = vocabulary_entry(spoken, written, clean_written=1) # # Make sure we are connected to SR system # if word == 'g' or word == 'g\\g': raise RuntimeError('I thought we agreed not to add single letters') if getWordInfo(word) == None: trace('sr_interface.addWord', 'this word is new to NatSpeak') if len(rest) == 0: flag = word_info_flag elif len(rest) == 1: flag = rest[0] else: return None try: natlink.addWord(word, flag) sr_user_needs_saving = 1 except: # In case the word's spoken form is rejected by # NatSpeak return None # # Note: Need to add redundant entry without special # characters (e.g. {Spacebar}}) in the written form, # because Select XYZ will not work if XYZ has some spaces # in its written form. This means that there will be two # vocabulary entries in the vocabulary. The entry without # spaces will always be used by Select XYZ, but # unfortunately, the dictation grammar may chose the one # without spaces over the one with spaces. Hopefully, # user correction will address that # word_no_special_chars = re.sub('{Spacebar}', '', word) if word_no_special_chars != word: # trace('sr_interface.addWord', 'adding redundant form with no spaces \'%s\'' % word_no_special_chars) try: natlink.addWord(word_no_special_chars, flag) except: return None return 1
def addWord(word, *rest): """Add a word to NatSpeak's vocabulary. We only add the word if it doesn't already exist in the vocabulary. Returns *TRUE* iif the word was successfully added. """ global word_info_flag # # First, fix the written form of the word # # DCF: no, this is stupid. Let the caller do this if desired, but allow # the caller to add a word with the desired spoken form. # spoken, written = spoken_written_form(word) # word = vocabulary_entry(spoken, written, clean_written=1) # # Make sure we are connected to SR system # #ignore requests to add single letters - they should already exist if word in string.ascii_letters: return 1 if word == 'g' or word == 'g\\g': raise RuntimeError('I thought we agreed not to add single letters') origWord = word if len(word.split('\\')[0]) == 1 and word.split('\\')[0] and word.split('\\')[0][0] in string.letters: trace('sr_interface.addWord', 'single letter word, should not be added! "%s"'% word) return trace('sr_interface.addWord', 'normalizing word for Dragon: "%s"'% word) word = normalize_word_for_Dragon(word) trace('sr_interface.addWord', 'after normalize word for Dragon: "%s"'% word) if word in stringsOfNumbers: if word in numberstringToSpoken: word = numberstringToSpoken[word] #print 'addWord, take spoken form for number: %s'% word else: print 'addWord, no numbers without spoken form are accepted: "%s"'% word return if word is None: pass return if getWordInfo(word) is None: #trace('sr_interface.addWord', 'this word is new to NatSpeak: %s'% word) #trace_call_stack('sr_interface.addWord', '**') if word.startswith('.'): pass if word != origWord: trace('sr_interface.addWord', 'this word (to be added) is changed by normalize_word_for_Dragon: "%s" to "%s"'% (origWord, word)) if len(rest) == 0: flag = word_info_flag elif len(rest) == 1: flag = rest[0] else: return None try: natlink.addWord(word, flag) sr_user_needs_saving = 1 except: # In case the word's spoken form is rejected by # NatSpeak return None # # Note: Need to add redundant entry without special # characters (e.g. {Spacebar}}) in the written form, # because Select XYZ will not work if XYZ has some spaces # in its written form. This means that there will be two # vocabulary entries in the vocabulary. The entry without # spaces will always be used by Select XYZ, but # unfortunately, the dictation grammar may chose the one # without spaces over the one with spaces. Hopefully, # user correction will address that # word_no_special_chars = re.sub('{Spacebar}', '', word) if word_no_special_chars != word: trace('sr_interface.addWord', 'adding redundant form with no spaces \'%s\'' % word_no_special_chars) natlink.addWord(word_no_special_chars, flag) return 1
if flags != None: default_word_flags = flags # currently in backup dictionary print "promoting '%s' from backup to active dictionary" % name else: default_word_flags |= USER_ADDED # new word, added by user print "adding new user word '%s'" % name try: if natlink.addWord(name, default_word_flags) == 1: return except Exception, e: print " FAILED: " + type(e).__name__ + ": " + str(e) return currentProns = natlink.getWordProns(name) natlink.addWord(name, default_word_flags, currentProns[0]) # requires: name is already an active dictation word def set_word_properties(name, properties): old_flags = natlink.getWordInfo(name, 0) if old_flags == None: raise natlink.UnknownName flags = apply_properties(properties, old_flags) if flags == old_flags: return print "changing properties of '%s' to 0x%x" % (name, flags) print " from 0x%x" % old_flags natlink.setWordInfo(name, flags)
def add_words(self, words): for word in words: try: natlink.addWord(word) except: pass