0
s5=0
for phrase in root.findall('./PHRASE'):
    ens = {en.get('x'): en.text for en in phrase.findall('en')}
    if 'ORG' in ens and 'PERS' in ens:
      if (ens["ORG"] =="XYZ Corp" and 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 is printed, Y is the text in the XML document as long as I have 2 "en" tags, one ORG & 1 PERS.

So the output is:

John cofounder of XYZ Corp.
John works in XYZ Corp.
John named his company XYZ Corp. 

I have been trying to save each sentence on its own so I can use it later. For example I want to use the second sentence "John works in XYZ Corp" I don't know how to do that, I tried using the variable Y as 2d array but I failed.

1
  • 3
    What the problem to create a list and append results in for loop? l = [] and then l.append(y) before print statement... Commented Jan 5, 2016 at 23:22

1 Answer 1

1

As commented above:

    sentences = []
    y="".join(phrase.itertext())   #print whats in between
    print(y)
    sentences.append(y)

Then get the sentences back by indexing in to the 'sentences' list:

    print sentence[0] # first sentence
    print sentence[1] # second sentence, etc.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.