Example #1
0
File: app.py Project: NLeSC/ShiCo
def trackWord(terms):
    '''VocabularyMonitor.trackClouds service. Expects a list of terms to be
    sent to the Vocabulary monitor, and returns a JSON representation of the
    response.'''
    params = app.config['trackParser'].parse_args()
    termList = terms.split(',')
    termList = [ term.strip() for term in termList ]
    termList = [ term.lower() for term in termList ]
    results, links = \
        app.config['vm'].trackClouds(termList, maxTerms=params['maxTerms'],
                        maxRelatedTerms=params['maxRelatedTerms'],
                        startKey=params['startKey'],
                        endKey=params['endKey'],
                        minSim=params['minSim'],
                        wordBoost=params['wordBoost'],
                        forwards=params['forwards'],
                        sumSimilarity=params['boostMethod'],
                        algorithm=params['algorithm'],
                        cleaningFunction=app.config['cleaningFunction'] if params[
                            'doCleaning'] else None
                        )
    agg = VocabularyAggregator(weighF=params['aggWeighFunction'],
                               wfParam=params['aggWFParam'],
                               yearsInInterval=params['aggYearsInInterval'],
                               nWordsPerYear=params['aggWordsPerYear']
                               )

    aggResults, aggMetadata = agg.aggregate(results)
    embedded = doSpaceEmbedding(app.config['vm'], results, aggMetadata)
    networks = yearlyNetwork(aggMetadata, aggResults, results, links)
    return jsonify(stream=yearTuplesAsDict(aggResults),
                   networks=networks,
                   embedded=embedded,
                   vocabs=links)
Example #2
0
def trackWord(terms):
    '''VocabularyMonitor.trackClouds service. Expects a list of terms to be
    sent to the Vocabulary monitor, and returns a JSON representation of the
    response.'''
    params = app.config['trackParser'].parse_args()
    termList = terms.split(',')
    termList = [term.strip() for term in termList]
    termList = [term.lower() for term in termList]
    results, links = \
        app.config['vm'].trackClouds(termList, maxTerms=params['maxTerms'],
                        maxRelatedTerms=params['maxRelatedTerms'],
                        startKey=params['startKey'],
                        endKey=params['endKey'],
                        minSim=params['minSim'],
                        wordBoost=params['wordBoost'],
                        forwards=params['forwards'],
                        sumSimilarity=params['boostMethod'],
                        algorithm=params['algorithm'],
                        cleaningFunction=app.config['cleaningFunction'] if params[
                            'doCleaning'] else None
                        )
    agg = VocabularyAggregator(weighF=params['aggWeighFunction'],
                               wfParam=params['aggWFParam'],
                               yearsInInterval=params['aggYearsInInterval'],
                               nWordsPerYear=params['aggWordsPerYear'])

    aggResults, aggMetadata = agg.aggregate(results)
    embedded = doSpaceEmbedding(app.config['vm'], results, aggMetadata)
    networks = yearlyNetwork(aggMetadata, aggResults, results, links)
    return jsonify(stream=yearTuplesAsDict(aggResults),
                   networks=networks,
                   embedded=embedded,
                   vocabs=links)
Example #3
0
 def testYearTuplesAsDict(self):
     '''Test converting tuple dictionary to nested dictionary'''
     dicts = fmt.yearTuplesAsDict(self._aggVocab)
     self.assertEqual(sorted(dicts.keys()), list(self._aggVocab.keys()),
                      'A dictionary should be created for each aggregated '
                      'vocabulary')
     for year, d in dicts.iteritems():
         self.assertEqual(len(d), len(self._aggVocab[year]),
                          'Dict should have same number of items as '
                          'aggregated vocabulary but %s does not' % year)