marlontosta
commited on
Commit
•
b27b1aa
1
Parent(s):
61a6f67
Update direitodigital.py
Browse files- direitodigital.py +14 -7
direitodigital.py
CHANGED
@@ -5,6 +5,7 @@ Reference: https://huggingface.co/datasets/nielsr/funsd/blob/main/funsd.py
|
|
5 |
import ast
|
6 |
import os
|
7 |
import random
|
|
|
8 |
|
9 |
import datasets
|
10 |
import matplotlib.pyplot as plt
|
@@ -76,7 +77,6 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
76 |
"segment_class": datasets.Sequence(
|
77 |
datasets.features.ClassLabel(
|
78 |
names=["O", "B-PARTES","I-PARTES", "B-EMENTA","I-EMENTA", "B-ACORDAO","I-ACORDAO", "B-RELATORIO","I-RELATORIO", "B-VOTO", "I-VOTO"]
|
79 |
-
#names=["OUTROS", "PARTES", "EMENTA","ACORDAO","RELATORIO", "VOTO"]
|
80 |
)
|
81 |
),
|
82 |
"image": datasets.features.Image(),
|
@@ -88,8 +88,9 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
88 |
)
|
89 |
|
90 |
def _split_generators(self, dl_manager):
|
91 |
-
downloaded_file = dl_manager.download_and_extract("http://direitodigital.ufms.br:8000/direitodigital_dev.zip")
|
92 |
"""Returns SplitGenerators."""
|
|
|
|
|
93 |
return [
|
94 |
datasets.SplitGenerator(
|
95 |
name=datasets.NamedSplit('trainmini_stf'), gen_kwargs={"filepath": f"{downloaded_file}/trainmini/stf"}
|
@@ -133,12 +134,11 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
133 |
bbox = [[x0, y0, x1, y1] for _ in range(len(bboxs))]
|
134 |
return bbox
|
135 |
|
136 |
-
def _generate_examples():
|
137 |
guid = 0
|
138 |
-
|
139 |
file_paths = [
|
140 |
os.path.join(root, filename)
|
141 |
-
for root, dirs, files in os.walk(
|
142 |
for filename in files
|
143 |
if filename.endswith('.tsv')
|
144 |
]
|
@@ -149,11 +149,18 @@ class Funsd(datasets.GeneratorBasedBuilder):
|
|
149 |
for tsv_name in file_paths:
|
150 |
#for file in file_names:
|
151 |
#tsv_name = os.path.join(dir_path, file)
|
|
|
|
|
|
|
152 |
|
153 |
-
pdf_name = tsv_name.replace('
|
|
|
|
|
154 |
|
155 |
img_path = tsv_name.replace('.tsv','')
|
156 |
-
|
|
|
|
|
157 |
|
158 |
dataframe = pd.read_csv(tsv_name ,delimiter='\t', keep_default_na=False).replace(["None","SUMULA","CERTIDAO_DE_JULGAMENTO","AUTUACAO","CERTIDAO","EXTRATO_DE_ATA"], 'OUTROS')
|
159 |
for page in dataframe['page'].unique():
|
|
|
5 |
import ast
|
6 |
import os
|
7 |
import random
|
8 |
+
import re
|
9 |
|
10 |
import datasets
|
11 |
import matplotlib.pyplot as plt
|
|
|
77 |
"segment_class": datasets.Sequence(
|
78 |
datasets.features.ClassLabel(
|
79 |
names=["O", "B-PARTES","I-PARTES", "B-EMENTA","I-EMENTA", "B-ACORDAO","I-ACORDAO", "B-RELATORIO","I-RELATORIO", "B-VOTO", "I-VOTO"]
|
|
|
80 |
)
|
81 |
),
|
82 |
"image": datasets.features.Image(),
|
|
|
88 |
)
|
89 |
|
90 |
def _split_generators(self, dl_manager):
|
|
|
91 |
"""Returns SplitGenerators."""
|
92 |
+
downloaded_file = dl_manager.download_and_extract("http://direitodigital.ufms.br:8000/direitodigital.zip")
|
93 |
+
|
94 |
return [
|
95 |
datasets.SplitGenerator(
|
96 |
name=datasets.NamedSplit('trainmini_stf'), gen_kwargs={"filepath": f"{downloaded_file}/trainmini/stf"}
|
|
|
134 |
bbox = [[x0, y0, x1, y1] for _ in range(len(bboxs))]
|
135 |
return bbox
|
136 |
|
137 |
+
def _generate_examples(self, filepath):
|
138 |
guid = 0
|
|
|
139 |
file_paths = [
|
140 |
os.path.join(root, filename)
|
141 |
+
for root, dirs, files in os.walk(filepath)
|
142 |
for filename in files
|
143 |
if filename.endswith('.tsv')
|
144 |
]
|
|
|
149 |
for tsv_name in file_paths:
|
150 |
#for file in file_names:
|
151 |
#tsv_name = os.path.join(dir_path, file)
|
152 |
+
#print(file_paths)
|
153 |
+
base_path = os.path.dirname(os.path.dirname(filepath))
|
154 |
+
pdf_base_path = os.path.join(base_path, 'pdf')
|
155 |
|
156 |
+
pdf_name = tsv_name.replace('.tsv', '.pdf')
|
157 |
+
pdf_name = pdf_name.replace(base_path,pdf_base_path)
|
158 |
+
|
159 |
|
160 |
img_path = tsv_name.replace('.tsv','')
|
161 |
+
print(pdf_name)
|
162 |
+
|
163 |
+
pages_img = convert_from_path(pdf_name, size=(595,840),fmt="png")
|
164 |
|
165 |
dataframe = pd.read_csv(tsv_name ,delimiter='\t', keep_default_na=False).replace(["None","SUMULA","CERTIDAO_DE_JULGAMENTO","AUTUACAO","CERTIDAO","EXTRATO_DE_ATA"], 'OUTROS')
|
166 |
for page in dataframe['page'].unique():
|