Splitting sentences into sub-sentences using re package in Python

I have data from many sentences, regarding one example as the following sentence, I want to break it into 2 sub-sentences:

Both whole plasma and d <1.006 g / ml plasma density from 2/2 mice show this broad beta migration pattern (Fig. 1B) | T: ** 1SP3E3 |; | I: ** 1SP3E3 | | L: ** 1SP3E3 | on the contrary, 3/3 of plasma shows with virtually no lipid staining in beta position. | T: ** 1SN3E3 | | I: ** 1SN3E3 | | L: ** 1SN3E3 |

divide it into:

Both whole plasma and d <1.006 g / ml plasma density from 2/2 mice show this broad beta migration pattern (Fig. 1B)

and

in contrast to 3/3 of the plasma, lipid staining at the beta position is practically not observed.

My code is:

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])

. - ? .

+4
4
[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.']

, , .

+1
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]

:

[' , d < 1.006 / 2/2 - ( .1) "," , 3/3 -. "]

0

import re

string = [str.strip() str re.sub('\ |\w: **\w +\|', '', string).split(';')]

: [ " d < 1,006 / 2/2 - ( .1)", "", 3/3 -.]

0

b: (?: ?\|.*?\|\ ?\;?)
.
regex101

-1

Source: https://habr.com/ru/post/1623870/


All Articles