如何基于自定义词典数组对文本中的单词和短语进行超链接

时间:2019-08-26 10:45:50

标签: javascript php

我有一些合法的文本数据库。该文本包含短语和单词,其中  非常复杂,需要定义。例子是

loadData() {
    this.setState({loading: true});
    const path = `${url}/jira_jobs.php`;
    axios.get(path)
        .then(res  => {
            this.setState({
                posts: res['data'],
                loading: false
            });
        })
        .catch(err => {
            console.error(err);
        });
}

例如,我有一个庞大的单词和短语词典

var TEXT = "National Accountability Ordinance, 1999 or the Criminal Procedure Code, 1898  did not contain any provision authorizing the Court to         order for re-investigation after filing of reference or after submitting report under  section 173 Cr.P.C. before the competent Court of law and to call a person to  join fresh investigation after the quashment of the proceedings. Impugned  observation, whereby, NAB was empowered to re-investigate the matter, was therefore beyond the jurisdiction of the court....."

现在,我想了解一些Javascript方法,该方法可以根据下面的词典突出显示/ wikify上述文本中的文本。最终的图片将是这样的

Example

到目前为止,我所知道的方法是遍历字典数组并尝试在TEXT变量中查找字符串位置,并在找到时用var dictionary = ["National Accountability Ordinance"=>"NAB Ordinance is blah blah","quashment"=>"To overthrow; to annul; to make void or declare invalid",...] 替换短语/单词。但是,如果还有其他更好的方法或已经存在的第三方解决方案会很棒。

0 个答案:

没有答案
相关问题