Ejemplo n.º 1
0
    def _write_chartsheet_rels_files(self):
        # Write the chartsheet .rels files for links to drawing files.
        index = 0
        for worksheet in self.workbook.worksheets():

            if not worksheet.is_chartsheet:
                continue

            index += 1

            external_links = worksheet.external_drawing_links

            if not external_links:
                continue

            # Create the chartsheet .rels xlsx_dir.
            rels = Relationships()

            for link_data in external_links:
                rels._add_worksheet_relationship(*link_data)

            # Create .rels file such as /xl/chartsheets/_rels/sheet1.xml.rels.
            rels._set_xml_writer(self._filename('xl/chartsheets/_rels/sheet'
                                                + str(index) + '.xml.rels'))
            rels._assemble_xml_file()
Ejemplo n.º 2
0
    def _write_worksheet_rels_files(self):
        # Write data such as hyperlinks or drawings.
        index = 0
        for worksheet in self.workbook.worksheets():

            if worksheet.is_chartsheet:
                continue

            index += 1

            external_links = (worksheet.external_hyper_links +
                              worksheet.external_drawing_links +
                              worksheet.external_vml_links +
                              worksheet.external_table_links +
                              worksheet.external_comment_links)

            if not external_links:
                continue

            # Create the worksheet .rels dirs.
            rels = Relationships()

            for link_data in external_links:
                rels._add_worksheet_relationship(*link_data)

            # Create .rels file such as /xl/worksheets/_rels/sheet1.xml.rels.
            rels._set_xml_writer(self._filename('xl/worksheets/_rels/sheet'
                                                + str(index) + '.xml.rels'))
            rels._assemble_xml_file()
Ejemplo n.º 3
0
    def _write_workbook_rels_file(self):
        # Write the _rels/.rels xml file.
        rels = Relationships()

        worksheet_index = 1
        chartsheet_index = 1

        for worksheet in self.workbook.worksheets():
            if worksheet.is_chartsheet:
                rels._add_document_relationship('/chartsheet',
                                                'chartsheets/sheet'
                                                + str(chartsheet_index)
                                                + '.xml')
                chartsheet_index += 1
            else:
                rels._add_document_relationship('/worksheet',
                                                'worksheets/sheet'
                                                + str(worksheet_index)
                                                + '.xml')
                worksheet_index += 1

        rels._add_document_relationship('/theme', 'theme/theme1.xml')
        rels._add_document_relationship('/styles', 'styles.xml')

        # Add the sharedString rel if there is string data in the workbook.
        if self.workbook.str_table.count:
            rels._add_document_relationship('/sharedStrings',
                                            'sharedStrings.xml')

        # Add vbaProject if present.
        if self.workbook.vba_project:
            rels._add_ms_package_relationship('/vbaProject', 'vbaProject.bin')

        rels._set_xml_writer(self._filename('xl/_rels/workbook.xml.rels'))
        rels._assemble_xml_file()
Ejemplo n.º 4
0
 def get_relationships(self):
     if self.relationships:
         return self.relationships
     doc_path = os.path.join(self.file_path, "word/_rels/document.xml.rels")
     with open(doc_path, encoding="UTF-8") as f:
         doc = f.read()
     doc = BeautifulSoup(doc, "xml")
     self.relationships = Relationships(doc)
     return self.relationships
Ejemplo n.º 5
0
	def _find_relationships(self, list_tagged, global_entities):
		relationships = Relationships()
		relation_stops_type = ['CONJ', 'WPRO', ',', '(', ')']
		relationship_stop_words = ['ex']

		for tagged in list_tagged:
			for index_sentence, sentence in enumerate(tagged):
				last_entity = None
				last_entity_index = 0
				last_relation = None

				for index, item in enumerate(sentence):
					# In order to avoid stop words
					if( len(item[0]) == 1 or item[0].lower() in relationship_stop_words):
						continue
					# to get the entity already identified
					elif( item[1] == 'NE'):
						# In order to build the relationship
						if(last_entity is not None and self._contain_main_entity(last_entity[0], item[0])):
							# to build a relationship with anything between entities
							# just if there is only one token between entities
							if(index-last_entity_index == 2 and len(sentence[index-1][0])>1 ):
								id1 = self._search_parent_entity(last_entity[2], global_entities).id()
								id2 = self._search_parent_entity(item[2], global_entities).id()
								relation = (sentence[index-1][0], id1, last_entity[0], id2, item[0])
								relationships.add(relation)
							# In order to build a relationship from relation already identified
							elif(last_relation is not None):
								id1 = self._search_parent_entity(last_entity[2], global_entities).id()
								id2 = self._search_parent_entity(item[2], global_entities).id()
								relation = (last_relation, id1, last_entity[0], id2, item[0])
								relationships.add(relation)
						last_entity = item
						last_entity_index = index
						last_relation = None

					# In order to get just relationships between entities
					if(last_entity is None):
						continue
					# In order to get relationship composed by verb and noun
					elif('N' in item[1]):
						last_relation = self._compose_verb_noun(sentence, index, last_entity_index, relation_stops_type)
					# In order to get relationship composed by one or more verbs
					elif('VB' in item[1]):
						last_relation = self._get_composed_verbs(sentence, index, last_entity_index, relation_stops_type)
					# In order to break relationships
					elif(item[1] in relation_stops_type):
						last_relation = None
						last_entity = None
						last_entity_index = 0

					# In order to remove relationships if a conjuction is found
					if last_relation is not None and last_relation[0].isupper():
						last_relation = None

		return relationships
Ejemplo n.º 6
0
    def _write_root_rels_file(self):
        # Write the _rels/.rels xml file.
        rels = Relationships()

        rels._add_document_relationship('/officeDocument', 'xl/workbook.xml')
        rels._add_package_relationship('/metadata/core-properties',
                                       'docProps/core.xml')
        rels._add_document_relationship('/extended-properties',
                                        'docProps/app.xml')

        rels._set_xml_writer(self._filename('_rels/.rels'))
        rels._assemble_xml_file()
Ejemplo n.º 7
0
    def _write_vml_drawing_rels_file(self, worksheet, index):
        # Write the vmlDdrawing .rels files for worksheets with images in
        # headers or footers.

        # Create the drawing .rels dir.
        rels = Relationships()

        for drawing_data in worksheet.vml_drawing_links:
            rels._add_document_relationship(*drawing_data)

        # Create .rels file such as /xl/drawings/_rels/vmlDrawing1.vml.rels.
        rels._set_xml_writer(self._filename('xl/drawings/_rels/vmlDrawing'
                                            + str(index)
                                            + '.vml.rels'))
        rels._assemble_xml_file()
Ejemplo n.º 8
0
    def _write_drawing_rels_files(self):
        # Write the drawing .rels files for worksheets with charts or drawings.
        index = 0
        for worksheet in self.workbook.worksheets():
            if not worksheet.drawing_links:
                continue
            index += 1

            # Create the drawing .rels xlsx_dir.
            rels = Relationships()

            for drawing_data in worksheet.drawing_links:
                rels._add_document_relationship(*drawing_data)

            # Create .rels file such as /xl/drawings/_rels/sheet1.xml.rels.
            rels._set_xml_writer(self._filename('xl/drawings/_rels/drawing'
                                                + str(index) + '.xml.rels'))
            rels._assemble_xml_file()