parameters: (XfileName, labelsFileName, datasetFileName)
docstring: make a sparse format data file out of an unlabeled sparse data file
      and a labels file (comma delimited:  id,label)
docstring_summary: make a sparse format data file out of an unlabeled sparse data file
      and a labels file (comma delimited:  id,label)
docstring_tokens: make a sparse format data file out of an unlabeled sparse data file and a labels file ( comma delimited : id label )
function: def makeDataSet(XfileName, labelsFileName, datasetFileName) :
      '''make a sparse format data file out of an unlabeled sparse data file
      and a labels file (comma delimited:  id,label)
      '''
      
      if not os.path.exists(XfileName) :
          raise ValueError, "Xfile does not exist at %s" % XfileName
  
      if not os.path.exists(labelsFileName) :
          raise ValueError, "labels file does not exist at %s" % LabelsFileName
  
      labelsFile = open(labelsFileName)
  
      labels = {}
      for line in labelsFile :
          line = line[:-1]
          if len(line.split()) ==2 :
              (id,label) = line.split()
          else :
              (id,label) = line.split(',')
          labels[id] = label
  
      print len(labels)
      labelsFile.close()
      
      Xfile = open(XfileName)
      datasetFile = open(datasetFileName, 'w')
  
      for line in Xfile :
          (id, restOfLine) = line.split(',')
          if labels.has_key(id) :
              datasetFile.write(id + ',' + labels[id] + ' ' + restOfLine)
  
      Xfile.close()
      datasetFile.close()
function_tokens: def makeDataSet ( XfileName , labelsFileName , datasetFileName ) : if not os . path . exists ( XfileName ) : raise ValueError , "Xfile does not exist at %s" % XfileName if not os . path . exists ( labelsFileName ) : raise ValueError , "labels file does not exist at %s" % LabelsFileName labelsFile = open ( labelsFileName ) labels = { } for line in labelsFile : line = line [ : - 1 ] if len ( line . split ( ) ) == 2 : ( id , label ) = line . split ( ) else : ( id , label ) = line . split ( ',' ) labels [ id ] = label print len ( labels ) labelsFile . close ( ) Xfile = open ( XfileName ) datasetFile = open ( datasetFileName , 'w' ) for line in Xfile : ( id , restOfLine ) = line . split ( ',' ) if labels . has_key ( id ) : datasetFile . write ( id + ',' + labels [ id ] + ' ' + restOfLine ) Xfile . close ( ) datasetFile . close ( )