# -*- coding: utf-8 -*-
#
# Autogenerated by Thrift Compiler (0.11.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py:coding=utf-8
#

from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
from thrift.protocol.TProtocol import TProtocolException
from thrift.TRecursive import fix_spec

import sys
import concrete.metadata.ttypes
import concrete.uuid.ttypes

from thrift.transport import TTransport
all_structs = []


class LanguageIdentification(object):
    """
    A theory about what languages are present in a given communication
    or piece of communication.  Note that it is possible to have more
    than one language present in a given communication.

    Attributes:
     - uuid: Unique identifier for this language identification.
     - metadata: Information about where this language identification came from.
     - languageToProbabilityMap: A list mapping from a language to the probability that that
    language occurs in a given communication.  Each language code should
    occur at most once in this list.  The probabilities do <i>not</i>
    need to sum to one -- for example, if a single communication is known
    to contain both English and French, then it would be appropriate
    to assign a probability of 1 to both langauges.  (Manually
    annotated LanguageProb objects should always have probabilities
    of either zero or one; machine-generated LanguageProbs may have
    intermediate probabilities.)

    Note: The string key should represent the ISO 639-3 three-letter code.
    """


    def __init__(self, uuid=None, metadata=None, languageToProbabilityMap=None,):
        self.uuid = uuid
        self.metadata = metadata
        self.languageToProbabilityMap = languageToProbabilityMap

    def read(self, iprot):
        if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
            iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
            return
        iprot.readStructBegin()
        while True:
            (fname, ftype, fid) = iprot.readFieldBegin()
            if ftype == TType.STOP:
                break
            if fid == 1:
                if ftype == TType.STRUCT:
                    self.uuid = concrete.uuid.ttypes.UUID()
                    self.uuid.read(iprot)
                else:
                    iprot.skip(ftype)
            elif fid == 2:
                if ftype == TType.STRUCT:
                    self.metadata = concrete.metadata.ttypes.AnnotationMetadata()
                    self.metadata.read(iprot)
                else:
                    iprot.skip(ftype)
            elif fid == 3:
                if ftype == TType.MAP:
                    self.languageToProbabilityMap = {}
                    (_ktype1, _vtype2, _size0) = iprot.readMapBegin()
                    for _i4 in range(_size0):
                        _key5 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
                        _val6 = iprot.readDouble()
                        self.languageToProbabilityMap[_key5] = _val6
                    iprot.readMapEnd()
                else:
                    iprot.skip(ftype)
            else:
                iprot.skip(ftype)
            iprot.readFieldEnd()
        iprot.readStructEnd()

    def write(self, oprot):
        if oprot._fast_encode is not None and self.thrift_spec is not None:
            oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec]))
            return
        oprot.writeStructBegin('LanguageIdentification')
        if self.uuid is not None:
            oprot.writeFieldBegin('uuid', TType.STRUCT, 1)
            self.uuid.write(oprot)
            oprot.writeFieldEnd()
        if self.metadata is not None:
            oprot.writeFieldBegin('metadata', TType.STRUCT, 2)
            self.metadata.write(oprot)
            oprot.writeFieldEnd()
        if self.languageToProbabilityMap is not None:
            oprot.writeFieldBegin('languageToProbabilityMap', TType.MAP, 3)
            oprot.writeMapBegin(TType.STRING, TType.DOUBLE, len(self.languageToProbabilityMap))
            for kiter7, viter8 in self.languageToProbabilityMap.items():
                oprot.writeString(kiter7.encode('utf-8') if sys.version_info[0] == 2 else kiter7)
                oprot.writeDouble(viter8)
            oprot.writeMapEnd()
            oprot.writeFieldEnd()
        oprot.writeFieldStop()
        oprot.writeStructEnd()

    def validate(self):
        if self.uuid is None:
            raise TProtocolException(message='Required field uuid is unset!')
        if self.metadata is None:
            raise TProtocolException(message='Required field metadata is unset!')
        if self.languageToProbabilityMap is None:
            raise TProtocolException(message='Required field languageToProbabilityMap is unset!')
        return

    def __repr__(self):
        L = ['%s=%r' % (key, value)
             for key, value in self.__dict__.items()]
        return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

    def __eq__(self, other):
        return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

    def __ne__(self, other):
        return not (self == other)
all_structs.append(LanguageIdentification)
LanguageIdentification.thrift_spec = (
    None,  # 0
    (1, TType.STRUCT, 'uuid', [concrete.uuid.ttypes.UUID, None], None, ),  # 1
    (2, TType.STRUCT, 'metadata', [concrete.metadata.ttypes.AnnotationMetadata, None], None, ),  # 2
    (3, TType.MAP, 'languageToProbabilityMap', (TType.STRING, 'UTF8', TType.DOUBLE, None, False), None, ),  # 3
)
fix_spec(all_structs)
del all_structs
