diff --git a/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py b/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py index fff6a0b3..3e49ac09 100644 --- a/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py +++ b/app/corpora/cqi_over_socketio/cqi_corpora_corpus.py @@ -50,9 +50,52 @@ def cqi_corpora_corpus_update_db(cqi_client: cqi.CQiClient, corpus_name: str): @cqi_over_socketio def cqi_corpora_corpus_get_visualization_data(cqi_client: cqi.CQiClient, corpus_name: str): corpus = cqi_client.corpora.get(corpus_name) + # s_attrs = [x for x in corpus.structural_attributes.list() if not x.has_values] + # p_attrs = corpus.positional_attributes.list() + # payload = { + # 's_attrs': {}, + # 'p_attrs': {}, + # 'values': { + # 's_attrs': {}, + # 'p_attrs': {} + # } + # } + # for s_attr in s_attrs: + # s_attr_lbound, s_attr_rbound = s_attr.cpos_by_id(text_id) + # s_attr_cpos_range = range(s_attr_lbound, s_attr_rbound + 1) + # payload['text']['lexicon'][text_id] = { + # 's_attrs': [s_attr_lbound, s_attr_rbound], + # 'counts': { + # 'token': s_attr_rbound - s_attr_lbound + 1 + # }, + # 'freqs': { + # p_attr.name: dict(Counter(p_attr.ids_by_cpos(list(s_attr_cpos_range)))) + # for p_attr in p_attrs + # } + # } + # for p_attr in p_attrs: + # payload['p_attrs'] = dict( + + # ) + # payload['values']['p_attrs'] = dict( + # zip( + # range(0, p_attr.lexicon_size), + # p_attr.values_by_ids(list(range(0, p_attr.lexicon_size))) + # ) + # ) text = corpus.structural_attributes.get('text') + text_value_names = [] + text_values = [] + for text_sub_attr in corpus.structural_attributes.list(filters={'part_of': text}): + text_value_names.append(text_sub_attr.name[(len(text.name) + 1):]) + text_values.append(text_sub_attr.values_by_ids(list(range(0, text.size)))) s = corpus.structural_attributes.get('s') ent = corpus.structural_attributes.get('ent') + ent_value_names = [] + ent_values = [] + for ent_sub_attr in corpus.structural_attributes.list(filters={'part_of': ent}): + ent_value_names.append(ent_sub_attr.name[(len(ent.name) + 1):]) + ent_values.append(ent_sub_attr.values_by_ids(list(range(0, ent.size)))) word = corpus.positional_attributes.get('word') lemma = corpus.positional_attributes.get('lemma') pos = corpus.positional_attributes.get('pos') @@ -122,10 +165,7 @@ def cqi_corpora_corpus_get_visualization_data(cqi_client: cqi.CQiClient, corpus_ ) } } - payload['text']['values'] = [ - sub_attr.name[(len(text.name) + 1):] - for sub_attr in corpus.structural_attributes.list(filters={'part_of': text}) - ] + payload['text']['values'] = text_value_names payload['s'] = {'lexicon': {}, 'values': None} for s_id in range(0, s.size): payload['s']['lexicon'][s_id] = { @@ -140,15 +180,22 @@ def cqi_corpora_corpus_get_visualization_data(cqi_client: cqi.CQiClient, corpus_ payload['ent']['lexicon'][ent_id] = { # 'bounds': ent.cpos_by_id(ent_id) } - payload['ent']['values'] = [ - sub_attr.name[(len(ent.name) + 1):] - for sub_attr in corpus.structural_attributes.list(filters={'part_of': ent}) - ] + payload['ent']['values'] = ent_value_names payload['lookups'] = { 'corpus': {}, - 'text': {}, + 'text': { + text_id: { + text_value_name: text_values[text_value_name_idx][text_id_idx] + for text_value_name_idx, text_value_name in enumerate(text_value_names) + } for text_id_idx, text_id in enumerate(range(0, text.size)) + }, 's': {}, - 'ent': {}, + 'ent': { + ent_id: { + ent_value_name: ent_values[ent_value_name_idx][ent_id_idx] + for ent_value_name_idx, ent_value_name in enumerate(ent_value_names) + } for ent_id_idx, ent_id in enumerate(range(0, ent.size)) + }, 'word': dict( zip( range(0, word.lexicon_size), diff --git a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js index c955117b..77dfdbe1 100644 --- a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js +++ b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js @@ -34,6 +34,7 @@ class CorpusAnalysisApp { .then( cQiCorpus => { this.data.corpus = {o: cQiCorpus}; + this.data.corpus.o.getVisualizationData().then(data => console.log(data)); // this.data.corpus.o.getVisualizationData() // .then( // (visualizationData) => {