title: Creating custom component in SpaCy
body: <p>I am trying to create SpaCy pipeline component to return Spans of meaningful text (my corpus comprises pdf documents that have a lot of garbage that I am not interested in - tables, headers, etc.)</p>
  
  <p>More specifically I am trying to create a function  that:</p>
  
  <ol>
  <li>takes a <code>doc</code> object as an argument </li>
  <li>iterates over the <code>doc tokens</code></li>
  <li>When certain rules are met, yield a <code>Span</code> object </li>
  </ol>
  
  <blockquote>
    <p>Note I would also be happy with returning a <code>list([span_obj1, span_obj2])</code></p>
  </blockquote>
  
  <p>What is the best way to do something like this? I am a bit confused on the difference between a pipeline component and an extension attribute.</p>
  
  <p>So far I have tried:</p>
  
  <pre class="lang-py prettyprint-override"><code>nlp = English()
  
  Doc.set_extension('chunks', method=iQ_chunker)
  
  ####
  
  raw_text = get_test_doc()
  
  doc = nlp(raw_text)
  
  print(type(doc._.chunks))
  
  &gt;&gt;&gt; &lt;class 'functools.partial'&gt;
  </code></pre>
  
  <blockquote>
    <p>iQ_chunker is a method that does what I explain above and it returns a list of <code>Span</code> objects</p>
  </blockquote>
  
  <p>this is not the results I expect as the function I pass in as method returns a <code>list</code>.</p>