第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

檢查數(shù)組的某個(gè)元素是否與以下相同

檢查數(shù)組的某個(gè)元素是否與以下相同

海綿寶寶撒 2023-03-18 17:15:44
我正在創(chuàng)建一個(gè)將 pdf 解析為文本的服務(wù)。當(dāng)我有該文本時(shí),我必須匹配一組單詞。每次匹配時(shí),它都會(huì)增加一個(gè)計(jì)數(shù)器。到目前為止,一切都很好。困難在于,在解析為文本時(shí),我無法檢查我在 pdf 的哪一頁(yè)。我已經(jīng)意識(shí)到,在拆分中,每次出現(xiàn)兩個(gè)連續(xù)的換行符(/n/n)就意味著發(fā)生了換頁(yè)。我想做的是檢查頁(yè)面是否已更改,并且除了計(jì)算一個(gè)單詞總共被找到的次數(shù)外,還要說出它在哪些頁(yè)面上。例子let data =  `resignations / resignations. adm. mancom .: berenguer llinaresappointments. adm. unique: calvo valenzuela. other concepts: change of the administrative body:joint administrators to sole administrator. change of registered office. ptda colomer, 6Official Gazette of the Commercial Registryno. 182 Friday, September 18, 2020 p. 33755cve: borme-a-2020-182-03 verifiable insarria). registry data. t 2257, f 100, s 8, h a 54815, i / a 4 (10.09.20) .`let wordsToSearch = ['resignations', "administrators"]    wordsToSearch.forEach((word) => {// inside of here would like to have track of the page as well        let stringArray = data.split(' ');        let count = 0;        let result = ""        for (var i = 0; i < stringArray.length; i++) {            let wordText = stringArray[i];            if (new RegExp(word).test(wordText)) {                count++            }        }        // the expected result would word has appeared count times in the pages etc        result += `${word} has appeared ${count} times\n`        console.log(result)        /*        resignations has appeared 2 times        administrators has appeared 1 times        */    })如果有人也想出另一種方法,那就太好了
查看完整描述

1 回答

?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以在那些雙換行符處拆分文本,然后單獨(dú)分析每個(gè)頁(yè)面。我會(huì)這樣做:


let data = `resignations / Friday resignations. adm. mancom .: berenguer llinares

            appointments. adm. unique: calvo Friday valenzuela. other concepts: change of the administrative body:

            joint administrators to sole administrator. change of registered office. ptda colomer, 6, Friday


            Official Gazette of the Commercial Registry

            no. 182 Friday, September 18, 2020 p. 33755

            cve: borme-a-2020-182-03 verifiable in

            sarria). registry data. t 2257, f 100, s 8, h a 54815, i / a 4 (10.09.20) .`



function analyseText(text, wordsToFind) {

    const pages = data.split("\n\n");

    const result = {};

    for (let pageIndex = 0; pageIndex < pages.length; pageIndex++) {

        analysePage({

            pageIndex,

            pageText: pages[pageIndex]

        }, wordsToFind, result);

    }

    return Object.keys(result).map(k => result[k]);

}


function analysePage(page, wordsToFind, result) {

    const {

        pageText,

        pageIndex

    } = page;

    wordsToFind.forEach(word => {

        const count = (pageText.match(new RegExp(word, 'g')) || []).length;

        if (count > 0) {

            if (!result[word]) {

                result[word] = {

                    name: word,

                    pageIndices: [],

                    count: 0

                };

            }

            result[word].pageIndices.push(pageIndex);

            result[word].count += count;

        }

    });


}


const result = analyseText(data, ['resignations', "administrators", "Friday"]);

console.log(result);

在此示例中,我只是打印每一頁(yè)的結(jié)果,但您當(dāng)然可以構(gòu)建一些結(jié)果對(duì)象,在其中保存每一頁(yè)的結(jié)果。



查看完整回答
反對(duì) 回復(fù) 2023-03-18
  • 1 回答
  • 0 關(guān)注
  • 90 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)