#
# Autogenerated by Thrift Compiler (1.0.0-dev)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py:new_style,utf8strings
#

from thrift.Thrift import TType, TMessageType, TException, TApplicationException
import concrete.uuid.ttypes
import concrete.language.ttypes
import concrete.structure.ttypes
import concrete.entities.ttypes
import concrete.situations.ttypes
import concrete.email.ttypes
import concrete.twitter.ttypes
import concrete.audio.ttypes
import concrete.nitf.ttypes


from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol, TProtocol
try:
  from thrift.protocol import fastbinary
except:
  fastbinary = None



class Communication(object):
  """
  A single communication instance, containing linguistic content
  generated by a single speaker or author.  This type is used for
  both inter-personal communications (such as phone calls or
  conversations) and third-party communications (such as news
  articles).

  Each communication instance is grounded by its original
  (unannotated) contents, which should be stored in either the
  "text" field (for text communications) or the "audio" field (for
  audio communications).  If the communication is not available in
  its original form, then these fields should store the
  communication in the least-processed form available.

  Attributes:
   - id: Stable identifier for this communication, identifying both the
  name of the source corpus and the document that it corresponds to
  in that corpus.
   - uuid: Universally unique identifier for this communication instance.
  This is generated randomly, and can *not* be mapped back to the
  source corpus. It is used as a target for symbolic "pointers".
   - type: An enumeration used to indicate what type of communication this
  is. The optional fields named "<i>kind</i>Info" can be used to
  store extra fields that are specific to the communication
  type.
   - text: The full text contents of this communication in its original
  form, or in the least-processed form available, if the original
  is not available.
   - startTime: The time when this communication started (in unix time UTC --
  i.e., seconds since January 1, 1970).
   - endTime: The time when this communication ended (in unix time UTC --
  i.e., seconds since January 1, 1970).
   - processedContent: Text that can be lightly processed - for example, taking an
  HTML document and removing tags so that NLP tools can better
  run over it.
   - lids: Theories about the languages that are present in this
  communication.
   - sectionSegmentations: Theories about the block structure of this communication.
   - entityMentionSets: Theories about which spans of text are used to mention entities
  in this communication.
   - entitySets: Theories about what entities are discussed in this
  communication, with pointers to individual mentions.
   - situationMentionSets: Theories about what situations are explicitly mentioned in this
  communication.
   - situationSets: Theories about what situations are asserted in this
  communication.
   - sound: The full audio contents of this communication in its original
  form, or in the least-processed form available, if the original
  is not available.
   - tweetInfo: Extra information for communications where kind==TWEET:
  Information about this tweet that is provided by the Twitter
  API.  For information about the Twitter API, see:
  <https://dev.twitter.com/docs/platform-objects>
   - emailInfo: Extra information for communications where kind==EMAIL
   - nitfInfo: Extra information that may come from the NITF
  (News Industry Text Format) schema. See 'nitf.thrift'.
   - keyValueMap: A catch-all store of keys and values. Use sparingly!
  """

  thrift_spec = (
    None, # 0
    (1, TType.STRING, 'id', None, None, ), # 1
    (2, TType.STRUCT, 'uuid', (concrete.uuid.ttypes.UUID, concrete.uuid.ttypes.UUID.thrift_spec), None, ), # 2
    (3, TType.STRING, 'type', None, None, ), # 3
    (4, TType.STRING, 'text', None, None, ), # 4
    (5, TType.I64, 'startTime', None, None, ), # 5
    (6, TType.I64, 'endTime', None, None, ), # 6
    (7, TType.STRING, 'processedContent', None, None, ), # 7
    None, # 8
    None, # 9
    (10, TType.LIST, 'lids', (TType.STRUCT,(concrete.language.ttypes.LanguageIdentification, concrete.language.ttypes.LanguageIdentification.thrift_spec)), None, ), # 10
    (11, TType.LIST, 'sectionSegmentations', (TType.STRUCT,(concrete.structure.ttypes.SectionSegmentation, concrete.structure.ttypes.SectionSegmentation.thrift_spec)), None, ), # 11
    (12, TType.LIST, 'entityMentionSets', (TType.STRUCT,(concrete.entities.ttypes.EntityMentionSet, concrete.entities.ttypes.EntityMentionSet.thrift_spec)), None, ), # 12
    (13, TType.LIST, 'entitySets', (TType.STRUCT,(concrete.entities.ttypes.EntitySet, concrete.entities.ttypes.EntitySet.thrift_spec)), None, ), # 13
    (14, TType.LIST, 'situationMentionSets', (TType.STRUCT,(concrete.situations.ttypes.SituationMentionSet, concrete.situations.ttypes.SituationMentionSet.thrift_spec)), None, ), # 14
    (15, TType.LIST, 'situationSets', (TType.STRUCT,(concrete.situations.ttypes.SituationSet, concrete.situations.ttypes.SituationSet.thrift_spec)), None, ), # 15
    None, # 16
    None, # 17
    None, # 18
    None, # 19
    (20, TType.STRUCT, 'sound', (concrete.audio.ttypes.Sound, concrete.audio.ttypes.Sound.thrift_spec), None, ), # 20
    (21, TType.STRUCT, 'tweetInfo', (concrete.twitter.ttypes.TweetInfo, concrete.twitter.ttypes.TweetInfo.thrift_spec), None, ), # 21
    (22, TType.STRUCT, 'emailInfo', (concrete.email.ttypes.EmailCommunicationInfo, concrete.email.ttypes.EmailCommunicationInfo.thrift_spec), None, ), # 22
    (23, TType.STRUCT, 'nitfInfo', (concrete.nitf.ttypes.NITFInfo, concrete.nitf.ttypes.NITFInfo.thrift_spec), None, ), # 23
    None, # 24
    None, # 25
    None, # 26
    None, # 27
    None, # 28
    None, # 29
    (30, TType.MAP, 'keyValueMap', (TType.STRING,None,TType.STRING,None), None, ), # 30
  )

  def __init__(self, id=None, uuid=None, type=None, text=None, startTime=None, endTime=None, processedContent=None, lids=None, sectionSegmentations=None, entityMentionSets=None, entitySets=None, situationMentionSets=None, situationSets=None, sound=None, tweetInfo=None, emailInfo=None, nitfInfo=None, keyValueMap=None,):
    self.id = id
    self.uuid = uuid
    self.type = type
    self.text = text
    self.startTime = startTime
    self.endTime = endTime
    self.processedContent = processedContent
    self.lids = lids
    self.sectionSegmentations = sectionSegmentations
    self.entityMentionSets = entityMentionSets
    self.entitySets = entitySets
    self.situationMentionSets = situationMentionSets
    self.situationSets = situationSets
    self.sound = sound
    self.tweetInfo = tweetInfo
    self.emailInfo = emailInfo
    self.nitfInfo = nitfInfo
    self.keyValueMap = keyValueMap

  def read(self, iprot):
    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
      fastbinary.decode_binary(self, iprot.trans, (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.STRING:
          self.id = iprot.readString().decode('utf-8')
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.STRUCT:
          self.uuid = concrete.uuid.ttypes.UUID()
          self.uuid.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 3:
        if ftype == TType.STRING:
          self.type = iprot.readString().decode('utf-8')
        else:
          iprot.skip(ftype)
      elif fid == 4:
        if ftype == TType.STRING:
          self.text = iprot.readString().decode('utf-8')
        else:
          iprot.skip(ftype)
      elif fid == 5:
        if ftype == TType.I64:
          self.startTime = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 6:
        if ftype == TType.I64:
          self.endTime = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 7:
        if ftype == TType.STRING:
          self.processedContent = iprot.readString().decode('utf-8')
        else:
          iprot.skip(ftype)
      elif fid == 10:
        if ftype == TType.LIST:
          self.lids = []
          (_etype3, _size0) = iprot.readListBegin()
          for _i4 in xrange(_size0):
            _elem5 = concrete.language.ttypes.LanguageIdentification()
            _elem5.read(iprot)
            self.lids.append(_elem5)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 11:
        if ftype == TType.LIST:
          self.sectionSegmentations = []
          (_etype9, _size6) = iprot.readListBegin()
          for _i10 in xrange(_size6):
            _elem11 = concrete.structure.ttypes.SectionSegmentation()
            _elem11.read(iprot)
            self.sectionSegmentations.append(_elem11)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 12:
        if ftype == TType.LIST:
          self.entityMentionSets = []
          (_etype15, _size12) = iprot.readListBegin()
          for _i16 in xrange(_size12):
            _elem17 = concrete.entities.ttypes.EntityMentionSet()
            _elem17.read(iprot)
            self.entityMentionSets.append(_elem17)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 13:
        if ftype == TType.LIST:
          self.entitySets = []
          (_etype21, _size18) = iprot.readListBegin()
          for _i22 in xrange(_size18):
            _elem23 = concrete.entities.ttypes.EntitySet()
            _elem23.read(iprot)
            self.entitySets.append(_elem23)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 14:
        if ftype == TType.LIST:
          self.situationMentionSets = []
          (_etype27, _size24) = iprot.readListBegin()
          for _i28 in xrange(_size24):
            _elem29 = concrete.situations.ttypes.SituationMentionSet()
            _elem29.read(iprot)
            self.situationMentionSets.append(_elem29)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 15:
        if ftype == TType.LIST:
          self.situationSets = []
          (_etype33, _size30) = iprot.readListBegin()
          for _i34 in xrange(_size30):
            _elem35 = concrete.situations.ttypes.SituationSet()
            _elem35.read(iprot)
            self.situationSets.append(_elem35)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 20:
        if ftype == TType.STRUCT:
          self.sound = concrete.audio.ttypes.Sound()
          self.sound.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 21:
        if ftype == TType.STRUCT:
          self.tweetInfo = concrete.twitter.ttypes.TweetInfo()
          self.tweetInfo.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 22:
        if ftype == TType.STRUCT:
          self.emailInfo = concrete.email.ttypes.EmailCommunicationInfo()
          self.emailInfo.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 23:
        if ftype == TType.STRUCT:
          self.nitfInfo = concrete.nitf.ttypes.NITFInfo()
          self.nitfInfo.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 30:
        if ftype == TType.MAP:
          self.keyValueMap = {}
          (_ktype37, _vtype38, _size36 ) = iprot.readMapBegin()
          for _i40 in xrange(_size36):
            _key41 = iprot.readString().decode('utf-8')
            _val42 = iprot.readString().decode('utf-8')
            self.keyValueMap[_key41] = _val42
          iprot.readMapEnd()
        else:
          iprot.skip(ftype)
      else:
        iprot.skip(ftype)
      iprot.readFieldEnd()
    iprot.readStructEnd()

  def write(self, oprot):
    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
      return
    oprot.writeStructBegin('Communication')
    if self.id is not None:
      oprot.writeFieldBegin('id', TType.STRING, 1)
      oprot.writeString(self.id.encode('utf-8'))
      oprot.writeFieldEnd()
    if self.uuid is not None:
      oprot.writeFieldBegin('uuid', TType.STRUCT, 2)
      self.uuid.write(oprot)
      oprot.writeFieldEnd()
    if self.type is not None:
      oprot.writeFieldBegin('type', TType.STRING, 3)
      oprot.writeString(self.type.encode('utf-8'))
      oprot.writeFieldEnd()
    if self.text is not None:
      oprot.writeFieldBegin('text', TType.STRING, 4)
      oprot.writeString(self.text.encode('utf-8'))
      oprot.writeFieldEnd()
    if self.startTime is not None:
      oprot.writeFieldBegin('startTime', TType.I64, 5)
      oprot.writeI64(self.startTime)
      oprot.writeFieldEnd()
    if self.endTime is not None:
      oprot.writeFieldBegin('endTime', TType.I64, 6)
      oprot.writeI64(self.endTime)
      oprot.writeFieldEnd()
    if self.processedContent is not None:
      oprot.writeFieldBegin('processedContent', TType.STRING, 7)
      oprot.writeString(self.processedContent.encode('utf-8'))
      oprot.writeFieldEnd()
    if self.lids is not None:
      oprot.writeFieldBegin('lids', TType.LIST, 10)
      oprot.writeListBegin(TType.STRUCT, len(self.lids))
      for iter43 in self.lids:
        iter43.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.sectionSegmentations is not None:
      oprot.writeFieldBegin('sectionSegmentations', TType.LIST, 11)
      oprot.writeListBegin(TType.STRUCT, len(self.sectionSegmentations))
      for iter44 in self.sectionSegmentations:
        iter44.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.entityMentionSets is not None:
      oprot.writeFieldBegin('entityMentionSets', TType.LIST, 12)
      oprot.writeListBegin(TType.STRUCT, len(self.entityMentionSets))
      for iter45 in self.entityMentionSets:
        iter45.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.entitySets is not None:
      oprot.writeFieldBegin('entitySets', TType.LIST, 13)
      oprot.writeListBegin(TType.STRUCT, len(self.entitySets))
      for iter46 in self.entitySets:
        iter46.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.situationMentionSets is not None:
      oprot.writeFieldBegin('situationMentionSets', TType.LIST, 14)
      oprot.writeListBegin(TType.STRUCT, len(self.situationMentionSets))
      for iter47 in self.situationMentionSets:
        iter47.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.situationSets is not None:
      oprot.writeFieldBegin('situationSets', TType.LIST, 15)
      oprot.writeListBegin(TType.STRUCT, len(self.situationSets))
      for iter48 in self.situationSets:
        iter48.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.sound is not None:
      oprot.writeFieldBegin('sound', TType.STRUCT, 20)
      self.sound.write(oprot)
      oprot.writeFieldEnd()
    if self.tweetInfo is not None:
      oprot.writeFieldBegin('tweetInfo', TType.STRUCT, 21)
      self.tweetInfo.write(oprot)
      oprot.writeFieldEnd()
    if self.emailInfo is not None:
      oprot.writeFieldBegin('emailInfo', TType.STRUCT, 22)
      self.emailInfo.write(oprot)
      oprot.writeFieldEnd()
    if self.nitfInfo is not None:
      oprot.writeFieldBegin('nitfInfo', TType.STRUCT, 23)
      self.nitfInfo.write(oprot)
      oprot.writeFieldEnd()
    if self.keyValueMap is not None:
      oprot.writeFieldBegin('keyValueMap', TType.MAP, 30)
      oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.keyValueMap))
      for kiter49,viter50 in self.keyValueMap.items():
        oprot.writeString(kiter49.encode('utf-8'))
        oprot.writeString(viter50.encode('utf-8'))
      oprot.writeMapEnd()
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

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


  def __repr__(self):
    L = ['%s=%r' % (key, value)
      for key, value in self.__dict__.iteritems()]
    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)
