Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def build_bloc(self):
- '''
- Build the principal bloc.
- '''
- self._p_list = []
- self._assossiated_list = {}
- tmp_list = list()
- tag_class = defaultdict(dict)
- tag_dict = defaultdict(dict)
- def get_astd(tag):
- rgx = re.compile(r"xml-(\w+)")
- if 'class' in tag.attrib:
- logging.info(tag.attrib['class'])
- try:
- logging.info('Checking if had many value')
- if tag.attrib['class'].split(' ')[1]:
- logging.info('Ok it has')
- for t in tag.attrib['class'].split(' '):
- logging.info(t)
- logging.info('Lauching the matching process')
- srch_res = re.match(rgx, t)
- logging.debug('srch_res : '+str(srch_res))
- if srch_res is not None:
- logging.info('Match !')
- # Source : http://stackoverflow.com/a/12906014/5527968
- tag_class = (tag.attrib['class'].split(' ')[0])
- tag_dict[srch_res.group(1)][tag.tag] = [tag_class]
- logging.info('tag_dict : ')
- logging.info(pprint.pprint(tag_dict))
- #self._assossiated_list.setdefault(srch_res.group(1), {})[tag.tag] = tag_class
- else:
- continue
- else:
- pass
- except Exception as e:
- logging.info(e)
- pass
- logging.info(tmp_list)
- def find_xml_tag():
- logging.info('Find all xml-tag')
- self._p_list = self._tree.xpath('//*') # For all existing tag
- for p in self._p_list:
- get_astd(p)
- find_xml_tag()
- logging.info(pprint.pprint(self._assossiated_list))
- # Expected output :
- # {'caption': {'p': ['Citation', 'Ct']},
- # 'chapter': {'head': 'Chapter'},
- # 'niv1': {'h2': 'Stitre1', 'p': 'Stitre1'},
- # 'niv2': {'h3': 'Stitre2'}}
- # Ouput :
- # {'caption': {'p': 'Citation'},
- # 'chapter': {'head': 'Chapter'},
- # 'niv1': {'h2': 'Stitre1', 'p': 'Stitre1'},
- # 'niv2': {'h3': 'Stitre2'}}
Advertisement
Add Comment
Please, Sign In to add comment