-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask5.py
More file actions
91 lines (76 loc) · 2.56 KB
/
task5.py
File metadata and controls
91 lines (76 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import csv
class Iterator1:
'''
class Iterator1:
methods:
__init__ : initializing fields class
__iter__ : return iterator
__next__ : return object and the counter is incremented by one, that is, it moves to the next element
'''
def __init__(self, path_file: str):
self.count = 0
self.files = os.listdir(os.path.join("dataset", path_file))
self.limit = len(self.files)
self.path = path_file
return self
def __iter__(self):
return self
def __next__(self):
if self.count < self.limit:
obj = self.files[self.count]
self.count += 1
return obj
raise StopIteration
class Iterator2:
'''
class Iterator2:
methods:
__init__ : initializing fields class and check: if the element doesn`t contain the name
of the class, then it is deleted
__iter__ : return iterator
__next__ : return object and the counter is incremented by one, that is, it moves to the next element
'''
def __init__(self, class_n: str, path_file: str):
self.files = os.listdir(path_file)
for elem in self.files:
if not class_n in elem:
self.files.remove(elem)
self.limit = len(self.files)
self.count = 0
self.path = path_file
def __iter__(self):
return self
def __next__(self):
if self.count < self.limit:
obj = self.files[self.count]
self.count += 1
return obj
raise StopIteration
class IteratorTask3:
'''
class Iterator3:
methods:
__init__ : reads elements from a csv file and writes them to a list; initialize fields class
__iter__ : return iterator
__next__ : return object and the counter is incremented by one, that is, it moves to the next element
'''
def __init__(self, class_name: str, path: str, annotation_n: str):
self.files = []
with open(os.path.join(path, annotation_n), encoding='UTF-16') as f:
reader = csv.reader(f, delimiter=';')
for elem in reader:
if elem[2] == class_name:
self.files.append(os.path.basename(elem[0]))
pass
self.limit = len(self.files)
self.count = 0
self.path = path
def __iter__(self):
return self
def __next__(self):
if self.count < self.limit:
obj = self.files[self.count]
self.count += 1
return obj
raise StopIteration