#
# <one line to give the library's name and an idea of what it does.>
# Copyright (C) 2015  <copyright holder> <email>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 
#


import sys

import wccl
import corpus2
import logging

class MWEBuilder:
  """!
  This class implements MWE extraction from the text.

  When the MWE is extracted from the text, then is inserted as the single node.

  WARNING! 
    If you would like to use this builder mwe_extract 
    repository must be installed into your system!
  """

  def __init__(self, mwedictpath):
    """!
    Constructor reads the MWE from path to dictionary given as argument.

    @param mwedict
    @type mwedict: mwe
    """
    # reads the dictonary
    self._logger = logging.getLogger(__name__)
    self._logger.debug('Reading MWE dictionary from file %s' % mwedictpath)

    from mwe_extract import mwedictreader
    mwerdr = mwedictreader.MWEDictReader()
    self._mwedictionary = mwerdr.read(mwedictpath)

  def apply(self, sentence, tagset):
    asent = corpus2.AnnotatedSentence.wrap_sentence(sentence)
    con = wccl.SentenceContext(asent.clone_shared())
    # con.goto_start()

    for mwegrp in self._mwedictionary:
      op = mwegrp.operator
      for conpos in range(0, con.size()):
        con.set_position(conpos)
        res = op.base_apply(con).to_string(tagset)
        print >> sys.stderr, res
    return None