Saturday 15 June 2013

regex - Python search for specific word and show them with boundaries in a intermittent word sequence -


I have a Chinese sentence with POS tags and an object is associated with it.

  '另外 / c, / wd 宝来 / nz 所 / usuo 具有 / v / ude1 麦弗逊式 / n, / wd 螺旋 / n 弹簧 / N, / wd 筒式 / n 减振 器 / n, / wd 带 / v 稳定杆 / nz // w 纵向 / n 托 臂 式 / n, / wd 螺旋 / n 弹簧 / n, / wd 筒式 / n减振器 / n, / wd 带 / v 稳定杆 / nj 悬挂 / n 系统 / n 明显 / ad 比 / p 思 域 / nj / ude1 麦弗逊式 / n 独立 / ad 悬架 / nj, / wn双 横 臂 式 / n 独立 / ad 悬架 / nz 系统 / n / ude1 乘坐 / v 舒适 性 / n (/ wkz 空间 / n 不够 / a) / wky 更 / d 好 / a! / 'Wt'  

itemet

  ['宝来', '麦弗逊式', '螺旋 弹簧', '筒式 减振器', '杆 / 纵向 托 臂 式', '螺旋 弹簧', '筒式 减振器', '悬挂 系统', '比', '思 域', '麦弗逊式', '悬架 系统', '乘坐舒适性 ',' 更好 ']  

desired result

 ' 另外 / c, / wd [宝来 / nz] 所 / usuo 具有 / V 的 / ude1 [麦弗逊式 / n], / wd [螺旋 / n 弹簧 / n], / wd [筒式 / n 减振器 / n], / wd 带 / v 稳定 [杆 / nz // W 纵向 / n 托 臂 式 / n], / wd [螺旋 / n 弹簧 / n], / wd [筒式 / n 减振器 / n], / wd 带 / v 稳定杆 / nz [悬挂 / n 系统/ N] 明显 / ad [比 / p] [思 域 / nz] k / ude1 [麦弗逊式 / n] 独立 / ad 悬架 / nz, / wn 双 横 臂 式 / n 独立 / advertising [悬架/ Nz 系统 / n] 的 / ude1 [乘坐 / v 舒适 性 / n] (/ wkz 空间 / N 不够 / a) / wky [更 / d 好 / a]! I want to insert one or a few words / tag tokens into sentences, but as the sentence has already been tagged POS-tags, I use re.sub Can not do or suggest similar ways. Taking this further burden is that the boundary of an object (杆 / 纵向 托 臂 式) is not linked to the token's limit. 

Please comment on the solution or introduce an algorithm related to this problem. Thank you.


No comments:

Post a Comment