首页 > 解决方案 > 如何在python中访问这些标签内的文本?

问题描述

我有一个数据集,我在其中标记了名词短语。如何找到这些标签并从标签内提取数据。

در
همین
حال
<coref coref_coref_class="set_0" coref_mentiontype="ne" markable_scheme="coref" coref_coreftype="ident">
نجیب
الله
خواجه
عمری
</coref>
<coref coref_coref_class="set_0" coref_mentiontype="np" markable_scheme="coref" coref_coreftype="ident">
سرپرست
وزارت
تحصیلات
عالی
افغانستان
</coref>
گفت
که


 def ex_feature(text):
    for w in text:
        if w.startswith("<coref") and w.endswith("</coref>"):
            print(w)

标签: pythonnlpnltkdata-science

解决方案


怎么样

import re
print(re.findall(r'<coref.*?>(.*?)</coref>', text, re.S))

推荐阅读