# Path: cptm/utils/experiment.py
# def get_sampler(params, corpus, nTopics=None, initialize=True):
#     if nTopics is None:
#         nTopics = params.get('nTopics')
#     out_dir = params.get('outDir')
#     nIter = params.get('nIter')
#     alpha = 50.0/nTopics
#     beta = params.get('beta')
#     beta_o = params.get('beta_o')
#     logger.info('creating Gibbs sampler (nTopics: {}, nIter: {}, alpha: {}, '
#                 'beta: {}, beta_o: {})'.format(nTopics, nIter, alpha, beta,
#                                                beta_o))
#     sampler = GibbsSampler(corpus, nTopics=nTopics, nIter=nIter,
#                            alpha=alpha, beta=beta, beta_o=beta_o,
#                            out_dir=out_dir.format(nTopics),
#                            initialize=initialize)
#     return sampler
# 
# def thetaFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'theta_{}.csv'.format(nTopics))
# 
# def load_config(fName):
#     with open(fName) as f:
#         config = json.load(f)
# 
#     logger.debug('configuration of experiment: ')
#     params = ['{}: {}'.format(p, v) for p, v in config.iteritems()]
#     for p in params:
#         logger.debug(p)
# 
#     params = {}
#     params['inputData'] = config.get('inputData')
#     params['outDir'] = config.get('outDir', '/{}')
#     params['testSplit'] = config.get('testSplit', 20)
#     params['minFreq'] = config.get('minFreq')
#     params['removeTopTF'] = config.get('removeTopTF')
#     params['removeTopDF'] = config.get('removeTopDF')
#     params['nIter'] = config.get('nIter', 200)
#     params['beta'] = config.get('beta', 0.02)
#     params['beta_o'] = config.get('beta_o', 0.02)
#     params['expNumTopics'] = config.get('expNumTopics', range(20, 201, 20))
#     params['nTopics'] = config.get('nTopics')
#     params['nProcesses'] = config.get('nProcesses', None)
#     params['topicLines'] = config.get('topicLines', [0])
#     params['opinionLines'] = config.get('opinionLines', [1])
#     params['sampleEstimateStart'] = config.get('sampleEstimateStart')
#     params['sampleEstimateEnd'] = config.get('sampleEstimateEnd')
# 
#     return params
# 
# def topicFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'topics_{}.csv'.format(nTopics))


import logging
import argparse
import pandas as pd
import os
from CPTCorpus import CPTCorpus
from cptm.utils.experiment import get_sampler, thetaFileName, load_config, \
    topicFileName
"""Script to extract a document/topic matrix for a set of text documents.

The corpus is not divided in perspectives.

Used to calculate theta for the CAP vragenuurtje data.

Before this script can be run, a cptm corpus should be created. Use the
tabular2cptm_input.py script to create a corpus that can be used
as input.

Usage: python experiment_theta_for_texts_perspectives.py <experiment.json>
<input dir> <output dir>
"""


logger = logging.getLogger(__name__)
logging.basicConfig(format='%(levelname)s : %(message)s', level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument('json', help='json file containing experiment '
                    'configuration.')
parser.add_argument('data_dir', help='dir containing the input data.')
parser.add_argument('out_dir', help='dir to write results to.')
args = parser.parse_args()

params = load_config(args.json)

input_dir = [args.data_dir]
topicDict = params.get('outDir').format('topicDict.dict')
opinionDict = params.get('outDir').format('opinionDict.dict')

# Path: cptm/utils/experiment.py
# def get_sampler(params, corpus, nTopics=None, initialize=True):
#     if nTopics is None:
#         nTopics = params.get('nTopics')
#     out_dir = params.get('outDir')
#     nIter = params.get('nIter')
#     alpha = 50.0/nTopics
#     beta = params.get('beta')
#     beta_o = params.get('beta_o')
#     logger.info('creating Gibbs sampler (nTopics: {}, nIter: {}, alpha: {}, '
#                 'beta: {}, beta_o: {})'.format(nTopics, nIter, alpha, beta,
#                                                beta_o))
#     sampler = GibbsSampler(corpus, nTopics=nTopics, nIter=nIter,
#                            alpha=alpha, beta=beta, beta_o=beta_o,
#                            out_dir=out_dir.format(nTopics),
#                            initialize=initialize)
#     return sampler
# 
# def thetaFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'theta_{}.csv'.format(nTopics))
# 
# def load_config(fName):
#     with open(fName) as f:
#         config = json.load(f)
# 
#     logger.debug('configuration of experiment: ')
#     params = ['{}: {}'.format(p, v) for p, v in config.iteritems()]
#     for p in params:
#         logger.debug(p)
# 
#     params = {}
#     params['inputData'] = config.get('inputData')
#     params['outDir'] = config.get('outDir', '/{}')
#     params['testSplit'] = config.get('testSplit', 20)
#     params['minFreq'] = config.get('minFreq')
#     params['removeTopTF'] = config.get('removeTopTF')
#     params['removeTopDF'] = config.get('removeTopDF')
#     params['nIter'] = config.get('nIter', 200)
#     params['beta'] = config.get('beta', 0.02)
#     params['beta_o'] = config.get('beta_o', 0.02)
#     params['expNumTopics'] = config.get('expNumTopics', range(20, 201, 20))
#     params['nTopics'] = config.get('nTopics')
#     params['nProcesses'] = config.get('nProcesses', None)
#     params['topicLines'] = config.get('topicLines', [0])
#     params['opinionLines'] = config.get('opinionLines', [1])
#     params['sampleEstimateStart'] = config.get('sampleEstimateStart')
#     params['sampleEstimateEnd'] = config.get('sampleEstimateEnd')
# 
#     return params
# 
# def topicFileName(params):
#     nTopics = params.get('nTopics')
#     return os.path.join(params.get('outDir').format(''),
#                         'topics_{}.csv'.format(nTopics))


# Path: cptm/experiment_theta_for_texts_perspectives.py
import logging
import argparse
import pandas as pd
import os
from CPTCorpus import CPTCorpus
from cptm.utils.experiment import get_sampler, thetaFileName, load_config, \
    topicFileName

"""Script to extract a document/topic matrix for a set of text documents.

The corpus is not divided in perspectives.

Used to calculate theta for the CAP vragenuurtje data.

Before this script can be run, a cptm corpus should be created. Use the
tabular2cptm_input.py script to create a corpus that can be used
as input.

Usage: python experiment_theta_for_texts_perspectives.py <experiment.json>
<input dir> <output dir>
"""


logger = logging.getLogger(__name__)
logging.basicConfig(format='%(levelname)s : %(message)s', level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument('json', help='json file containing experiment '
                    'configuration.')
parser.add_argument('data_dir', help='dir containing the input data.')
parser.add_argument('out_dir', help='dir to write results to.')
args = parser.parse_args()

params = load_config(args.json)

input_dir = [args.data_dir]
topicDict = params.get('outDir').format('topicDict.dict')
opinionDict = params.get('outDir').format('opinionDict.dict')

phi_topic_file = topicFileName(params)