code: def get_sentences(instream):
      sentence = []
      expect = 0
  
      for line in instream:
          if expect == 0 and line.startswith("Sentence #"):
              if sentence:
                  yield sentence
              sentence = []
              expect = 1
  
          elif line == "\n":
              expect = 0
  
          elif expect == 3:
              try:
                  rel, remainder = line.split("(")
              except:
                  sys.stderr.write(line + "\n")
                  raise
              head, dep = remainder.split()
              head_int = int(head.split("-")[-1][:-1])
              dep_int = int(dep.split("-")[-1][:-1])
              sentence[dep_int - 1]["head"] = head_int
              sentence[dep_int - 1]["label"] = rel
  
          elif expect == 2:
              linesplit = (
                  line.split("[", 1)[1].rsplit("]", 1)[0].split("] [")
              )
              if len(linesplit) != len(sentence):
                  sys.stderr.write(
                      "Warning: mismatch in number of words in sentence\n"
                  )
                  sys.stderr.write(
                      " ".join(w["word"] for w in sentence)
                  )
                  for i in range(len(sentence)):
                      sentence[i]["pos"] = "-"
                      sentence[i]["lemma"] = "-"
                      sentence[i]["head"] = 0
                      sentence[i]["label"] = "-"
                  expect = 0
                  continue
              for i, w in enumerate(linesplit):
                  sentence[i]["pos"] = w.split(" PartOfSpeech=")[
                      -1
                  ].split()[0]
                  sentence[i]["lemma"] = w.split(" Lemma=")[-1]
              expect = 3
  
          elif expect == 1:
              for w in line.split():
                  sentence.append({"word": w})
              expect = 2
  
      if sentence:
          yield sentence
  
file_path: TextBox/asset/sacrebleu-romanian/preprocess/stanford-conll-wrapper.py
imports: from __future__ import print_function, unicode_literals
  import os
  import sys
  import codecs
  import io
  import argparse
  from collections import defaultdict
  from subprocess import Popen, PIPE
label_desc: Use image node_id 3 for calling a global function with example usage: get_sentences(instream) without return types