gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:49:33 25 4
gpt4 key购买 nike

我有一个 javascript 文件,我想知道如何使用 javascript 计算我的文本区域中印地语单词的数量。它可以计算英文单词的数量,但不能计算印地语单词的数量。有人可以帮帮我吗?

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(" ");
}

最佳答案

您不需要为印地语字体做任何单独的事情。你仍然可以得到的值(value)textarea 以相同的方式并按分隔符(' ') 拆分将给出一个数组,然后使用 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>

关于javascript - 如何计算印地语中的单词数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58637791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com