예제 #1
0
    def check ( vtb , ts , kl=None ):
        """ lookup method for unit testing
            arguments:
                vtb  - target vocabulary table
                ts   - text as list of chars
                kl   - length of text to use as key
        """
        lts = len(ts)
        if kl == None or kl > lts: kl = lts
        rs = vtb.lookUp(ts,kl)               # check for possible vocabulary matches
        print 'full text=' , '<' + u''.join(ts) + '>' ,
        if len(rs) == 0:                     # any vocabulary entries found?
            print 'FOUND NONE'
        else:
            print 'FOUND' , len(rs)
            print ''
            for r in rs:                     # if found, note each entry
                print '=' , unicode(r.vem)   # show each match
                print ' ' , r.nspan , 'chars matched, endings included'
                if r.suffx != '':
                    print '  ending=' , '[' +  r.suffx + ']'
#               print 'generative semantics'
                showCode(r.vem.gen.logic)
                print ''
            print '--'
예제 #2
0
    def check(vtb, ts, kl=None):
        """ lookup method for unit testing
            arguments:
                vtb  - target vocabulary table
                ts   - text as list of chars
                kl   - length of text to use as key
        """
        lts = len(ts)
        if kl == None or kl > lts: kl = lts
        rs = vtb.lookUp(ts, kl)  # check for possible vocabulary matches
        #       print ( 'full text=' , '<' + ''.join(ts) + '>' , end=' ' )
        if len(rs) == 0:  # any vocabulary entries found?
            print('FOUND NONE')
        else:
            print('FOUND', len(rs))
            print()
            for r in rs:  # if found, note each entry
                print('=', str(r.vem))  # show each match
                print(' ', r.nspan, 'chars matched, endings included')
                if r.suffx != '':
                    print('  ending=', '[' + r.suffx + ']')
#               print ( 'generative semantics' )
                showCode(r.vem.gen.logic)
                print()
            print('--')
예제 #3
0
    def __str__(self):
        """
        show procedure logic

        arguments:
            self
        """

        generativeDefiner.showCode(self.logic)
예제 #4
0
    def __unicode__ ( self ):

        """
        show procedure logic

        arguments:
            self
        """

        generativeDefiner.showCode(self.logic)
예제 #5
0
def showProcedures(r):
    """
    show semantic procedures for rule

    arguments:
        r    - rule
    """

    print '  ** cognitive'
    if r.cogs != None:
        cognitiveDefiner.showCode(r.cogs.logic)
    print '  ** generative'
    if r.gens != None:
        generativeDefiner.showCode(r.gens.logic)
    print ''
예제 #6
0
def dumpSubprocedures(index, full, pxl=None):
    """
    show standalone procedures

    arguments:
        index  - procedure index
        full   - flag for full dump
        pxl    - semantic subprocedure index
    returns:
        number of calls to unknown subprocedures
    """

    print()
    print("Semantic Subprocedures")
    print("----------------------")

    noe = 0
    lps = index.keys()
    for p in lps:
        print()
        print(p)
        if index[p] == None:
            print('** undefined!')
        elif full:
            noe += generativeDefiner.showCode(index[p].logic, pxl)
    return noe
예제 #7
0
def showProcedures ( r ):

    """
    show semantic procedures for rule

    arguments:
        r    - rule
    """

    print '  ** cognitive'
    if r.cogs != None:
        cognitiveDefiner.showCode(r.cogs.logic)
    print '  ** generative'
    if r.gens != None:
        generativeDefiner.showCode(r.gens.logic)
    print ''
예제 #8
0
 def check ( vtb , ts , kl ):
     """ lookup method for unit testing
     """
     vs = vtb.lookUp(ts,kl)               # check for possible vocabulary matches
     if len(vs) == 0:                     # any vocabulary entries found?
         print ts[:kl] , 'NOT FOUND'
     else:
         print ts[:kl] , 'FOUND' , len(vs)
         for v in vs:                     # if found, note each entry
             rec = v[0]
             vrs = v[1]
             print '=' , unicode(rec)     # show each match
             print ' ' , vrs.mtchl , 'chars matched, with' , vrs.dropn , 'extra'
             print '  suffix=' , '[-' +  vrs.suffx + ']' , 'restore=' , vrs.restr
             print 'generative semantics'
             showCode(rec.gen.logic)
         print '--'
예제 #9
0
def dumpSubprocedures ( index , full ):

    """
    show standalone procedures

    arguments:
        index  - procedure index
        full   - flag for full dump
    """

    print ""
    print "Semantic Subprocedures"
    print "----------------------"

    lps = index.keys()
    for p in lps:
        print ""
        print p
        if full:
            generativeDefiner.showCode(index[p].logic)
예제 #10
0
    def check ( vtb , ts , kl=None ):
        """ lookup method for unit testing
        """
        if kl == None: kl = len(ts)
        rs = vtb.lookUp(ts,kl)               # check for possible vocabulary matches
        print 'in text' , '"' + u''.join(ts) + '"' ,
        if len(rs) == 0:                     # any vocabulary entries found?
            print 'FOUND NONE'
        else:
            print 'FOUND' , len(rs)
            print ''
            for r in rs:                     # if found, note each entry
                print '=' , unicode(r.vem)   # show each match
                print ' ' , r.nspan , 'chars matched, endings included'
                if r.suffx != '':
                    print '  ending=' , '[' +  r.suffx + ']'
#               print 'generative semantics'
                showCode(r.vem.gen.logic)
                print ''
            print '--'
예제 #11
0
def dumpSubprocedures(index, full):
    """
    show standalone procedures

    arguments:
        index  - procedure index
        full   - flag for full dump
    """

    print ""
    print "Semantic Subprocedures"
    print "----------------------"

    lps = index.keys()
    for p in lps:
        print ""
        print p
        if index[p] == None:
            print '** undefined!'
        elif full:
            generativeDefiner.showCode(index[p].logic)
예제 #12
0
def showProcedures(r, pxl=None):
    """
    show semantic procedures for rule

    arguments:
        r    - rule
        pxl  - semantic subprocedure index
    returns:
        number of calls to undefined subprocedures
    """

    noe = 0
    print('  ** cognitive')
    if r.cogs != None:
        cognitiveDefiner.showCode(r.cogs.logic)
    print('  ** generative')
    if r.gens != None:
        noe += generativeDefiner.showCode(r.gens.logic, pxl)
    print()
    return noe
예제 #13
0
    for srcn in args:                      # test all specified input files
        ctx.clearLocalStack()              # reset context
        ctx.clearBuffers()
        print "------------" , srcn
        inp = ellyDefinitionReader.EllyDefinitionReader(srcn)
        if inp.error != None:              # check if input readable
            print >> sys.stderr, "cannot read procedure definition" , srcn
            print >> sys.stderr, inp.error
            continue
        for ln in inp.buffer:              # echo input file
            print ln
        print ''

        gp = GenerativeProcedure(stb,inp)  # compile procedure
        print '*CODE*'
        if gp.logic != None:
            showCode(gp.logic)             # dump procedure logic
        else:
            print 'null logic'
            continue
        res = gp.doRun(ctx,phr)            # run the procedure

        print '----'
        print 'run status=' , res          # show status
        print '----'
        frame.showBuffers()                # show output buffers

    print "------------"
    print len(args),'test file(s)'
예제 #14
0
    for srcn in args:                      # test all specified input files
        ctx.clearLocalStack()              # reset context
        ctx.clearBuffers()
        print "------------" , srcn
        inp = ellyDefinitionReader.EllyDefinitionReader(srcn)
        if inp.error != None:              # check if input readable
            print >> sys.stderr, "cannot read procedure definition" , srcn
            print >> sys.stderr, inp.error
            continue
        for ln in inp.buffer:              # echo input file
            print ln
        print ''

        gp = GenerativeProcedure(stb,inp)  # compile procedure

        print '*CODE*'
        if gp.logic != None:
            showCode(gp.logic)             # dump procedure logic
        else:
            print 'no logic'
            continue
        res = gp.doRun(ctx,phr)            # run the procedure

        print '----'
        print 'run status=' , res          # show status
        print '----'
        frame.showBuffers()                # show output buffers

    print "------------"
    print len(args),'test file(s)'