Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  2. # you may not use this file except in compliance with the License.
  3. # You may obtain a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. #
  13. import json
  14. from deepdoc.parser.resume.entities import degrees, regions, industries
  15. FIELDS = [
  16. "address STRING",
  17. "annual_salary int",
  18. "annual_salary_from int",
  19. "annual_salary_to int",
  20. "birth STRING",
  21. "card STRING",
  22. "certificate_obj string",
  23. "city STRING",
  24. "corporation_id int",
  25. "corporation_name STRING",
  26. "corporation_type STRING",
  27. "degree STRING",
  28. "discipline_name STRING",
  29. "education_obj string",
  30. "email STRING",
  31. "expect_annual_salary int",
  32. "expect_city_names string",
  33. "expect_industry_name STRING",
  34. "expect_position_name STRING",
  35. "expect_salary_from int",
  36. "expect_salary_to int",
  37. "expect_type STRING",
  38. "gender STRING",
  39. "industry_name STRING",
  40. "industry_names STRING",
  41. "is_deleted STRING",
  42. "is_fertility STRING",
  43. "is_house STRING",
  44. "is_management_experience STRING",
  45. "is_marital STRING",
  46. "is_oversea STRING",
  47. "language_obj string",
  48. "name STRING",
  49. "nation STRING",
  50. "phone STRING",
  51. "political_status STRING",
  52. "position_name STRING",
  53. "project_obj string",
  54. "responsibilities string",
  55. "salary_month int",
  56. "scale STRING",
  57. "school_name STRING",
  58. "self_remark string",
  59. "skill_obj string",
  60. "title_name STRING",
  61. "tob_resume_id STRING",
  62. "updated_at Timestamp",
  63. "wechat STRING",
  64. "work_obj string",
  65. "work_experience int",
  66. "work_start_time BIGINT"
  67. ]
  68. def refactor(df):
  69. def deal_obj(obj, k, kk):
  70. if not isinstance(obj, type({})):
  71. return ""
  72. obj = obj.get(k, {})
  73. if not isinstance(obj, type({})):
  74. return ""
  75. return obj.get(kk, "")
  76. def loadjson(line):
  77. try:
  78. return json.loads(line)
  79. except Exception as e:
  80. pass
  81. return {}
  82. df["obj"] = df["resume_content"].map(lambda x: loadjson(x))
  83. df.fillna("", inplace=True)
  84. clms = ["tob_resume_id", "updated_at"]
  85. def extract(nms, cc=None):
  86. nonlocal clms
  87. clms.extend(nms)
  88. for c in nms:
  89. if cc:
  90. df[c] = df["obj"].map(lambda x: deal_obj(x, cc, c))
  91. else:
  92. df[c] = df["obj"].map(
  93. lambda x: json.dumps(
  94. x.get(
  95. c,
  96. {}),
  97. ensure_ascii=False) if isinstance(
  98. x,
  99. type(
  100. {})) and (
  101. isinstance(
  102. x.get(c),
  103. type(
  104. {})) or not x.get(c)) else str(x).replace(
  105. "None",
  106. ""))
  107. extract(["education", "work", "certificate", "project", "language",
  108. "skill"])
  109. extract(["wechat", "phone", "is_deleted",
  110. "name", "tel", "email"], "contact")
  111. extract(["nation", "expect_industry_name", "salary_month",
  112. "industry_ids", "is_house", "birth", "annual_salary_from",
  113. "annual_salary_to", "card",
  114. "expect_salary_to", "expect_salary_from",
  115. "expect_position_name", "gender", "city",
  116. "is_fertility", "expect_city_names",
  117. "political_status", "title_name", "expect_annual_salary",
  118. "industry_name", "address", "position_name", "school_name",
  119. "corporation_id",
  120. "is_oversea", "responsibilities",
  121. "work_start_time", "degree", "management_experience",
  122. "expect_type", "corporation_type", "scale", "corporation_name",
  123. "self_remark", "annual_salary", "work_experience",
  124. "discipline_name", "marital", "updated_at"], "basic")
  125. df["degree"] = df["degree"].map(lambda x: degrees.get_name(x))
  126. df["address"] = df["address"].map(lambda x: " ".join(regions.get_names(x)))
  127. df["industry_names"] = df["industry_ids"].map(lambda x: " ".join([" ".join(industries.get_names(i)) for i in
  128. str(x).split(",")]))
  129. clms.append("industry_names")
  130. def arr2str(a):
  131. if not a:
  132. return ""
  133. if isinstance(a, list):
  134. a = " ".join([str(i) for i in a])
  135. return str(a).replace(",", " ")
  136. df["expect_industry_name"] = df["expect_industry_name"].map(
  137. lambda x: arr2str(x))
  138. df["gender"] = df["gender"].map(
  139. lambda x: "男" if x == 'M' else (
  140. "女" if x == 'F' else ""))
  141. for c in ["is_fertility", "is_oversea", "is_house",
  142. "management_experience", "marital"]:
  143. df[c] = df[c].map(
  144. lambda x: '是' if x == 'Y' else (
  145. '否' if x == 'N' else ""))
  146. df["is_management_experience"] = df["management_experience"]
  147. df["is_marital"] = df["marital"]
  148. clms.extend(["is_management_experience", "is_marital"])
  149. df.fillna("", inplace=True)
  150. for i in range(len(df)):
  151. if not df.loc[i, "phone"].strip() and df.loc[i, "tel"].strip():
  152. df.loc[i, "phone"] = df.loc[i, "tel"].strip()
  153. for n in ["industry_ids", "management_experience", "marital", "tel"]:
  154. for i in range(len(clms)):
  155. if clms[i] == n:
  156. del clms[i]
  157. break
  158. clms = list(set(clms))
  159. df = df.reindex(sorted(clms), axis=1)
  160. #print(json.dumps(list(df.columns.values)), "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL")
  161. for c in clms:
  162. df[c] = df[c].map(
  163. lambda s: str(s).replace(
  164. "\t",
  165. " ").replace(
  166. "\n",
  167. "\\n").replace(
  168. "\r",
  169. "\\n"))
  170. # print(df.values.tolist())
  171. return dict(zip([n.split(" ")[0] for n in FIELDS], df.values.tolist()[0]))