实现关键短语提取之后根据置信度在文本中进行高亮展示

实现关键短语提取之后根据置信度在文本中进行高亮展示

在前面几篇博客中,我提到了之前实现这个问题的想法,之后经过考虑打算使用js中的正则表达式实现。js的正则表达式有一个单词边界的工具,对于解决问题有很大的帮助,要不然就会出现如下图问题:en虽然是一个关键短语,但是我需要的en是它单独出现的单词,而不是他在类似于下图sent里面en高亮,所以经过查询我们找到了单词边界
在这里插入图片描述

单词边界使得我们可以精确替换单词,而不用担心类似与en会在别的单词里面高亮。实现的效果如下图
在这里插入图片描述

最终代码如下所示:

oText = "Body-centric mobile point-of-view augmented and virtual realityEmbodiments of a system and methods for displaying virtual or augmented reality are generally described herein. An image of a user may be captured using a camera. Real space in the image may be mapped and a first orientation may be determined relative to a static portion of the user, using the image. A first portion of a virtual reality image may be displayed on a display screen. In response to determining a second orientation of the device relative to the static portion of the user, a second portion of the virtual reality image may be displayed on a display screen.Methods and system for communicating control information using carrier aggregationAn apparatus may include a radio frequency (RF) transceiver to receive a first message over a first carrier in a first band in a downlink sub-frame of a first radio frame in a communications link, where the communications link comprises interband carriers aggregated over primary and secondary cells. The apparatus may also include a processor and a reply message assignment module operable on the processor to determine a downlink sub-frame in which the downlink transmission is received and to adjust timing of a reply/acknowledge message to be sent by the RF transceiver in response to the first message so as to coincide with a predetermined uplink sub-frame of a radio frame. Other embodiments are described and claimed.Presentation of direct accessed storage under a logical drive modelIn accordance with embodiments disclosed herein, there are provided methods, systems, mechanisms, techniques, and apparatuses for presentation of direct accessed storage under a logical drive model; for implementing a distributed architecture for cooperative NVM Data protection; data mirroring for consistent SSD latency; for boosting a controller's performance and RAS with DIF support via concurrent RAID processing; for implementing arbitration and resource schemes of a doorbell mechanism, including doorbell arbitration for fairness and prevention of attack congestion; and for implementing multiple interrupt generation using a messaging unit and NTB in a controller through use of an interrupt coalescing scheme.Composite solder TIM for electronic packageA method includes providing a mixture of molten indium and molten aluminum, and agitating the mixture while reducing its temperature until the aluminum changes from liquid phase to solid phase, forming particles distributed within the molten indium. Agitation of the mixture sufficiently to maintain the aluminum substantially suspended in the molten aluminum continues while further reducing the temperature of the mixture until the indium changes from a liquid phase to a solid phase. A metallic composition is formed, including indium and particles of aluminum suspended within the indium, the aluminum particles being substantially free from oxidation.The metallic (solder) composition can be used to form an assembly, including an integrated circuit (IC) device, at least a first thermal component disposed adjacent to the IC device, and a solder TIM interposed between and thermally coupled with each of the IC device and the first thermal component.Reference signal configuration for coordinated multipointCoordinated Multipoint (CoMP) involves multiple transmission points or cells coordinating their individual transmissions so that a target user equipment (LTE) experiences enhanced signal reception and/or reduced interference. In order to optimally implement downlink CoMP, a serving cell needs to obtain channel state information (CSI) for the downlink channels from the multiple transmission points to the UE. This disclosure deals with radio resource control (RRC) signaling for configuring the UE to obtain and report CSI for those downlink channels.Detecting a self-jammer signal in an RFID systemA radio frequency device capable of differentiating self-jammer signals.Object mapping techniques for mobile augmented reality applicationsTechniques are disclosed that involve mobile augmented reality (MAR) applications in which users (e.g., players) may experience augmented reality ge media may be described for identifying a wireless local area network (WLAN) selection preference rule for use by a user equipment (UE) during a re-association procedure of the UE. The UE may use the WLAN selection preference rule to identify a WLAN with which the UE should associate.Technologies for optical communication in rack clustersTechnologies for optical communication material."
keyWords = ['video conferencing', 'lightly doped', 'epitaxially deposited', 'remote raster', 'ad hoc', 'interlaced video', 'resist opening', 'phase modulation', 'texture filtering', 'scanning mirror', 'nonvolatile writeable', 'enclave page', 'texture mapping', 'conductive pathway', 'decoded video', 'wall opening', 'switched telephone', 'completion queue', 'phased array', 'thermo optical', 'carry generation', 'resource utilization', 'interactive display', 'current version', 'functional silicon', 'graphics rendering', 'impedance matching', 'body bias', 'spatial channel', 'mach zehnder', 'feed forward', 'unstrained channel', 'finite field', 'discrete wavelet', 'nand flash', 'receiving coil', 'lock state', 'spin polarized', 'reflected light', 'spatial stream', 'minimum voltage', 'asynchronous clock', 'timing recovery', 'unmasked result', 'alias table', 'load arm', 'logical sector', 'digital imaging', 'event driven', 'read references', 'volatile lock', 'step function', 'media player', 'dynamically allocated', 'uppermost surface', 'asynchronous transfer', 'packed integer', 'monotonic counter', 'length coding', 'omnidirectional antenna', 'compressed video', 'arrayed waveguide', 'subscriber identification', 'text entry', 'identity provider', 'authorized user', 'conductive photolithographic', 'support downlink', 'modulation coding', 'heavily doped', 'event notification', 'electroless plating', 'aligned floating', 'substantially planar', 'directory cache', 'performing multiply', 'error correcting', 'outer edge', 'uniaxially strained', 'polarized light', 'coarse tuning', 'vapor deposition', 'enhanced raman', 'explicit feedback', 'trace routing', 'multicarrier communications', 'stack surrounds', 'single precision', 'local column', 'regularity extraction', 'distributed scheduling', 'packaged semiconductor', 'inverting input', 'fuse block', 'initial link', 'run ahead', 'collimated light', 'speculatively executed', 'primary synchronization', 'pulse clock', 'trusted platform', 'packet scheduler', 'fabric adapter', 'electrical probe', 'color channel', 'trusted software', 'erasable programmable', 'wavelength selection', 'cyclical redundancy', 'application usage', 'authorization certificate', 'recently allocated', 'chip packaged', 'chemical mechanical', 'dry etch', 'remaining portion', 'sufficiently high', 'read pointer', 'interlaced display', 'electrically erasable', 'traffic pattern', 'ultraviolet light', 'electrically interconnected', 'fixed function', 'cross correlation', 'filtered image', 'network adaptor', 'planar semiconductor', 'previous frame', 'photo sensor', 'bulk semiconductor', 'cooling assembly', 'industry standard', 'socket body', 'protocol adaptation', 'integrity measurement', 'shallow trench', 'pulsed latch', 'local compressed', 'hermetically sealed', 'standing wave', 'forced idle', 'link failure', 'main core', 'modify write', 'disaggregated memory', 'substantially linear', 'head end', 'uni axial', 'color plane', 'original code', 'mac sublayer', 'lightly doped drain', 'selectively disable', 'generate interpolated', 'hall effect', 'linked network', 'shift keying', 'register templates', 'entire length', 'reduced capacitance', 'check codes', 'touch display', 'remains active', 'motion compensated', 'interconnect pads', 'type iii', 'gather scatter', 'complex angle', 'germanium active', 'virtualized environment', 'quantized phase']
lowKeyWords = ['output circuitry', 'includes decoding', 'comprising multiple', 'promoter', 'image input', 'instruction code', 'additional apparatus', 'optimistically', 'refer', 'buffer including', 'hardware systems', 'interacts', 'fiber optic phrase bundle', 'includes coupling', 'multiple user', 'device group', 'cache based', 'stack includes', 'processing techniques', 'gate circuit', 'improved method', 'overexposed', 'transfer mode', 'processor receives', 'component block', 'generated based', 'processor module', 'signal components', 'filter includes', 'device discovery', 'ops', 'theft phrase deterrence', 'responsible', 'operations including', 'power receiving', 'performable', 'register based', "receiver's", 'multi user multiple input multiple output', 'hardware apparatus', 'embedded ground plane and shielding', 'components include', 'current output', 'network location', 'sectorized', 'coupling device', 'looped', 'housing includes', 'signal comprises', 'switch circuit', 'attract', 'color interpolation and color space conversion', 'source coupled', 'circuit configured', 'block address', 'network comprises', 'structure formed', 'processor comprising', 'unit configured', 'val', 'processor]
function addKeyWorkHighline(oText, keyWords,lowKeyWords) {
    let returnVal = oText;
    keyWords.sort(compareWordLength);
    lowKeyWords.sort(compareWordLength);
    for (let i = 0; i < keyWords.length; i++) {
        if (keyWords[i] !== '') {
            let reg = RegExp("\\b" + keyWords[i] + "\\b", "g")
            returnVal = returnVal.replace(reg, '<span class="highLight">' + keyWords[i] + '</span>');
        }
    }
    for (let i = 0; i < lowKeyWords.length; i++) {
        if (lowKeyWords[i] !== '') {
            let reg = RegExp("\\b" + lowKeyWords[i] + "\\b", "g")
            returnVal = returnVal.replace(reg, '<i class="Light">' + lowKeyWords[i] + '</i>');
        }
    }
        return returnVal;
}
function compareWordLength(a,b){
    if(a.length>b.length){
        return -1;
    }
    else if(a.length<b.length){
        return 1;
    }
    else
        return 0;
}

console.log(addKeyWorkHighline(oText, keyWords,lowKeyWords));

之后将建立一个html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>关键字高亮展示(两种颜色)</title>
</head>
<style>
    .highLight{
        color:red;
    }
    .Light{
        color:blue;
    }
</style>
<body>
// 这里放入上一个程序生成的结果
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值