code: def build_request(doc, semgrex_patterns, enhanced=False):
      request = SemgrexRequest()
      for semgrex in semgrex_patterns:
          request.semgrex.append(semgrex)
  
      for sent_idx, sentence in enumerate(doc.sentences):
          query = request.query.add()
          if enhanced:
              # tokens will be added on to the graph object
              convert_networkx_graph(query.graph, sentence, sent_idx)
          else:
              word_idx = 0
              for token in sentence.tokens:
                  for word in token.words:
                      add_token(query.token, word, token)
                      add_word_to_graph(
                          query.graph, word, sent_idx, word_idx
                      )
  
                      word_idx = word_idx + 1
  
      return request
  
file_path: stanza/stanza/server/semgrex.py
imports: import argparse
  import copy
  import stanza
  from stanza.protobuf import SemgrexRequest, SemgrexResponse
  from stanza.server.java_protobuf_requests import send_request, add_token, add_word_to_graph, JavaProtobufContext, convert_networkx_graph
  from stanza.utils.conll import CoNLL
label_desc: Use image node_id 2 for calling a global function with example usage: build_request(doc, semgrex_patterns, enhanced) and returns: request