#
# Autogenerated by Thrift Compiler (0.9.1)
#
# 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.metadata.ttypes


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



class ClusterMember(object):
  """
  A member of a 'cluster'.

  Contains a communication ID, an Entity|Situation(Mention)Set ID,
  and an element ID that identifies the specific
  Entity|Situation(Mention) associated with this object.

  Attributes:
   - communicationId: The UUID of the Communication this ClusterMember is associated with.
   - setId: The UUID of the Entity|Situation(Mention)Set this ClusterMember
  is associated with.
   - elementId: The UUID of the specific EntityMention, Entity, SituationMention,
  or Situation that this ClusterMember is tied to.
  """

  thrift_spec = (
    None, # 0
    (1, TType.STRUCT, 'communicationId', (concrete.uuid.ttypes.UUID, concrete.uuid.ttypes.UUID.thrift_spec), None, ), # 1
    (2, TType.STRUCT, 'setId', (concrete.uuid.ttypes.UUID, concrete.uuid.ttypes.UUID.thrift_spec), None, ), # 2
    (3, TType.STRUCT, 'elementId', (concrete.uuid.ttypes.UUID, concrete.uuid.ttypes.UUID.thrift_spec), None, ), # 3
  )

  def __init__(self, communicationId=None, setId=None, elementId=None,):
    self.communicationId = communicationId
    self.setId = setId
    self.elementId = elementId

  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.STRUCT:
          self.communicationId = concrete.uuid.ttypes.UUID()
          self.communicationId.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.STRUCT:
          self.setId = concrete.uuid.ttypes.UUID()
          self.setId.read(iprot)
        else:
          iprot.skip(ftype)
      elif fid == 3:
        if ftype == TType.STRUCT:
          self.elementId = concrete.uuid.ttypes.UUID()
          self.elementId.read(iprot)
        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('ClusterMember')
    if self.communicationId is not None:
      oprot.writeFieldBegin('communicationId', TType.STRUCT, 1)
      self.communicationId.write(oprot)
      oprot.writeFieldEnd()
    if self.setId is not None:
      oprot.writeFieldBegin('setId', TType.STRUCT, 2)
      self.setId.write(oprot)
      oprot.writeFieldEnd()
    if self.elementId is not None:
      oprot.writeFieldBegin('elementId', TType.STRUCT, 3)
      self.elementId.write(oprot)
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

  def validate(self):
    if self.communicationId is None:
      raise TProtocol.TProtocolException(message='Required field communicationId is unset!')
    if self.setId is None:
      raise TProtocol.TProtocolException(message='Required field setId is unset!')
    if self.elementId is None:
      raise TProtocol.TProtocolException(message='Required field elementId is unset!')
    return


  def __hash__(self):
    value = 17
    value = (value * 31) ^ hash(self.communicationId)
    value = (value * 31) ^ hash(self.setId)
    value = (value * 31) ^ hash(self.elementId)
    return value

  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)

class Cluster(object):
  """
  A structure that represents a cluster of Communications.

  This structure allows for  specific grouping of ClusterMembers,
  as well as other Clusters that this Cluster object considers children.

  Attributes:
   - clusterMemberIndexList: A list of integers that represent indices into a list of ClusterMember
  objects (likely represented in a Clustering object).
   - confidenceList: Confidence values for members of 'memberIndexList' field.
   - childIndexList: A list of integers that represent indices into a list of Cluster objects,
  used to represent child Clusters associated with this particular Cluster.
  """

  thrift_spec = (
    None, # 0
    (1, TType.LIST, 'clusterMemberIndexList', (TType.I32,None), None, ), # 1
    (2, TType.LIST, 'confidenceList', (TType.DOUBLE,None), None, ), # 2
    (3, TType.LIST, 'childIndexList', (TType.I32,None), None, ), # 3
  )

  def __init__(self, clusterMemberIndexList=None, confidenceList=None, childIndexList=None,):
    self.clusterMemberIndexList = clusterMemberIndexList
    self.confidenceList = confidenceList
    self.childIndexList = childIndexList

  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.LIST:
          self.clusterMemberIndexList = []
          (_etype3, _size0) = iprot.readListBegin()
          for _i4 in xrange(_size0):
            _elem5 = iprot.readI32();
            self.clusterMemberIndexList.append(_elem5)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.LIST:
          self.confidenceList = []
          (_etype9, _size6) = iprot.readListBegin()
          for _i10 in xrange(_size6):
            _elem11 = iprot.readDouble();
            self.confidenceList.append(_elem11)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 3:
        if ftype == TType.LIST:
          self.childIndexList = []
          (_etype15, _size12) = iprot.readListBegin()
          for _i16 in xrange(_size12):
            _elem17 = iprot.readI32();
            self.childIndexList.append(_elem17)
          iprot.readListEnd()
        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('Cluster')
    if self.clusterMemberIndexList is not None:
      oprot.writeFieldBegin('clusterMemberIndexList', TType.LIST, 1)
      oprot.writeListBegin(TType.I32, len(self.clusterMemberIndexList))
      for iter18 in self.clusterMemberIndexList:
        oprot.writeI32(iter18)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.confidenceList is not None:
      oprot.writeFieldBegin('confidenceList', TType.LIST, 2)
      oprot.writeListBegin(TType.DOUBLE, len(self.confidenceList))
      for iter19 in self.confidenceList:
        oprot.writeDouble(iter19)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.childIndexList is not None:
      oprot.writeFieldBegin('childIndexList', TType.LIST, 3)
      oprot.writeListBegin(TType.I32, len(self.childIndexList))
      for iter20 in self.childIndexList:
        oprot.writeI32(iter20)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

  def validate(self):
    return


  def __hash__(self):
    value = 17
    value = (value * 31) ^ hash(self.clusterMemberIndexList)
    value = (value * 31) ^ hash(self.confidenceList)
    value = (value * 31) ^ hash(self.childIndexList)
    return value

  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)

class Clustering(object):
  """
  A structure that represents a "clustering" of Communications, to support
  cross-document coreference tasks.

  Attributes:
   - uuid: UUID for this Clustering object.
   - metadata: Metadata for this Clustering object.
   - clusterMemberList: A complete list of ClusterMember objects that this Clustering holds.
   - clusterList: A complete list of Cluster objects that this Clustering holds.
   - rootClusterIndexList: A list of integers that represent root Clusters. These integers should be
  indices into the 'clusterList' object.
  """

  thrift_spec = (
    None, # 0
    (1, TType.STRUCT, 'uuid', (concrete.uuid.ttypes.UUID, concrete.uuid.ttypes.UUID.thrift_spec), None, ), # 1
    (2, TType.STRUCT, 'metadata', (concrete.metadata.ttypes.AnnotationMetadata, concrete.metadata.ttypes.AnnotationMetadata.thrift_spec), None, ), # 2
    (3, TType.LIST, 'clusterMemberList', (TType.STRUCT,(ClusterMember, ClusterMember.thrift_spec)), None, ), # 3
    (4, TType.LIST, 'clusterList', (TType.STRUCT,(Cluster, Cluster.thrift_spec)), None, ), # 4
    (5, TType.LIST, 'rootClusterIndexList', (TType.I32,None), None, ), # 5
  )

  def __init__(self, uuid=None, metadata=None, clusterMemberList=None, clusterList=None, rootClusterIndexList=None,):
    self.uuid = uuid
    self.metadata = metadata
    self.clusterMemberList = clusterMemberList
    self.clusterList = clusterList
    self.rootClusterIndexList = rootClusterIndexList

  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.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.LIST:
          self.clusterMemberList = []
          (_etype24, _size21) = iprot.readListBegin()
          for _i25 in xrange(_size21):
            _elem26 = ClusterMember()
            _elem26.read(iprot)
            self.clusterMemberList.append(_elem26)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 4:
        if ftype == TType.LIST:
          self.clusterList = []
          (_etype30, _size27) = iprot.readListBegin()
          for _i31 in xrange(_size27):
            _elem32 = Cluster()
            _elem32.read(iprot)
            self.clusterList.append(_elem32)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 5:
        if ftype == TType.LIST:
          self.rootClusterIndexList = []
          (_etype36, _size33) = iprot.readListBegin()
          for _i37 in xrange(_size33):
            _elem38 = iprot.readI32();
            self.rootClusterIndexList.append(_elem38)
          iprot.readListEnd()
        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('Clustering')
    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.clusterMemberList is not None:
      oprot.writeFieldBegin('clusterMemberList', TType.LIST, 3)
      oprot.writeListBegin(TType.STRUCT, len(self.clusterMemberList))
      for iter39 in self.clusterMemberList:
        iter39.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.clusterList is not None:
      oprot.writeFieldBegin('clusterList', TType.LIST, 4)
      oprot.writeListBegin(TType.STRUCT, len(self.clusterList))
      for iter40 in self.clusterList:
        iter40.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.rootClusterIndexList is not None:
      oprot.writeFieldBegin('rootClusterIndexList', TType.LIST, 5)
      oprot.writeListBegin(TType.I32, len(self.rootClusterIndexList))
      for iter41 in self.rootClusterIndexList:
        oprot.writeI32(iter41)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

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


  def __hash__(self):
    value = 17
    value = (value * 31) ^ hash(self.uuid)
    value = (value * 31) ^ hash(self.metadata)
    value = (value * 31) ^ hash(self.clusterMemberList)
    value = (value * 31) ^ hash(self.clusterList)
    value = (value * 31) ^ hash(self.rootClusterIndexList)
    return value

  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)
