#
# <one line to give the library's name and an idea of what it does.>
# Copyright (C) 2014  <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 nodeinterface
import grafon.constants as constants

class SynsetNode(nodeinterface.NodeInterface):
  """!
  This class inherit from NodeInterface.
  Represents the token as a synset.
  """
  
  def __init__(self, tagset):
    """!
    A child of NodeInterface, constructor only calls the NodeInterface
    constructor and doing nothing else.

    @param tagset: Tagset used in process of document reading with type
                   corpus2.Tagset
    """
    super(SynsetNode, self).__init__(tagset)

  def key(self, token):
    """!
    Implementation of abstract key method.

    It gets as argument a tokent and convert it to synset identifier based
    on the token preperies. It checks into the token properties the metadata
    of WSD annotation in key named as "sense:ukb:syns_id"

    @param token: corpus2.Token which sould be converted to key
    @return synset identifier of given token or None if token is not given
                   or None in case when token is not disambiguated
    """
    if not token:
      return [None]
    md = token.get_metadata()
    if md:
      return [md.get_attribute(constants.TOKEN_SENSE_UKB_SYNSET_ID)]
    return [None]