import pandas as pd
def maybe_sort_df(df):
df = df.sort_values(by="did", kind="stable", ignore_index=True)
df.to_csv("generate/results/WD_YDLJ.csv", index=False)
dfi = pd.read_csv("generate/original_dataset/原始裁判文书/index.csv")
if dfi.isna().values.any():
print("\033[31mMissing data detected:\033[0m")
print(dfi[dfi.isna().any(axis=1)])
else:
print("\033[92mConfirm no missing data\033[0m")
if dfi["id"].is_unique:
print("\033[92mConfirm ids are unique\033[0m")
else:
print("\033[31mDuplicate ids detected:\033[0m")
print(dfi[dfi["id"].duplicated()])
missing_ids = set(range(len(dfi))).difference(set(dfi["id"]))
if missing_ids:
print("\033[31mMissing ids detected:\033[0m")
print(" ".join(map(str, sorted(missing_ids))))
else:
print(f"\033[92mConfirm no missing ids (0 ~ {len(dfi) - 1})\033[0m")
if dfi["title"].is_unique:
print("\033[92mConfirm titles are unique\033[0m")
else:
print("\033[31mDuplicate titles detected:\033[0m")
print(dfi[dfi["title"].duplicated()])
Confirm no missing data Confirm ids are unique Confirm no missing ids (0 ~ 359) Confirm titles are unique
民事与刑事的文书数量分布希望为1:1
.
dfi_grp = dfi.groupby(["type", "level", "year"]).size().to_frame(name="count")
dfi_grp_macro = dfi.groupby("type").size().to_frame(name="count")
dfi_grp_macro["%"] = dfi_grp_macro["count"] / dfi_grp_macro["count"].sum()
dfi_grp_macro["%"] = dfi_grp_macro["%"].apply("{:.2%}".format)
dfi_grp_macro
count | % | |
---|---|---|
type | ||
刑事 | 102 | 28.33% |
民事 | 258 | 71.67% |
基层法院、中级法院、高级法院、和最高法院的文书数量分布希望接近于数据库https://wenshu.court.gov.cn/中的分布。
注:原计划为均匀分布而此要求为6/13晚商定,又因文书数量随法院层级提升而指数下降,最终将不可能达到完美的分布。
ind = pd.MultiIndex.from_product(
[("刑事", "民事"), ("基层法院", "中级法院", "高级法院", "最高法院"), (2022, 2023)],
names=["type", "level", "year"]
)
df_ref = pd.DataFrame(index=ind, columns=["count"])
df_ref.loc[("刑事", "基层法院", 2022)] = 89185
df_ref.loc[("刑事", "基层法院", 2023)] = 14191
df_ref.loc[("刑事", "中级法院", 2022)] = 82758
df_ref.loc[("刑事", "中级法院", 2023)] = 11984
df_ref.loc[("刑事", "高级法院", 2022)] = 975
df_ref.loc[("刑事", "高级法院", 2023)] = 61
df_ref.loc[("刑事", "最高法院", 2022)] = 82
df_ref.loc[("刑事", "最高法院", 2023)] = 3
df_ref.loc[("民事", "基层法院", 2022)] = 4513220
df_ref.loc[("民事", "基层法院", 2023)] = 787645
df_ref.loc[("民事", "中级法院", 2022)] = 483979
df_ref.loc[("民事", "中级法院", 2023)] = 94326
df_ref.loc[("民事", "高级法院", 2022)] = 26942
df_ref.loc[("民事", "高级法院", 2023)] = 4452
df_ref.loc[("民事", "最高法院", 2022)] = 278
df_ref.loc[("民事", "最高法院", 2023)] = 2636
df_ref = df_ref.reset_index()
df_ref = df_ref.groupby(["type", "level"], as_index=False)["count"].sum()
df_ref_subtypes = {}
for tp in ("民事", "刑事"):
df_ref_subtype = df_ref[df_ref["type"] == tp].drop("type", axis=1).set_index("level")
df_ref_subtype["%"] = df_ref_subtype["count"] / df_ref_subtype["count"].sum()
df_ref_subtype = df_ref_subtype.drop("count", axis=1)
df_ref_subtypes[tp] = df_ref_subtype
dfi_comps = {}
for tp in ("民事", "刑事"):
dfi_comp = dfi_grp.reset_index()
dfi_comp = dfi_comp[dfi_comp["type"] == tp]
dfi_comp = dfi_comp.groupby("level", as_index=False)["count"].sum()
dfi_comp = dfi_comp.set_index("level")
dfi_comp["%"] = (dfi_comp["count"] / dfi_comp["count"].sum())
dfi_comp = dfi_comp.join(df_ref_subtypes[tp], how="outer", rsuffix=" (ref)")
dfi_comp = dfi_comp.fillna(0).astype({"count": int})
dfi_comp["%"] = dfi_comp["%"].apply("{:.2%}".format)
dfi_comp["% (ref)"] = dfi_comp["% (ref)"].apply("{:.2%}".format)
dfi_comp["type"] = tp
dfi_comp["lack"] = dfi_comp["%"] < dfi_comp["% (ref)"]
dfi_comp = dfi_comp.reset_index().set_index(["type", "level"])
dfi_comps[tp] = dfi_comp
dfi_comps["刑事"]
count | % | % (ref) | lack | ||
---|---|---|---|---|---|
type | level | ||||
刑事 | 中级法院 | 29 | 28.43% | 47.55% | True |
基层法院 | 53 | 51.96% | 51.89% | False | |
最高法院 | 0 | 0.00% | 0.04% | True | |
高级法院 | 20 | 19.61% | 0.52% | False |
dfi_comps["民事"]
count | % | % (ref) | lack | ||
---|---|---|---|---|---|
type | level | ||||
民事 | 中级法院 | 25 | 9.69% | 9.78% | True |
基层法院 | 213 | 82.56% | 89.64% | True | |
最高法院 | 20 | 7.75% | 0.05% | False | |
高级法院 | 0 | 0.00% | 0.53% | True |
df = pd.read_csv("generate/results/WD_YDLJ.csv")
print(f"Constructed data: {len(df)}")
missing_cons_dids = set(range(len(dfi))).difference(set(df["did"]))
if missing_cons_dids:
missing_cons_dids_str = " ".join(map(str, sorted(missing_cons_dids)))
print(f"\033[31mDetected {len(missing_cons_dids)} datasets not constructed:\033[0m")
print("> python generate/clean_wenshu_all.py")
print(f"> python generate/WD_YDLJ.py -p -d {missing_cons_dids_str}")
else:
print("\033[92mConfirm all existing datasets constructed\033[0m")
df
Constructed data: 7112
Confirm all existing datasets constructed
did | question | answer | |
---|---|---|---|
0 | 0 | 被告和原告分别是谁? | 一审被告为东莞市九鲨电子科技有限公司、深圳市尚品博林科技有限公司和谈杰,一审原告为蔡双双。 |
1 | 0 | 蔡双双的诉讼代理人是谁? | 蔡双双的诉讼代理人是吴军,来自广东深科律师事务所。 |
2 | 0 | 本案涉及的法律问题是什么? | 本案涉及侵害实用新型专利权的纠纷。 |
3 | 0 | 本案的一审判决结果是什么? | 广东省深圳市中级人民法院作出的一审判决结果是(2021)粤03民初513号民事判决。 |
4 | 0 | 本案二审的案件受理费应由哪方负担? | 本案一审案件受理费由蔡双双负担;二审案件受理费由东莞市九鲨电子科技有限公司负担。 |
... | ... | ... | ... |
7107 | 359 | 被告人在何时何地涉嫌犯罪? | 被告人在2021年11月19日20时许,在环县“某某音乐烤吧”与朋友聚会时涉嫌犯罪。 |
7108 | 359 | 被告人被判处什么刑罚? | 被告人被判处拘役一个月,缓刑二个月,并处罚金2000元。 |
7109 | 359 | 被告人的酒驾情况如何? | 被告人餒酒驾驶车辆,2021年11月21日鉴定血液中乙醇平均含量为114.51mg/100ml。 |
7110 | 359 | 可以对本案判决提出上诉吗? | 可以的。如果不服本判决,可在判决书送达之日起十日内向本院或甘肃省庆阳市中级人民法院提出上诉。 |
7111 | 359 | 被告人是否对指控的事实、罪名及量刑建议有异议? | 被告人对指控的事实、罪名及量刑建议没有异议,同意适用速裁程序且签字具结,在开庭审理过程中亦无异议。 |
7112 rows × 3 columns
bad_update_df = df[(df["question"].str.contains("无更新")) | (df["answer"].str.contains("无更新"))]
print(f"Incorrect update: {len(bad_update_df)} ({len(bad_update_df) / len(df):.3%}) out of {len(df)}")
bad_update_df
Incorrect update: 7 (0.098%) out of 7112
did | question | answer | |
---|---|---|---|
375 | 21 | 本案的最终结果是什么? | 无更新。 |
991 | 66 | 一审法院的终审判决是什么? | 无更新。 |
2759 | 151 | 文档中是否有其他值得注意的信息? | 无更新。 |
2775 | 152 | 本案的定罪量刑依据是什么? | 无更新。 |
4271 | 216 | 本案是否有其他更新? | 无更新。 |
6199 | 305 | 案件进展如何? | 本案近期无更新。 |
6231 | 306 | 本案将如何裁决? | 无更新。 |