您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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