vinaynischal14k

addOrganization to file

Dec 7th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import re
  2. import xml.etree.ElementTree
  3. tree = xml.etree.ElementTree.parse('output501-550.xml')
  4. e = tree.getroot()
  5.  
  6. for article in e.findall('Article'):
  7.     child = xml.etree.ElementTree.Element("Organization")
  8.    
  9.     if article[2].text != '-':
  10.         email = re.search(r'([A-Z][^\s,.]+[.]?\s[(]?)*(Centro|Associates|Station|Dept|Département|Departamento|Branch|Agency|Limited|Pharmaceutica|Ltd|MRC|Unit|Administration|Division|Inc|Incorporation|Commission|Corp|Corporation|Council|Foundation|Consultants|Board|Association of|Association|Pharmaceuticals|Office of|Office|Labs|Society|Hospital|hôpital|Hôpital|University|University of|Université|Universidad|Institute|Institut|Instituto|Istituto|Universität|Law School|Academy|College|Center|Centre|Laboratory|Laboratoire|Laboratories|Laboratorio|Department of|Department|Clinic|Univ|Bureau of|Research|for Research|Instytutu|Centrum|Ministry of|Company)[^,\d]*(?=,|\d)', article[2].text).group()
  11.         child.text = email
  12.     else:
  13.         child.text = '-'
  14.     article.insert(4,child)
  15. tree.write("output501-550.xml")
  16. print("completed")
Add Comment
Please, Sign In to add comment