Beispiel #1
0
def demo():
  log.debug('debug')
  log.info('info')
  log.warn('warn')
  log.error('error')
  log.fatal('fatal')
  
  log.error('error with function', True)
Beispiel #2
0
def unit_lex():
  log.debug('unit test: lex()')
  msg = '(ROOT hello)'
  print(lex(msg))
  msg = '(ROOT (DT a) (NP cat))'
  print(lex(msg))
  msg = '(ROOT (DT a) (NP cat) )'
  print(lex(msg))
  log.debug('unit test: OK')
def demo():
  log.info('lumin\'s rainbowlog demo in python')
  log.debug('debug')
  log.info('info')
  log.warn('warn')
  log.error('error')
  log.fatal('fatal')
  log.error('error report with function name', True)
  log.info('happy hacking!')
Beispiel #4
0
def unit_Tnode():
  log.debug('unit test: Tnode')
  a = Tnode('ROOT', 'hello')
  a.dump()
  print(a.sosdump())
  assert(a.treesize() == 1)
  a.dfsplrdump()
  a = Tnode('ROOT', [ Tnode('NN', 'nn1'), Tnode('NP', 'np2'),
    Tnode('XX', [ Tnode('x1', 'x1'), Tnode('x2', 'x2') ]) ])
  a.dump()
  print(a.sosdump())
  a.dfsplrdump()
  assert(a.treesize() == 6)
  a = None
  log.debug('unit test: OK')
Beispiel #5
0
def unit_seeknext():
  log.debug('unit test: seeknext()')
  msg = '0ello   1eek            2eek 3eek'
  cur = 0
  print(msg[cur])
  cur = 5
  cur = seeknext(cur, msg)
  print(msg[cur])
  cur = 12
  cur = seeknext(cur, msg)
  print(msg[cur])
  cur = 28
  cur = seeknext(cur, msg)
  print(msg[cur])
  msg = None
  cur = None
  log.debug('unit test: OK')
Beispiel #6
0
def unit_yyparse():
  log.debug('unit test: yyparse()')
  lexout = lex('(ROOT hello)')
  tree = yyparse(lexout)[0]
  tree.dump()
  lexout = lex('(ROOT (DT a) (NP cat))')
  tree = yyparse(lexout)[0]
  tree.dump()
  lexout = lex('(ROOT (NP (DT a) (NP cat)) (VP sits) (XX on) (NP (YY the) (NP mat)))')
  tree = yyparse(lexout)[0]
  tree.dump()
  lexout = lex('''
(ROOT
  (NP
    (NP (DT a) (NN person) (NN standing))
    (PP (IN inside))
    (PP (IN of)
      (NP (DT a) (NN phone) (NN booth)))
    (. .)))''')
  tree = yyparse(lexout)[0]
  tree.dump()
  lexout = None
  tree = None
  log.debug('unit test: OK')
Beispiel #7
0
debug = 1
log.info('Tree parser and converter, debug = %d' % debug)

yaccspec='''
tnode:
  (ATTR WORD)
| (ATTR tnode*)
;
'''

if debug:
  log.info('dump language spec')
  print(yaccspec)

if debug: log.debug('initialize Tnode')
class Tnode(object):
  def __init__(self, attr, content=None):
    self.attr_ = attr
    self.content_ = content
    #self.content = word or unit list
  def dump(self, indent=0):
    assert(self.content_)
    if isinstance(self.content_, str):
      print('%s(%s %s)'%(' '*indent, self.attr_, self.content_))
    else:
      print('%s(%s'%(' '*indent, self.attr_))
      for item in self.content_:
        item.dump(indent+2)
      print('%s)'%(' '*indent))
  def setcontent(self, content):