#!/usr/bin/python
#encoding:utf8

__author__ = 'marlena'
from plumper.sumo.plwnpwnsumo_file import MappingFileOperator
import collections
import sys
import argparse

class Rubin(MappingFileOperator):
	def __init__(self):
		MappingFileOperator.__init__(self)
		self._plwn_sumo_rels = None


	def __linefunc(self, synset_id, sumo_str):
		self._plwn_sumo_rels[synset_id].add(sumo_str)


	def szlifuj(self, mapping_result_file, out_fileobj=sys.stdout):
		self._plwn_sumo_rels = collections.defaultdict(set)

		self.read_mapping_file(mapping_result_file,
                               (u'synset_id_plwn', u'pojecie_sumo'),
                               self.__linefunc)

		list_len = len(self._linebuffer)
		i = 0
		while i < list_len:
			synset_id = self._linebuffer[i][2]
			sumo_concept = self._linebuffer[i][8]
			if self._plwn_sumo_rels.has_key(synset_id) \
			and len(self._plwn_sumo_rels[synset_id]) > 1 \
			and sumo_concept == 'SubjectiveAssessmentAttribute':
				self._linebuffer.pop(i)
				list_len = list_len - 1
				continue
			i = i + 1

		self.print_contents(out_fileobj)


def main():
	argparser = argparse.ArgumentParser(description=__doc__)
	argparser.add_argument('mapping_result_file', help="csv file with " + 
													   "plWN -> SUMO " + 
													   "output")

	args = argparser.parse_args()

	r = Rubin()
	r.szlifuj(args.mapping_result_file)


if __name__ == '__main__':
	main()