Update for real data visualization

This commit is contained in:
Inga Kirschnick 2023-06-19 18:33:36 +02:00
parent 11b697145b
commit d6e17e1554
3 changed files with 94 additions and 82 deletions

View File

@ -34,22 +34,22 @@ class CorpusAnalysisApp {
.then( .then(
cQiCorpus => { cQiCorpus => {
this.data.corpus = {o: cQiCorpus}; this.data.corpus = {o: cQiCorpus};
this.data.corpus.o.getVisualizationData().then(data => console.log(data)); this.data.corpus.o.getVisualizationData()
// this.data.corpus.o.getVisualizationData() .then(
// .then( (data) => {
// (visualizationData) => { console.log(data);
// console.log(visualizationData); this.renderGeneralCorpusInfo(data);
// this.renderGeneralCorpusInfo(visualizationData); this.renderTextInfoList(data);
// this.renderTextInfoList(visualizationData); this.renderTextProportionsGraphic(data);
// this.renderTextProportionsGraphic(visualizationData); this.renderWordFrequenciesGraphic(data);
// } }
// ); );
this.data.corpus.o.getCorpusData() this.data.corpus.o.getCorpusData()
.then(corpusData => { .then(corpusData => {
this.renderGeneralCorpusInfo(corpusData); // this.renderGeneralCorpusInfo(corpusData);
this.renderTextInfoList(corpusData); // this.renderTextInfoList(corpusData);
this.renderTextProportionsGraphic(corpusData); // this.renderTextProportionsGraphic(corpusData);
this.renderWordFrequenciesGraphic(corpusData); // this.renderWordFrequenciesGraphic(corpusData);
this.renderWordDistributionsGraphic(corpusData); this.renderWordDistributionsGraphic(corpusData);
}); });
// TODO: Don't do this hgere // TODO: Don't do this hgere
@ -115,66 +115,78 @@ class CorpusAnalysisApp {
} }
renderGeneralCorpusInfo(corpusData) { renderGeneralCorpusInfo(corpusData) {
document.querySelector('.corpus-num-tokens').innerHTML = corpusData.corpus.counts.token; document.querySelector('.corpus-num-tokens').innerHTML = corpusData.corpus.lexicon[0].counts.token;
document.querySelector('.corpus-num-s').innerHTML = corpusData.corpus.counts.s; document.querySelector('.corpus-num-s').innerHTML = corpusData.corpus.lexicon[0].counts.s;
// corpusGeneralInfoListElement.querySelector('.corpus-text-count').innerHTML = <b>Corpus text count:</b> ${Object.entries(corpusData.text).length; document.querySelector('.corpus-num-unique-words').innerHTML = Object.entries(corpusData.corpus.lexicon[0].freqs.word).length;
document.querySelector('.corpus-num-unique-words').innerHTML = Object.entries(corpusData.corpus.freqs.word).length; document.querySelector('.corpus-num-unique-lemmas').innerHTML = Object.entries(corpusData.corpus.lexicon[0].freqs.lemma).length;
document.querySelector('.corpus-num-unique-lemmas').innerHTML = Object.entries(corpusData.corpus.freqs.lemma).length; document.querySelector('.corpus-num-unique-pos').innerHTML = Object.entries(corpusData.corpus.lexicon[0].freqs.pos).length;
document.querySelector('.corpus-num-unique-pos').innerHTML = Object.entries(corpusData.corpus.freqs.pos).length; document.querySelector('.corpus-num-unique-simple-pos').innerHTML = Object.entries(corpusData.corpus.lexicon[0].freqs.simple_pos).length;
document.querySelector('.corpus-num-unique-simple-pos').innerHTML = Object.entries(corpusData.corpus.freqs.simple_pos).length;
} }
renderTextInfoList(corpusData) { renderTextInfoList(corpusData) {
// let corpusTextInfoListElement = document.querySelector('.corpus-text-info-list'); let corpusTextInfoListElement = document.querySelector('.corpus-text-info-list');
// let corpusTextInfoList = new CorpusTextInfoList(corpusTextInfoListElement); let corpusTextInfoList = new CorpusTextInfoList(corpusTextInfoListElement);
// for (let text of Object.values(corpusData.text)) { let texts = corpusData.text.lexicon;
// text.values.title = corpusData.value_lookups.text.title[text.values.title]; let textData = [];
// } for (let i = 0; i < Object.entries(texts).length; i++) {
// corpusTextInfoList.add(Object.values(corpusData.text)); let resource = {
title: corpusData.lookups.text[i].title,
publishing_year: corpusData.lookups.text[i].publishing_year,
num_tokens: corpusData.text.lexicon[i].counts.token,
num_sentences: corpusData.text.lexicon[i].counts.s,
num_unique_words: Object.entries(corpusData.text.lexicon[i].freqs.word).length,
num_unique_lemmas: Object.entries(corpusData.text.lexicon[i].freqs.lemma).length,
num_unique_pos: Object.entries(corpusData.text.lexicon[i].freqs.pos).length,
num_unique_simple_pos: Object.entries(corpusData.text.lexicon[i].freqs.simple_pos).length
};
// let textCountChipElement = document.querySelector('.text-count-chip'); textData.push(resource);
// textCountChipElement.innerHTML = `Text count: ${Object.values(corpusData.text).length}`; }
corpusTextInfoList.add(textData);
let textCountChipElement = document.querySelector('.text-count-chip');
textCountChipElement.innerHTML = `Text count: ${Object.values(corpusData.text.lexicon).length}`;
} }
renderTextProportionsGraphic(corpusData) { renderTextProportionsGraphic(corpusData) {
// let textProportionsGraphicElement = document.querySelector('#text-proportions-graphic'); let textProportionsGraphicElement = document.querySelector('#text-proportions-graphic');
// let texts = Object.values(corpusData.text); let texts = Object.entries(corpusData.text.lexicon);
// let graphData = [ let graphData = [
// { {
// values: texts.map(text => text.counts.token), values: texts.map(text => text[1].counts.token),
// labels: texts.map(text => `${text.values.title} (${text.values.publishing_year})`), labels: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`),
// type: 'pie' type: 'pie'
// } }
// ]; ];
// let graphLayout = { let graphLayout = {
// height: 400, height: 600,
// width: 500 width: 600
// }; };
// Plotly.newPlot(textProportionsGraphicElement, graphData, graphLayout); Plotly.newPlot(textProportionsGraphicElement, graphData, graphLayout);
} }
renderWordFrequenciesGraphic(corpusData) { renderWordFrequenciesGraphic(corpusData) {
// let wordFrequenciesGraphicElement = document.querySelector('#word-frequencies-graphic'); let wordFrequenciesGraphicElement = document.querySelector('#word-frequencies-graphic');
// let words = Object.entries(corpusData.value_lookups.token.word); let words = Object.entries(corpusData.corpus.lexicon[0].freqs.word).sort((a, b) => b[1] - a[1]).slice(0, 5);
// let texts = Object.values(corpusData.text); let texts = Object.entries(corpusData.text.lexicon);
// let graphData = []; let graphData = [];
// for (let word of words) { for (let word of words) {
// let data = { let data = {
// x: texts.map(text => `${text.values.title} (${text.values.publishing_year})`), x: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`),
// y: texts.map(text => text.freqs.word[word[0]]), y: texts.map(text => text[1].freqs.word[word[0]]),
// name: word[1], name: corpusData.lookups.word[word[0]],
// type: 'bar' type: 'bar'
// }; };
// graphData.push(data); graphData.push(data);
// } }
// let graphLayout = { let graphLayout = {
// height: 400, height: 600,
// width: 500, width: 600,
// barmode: 'stack', barmode: 'stack',
// type: 'bar' type: 'bar'
// }; };
// Plotly.newPlot(wordFrequenciesGraphicElement, graphData, graphLayout); Plotly.newPlot(wordFrequenciesGraphicElement, graphData, graphLayout);
} }
renderWordDistributionsGraphic(corpusData) { renderWordDistributionsGraphic(corpusData) {
@ -191,7 +203,7 @@ class CorpusAnalysisApp {
// var layout = { // var layout = {
// title: 'Marker Size', // title: 'Marker Size',
// showlegend: false, // showlegend: false,
// height: 600, // height: 500,
// width: 600 // width: 600
// }; // };
// Plotly.newPlot(wordDistributionGraphicElement, data, layout); // Plotly.newPlot(wordDistributionGraphicElement, data, layout);

View File

@ -83,14 +83,14 @@ class CorpusTextInfoList extends ResourceList {
mapResourceToValue(corpusTextData) { mapResourceToValue(corpusTextData) {
return { return {
title: corpusTextData.values.title, title: corpusTextData.title,
publishing_year: corpusTextData.values.publishing_year, publishing_year: corpusTextData.publishing_year,
num_tokens: corpusTextData.counts.token, num_tokens: corpusTextData.num_tokens,
num_sentences: corpusTextData.counts.s, num_sentences: corpusTextData.num_sentences,
num_unique_words: Object.entries(corpusTextData.freqs.word).length, num_unique_words: corpusTextData.num_unique_words,
num_unique_lemmas: Object.entries(corpusTextData.freqs.lemma).length, num_unique_lemmas: corpusTextData.num_unique_lemmas,
num_unique_pos: Object.entries(corpusTextData.freqs.pos).length, num_unique_pos: corpusTextData.num_unique_pos,
num_unique_simple_pos: Object.entries(corpusTextData.freqs.simple_pos).length num_unique_simple_pos: corpusTextData.num_unique_simple_pos
}; };
} }

View File

@ -40,7 +40,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center;"> <div class="card-content" style="padding:10px !important; text-align:center;">
<p>Number of tokens</p> <p><b>Number of tokens</b></p>
<span class="card-title corpus-num-tokens"></span> <span class="card-title corpus-num-tokens"></span>
</div> </div>
</div> </div>
@ -48,7 +48,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center"> <div class="card-content" style="padding:10px !important; text-align:center">
<p>Number of sentences</p> <p><b>Number of sentences</b></p>
<span class="card-title corpus-num-s"></span> <span class="card-title corpus-num-s"></span>
</div> </div>
</div> </div>
@ -56,7 +56,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center"> <div class="card-content" style="padding:10px !important; text-align:center">
<p>Number of unique words</p> <p><b>Number of unique words</b></p>
<span class="card-title corpus-num-unique-words"></span> <span class="card-title corpus-num-unique-words"></span>
</div> </div>
</div> </div>
@ -64,7 +64,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center"> <div class="card-content" style="padding:10px !important; text-align:center">
<p>Number of unique lemmas</p> <p><b>Number of unique lemmas</b></p>
<span class="card-title corpus-num-unique-lemmas"></span> <span class="card-title corpus-num-unique-lemmas"></span>
</div> </div>
</div> </div>
@ -72,7 +72,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center"> <div class="card-content" style="padding:10px !important; text-align:center">
<p>Number of unique pos</p> <p><b>Number of unique pos</b></p>
<span class="card-title corpus-num-unique-pos"></span> <span class="card-title corpus-num-unique-pos"></span>
</div> </div>
</div> </div>
@ -80,7 +80,7 @@
<div class="col s2"> <div class="col s2">
<div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white"> <div class="card hoverable" style="border-radius: 10px !important; background-color:#6b3f89; color:white">
<div class="card-content" style="padding:10px !important; text-align:center"> <div class="card-content" style="padding:10px !important; text-align:center">
<p>Number of unique simple_pos</p> <p><b>Number of unique simple_pos</b></p>
<span class="card-title corpus-num-unique-simple-pos"></span> <span class="card-title corpus-num-unique-simple-pos"></span>
</div> </div>
</div> </div>
@ -90,7 +90,7 @@
<div class="col s12"> <div class="col s12">
<div class="card hoverable"> <div class="card hoverable">
<div class="card-content"> <div class="card-content">
<span class="card-title">Text information</span> <span class="card-title">Text Information Overview</span>
<div class="chip text-count-chip" style="background-color:#6b3f89; color:white""></div> <div class="chip text-count-chip" style="background-color:#6b3f89; color:white""></div>
<div class="corpus-text-info-list no-autoinit"></div> <div class="corpus-text-info-list no-autoinit"></div>
</div> </div>
@ -98,7 +98,7 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col s3"> <div class="col s4">
<div class="card hoverable"> <div class="card hoverable">
<div class="card-content"> <div class="card-content">
<span class="card-title">Text proportions within the corpus</span> <span class="card-title">Text proportions within the corpus</span>
@ -106,7 +106,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col s3"> <div class="col s4">
<div class="card hoverable"> <div class="card hoverable">
<div class="card-content"> <div class="card-content">
<span class="card-title">Word frequencies</span> <span class="card-title">Word frequencies</span>
@ -114,7 +114,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col s6"> <div class="col s4">
<div class="card hoverable"> <div class="card hoverable">
<div class="card-content"> <div class="card-content">
<span class="card-title">Word distributions</span> <span class="card-title">Word distributions</span>