docs: def filesampler(files, testsetsize = 0.1, devsetsize = 0, trainsetsize = 0, outputdir = '', encoding='utf-8'):
          """Extract a training set, test set and optimally a development set from one file, or multiple *interdependent* files (such as a parallel corpus). It is assumed each line contains one instance (such as a word or sentence for example)."""
  
          if not isinstance(files, list):
              files = list(files)
  
          total = 0
          for filename in files:
              f = io.open(filename,'r', encoding=encoding)
              count = 0
              for line in f:
                  count += 1
              f.close()
              if total == 0:
                  total = count
              elif total != count:
                  raise Exception("Size mismatch, when multiple files are specified they must contain the exact same amount of lines! (" +str(count)  + " vs " + str(total) +")")
  
          #support for relative values:
          if testsetsize < 1:
              testsetsize = int(total * testsetsize)
          if devsetsize < 1 and devsetsize > 0:
              devsetsize = int(total * devsetsize)
  
  
          if testsetsize >= total or devsetsize >= total or testsetsize + devsetsize >= total:
              raise Exception("Test set and/or development set too large! No samples left for training set!")
  
  
          trainset = {}
          testset = {}
          devset = {}
          for i in range(1,total+1):
              trainset[i] = True
          for i in random.sample(trainset.keys(), int(testsetsize)):
              testset[i] = True
              del trainset[i]
  
          if devsetsize > 0:
              for i in random.sample(trainset.keys(), int(devsetsize)):
                  devset[i] = True
                  del trainset[i]
  
          if trainsetsize > 0:
              newtrainset = {}
              for i in random.sample(trainset.keys(), int(trainsetsize)):
                  newtrainset[i] = True
              trainset = newtrainset
  
          for filename in files:
              if not outputdir:
                  ftrain = io.open(filename + '.train','w',encoding=encoding)
              else:
                  ftrain = io.open(outputdir + '/' +  os.path.basename(filename) + '.train','w',encoding=encoding)
              if not outputdir:
                  ftest = io.open(filename + '.test','w',encoding=encoding)
              else:
                  ftest = io.open(outputdir + '/' + os.path.basename(filename) + '.test','w',encoding=encoding)
              if devsetsize > 0:
                  if not outputdir:
                      fdev = io.open(filename + '.dev','w',encoding=encoding)
                  else:
                      fdev = io.open(outputdir + '/' +  os.path.basename(filename) + '.dev','w',encoding=encoding)
  
              f = io.open(filename,'r',encoding=encoding)
              for linenum, line in enumerate(f):
                  if linenum+1 in trainset:
                      ftrain.write(line)
                  elif linenum+1 in testset:
                      ftest.write(line)
                  elif devsetsize > 0 and linenum+1 in devset:
                      fdev.write(line)
              f.close()
  
              ftrain.close()
              ftest.close()
              if devsetsize > 0: fdev.close()