Exemplo n.º 1
0
Arquivo: app.py Projeto: 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)
Exemplo n.º 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)
Exemplo n.º 3
0
    def testYearlyNetwork(self):
        '''Test building of yearly networks'''
        networks = fmt.yearlyNetwork(self._aggPeriods, self._aggVocab,
                                     self._vocab, self._links)

        self.assertEqual(sorted(networks.keys()), list(self._aggVocab.keys()),
                         'A network should be created for each aggregated '
                         'vocabulary')

        self.assertEqual(
            sorted(networks.keys()), list(self._aggPeriods.keys()),
            'A network should be created for each aggregation period')
        for year, net in networks.iteritems():
            self.assertEqual(sorted(net.keys()), sorted(['nodes', 'links']),
                             'Each network should contain "nodes" and "links"'
                             'but %s does not' % year)
            for node in net['nodes']:
                self.assertEqual(sorted(node.keys()),
                                 sorted(['name', 'type', 'count']),
                                 'Each node should contain "name", "type" and '
                                 '"count", but a node on %s does not' % year)
            for link in net['links']:
                self.assertEqual(sorted(link.keys()),
                                 sorted(['source', 'target', 'value']),
                                 'Each link should contain "source", "target" '
                                 'and "value", but a link on %s does not'
                                 % year)