Charty/resources/ChartyPy.py
def parse(inp, grammar):
   """Parse a list of tokens.

      Arguments:
      inp = a list of tokens
      grammar = an object returned by PSGParse
   """
   chart = []
   inputlength = len(inp)

   chartpos = 0  # remember start-position in chart
   for i in range(inputlength):
      # initialize with input token
      rules = grammar.rhshash.get(grammar.symb2id[inp[i]], ( ("", ()) ) )
      for rule in rules:
         if rule[0]:
            chart.append( ( i, i + 1, 1, rule[0], rule[1], () ) )
      if DEBUG:
         print "Adding edge:", edgeStr(chart[len(chart) - 1], grammar)
      change = 1
      while change:
         change = 0
         chartlen = len(chart)
         if ruleInvocation(chartpos, chart, inputlength, grammar):
            change = 1
         chartpos = chartlen  # set pointer to new edge in chart
         if fundamentalRule(chart, grammar):
            change = 1
   if DEBUG:
      print "Chart:"
      for i in range(len(chart)):
         if isActive(chart[i]):
            print i, "Active:",
         else:
            print i, "Inactive:",
         print edgeStr(chart[i], grammar)
   if QTREE:
      return getQtreeParse(inputlength, chart, grammar)
   return getParse(inputlength, chart, grammar)
Parse a list of tokens.

      Arguments:
      inp = a list of tokens
      grammar = an object returned by PSGParse
   
Parse a list of tokens.
Arguments:
inp = a list of tokens
grammar = an object returned by PSGParse
Parse a list of tokens . Arguments : inp = a list of tokens grammar = an object returned by PSGParse
def parse(inp, grammar):
   chart = []
   inputlength = len(inp)
   chartpos = 0  
   for i in range(inputlength):
      rules = grammar.rhshash.get(grammar.symb2id[inp[i]], ( ("", ()) ) )
      for rule in rules:
         if rule[0]:
            chart.append( ( i, i + 1, 1, rule[0], rule[1], () ) )
      if DEBUG:
         print "Adding edge:", edgeStr(chart[len(chart) - 1], grammar)
      change = 1
      while change:
         change = 0
         chartlen = len(chart)
         if ruleInvocation(chartpos, chart, inputlength, grammar):
            change = 1
         chartpos = chartlen  
         if fundamentalRule(chart, grammar):
            change = 1
   if DEBUG:
      print "Chart:"
      for i in range(len(chart)):
         if isActive(chart[i]):
            print i, "Active:",
         else:
            print i, "Inactive:",
         print edgeStr(chart[i], grammar)
   if QTREE:
      return getQtreeParse(inputlength, chart, grammar)
   return getParse(inputlength, chart, grammar)
def parse ( inp , grammar ) : chart = [ ] inputlength = len ( inp ) chartpos = 0 for i in range ( inputlength ) : rules = grammar . rhshash . get ( grammar . symb2id [ inp [ i ] ] , ( ( "" , ( ) ) ) ) for rule in rules : if rule [ 0 ] : chart . append ( ( i , i + 1 , 1 , rule [ 0 ] , rule [ 1 ] , ( ) ) ) if DEBUG : print "Adding edge:" , edgeStr ( chart [ len ( chart ) - 1 ] , grammar ) change = 1 while change : change = 0 chartlen = len ( chart ) if ruleInvocation ( chartpos , chart , inputlength , grammar ) : change = 1 chartpos = chartlen if fundamentalRule ( chart , grammar ) : change = 1 if DEBUG : print "Chart:" for i in range ( len ( chart ) ) : if isActive ( chart [ i ] ) : print i , "Active:" , else : print i , "Inactive:" , print edgeStr ( chart [ i ] , grammar ) if QTREE : return getQtreeParse ( inputlength , chart , grammar ) return getParse ( inputlength , chart , grammar )
Parse a list of tokens.
Parse a list of tokens .
"""Parse a list of tokens.

      Arguments:
      inp = a list of tokens
      grammar = an object returned by PSGParse
   """ # remember start-position in chart # initialize with input token # set pointer to new edge in chart
inp
grammar