Apply the transformation
@param ITokenTransformation $transformer
@param boolean Remove nulls, we need nulls to indictate where stop words are
@return \TextAnalysis\Documents\TokensDocument
428426
public function applyTransformation(ITokenTransformation $transformer, $removeNulls = true) 
    {        
        foreach($this->tokens as &$token) 
        { 
            $token = $transformer->transform($token);
        }
        //filter null tokens and re-index
        if($removeNulls) {
            $this->tokens = array_values(array_filter($this->tokens));
        }
        return $this;
    }
181612
public function applyStemmer(IStemmer $stemmer, $removeNulls = true) 
    {        
        foreach($this->tokens as &$token) 
        { 
            $token = $stemmer->stem($token);
        }
        
        if($removeNulls) {
            //filter null tokens and re-index
            $this->tokens = array_values(array_filter($this->tokens));            
        }
        return $this;
    }
123340
public function itemWith($entity, $transformer, $key = null): TransformationFactory
	{
		$this->entity      = $entity;
		$this->transformer = $transformer;
		$this->resource    = new Item($entity, $transformer, $key);

		return $this;
	}
27922
public function setTransformer($transformer)
    {
        if (!(new \ReflectionClass($transformer))->implementsInterface(TransformerInterface::class)) {
            throw new InvalidTransformer();
        }

        $this->transformer = $transformer;

        return $this;
    }
487259
public function transform(callable $transformer)
    {
        $items = $this->getItems();

        $transformed = $transformer($items instanceof Collection ? $items : new Collection($items));

        if (!($transformed instanceof Collection)) {
            throw new InvalidReturnValue;
        }

        return $transformed;
    }
620230
public function detachCodeTransformer(AbstractCodeTransform $codeTransformer)
    {
        if (!empty(static::$codeTransformers[$codeTransformer::NAME])) {
            unset(static::$codeTransformers[$codeTransformer::NAME]);
        }
    }
298902
public function add($field, DataSetTransformerInterface $transformer)
    {
        if ($this->has($field)) {
            throw new TransformerInvalidColumnException($field);
        }

        $this->items[$field] = $transformer;
    }
279790
public void transformSelectedNodes(TransformerImpl transformer)
          throws TransformerException
  {

    final XPathContext xctxt = transformer.getXPathContext();
    final int sourceNode = xctxt.getCurrentNode();
    DTMIterator sourceNodes = m_selectExpression.asIterator(xctxt,
            sourceNode);

    try
    {

      final Vector keys = (m_sortElems == null)
              ? null
              : transformer.processSortKeys(this, sourceNode);

      // Sort if we need to.
      if (null != keys)
        sourceNodes = sortNodes(xctxt, keys, sourceNodes);

      xctxt.pushCurrentNode(DTM.NULL);

      IntStack currentNodes = xctxt.getCurrentNodeStack();

      xctxt.pushCurrentExpressionNode(DTM.NULL);

      IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();

      xctxt.pushSAXLocatorNull();
      xctxt.pushContextNodeList(sourceNodes);
      transformer.pushElemTemplateElement(null);

      // pushParams(transformer, xctxt);
      // Should be able to get this from the iterator but there must be a bug.
      DTM dtm = xctxt.getDTM(sourceNode);
      int docID = sourceNode & DTMManager.IDENT_DTM_DEFAULT;
      int child;

      while (DTM.NULL != (child = sourceNodes.nextNode()))
      {
        currentNodes.setTop(child);
        currentExpressionNodes.setTop(child);

        if ((child & DTMManager.IDENT_DTM_DEFAULT) != docID)
        {
          dtm = xctxt.getDTM(child);
          docID = child & DTMManager.IDENT_DTM_DEFAULT;
        }

        //final int exNodeType = dtm.getExpandedTypeID(child);
        final int nodeType = dtm.getNodeType(child); 

        // And execute the child templates.
        // Loop through the children of the template, calling execute on 
        // each of them.
        for (ElemTemplateElement t = this.m_firstChild; t != null;
             t = t.m_nextSibling)
        {
          xctxt.setSAXLocator(t);
          transformer.setCurrentElement(t);
          t.execute(transformer);
        }

        // KLUGE: Implement <?xalan:doc_cache_off?>
	 	// ASSUMPTION: This will be set only when the XPath was indeed
	 	// a call to the Document() function. Calling it in other
	 	// situations is likely to fry Xalan.
	 	//
	 	// %REVIEW% We need a MUCH cleaner solution -- one that will
	 	// handle cleaning up after document() and getDTM() in other
		// contexts. The whole SourceTreeManager mechanism should probably
	 	// be moved into DTMManager rather than being explicitly invoked in
	 	// FuncDocument and here.
	 	if(m_doc_cache_off)
		{
	 	  if(DEBUG)
	 	    System.out.println("JJK***** CACHE RELEASE *****\n"+
				       "\tdtm="+dtm.getDocumentBaseURI());
	  	// NOTE: This will work because this is _NOT_ a shared DTM, and thus has
	  	// only a single Document node. If it could ever be an RTF or other
	 	// shared DTM, this would require substantial rework.
	 	  xctxt.getSourceTreeManager().removeDocumentFromCache(dtm.getDocument());
	 	  xctxt.release(dtm,false);
	 	}
      }
    }
    finally
    {
      xctxt.popSAXLocator();
      xctxt.popContextNodeList();
      transformer.popElemTemplateElement();
      xctxt.popCurrentExpressionNode();
      xctxt.popCurrentNode();
      sourceNodes.detach();
    }
  }
636447
public function editChildren(
        ResourceTransformer $transformer,
        $entity,
        RelationshipField $field,
        array $childEntities,
        Context $context
    )
    {
        list($entity, $name, $parameters) = $this->resolvePath($transformer, $entity, $field, $context);
        $this->editChildrenInEntity($entity, $name, $childEntities, $parameters);
    }
239151
private function makeTemplate($transformer, $model, $template)
    {
        $template = !empty($template) ? "-{$template}" : "";
        $file = __DIR__ . "/../templates/transformer/transformer{$template}.php.dist";

        if (file_exists($file))
        {
            $template = strtr(file_get_contents($file), [
                '{{namespace}}' => get_app_namespace(),
                '{{transformer}}' => $transformer,
                '{{model}}' => $model,
                '{{model_small}}' => strtolower($model),
            ]);

            if (!file_exists(app_path("Transformers")))
            {
                mkdir(app_path("Transformers"), 0755, true);
            }

            $file_path = app_path("Transformers/{$transformer}.php");

            $file = fopen($file_path, "w");
            fwrite($file, $template);
            fclose($file);

            return file_exists($file_path);
        }

        return false;
    }
1113757
public function executeOn(Collection $collection)
    {
        if (empty($collection) || $collection->first() === null) {
            return $collection;
        }

        $transformer = $this->repository->transformer;

        if (!(new \ReflectionClass($transformer))->implementsInterface(TransformerInterface::class)) {
            throw new InvalidTransformer();
        }

        /** @var TransformerInterface $transformer */
        $transformer = new $transformer($collection);

        return $transformer->execute();
    }
298214
@SuppressWarnings("unchecked")
    public <TO> ChainedTransformer<I, TO> chain(Transformer<O, TO> transformer) {
        if (transformer != null) {
            transformers.add(transformer);
        }
        return (ChainedTransformer<I, TO>) this;
    }
635846
public function setTransformer($transformer = null)
    {
        if (!$this->resource) {
            throw new MissingResourceException('Resource must be specified before setting a transformer');
        }
        $this->resource->setTransformer($transformer);

        return $this;
    }
1294012
public function isValidTransformer($transformer): bool
    {
        if ($transformer instanceof TransformerInterface) {
            return true;
        }

        if (\is_callable($transformer)) {
            return true;
        }

        return false;
    }
918837
public function removeTransformation(TransformationInterface $transformation)
    {

        $this->transformations = array_filter($this->transformations, function (TransformationInterface $t) use ($transformation) {

            return $t !== $transformation;
        });

        return $this;
    }
807717
protected function appendReceivedTransformations(Transformer $transformer, $received)
    {
        if (!empty($received)) {
            $template = new Template('__');
            foreach ($received as $transformation) {
                $template[] = $transformation;
            }
            $transformer->getTemplates()->append($template);
        }
    }
274181
private Transformer createTransformer(boolean indent) {

    try {
      Transformer result = this.transformerFactory.newTransformer();
      if (indent) {
        result.setOutputProperty(OutputKeys.INDENT, "yes");
      }
      return result;
    } catch (TransformerConfigurationException e) {
      throw new IllegalStateException("XML Transformer misconfigured!" + " Probably your JVM does not support the required JAXP version!", e);
    }
  }