def parse_stories(lines, only_supporting=False):
 data = []
 story = []
 for line in lines:
  line = line.decode('utf-8').strip()
  (nid, line) = line.split(' ', 1)
  nid = int(nid)
  if (nid == 1):
   story = []
  if (' DCTB ' in line):
   (q, a, supporting) = line.split(' DCTB ')
   q = tokenize(q)
   substory = None
   if only_supporting:
    supporting = map(int, supporting.split())
    substory = [story[(i - 1)] for i in supporting]
   else:
    substory = [x for x in story if x]
   data.append((substory, q, a))
   story.append('')
  else:
   sent = tokenize(line)
   story.append(sent)
 return data

def parse_stories ( lines , only_supporting = False ) : data = [ ] story = [ ] for line in lines : line = line . decode ( 'utf-8' ) . strip ( ) ( nid , line ) = line . split ( ' ' , 1 ) nid = int ( nid ) if ( nid == 1 ) : story = [ ] if ( ' DCTB ' in line ) : ( q , a , supporting ) = line . split ( ' DCTB ' ) q = tokenize ( q ) substory = None if only_supporting : supporting = map ( int , supporting . split ( ) ) substory = [ story [ ( i - 1 ) ] for i in supporting ] else : substory = [ x for x in story if x ] data . append ( ( substory , q , a ) ) story . append ( '' ) else : sent = tokenize ( line ) story . append ( sent ) return data
parse stories provided in the babi tasks format if only_supporting is true .