import corpus2
from flow_elem import FlowElem
import saper.saperio.malt


class Malt(FlowElem):
    """Run MaltParser in order to get extra information."""

    def __init__(self, config):
        u"""Initialize MaltRunner class.

        The config must have section 'maltparser' which contains: 
        'malt_parser_path', 'data_model', 'data_model_localization'.

        Args:
            config (saper.config.ConfigLoader): it contains MaltParser 
                configuration.
        """
        self.tagset = corpus2.get_named_tagset(config.get('saper','tagset'))
        self.malt_runner = saper.saperio.malt.MaltRunner(config)

    def feed_flow(self, document):
        u"""Add MaltParser information to the corpus2.Document.

        Args:
            document (corpus2.Document): the document to extend.

        Returns:
            (corpus2.Document): extended input document.
        """
        return self.malt_runner.process_document(document)
