Ejemplo n.º 1
0
    def xxxxtestControlGrammarNld(self):
        """test the reload of the control grammar
        
        The obsolete words seem to be reversed.

        !!Enable ONLY this test function, disable NatLink (leaving Unimacro and possibly Vocola enabled)
        !!enable the "start_natlink" line in def connect and
        then restart Dragon and run this module.
        
        Note the test function writes the number into this file, so leave the cursor here or after a comment
        before running the function!! Or you comment out the line self.outputNumber() (line 99) in _number simple.py.Zwitserland kiest Rooks hallo

        This test was because at reload time the self.gramSpec instance variable was used for translation instead of
        self.__class__.gramSpec.
        
        Next lines of test are not very sensible. Problem was at natlinkutilsbj line 2324, QH sept 2013

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        import _control
        cgrammar = _control.utilGrammar  # why this name?
        print 'gramSpec: %s' % cgrammar.gramSpec
        words = ['schakel', 'in', 'toetsen']
        fullResults = [('schakel', 'switch'), ('in', 'switch'),
                       ('toetsen', 'switch')]
        seqsAndRules = [(['schakel', 'in', 'toetsen'], 'switch')]

        moduleInfo = natlink.getCurrentModule()
        cgrammar.checkInifile()

        # now call the different functions in the resultsCallback procedure:
        print 'after second initialise gramSpec: %s' % cgrammar.gramSpec
        pass
Ejemplo n.º 2
0
    def xxxxtestKeystrokesGrammarEnx(self):
        """test the keystrokes grammar

        with language english (this grammar must be in the Unimacro directory)
        the inactive mode seemed not to be working. Deactivate was not enough. Hard to test.
        But hopefully solved, Quintijn, September 26, 2013...

        !!Enable ONLY this test function, disable NatLink (leaving Unimacro and possibly Vocola enabled)
        !!enable the "start_natlink" line in def connect and
        then restart Dragon and run this module.
        
        Note the test function writes the number into this file, so leave the cursor here or after a comment
        before running the function!! Or you comment out the line self.outputNumber() (line 99) in _number simple.py.

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        import _keystrokes
        kgrammar = _keystrokes.thisGrammar

        # the Backspace gives an error:
        words = ['Backspace']
        fullResults = [('Backspace', 'repkey')]
        seqsAndRules = [(['Backspace'], 'repkey')]

        # now call the different functions in the resultsCallback procedure:
        moduleInfo = natlink.getCurrentModule()
        # initialise things in gotBegin
        kgrammar.callIfExists('gotBegin', (moduleInfo, ))
        # and run the rules:
        kgrammar.callIfExists('gotResultsInit', (words, fullResults))
        kgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        kgrammar.callIfExists('gotResults', (words, fullResults))
        pass
Ejemplo n.º 3
0
    def testCalculatorNld(self):
        """test the numbers grammar rules in calculator grammar
        
        Note the precautions stated above around line 390.
        This is for testing the _calculator grammar in the debugger

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'

        _calc = __import__("_calculator")
        calcgrammar = _calc.thisGrammar

        ## testing  simple calculation (dutch):
        seqsAndRules = [(['bereken'], 'calculation'), (['drie'], '__0to9'),
                        (['plus'], 'operator'), (['vijf'], '__0to9'),
                        (['is gelijk aan'], 'calculation')]
        fullResults = [('bereken', 'calculation'), ('drie', '__0to9'),
                       ('plus', 'operator'), ('vijf', '__0to9'),
                       ('is gelijk aan', 'calculation')]
        words = ['bereken', 'drie', 'plus', 'vijf', 'is gelijk aan']
        words = ['reken uit', 'drie', 'keer', 'min', 'vier', 'is gelijk aan']
        seqsAndRules = [(['reken uit'], 'calcnormal'), (['drie'], '__0to9'),
                        (['keer', 'min'], 'operator'), (['vier'], '__0to9'),
                        (['is gelijk aan'], 'calcnormal')]
        fullResults = [('reken uit', 'calcnormal'), ('drie', '__0to9'),
                       ('keer', 'operator'), ('min', 'operator'),
                       ('vier', '__0to9'), ('is gelijk aan', 'calcnormal')]

        # now call the different func-12tions in the resultsCallback procedure
        # -12
        calcgrammar.callIfExists('gotResultsInit', (words, fullResults))
        calcgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        calcgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '03'
        numberGot = calcgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "calc grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
Ejemplo n.º 4
0
    def xxxxtestNumbersSimpleGrammarEnx(self):
        """test the numbers grammar rules as written in natlinkutilsbj
        
        
        attach to the _number simple.py grammar, with language english (this grammar must be in the Unimacro directory)
        please remove (if applicable) _number extended.py

        !!Enable ONLY this test function, disable NatLink (leaving Unimacro and possibly Vocola enabled)
        !!enable the "start_natlink" line in def connect and
        then restart Dragon and run this module.
        
        Note the test function writes the number into this file, so leave the cursor here or after a comment
        before running the function!! Or you comment out the line self.outputNumber() (line 99) in _number simple.py.

        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'

        _number = __import__("_number simple")
        numbersgrammar = _number.thisGrammar

        ## testing leading 0: 03, oh three:
        words = ['Number', 'oh', 'three']
        seqsAndRules = [(['Number'], 'testnumber'), (['oh',
                                                      'three'], '__0to99')]
        fullResults = [('Number', 'testnumber'), ('oh', '__0to99'),
                       ('three', '__0to99')]

        # now call the different functions in the resultsCallback procedure:
        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '03'
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))

        ## 302000303:
        words = [
            'Number', 'three', 'hundred', 'two', 'million', 'three', 'hundred',
            'three'
        ]
        seqsAndRules = [(['Number'], 'testnumber'), (['three'], '__1to99'),
                        (['hundred'], '__hundreds'), (['two'], '__1to99'),
                        (['million'], '__millions'), (['three'], '__1to99'),
                        (['hundred'], '__hundreds'), (['three'], '__1to99')]
        fullResults = [('Number', 'testnumber'), ('three', '__1to99'),
                       ('hundred', '__hundreds'), ('two', '__1to99'),
                       ('million', '__millions'), ('three', '__1to99'),
                       ('hundred', '__hundreds'), ('three', '__1to99')]

        # now call the different functions in the resultsCallback procedure:
        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '302000303'
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
Ejemplo n.º 5
0
    def ttttestNumbersExtendedFixedLengthNld(self):
        """test the numbers grammar rules as written in natlinkutilsbj
        
        attach to the _number grammar, with language dutch (translated word for number is "getal").
        (this grammar must be in the Unimacro directory)
        please remove (if applicable) _number_simple.py
        
        handle with care, run or debug ONLY this function, with NatLink disabled, see next function (below)
        
        
        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        _number = __import__("_number extended")
        numbersgrammar = _number.thisGrammar

        ## example fixed length punt (point) + four digits,
        ## to be dictated as "two thousand" ("twee duizend")
        words = ['punt', 'twee', 'duizend']
        fullResults = [('punt', 'numberaztwo'), ('twee', '__2to9before'),
                       ('duizend', '__thousandslimited')]
        seqsAndRules = [(['punt'], 'numberaztwo'), (['twee'], '__2to9before'),
                        (['duizend'], '__thousandslimited')]

        # ## 8623, note we test this inside the rule numberazone, initially developed for a user in Amsterdam Zuid
        # words = ['zesentachtig', 'drie', 'drie\xebntwintig']  #
        # seqsAndRules = [(['zesentachtig'], 'numberazone'), (['drie\xebntwintig'], 'numbertwodigits')]
        # fullResults = [('zesentachtig', 'numberazone'), ('drie\xebntwintig', 'numbertwodigits')]

        # now call the different functions in the resultsCallback procedure:
        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '.2000'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
        #

        # next:
        # 3200005: (foutje: 3201005)
        words = [
            'getal', 'drie', 'miljoen', 'twee', 'honderd', 'duizend', 'vijf'
        ]

        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__1to99'),
                        (['miljoen'], '__millions'), (['twee'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['duizend'], '__thousands'), (['vijf'], '__1to99')]

        fullResults = [('getal', 'testnumber'), ('drie', '__1to99'),
                       ('miljoen', '__millions'), ('twee', '__1to99'),
                       ('honderd', '__hundreds'), ('duizend', '__thousands'),
                       ('vijf', '__1to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '3200005'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))

        # 324700024    (foutje: 3201005)
        words = [
            'getal', 'drie', 'honderd', 'vierentwintig', 'miljoen', 'zeven',
            'honderd', 'duizend', 'vierentwintig'
        ]

        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['vierentwintig'], '__1to99'),
                        (['miljoen'], '__millions'), (['zeven'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['duizend'], '__thousands'),
                        (['vierentwintig'], '__1to99')]

        fullResults = [('getal', 'testnumber'), ('drie', '__1to99'),
                       ('honderd', '__hundreds'), ('vierentwintig', '__1to99'),
                       ('miljoen', '__millions'), ('zeven', '__1to99'),
                       ('honderd', '__hundreds'), ('duizend', '__thousands'),
                       ('vierentwintig', '__1to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '324700024'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
        #

        # 3,5
        words = ['getal', 'drie', 'komma', 'vijf']
        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__0to99'),
                        (['komma'], 'float'), (['vijf'], '__0to99')]
        fullResults = [('getal', 'testnumber'), ('drie', '__0to99'),
                       ('komma', 'float'), ('vijf', '__0to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '3,5'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
Ejemplo n.º 6
0
    def xxxtestNumbersSimpleGrammarNld(self):
        """test the numbers grammar rules as written in natlinkutilsbj
        
        attach to the _number grammar, with language dutch (translated word for number is "getal").
        (this grammar must be in the Unimacro directory)
        please remove (if applicable) _number extended.py
        
        handle with care, run or debug ONLY this function, with NatLink disabled, see next function (below)
        get the seqsAndRules and fullResults by uncommenting 2 print lines in natlinkutils.py, lin 670.
        
        """
        natlinkmain.start_natlink()
        print 'started natlink (Unimacro)'
        _number = __import__("_number simple")
        numbersgrammar = _number.thisGrammar

        ## 302000303:
        words = [
            'getal', 'drie', 'honderd', 'twee', 'miljoen', 'drie', 'honderd',
            'drie'
        ]
        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__1to99'),
                        (['honderd'], '__hundreds'), (['twee'], '__1to99'),
                        (['miljoen'], '__millions'), (['drie'], '__1to99'),
                        (['honderd'], '__hundreds'), (['drie'], '__1to99')]
        fullResults = [('getal', 'testnumber'), ('drie', '__1to99'),
                       ('honderd', '__hundreds'), ('twee', '__1to99'),
                       ('miljoen', '__millions'), ('drie', '__1to99'),
                       ('honderd', '__hundreds'), ('drie', '__1to99')]

        # now call the different functions in the resultsCallback procedure:
        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '302000303'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
        #

        # next:
        # 3200005: (foutje: 3201005)
        words = [
            'getal', 'drie', 'miljoen', 'twee', 'honderd', 'duizend', 'vijf'
        ]

        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__1to99'),
                        (['miljoen'], '__millions'), (['twee'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['duizend'], '__thousands'), (['vijf'], '__1to99')]

        fullResults = [('getal', 'testnumber'), ('drie', '__1to99'),
                       ('miljoen', '__millions'), ('twee', '__1to99'),
                       ('honderd', '__hundreds'), ('duizend', '__thousands'),
                       ('vijf', '__1to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '3200005'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))

        # 324700024    (foutje: 3201005)
        words = [
            'getal', 'drie', 'honderd', 'vierentwintig', 'miljoen', 'zeven',
            'honderd', 'duizend', 'vierentwintig'
        ]

        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['vierentwintig'], '__1to99'),
                        (['miljoen'], '__millions'), (['zeven'], '__1to99'),
                        (['honderd'], '__hundreds'),
                        (['duizend'], '__thousands'),
                        (['vierentwintig'], '__1to99')]

        fullResults = [('getal', 'testnumber'), ('drie', '__1to99'),
                       ('honderd', '__hundreds'), ('vierentwintig', '__1to99'),
                       ('miljoen', '__millions'), ('zeven', '__1to99'),
                       ('honderd', '__hundreds'), ('duizend', '__thousands'),
                       ('vierentwintig', '__1to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '324700024'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))
        #

        # 3,5
        words = ['getal', 'drie', 'komma', 'vijf']
        seqsAndRules = [(['getal'], 'testnumber'), (['drie'], '__0to99'),
                        (['komma'], 'float'), (['vijf'], '__0to99')]
        fullResults = [('getal', 'testnumber'), ('drie', '__0to99'),
                       ('komma', 'float'), ('vijf', '__0to99')]

        numbersgrammar.callIfExists('gotResultsInit', (words, fullResults))
        numbersgrammar.callRuleResultsFunctions(seqsAndRules, fullResults)
        numbersgrammar.callIfExists('gotResults', (words, fullResults))
        numberExpected = '3,5'
        numbersgrammar.collectNumber()
        numberGot = numbersgrammar.number
        self.assertEquals(
            numberExpected, numberGot,
            "numbers grammar gives unexpected result\nexpected: %s\ngot: %s" %
            (numberExpected, numberGot))