コード例 #1
0
ファイル: _mathfly_main.py プロジェクト: alexboche/mathfly
def build(startup=False):
    SETTINGS = utilities.load_toml_relative("config/settings.toml")
    for word in SETTINGS["delete_words"]:
        try:
            natlink.deleteWord(word)
        except:
            pass
    MF_NEXUS.merger.wipe()
    MF_NEXUS.merger._global_rules = {}
    MF_NEXUS.merger._app_rules = {}
    MF_NEXUS.merger._self_modifying_rules = {}
    if startup:
        apploaded = []
        for module_name in SETTINGS["app_modules"]:
            try:
                lib = __import__("mathfly.apps." + module_name)
                apploaded.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
        if apploaded:
            print("App modules loaded: " + ", ".join(apploaded))
    ccrloaded = []
    ccrrebuilt = []
    for module_name in SETTINGS["ccr_modules"]:
        if "mathfly.ccr." + module_name in sys.modules:
            try:
                want_reload_module = sys.modules["mathfly.ccr." + module_name]
                reload(want_reload_module)
                ccrrebuilt.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
        else:
            try:
                lib = __import__("mathfly.ccr." + module_name)
                ccrloaded.append(module_name)
            except Exception as e:
                print("Ignoring rule '{}'. Failed to load with: ".format(
                    module_name))
                print(e)
    if ccrloaded:
        print("CCR modules loaded: " + ", ".join(ccrloaded))
    if ccrrebuilt:
        print("CCR modules rebuilt: " + ", ".join(ccrrebuilt))
    MF_NEXUS.merger.update_config()
    MF_NEXUS.merger.merge(MergeInf.BOOT)
    print("*- Starting mathfly -*")
    print("Modules available:")
    MF_NEXUS.merger.display_rules()
    print(
        "Say \"enable <module name>\" to begin, \n\"configure <module name>\" to make changes, \nand \"mathfly help\" to open the documentation"
    )
コード例 #2
0
ファイル: delete_words.py プロジェクト: thetrad9/bit-bucket
def delete_word(word):
    try:
        natlink.deleteWord(word)
        result = find_word(word)
        if result == 2:
            print >> sys.stderr, "Error: deletion of word '%s' failed" % word
        elif result == 1:
            print "demoting word '%s' to backup dictionary" % word
        else:
            print "deleting word '%s'" % word
    except natlink.UnknownName:
        pass
    except natlink.InvalidWord:
        print >> sys.stderr, "Error: '%s' is an invalid word" % name
コード例 #3
0
def deleteWord(word, *rest):
    """Delete a word from NatSpeak's vocabulary.

    Also, we only remove it if the word was added to the vocabulary by
    VoiceCode, i.e. if the word info has 'added by Vocabulary Builder'
    flag set and if the word is a phrase (single words might actually
    have ben added by the real Vocabulary Builder)
    
    Dragon 11: flags are not recognised any more, so delete if not a lowercase single word.
    
    """
    word = normalize_word_for_Dragon(word)
    flag = getWordInfo(word)
    num_words = len(re.split('\s+', word))
    if reSimpleWord.match(word):
        trace(
            'sr_interface.deleteWord',
            'word not deleted by VoiceCode "%s", because of simple lowercase word phrase'
            % word)
        return None

    if DNSVersion >= 11 or addedByVC(flag):
        trace('sr_interface.deleteWord', 'actually deleting word %s' % word)
        sr_user_needs_saving = 1
        return natlink.deleteWord(word)
    else:
        trace(
            'sr_interface.deleteWord',
            'word not deleted by VoiceCode "%s", NatSpeak 10 or before, and not addedByVC'
            % word)
        return None
コード例 #4
0
ファイル: sr_interface.py プロジェクト: vine77/nrc-voicecode
def deleteWord(word, *rest):
    """Delete a word from NatSpeak's vocabulary.

    Also, we only remove it if the word was added to the vocabulary by
    VoiceCode, i.e. if the word info has 'added by Vocabulary Builder'
    flag set and if the word is a phrase (single words might actually
    have ben added by the real Vocabulary Builder)
    
    Dragon 11: flags are not recognised any more, so delete if not a lowercase single word.
    
    """
    word = normalize_word_for_Dragon(word)
    flag = getWordInfo(word)
    num_words = len(re.split('\s+', word))
    if reSimpleWord.match(word):
        trace('sr_interface.deleteWord', 'word not deleted by VoiceCode "%s", because of simple lowercase word phrase' % word)
        return None
    
    if DNSVersion >= 11 or addedByVC(flag):
        trace('sr_interface.deleteWord', 'actually deleting word %s' % word)
        sr_user_needs_saving = 1
        return natlink.deleteWord(word)
    else:
        trace('sr_interface.deleteWord', 'word not deleted by VoiceCode "%s", NatSpeak 10 or before, and not addedByVC' % word)
        return None
コード例 #5
0
def deleteWord(word, *rest):
    """Delete a word from NatSpeak's vocabulary.

    Also, we only remove it if the word was added to the vocabulary by
    VoiceCode, i.e. if the word info has 'added by Vocabulary Builder'
    flag set and if the word is a phrase (single words might actually
    have ben added by the real Vocabulary Builder)"""

#    trace('sr_interface.deleteWord', 'word=%s, rest=%s' % (word, rest))
    flag = getWordInfo(word)
    num_words = len(re.split('\s+', word))
    if addedByVC(flag) and num_words > 1:
#            trace('sr_interface.deleteWord', 'actually deleting word %s' % word)
        sr_user_needs_saving = 1
        return natlink.deleteWord(word)
    else:
#            trace('sr_interface.deleteWord', 'word not added by VoiceCode %s' % word)
        return None
コード例 #6
0
    def gotResults_choose(self, words, fullResults):
        self.nChoice = None
        if self.hasCommon(words[-1], 'Medium'):
            self.nChoice = choiceMiddle
        elif self.hasCommon(words[-1], 'Strong'):
            self.nChoice = choiceStrong
        elif self.hasCommon(words[-1], 'Weak'):
            self.nChoice = choiceWeak
        if self.nChoice:
            del words[-1]
        else:
            self.nChoice = choiceMiddle

        if words[-1] in ChooseList:
            choice = int(words[-1])
        if not choice:
            print 'no valid choice given'
            natqh.Wait(0.2)
            self.cancelMode()
            natqh.returnFromMessagesWindow()
            return
        newWords = self.lastResObj.getWords(choice - 1)
        res = self.lastResObj.getResults(choice - 1)
        resCode = res[0][1]
        resCode = resCode & 0x7fffffff
        # formatting:===========================================
        if 'Format' in words:
            if not DoFormatting:
                print 'formatting options invalid!'
                return

            if resCode:
                print 'no formatting can be done on a command!'
                time.sleep(1.5)
            elif len(newWords) > 1:
                print 'no formatting can be done on a list of words'
                time.sleep(1.5)
            else:
                self.newWord = newWords[0]
                fKeys = FORMATS.keys()
                fKeys.sort()
                fcKeys = FormatComments.keys()
                fcKeys.sort()
                if fKeys != fcKeys:
                    print 'keys of FORMATS and FormatComments do not match'
                    return
                numChoices = len(fKeys)
                if language == 'nld':
                    print 'Formatteren van: %s' % self.newWord
                    print 'Kies Format 1, ..., %i of zeg "Annuleren"' % numChoices
                elif language == 'enx':
                    print 'Formating: %s' % self.newWord
                    print 'Choose Format 1, ..., %i, or say "Cancel"' % numChoices
                else:
                    print 'invalid language, skip this'
                    self.cancelMode()
                    return
                for n in range(numChoices):
                    print '%s:\t%s' % (n + 1, FormatComments[n + 1])

                #  Entered the new exclusive grammar rules, for the right
                #    format to be chosen
                self.oopsFlag = 3
                self.activateSet(['inoops2'], exclusive=1)
                return
        # deleting:===========================================
        elif self.hasCommon(words, ['Delete', 'Verwijder']):
            if resCode:
                print 'no delete of a command!'
                time.sleep(1.5)
            elif len(newWords) > 1:
                print 'no delete on a list of words'
                time.sleep(1.5)
            else:
                natlink.deleteWord(newWords[0])
                print 'deleted: %s' % newWords[0]
        elif self.hasCommon(words, ['Properties', 'Eigenschappen']):
            if resCode:
                print 'no properties on a command!'
                time.sleep(1.0)
            elif len(newWords) > 1:
                print 'no properties of a list of words'
                time.sleep(1.0)
            else:
                self.newWord = newWords[0]
                props = natlink.getWordInfo(self.newWord)
                print 'properties of %s: %x' % (self.newWord, props)
                p = natqh.ListOfProperties(props)
                if p:
                    for pp in p:
                        print pp
                    time.sleep(4.0)
        elif self.hasCommon(words, ['Choose', 'Kies', 'OK']):
            hadChoose = 1
            print 'correcting: %s (%s times)' % (newWords, self.nChoice)
            for i in range(self.nChoice):
                result = self.lastResObj.correction(newWords)
                if not result:
                    print 'correction failed'
                    break
            else:
                print 'corrected %s times' % self.nChoice
        else:
            print 'invalid word in command: %s' % ` words `
            time.sleep(2.0)
        time.sleep(1.0)
        self.cancelMode()
        natqh.returnFromMessagesWindow()
        #  Like in DragonDictate, when the word was not a command but a
        #    dictate word, the last phrase is scratched and replaced by the new
        #    text or the new command.
        if hadChoose and self.FirstIsDictate:
            print 'mimic first: %s' % ScratchThatCommand
            natlink.recognitionMimic(ScratchThatCommand)
            print 'now mimic: %s' % newWords
            natlink.recognitionMimic(newWords)
コード例 #7
0
ファイル: vocabulary_processing.py プロジェクト: j127/caster
def process_delete(data):
    import natlink
    natlink.deleteWord(data["word"])
    
コード例 #8
0
def process_delete(data):
    import natlink
    natlink.deleteWord(data["word"])
コード例 #9
0
 def delete_words(self, words):
     for word in words:
         try:
             natlink.deleteWord(word)
         except:
             pass