      def _find_new_head(self, rootid, tokenid, headlabel, heads, labels, spans=None):
          # search through the tree starting from root
          # returns the id of the first descendant with the given label
          # if there is none, return the current head (no change)
          if not spans:
              spans = self._make_span_index(heads)
          queue = spans.get(rootid,[])
          queue.remove(tokenid) # don't search in the subtree of the nonproj arc
          while queue:
              next_queue = []
              for idx in queue:
                  if labels[idx] == headlabel:
                      return idx
 
</s> remove     def _find_new_head(self, rootid, tokenid, headlabel, heads, labels, spans=None):
 </s> add     @classmethod
    def _find_new_head(cls, token, headlabel): </s> remove             for idx in queue:
                if labels[idx] == headlabel:
                    return idx
                next_queue.extend(spans.get(idx,[]))
 </s> add             for qtoken in queue:
                for child in qtoken.children:
                    if child == token:
                        continue
                    if child.dep_ == headlabel:
                        return child
                    next_queue.append(child) </s> remove         return heads[tokenid]
 </s> add         return token.head </s> remove     def _make_span_index(self, heads):
        # stores the direct dependents for each token
        # for searching top-down through a tree
        spans = {}
        for tokenid, head in enumerate(heads):
            if tokenid == head: # root
                continue
            if head not in spans:
                spans[head] = []
            spans[head].append(tokenid)
        return spans


    def _filter_labels(self, labeled_trees, cutoff):
 </s> add     @classmethod
    def _filter_labels(cls, gold_tuples, cutoff, freqs): </s> remove         for heads,labels in labeled_trees:
            proj_heads,deco_labels = self.projectivize(heads,labels)
            # set the label to ROOT for each root dependent
            deco_labels = [ 'ROOT' if head == i else deco_labels[i] for i,head in enumerate(proj_heads) ]
            preprocessed.append((proj_heads,deco_labels))
 </s> add         freqs = Counter()
        for raw_text, sents in gold_tuples:
            prepro_sents = []
            for (ids, words, tags, heads, labels, iob), ctnts in sents:
                proj_heads,deco_labels = cls.projectivize(heads,labels)
                # set the label to ROOT for each root dependent
                deco_labels = [ 'ROOT' if head == i else deco_labels[i] for i,head in enumerate(proj_heads) ]
                # count label frequencies
                if label_freq_cutoff > 0:
                    freqs.update( label for label in deco_labels if cls.is_decorated(label) )
                prepro_sents.append(((ids,words,tags,proj_heads,deco_labels,iob), ctnts))
            preprocessed.append((raw_text, prepro_sents))
        queue = [token.head]
      def _find_new_head(self, rootid, tokenid, headlabel, heads, labels, spans=None):
          # search through the tree starting from root
          # returns the id of the first descendant with the given label
          # if there is none, return the current head (no change)
        queue = [token.head]
        queue = [token.head]
        queue = [token.head]
        queue = [token.head]
          while queue:
              next_queue = []
              for idx in queue:
                  if labels[idx] == headlabel:
                      return idx
keep keep keep keep replace replace replace replace keep keep keep keep keep
 integrated pseudo-projective parsing into parser

- nonproj.pyx holds a class PseudoProjectivity which currently holds
  all functionality to implement Nivre & Nilsson 2005's pseudo-projective
  parsing using the HEAD decoration scheme
- changed lefts/rights in Token to account for possible non-projective
  structures 
spacy/syntax/nonproj.pyx