-
Notifications
You must be signed in to change notification settings - Fork 0
/
021700201.py
178 lines (157 loc) · 4.55 KB
/
021700201.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import cpca
import json
def split_name(s:str):#将名字从字符串中提取出来
match = s.split(",")
return match
def split_num(s:str):#将电话号码从字符串提取出来
phone = re.search(r'1\d{10}',s).group(0)
match = re.split(r'1\d{10}',s)
addr = match[0]+match[1]#将电话号码提取出来后,连接两个被分开的字符串
return (phone, addr)
def solve_5(str0:str):
#str0 = input()
#print(str0)
if str0[-1] == ".":
str0=str0.split(".")[0]
s1 = split_name(str0)
name = s1[0]
s2 = split_num(s1[1])
phone = s2[0]
addr0 = s2[1]
#print(name, phone, addr0, end="\n")
df = cpca.transform([addr0])#必须使用列表才能映射
#print(df)
#print(dict(df.iloc[0,0:4]))
tmp = dict(df.iloc[0,0:4])
addr1 = tmp['地址']#提取出详细地址
#镇,乡
zhen = xiang = jiedao = lu = xiang1 = None#init
if "镇" in addr1:
zhen = addr1.split("镇")[0]+"镇"
addr1 = addr1.split("镇")[1]
if "乡" in addr1:
xiang = addr1.split("乡")[0]+"乡"
addr1 = addr1.split("乡")[1]
if "街" in addr1:
if "街道" in addr1:
jiedao = addr1.split("街道")[0] + "街道"
addr1 = addr1.split("街道")[1]
else:
jiedao = addr1.split("街")[0]+"街"
addr1 = addr1.split("街")[1]
if "路" in addr1:
lu = addr1.split("路")[0]+"路"
addr1 = addr1.split("路")[1]
if "巷" in addr1:
xiang1 = addr1.split("巷")[0]+"巷"
addr1 = addr1.split("巷")[1]
addr = [tmp['省'],tmp['市'],tmp['区'],"","",]
if zhen != None:
addr[3] += (zhen)
if xiang != None:
addr[3] += (xiang)
if jiedao != None:
addr[3] += (jiedao)
if lu != None:
addr[4] += (lu)
if xiang1 != None:
addr[4] += (xiang1)
if jiedao==None:
if lu==None:
if xiang1==None:
if zhen == None:
if xiang == None:
addr[4] = ""
addr[4] += addr1
info = {
"姓名": name,
"手机": phone,
"地址": addr
}
#编码成json类型数据
info_data = json.dumps(info, ensure_ascii=False)
print(info_data)
#print(json.loads(info_data))#打印结果
def solve_7(str0:str):
#str0 = input()
#print(str0)
if str0[-1] == ".":
str0=str0.split(".")[0]
s1 = split_name(str0)
name = s1[0]
s2 = split_num(s1[1])
phone = s2[0]
addr0 = s2[1]
#print(name, phone, addr0, end="\n")
df = cpca.transform([addr0])#必须使用列表才能映射
#print(df)
#print(dict(df.iloc[0,0:4]))
tmp = dict(df.iloc[0,0:4])
addr1 = tmp['地址']#提取出详细地址
#镇,乡
zhen = xiang = jiedao = lu = xiang1 = None#init
if "镇" in addr1:
zhen = addr1.split("镇")[0]+"镇"
addr1 = addr1.split("镇")[1]
if "乡" in addr1:
xiang = addr1.split("乡")[0]+"乡"
addr1 = addr1.split("乡")[1]
#路,巷,街道
if "街" in addr1:
if "街道" in addr1:
jiedao = addr1.split("街道")[0] + "街道"
addr1 = addr1.split("街道")[1]
else:
jiedao = addr1.split("街")[0]+"街"
addr1 = addr1.split("街")[1]
if "路" in addr1:
lu = addr1.split("路")[0]+"路"
addr1 = addr1.split("路")[1]
if "巷" in addr1:
xiang1 = addr1.split("巷")[0]+"巷"
addr1 = addr1.split("巷")[1]
if re.search(r"\d*号",addr1) is None:
hao = None
else:
hao = re.search(r"\d*号",addr1).group(0)
addr1 = addr1.split("号")[1]
addr = [tmp['省'],tmp['市'],tmp['区'],"","","",]
if zhen != None:
addr[3] += zhen
if xiang != None:
addr[3] += xiang
#print(addr)
if jiedao != None:
if zhen is None and xiang is None:
addr[3] += jiedao
else:
addr[4] += jiedao
if lu != None:
addr[4] +=lu
if xiang1 != None:
addr[4] += xiang1
if hao != None:
addr[5] += hao
addr.append(addr1)
info = {
"姓名": name,
"手机": phone,
"地址": addr
}
#编码成json类型数据
info_data = json.dumps(info, ensure_ascii=False)
print(info_data)
#print(json.loads(info_data))#打印结果
str0 = input()
level = str0.split("!")[0]
level = int(level)
str0 = str0.split("!")[1]
if level == 1:
solve_5(str0)
if level == 2:
solve_7(str0)
if level == 3:
solve_7(str0)