from flow_elem import FlowElem
from defender import defender
__author__ = 'blaz'


class Defender(FlowElem):
    """
    It is wrapped defender document processor.
    """
    def __init__(self, config):
        self.defender_processor = \
            defender.Defender(config.get('defender','first_type_predicate'),
                              config.get('defender', 'gerundium_dictionary'),
                              config.get('defender', 'second_type_predicate'),
                              config.get('defender', 'only_continous')=='True',
                              tagset=config.get('saper', 'tagset'))

    def feed_flow(self, document):
        """
        Method processes document via defender and returns the result.

        @type document: corpus2.Document
        @rtype: corpus2.Document
        """
        np, agp, adjp = \
            self.defender_processor.read_all_phrases_from_document(document)
        annotated_document = \
            self.defender_processor.update_document_annotations_and_relations(
                document, 
                (np, adjp),
                update = True)
        return annotated_document