forked from AKSW/ffe.pfarrerbuch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer.py
139 lines (114 loc) · 5.56 KB
/
analyzer.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
"""
Class for analyzing a certain input string
Author: Robert R.
"""
from vicar import Vicar
class Analyzer:
def __init__(self, inputLine, vicar): # initilization
self.inputLine = inputLine
self.vicar = vicar
def parseOrdination(self):
if 'Ord.:' == self.inputLine[:5] and len(self.inputLine) > 8:
self.vicar.ordination = self.inputLine[6:]
def parseBirthday(self):
if '*' == self.inputLine[0] and len(self.inputLine) > 6:
self.vicar.birthday = self.inputLine[2:]
def parseObit(self):
if '†' == self.inputLine[0] and len(self.inputLine) > 6:
self.vicar.obit = self.inputLine[2:]
def parseMarried(self):
if '8' == self.inputLine[0] and len(self.inputLine) > 6:
self.vicar.inputLine = self.inputLine[2:]
def parseFather(self): # parse father
if 'P:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.father = self.inputLine[3:]
def parseMother(self):
if 'M:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.mother = self.inputLine[3:]
def parseSiblings(self):
if 'Fr:' == self.inputLine[:3] and len(self.inputLine) > 7:
self.vicar.siblings[:] = self.inputLine[4:].split(',')
for i, sibling in enumerate(self.vicar.siblings):
if ")" in sibling and not "(" in sibling:
self.vicar.siblings[i-1] = self.vicar.siblings[i-1] + ', ' + sibling
self.vicar.siblings.remove(sibling)
def parseOffspring(self):
if 'Fi:' == self.inputLine[:3] and len(self.inputLine) > 7:
self.vicar.offspring[:] = self.inputLine[4:].split(',')
for i, offspring in enumerate(self.vicar.offspring):
if ")" in offspring and not "(" in offspring:
self.vicar.offspring[i-1] = self.vicar.offspring[i-1] + ', ' + offspring
self.vicar.offspring.remove(offspring)
def parseVicars(self):
if 'V:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.vicars[:] = self.inputLine[3:].split(',')
for i, vicar in enumerate(self.vicar.vicars):
if ")" in vicar and not "(" in vicar:
self.vicar.vicars[i-1] = self.vicar.vicars[i-1] + ', ' + vicar
self.vicar.vicars.remove(vicar)
def parsePastors(self):
if 'VDM:' == self.inputLine[:4] and len(self.inputLine) > 8:
self.vicar.pastors[:] = self.inputLine[5:].split(',')
for i, pastor in enumerate(self.vicar.pastors):
if ")" in pastor and not "(" in pastor:
self.vicar.pastors[i-1] = self.vicar.pastors[i-1] + ', ' + pastor
self.vicar.pastors.remove(pastor)
def parseInstitutions(self):
if 'S:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.institutions[:] = self.inputLine[3:].split(',')
for i, institution in enumerate(self.vicar.institutions):
if ")" in institution and not "(" in institution:
self.vicar.institutions[i-1] = self.vicar.institutions[i-1] + ', ' + institution
self.vicar.institutions.remove(institution)
def parseTeachers(self):
if 'LM:' == self.inputLine[:3] and len(self.inputLine) > 7:
self.vicar.teachers[:] = self.inputLine[4:].split(',')
for i, teacher in enumerate(self.vicar.teachers):
if ")" in teacher and not "(" in teacher:
self.vicar.teachers[i-1] = self.vicar.teachers[i-1] + ', ' + teacher
self.vicar.teachers.remove(teacher)
def parseEducation(self):
if 'St:' == self.inputLine[:3] and len(self.inputLine) > 7:
self.vicar.education[:] = self.inputLine[4:].split(',')
for i, education in enumerate(self.vicar.education):
if ")" in education and not "(" in education:
self.vicar.education[i-1] = self.vicar.education[i-1] + ', ' + education
self.vicar.education.remove(education)
def parseMisc(self):
if 'N:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.misc = self.inputLine[3:]
def parseArchive(self):
if 'A:' == self.inputLine[:2] and len(self.inputLine) > 6:
self.vicar.archive = self.inputLine[3:]
def parseLiterature(self):
if 'Lit:' == self.inputLine[:4] and len(self.inputLine) > 8:
self.vicar.literature = self.inputLine[5:]
def analyze(self): # general analyzation of input
self.parseArchive()
self.parseBirthday()
self.parseEducation()
self.parseFather()
self.parseInstitutions()
self.parseLiterature()
self.parseMarried()
self.parseMisc()
self.parseMother()
self.parseObit()
self.parseOffspring()
self.parseOrdination()
self.parsePastors()
self.parseSiblings()
self.parseTeachers()
self.parseVicars()
def main(): # main class (testing)
text = 'T. Konrad, * Bucha b. Jena 21.08.1872 '
analyzer = Analyzer(text)
output = analyzer.analyze()
print(analyzer.analyze())
vicar = Vicar('k.A.', 'k.A.', 'k.A.', 'k.A.', 'k.A.', 'k.A.', 'k.A.'
'k.A.', 'k.A.', 'k.A.')
print(vicar.birthday)
print(vicar.obit)
if __name__ == '__main__': # call if module is called as main
main()