我有很多句子的数据,以一个例子作为下面的句子,我想把它分成两个子句子:
2/2小鼠血浆全血及d< 1.006 g/ml密度分数均呈宽的β-迁移模式(图1B):**1SP3E3_3;\x I:**1SP3E3~(3+):**1SP3E3:**1SP3E3:**1SP3E3: 3/3血浆在β-位几乎没有脂质染色。T:**1 SN3E3\x{e 010}I:**1SN3E3\x{e76f}L:**1SN3E3
分成以下两部分:
2/2小鼠血浆全血及d< 1.006 g/ml密度分数均呈现出广泛的β-迁移模式(图1 B)。
和
相反,3/3的血浆在β位几乎没有脂质染色。
我的代码是:
newData =[]
for item in Data:
test2= re.split(r" (?:\|.*?\| ?)+", item[0])
test2 =test2[:-1]
for tx in test2:
newData.append(tx)
print len(newData)
print newData但是,我得到了3项结果,包括一个;。我检查了原来的句子,发现;在|T:**1SP3E3| ; |I:**1SP3E3|中,所以我需要从结果中删除这个;。我将代码修改为
test2= re.split(r" (?:\|.*?\| ?;?)+", item[0])但我不能得到正确的结果。有人能帮忙吗?非常感谢。
发布于 2016-01-12 06:15:38
[i.strip() for i in re.sub(r'\|\w:\*\*\w*\|', '', re.sub(r' +', r' ', s.strip())).split(';')]返回
['Both whole plasma and the d < 1.006 g/ml density fraction of plasma from 2/2 mice show this broad beta-migration pattern (Fig. 1 B)', 'in contrast, 3/3 plasma shows virtually no lipid staining at the beta-position.']但是,这取决于你的文本是否与你的例子一致。
发布于 2016-01-12 06:23:05
import re
x="""Both whole plasma and the d < 1.006 g/ml density fraction of plasma from 2/2 mice show this broad beta-migration pattern (Fig. 1 B) |T:**1SP3E3| ; |I:**1SP3E3| |L:**1SP3E3| in contrast, 3/3 plasma shows virtually no lipid staining at the beta-position. |T:**1SN3E3| |I:**1SN3E3| |L:**1SN3E3|"""
print [i for i in re.split(r"(?:\|[^:]*:.*?\|(?:[\s;]+|$))+",x) if i]输出将如下所示:
“整个血浆和2/2小鼠血浆的d< 1.006 g/ml密度分数都显示出这种广泛的β-迁移模式(图1B)”,“相比之下,3/3的血浆在β-位置几乎没有脂质染色。”
发布于 2016-01-14 00:37:37
导入re
string = str.strip()用于re.sub中的str (‘\w:**\w+x’,'',string).split(';')
输出结果将是:“整个血浆和2/2小鼠血浆的d< 1.006 g/ml密度分数都显示出这种广泛的β-迁移模式(图1B)”,“相反,3/3血浆在β-位置几乎没有脂质染色。”
https://stackoverflow.com/questions/34736440
复制相似问题