<commit_before>import React from 'react';
import { getDefsAndSyns, analyzeText } from '../../server/utils/customTextAnalytics.js';

function renderAnalytics(string) {
  const analyticsObj = analyzeText(string);
  // const countEachWordResult = analyticsObj.allTotals;
  const topThreeWordsResult = analyticsObj.topThree;
  const results = [];
  for (const key in topThreeWordsResult) {
    if (topThreeWordsResult.hasOwnProperty(key)) {
      results.push([key, `: ${topThreeWordsResult[key]} times`]);
    }
  }
  return results;
}

export default function TextAnalytics(prop) {
  if (prop.text) {
    const topThree = renderAnalytics(prop.text).map((word) =>
      <div id={word[0]}>{word}
        <div id="partOfSpeech">Part of Speech: {getDefsAndSyns(word[0]).pos}</div>
        <div id="definition">Definition: {getDefsAndSyns(word[0]).def}</div>
        { getDefsAndSyns(word[0]).syns.map((syn) => <li>{syn.word}</li>) }
      <hr />
      </div>
    );
    return (
      <div>
        <p>Here are your results:</p>
        <p>Top Three Most Used Words: </p>
        {topThree}
      </div>
    );
  }
  return (
    <div>Enter some text to analyze</div>
  );
}
<commit_msg>Asynchronously display defintions and synonyms when analyzing text<commit_after>import React from 'react';
import $ from 'jquery';
import { getDefs, getSyns, analyzeText } from '../../server/utils/customTextAnalytics.js';

function renderAnalytics(string) {
  const analyticsObj = analyzeText(string);
  // const countEachWordResult = analyticsObj.allTotals;
  const topThreeWordsResult = analyticsObj.topThree;
  const results = [];
  for (const key in topThreeWordsResult) {
    if (topThreeWordsResult.hasOwnProperty(key)) {
      results.push([key, `: ${topThreeWordsResult[key]} times`]);
    }
  }
  return results;
}

export default function TextAnalytics(prop) {
  if (prop.text) {
    renderAnalytics(prop.text).map((word) => {
      getDefs(word[0], (defErr, defData) => {
        if (defErr) {
          return defErr;
        }
        const defintionAndPos = defData;
        getSyns(word[0], (synErr, synData) => {
          if (synErr) {
            return synErr;
          }
          const synonyms = synData.syns;
          $('#text-input').append(`<div id=${word[0]}>${word}
            <div id="partOfSpeech">Part of Speech: ${defintionAndPos.pos}</div>
            <div id="definition">Definition: ${defintionAndPos.def}</div>
          </div>`);
          synonyms.map((syn) => $('#text-input').append(`<li>${syn.word}</li>`));
          $('#text-input').append('<hr />');
          return 'rendered synonyms';
        });
        return 'rendered definitions';
      });
      return 'rendered analytics';
    });
    return (
      <div>
        <p>Here are your results:</p>
        <p id="topThreeMostUsed">Top Three Most Used Words: </p>
      </div>
    );
  }
  return (
    <div>Enter some text to analyze</div>
  );
}

{'fraction_non_alphanumeric': 0.15762538382804503, 'fraction_numerical': 0.002388263391334016, 'mean_word_length': 2.9197860962566846, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2118987', 'n_tokens_mistral': 952, 'n_tokens_neox': 931, 'n_words': 192}