code: def load_trees(filename, pipeline):
      # some of the files are in latin-1 encoding rather than utf-8
      try:
          raw_text = load_without_asterisks(filename, "utf-8")
      except UnicodeDecodeError:
          raw_text = load_without_asterisks(filename, "latin-1")
  
      # also, some have messed up validation (it will be logged)
      # hence the broken_ok=True argument
      trees = tree_reader.read_trees("".join(raw_text), broken_ok=True)
  
      filtered_trees = []
      for tree in trees:
          if tree.children[0].label is None:
              print(
                  "Skipping a broken tree (missing label) in {}: {}".format(
                      filename, tree
                  )
              )
              continue
  
          try:
              words = tuple(tree.leaf_labels())
          except ValueError:
              print(
                  "Skipping a broken tree (missing preterminal) in {}: {}".format(
                      filename, tree
                  )
              )
              continue
  
          if any(
              "www.facebook" in pt.label for pt in tree.preterminals()
          ):
              print(
                  "Skipping a tree with a weird preterminal label in {}: {}".format(
                      filename, tree
                  )
              )
              continue
  
          tree = tree.prune_none().simplify_labels(CONSTITUENT_SPLIT)
  
          if len(tree.children) > 1:
              print(
                  "Found a tree with a non-unary root!  {}: {}".format(
                      filename, tree
                  )
              )
              continue
          if tree.children[0].is_preterminal():
              print(
                  "Found a tree with a single preterminal node!  {}: {}".format(
                      filename, tree
                  )
              )
              continue
  
          # The expectation is that the retagging will handle this anyway
          for pt in tree.preterminals():
              if not pt.label:
                  pt.label = "UNK"
                  print(
                      "Found a tree with a blank preterminal label.  Setting it to UNK.  {}: {}".format(
                          filename, tree
                      )
                  )
  
          tree = tree.remap_constituent_labels(REMAP_NODES)
          tree = tree.remap_words(REMAP_WORDS)
  
          tree = split_mwe(tree, pipeline)
          if tree is None:
              continue
  
          constituents = set(
              parse_tree.Tree.get_unique_constituent_labels(tree)
          )
          for weird_label in NODES_TO_ELIMINATE:
              if weird_label in constituents:
                  break
          else:
              weird_label = None
          if weird_label is not None:
              print(
                  "Skipping a tree with a weird label {} in {}: {}".format(
                      weird_label, filename, tree
                  )
              )
              continue
  
          filtered_trees.append(tree)
  
      return filtered_trees
  
file_path: stanza/stanza/utils/datasets/constituency/convert_it_turin.py
imports: import glob
  import os
  import re
  import sys
  import stanza
  from stanza.models.constituency import parse_tree
  from stanza.models.constituency import tree_reader
label_desc: Use image node_id 3 for calling a global function with example usage: load_trees(filename, pipeline) and returns: filtered_trees