original_docstring: Write examples, and also return a second KB-like structure ex_kb,
    which contains the facts that describe the examples, namely the
    'mentions_entity' and 'has_feature' relations.  Em is an
    EntityMatcher, qas is a list of (question,answer_list) pairs,
    filename is the output file, and n is an upper bound on how many
    things to write out.
    
docstring: Write examples, and also return a second KB-like structure ex_kb,
  which contains the facts that describe the examples, namely the
  'mentions_entity' and 'has_feature' relations.  Em is an
  EntityMatcher, qas is a list of (question,answer_list) pairs,
  filename is the output file, and n is an upper bound on how many
  things to write out.
docstring_tokens: Write examples and also return a second KB - like structure ex_kb which contains the facts that describe the examples namely the ' mentions_entity ' and ' has_feature ' relations . Em is an EntityMatcher qas is a list of ( question answer_list ) pairs filename is the output file and n is an upper bound on how many things to write out .
code: def write_exams(em,qas,stem,filename,n=None):
    """Write examples, and also return a second KB-like structure ex_kb,
    which contains the facts that describe the examples, namely the
    'mentions_entity' and 'has_feature' relations.  Em is an
    EntityMatcher, qas is a list of (question,answer_list) pairs,
    filename is the output file, and n is an upper bound on how many
    things to write out.
    """
    if (n is not None) and (n<len(qas)): qas = random.sample(qas,n)
    ex_kb = collections.defaultdict(lambda:collections.defaultdict(set))
    with open(filename,'w') as fp:
      for i,(question,answers) in enumerate(qas):
        if len(answers)==0:
          logging.warn('no answers for question %r' % question)
        else:
          qid = 'q%s%04d' % (stem,i)
          toks = simple_tokenize(question)
          entity_tokens = em.as_entity_list(question,keep_nonentities=False)
          for e in entity_tokens:
            ex_kb['mentions_entity'][qid].add(e)
          for w in toks:
            ex_kb['has_feature'][qid].add(w)
          fp.write('# ' + question + ' ' + repr(answers) + '\n')
          fp.write('\t'.join(['answer',qid]+answers) + '\n')
    return ex_kb
code_tokens: def write_exams ( em , qas , stem , filename , n = None ) : if ( n is not None ) and ( n < len ( qas ) ) : qas = random . sample ( qas , n ) ex_kb = collections . defaultdict ( lambda : collections . defaultdict ( set ) ) with open ( filename , 'w' ) as fp : for i , ( question , answers ) in enumerate ( qas ) : if len ( answers ) == 0 : logging . warn ( 'no answers for question %r' % question ) else : qid = 'q%s%04d' % ( stem , i ) toks = simple_tokenize ( question ) entity_tokens = em . as_entity_list ( question , keep_nonentities = False ) for e in entity_tokens : ex_kb [ 'mentions_entity' ] [ qid ] . add ( e ) for w in toks : ex_kb [ 'has_feature' ] [ qid ] . add ( w ) fp . write ( '# ' + question + ' ' + repr ( answers ) + '\n' ) fp . write ( '\t' . join ( [ 'answer' , qid ] + answers ) + '\n' ) return ex_kb
short_docstring: Write examples, and also return a second KB-like structure ex_kb,
  which contains the facts that describe the examples, namely the
  'mentions_entity' and 'has_feature' relations.
short_docstring_tokens: Write examples and also return a second KB - like structure ex_kb which contains the facts that describe the examples namely the ' mentions_entity ' and ' has_feature ' relations .
comment: """Write examples, and also return a second KB-like structure ex_kb,
    which contains the facts that describe the examples, namely the
    'mentions_entity' and 'has_feature' relations.  Em is an
    EntityMatcher, qas is a list of (question,answer_list) pairs,
    filename is the output file, and n is an upper bound on how many
    things to write out.
    """