JSFiddle - React, Tailwind, and code Playground

by OjisanSeiuchi

HTML

<!-- features is a holding place for POS information -->
<div id="features"></div>

<div id="defwrapper" class="red larger definition-wrapper">
	<span class="underlined">благови́дный</span> - <span id="rupos"></span> <span id="rudef" class="clozeru">{{RussianDef}}</span>
</div>

JavaScript

$(document).ready(function() {
  function baseurl() {
    return 'http://159.203.4.190:43560';
  }

  function stripWordURL(word) {
    return baseurl() + `/strip/${word}`
  }

  function posURL(word) {
    return baseurl() + `/pos/${word}`
  }
  //$('#features').text('');
  const front = $('#defwrapper').text().replace(/ .*/, '');
  $.getJSON(stripWordURL(front), function(data, textStatus, req) {
    const baseword = decodeURIComponent(data['base']);
    $('#word').text(baseword);
    $.getJSON(posURL(baseword), function(data, textStatus, req) {
      //$('#features').text(data.features);
      var pos = data.pos
      const features = data.features
      var outText
      if (pos == 'ADJ') {
        pos = 'Прилагательное';
      } else if (pos == 'NOUN') {
        pos = 'Существительное';
        var m = features.match(/Animacy=([^\|]+)\|.*Gender=([^\|]+)/m)
        animacy = {
          'Anim': 'одушевлённое',
          'Inan': 'неодушевлённое'
        }
        pos = pos + ", " + animacy[m[1]]
        genders = {
          'Fem': "женский род",
          'Masc': "мужской род",
          "Neut": "средний род"
        }
        pos = pos + ", " + genders[m[2]]
        console.log(pos);
      } else if (pos == 'VERB') {
        pos = 'Глагол';
        var voice, aspect, tense;
        if (features.includes('VerbForm=Part')) {
          voice = features.includes('Pass') ? 'страд.' : 'действ.'
          aspect = features.includes('Perf') ? 'св' : 'нсв'
          tense = features.includes('Past') ? 'прош. вр.' : 'наст. вр.'
          lemma = data.lemma
          pos = `${voice} прич. ${tense} от ${lemma}`
        }
      } else if (pos == 'ADV') {
        pos = 'Наречие';
      } else if (pos == 'PRON') {
        pos = 'Местоимение';
      } else if (pos == 'PROPN') {
        pos = 'Собственное существительное';
      } else if (pos == 'NUM') {
        pos = 'Числительное'
      }
      $('#rupos').text(pos);
    })
  })
})