handling strings in python? -
s5=0 phrase in root.findall('./phrase'): ens = {en.get('x'): en.text en in phrase.findall('en')} if 'org' in ens , 'pers' in ens: if (ens["org"] =="xyz corp" , ens["pers"]=="john"): print("org is: {}, pers is: {} /".format(ens["org"], ens["pers"])) y="".join(phrase.itertext()) #print whats in between print(y) s5 = s5+1 print("occurrence of fifth seed : ",s5) here in each iteration, y printed, y text in xml document long have 2 "en" tags, 1 org & 1 pers.
so output is:
john cofounder of xyz corp. john works in xyz corp. john named company xyz corp. i have been trying save each sentence on own can use later. example want use second sentence "john works in xyz corp" don't know how that, tried using variable y 2d array failed.
as commented above:
sentences = [] y="".join(phrase.itertext()) #print whats in between print(y) sentences.append(y) then sentences indexing in 'sentences' list:
print sentence[0] # first sentence print sentence[1] # second sentence, etc.
Comments
Post a Comment