简体   繁体   English

如何计算印地语中的单词数

[英]how to count the number of words in hindi

I have a javascript file and I would like to know how to count the number of hindi words in my textarea using javascript.我有一个 javascript 文件,我想知道如何使用 javascript 计算我的文本区域中印地语单词的数量。 it counts the number of english words fine but not with hindi words.它计算英语单词的数量,但不是印地语单词。 Can someone help me please?有人能帮助我吗?

javascript code: javascript 代码:

function getDifficultSentences(p) {
    let sentences = getSentenceFromParagraph(p);
    data.sentences += sentences.length;
    let hardOrNot = sentences.map(sent => {
      let cleanSentence = sent.replace(/[^a-z|]/gi, "") + "|";
      let words = cleanSentence.split(" ").length;  // the line where the I used for counting the words
      document.getElementById("nice").innerHTML= words.toString();
      let letters = cleanSentence.split(" ").join("").length;
      data.words += words;
      sent = getAdverbs(sent);
      sent = getComplex(sent);
      sent = getPassive(sent);
      sent = getQualifier(sent);
      sent = countWords(sent);
      //sent = getComplexDigit(sent);
      let level = calculateLevel(letters, words, 1);
      if (words < 14) {
        return sent;
      } else if (words >= 14 && words< 25) {
        data.hardSentences += 1;
        return `<span class="hardSentence">${sent}</span>`;
      } else if (words >= 30) {
        data.veryHardSentences += 1;
        return `<span class="veryHardSentence">${sent}</span>`;
      } else {
        return sent;
      }
    });

    return hardOrNot.join(" ");
  }

You dont need to do anything separate for hindi font.你不需要为印地文字体做任何单独的事情。 You can still get the value of the textarea in same way and split by delimiter (' ') ahich will give an array and then use length to get the count您仍然可以以相同的方式获取 textarea 的值并通过分隔符(' ')进行拆分,ahich 将给出一个数组,然后使用length来获取计数

 document.getElementById('getCount').addEventListener('click', (e) => { let getWordCount = document.getElementById('test').value.split(' ').length; console.log(getWordCount) })
 #test { height: 200px; width: 200px; }
 <textarea id='test'></textarea><button id='getCount'>Get Count</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM