database_tools中新增几个和单元挂钩有关的functions
This commit is contained in:
parent
ba573b4dce
commit
963b8f8423
|
|
@ -1829,5 +1829,59 @@ def generateAnswerList(string,anspreamble = "答案: \\textcolor{red}{"): #从La
|
|||
return anslist
|
||||
|
||||
|
||||
def unUnitted(adict): #返回adict中未赋单元的id列表
|
||||
return [id for id in adict if not "单元" in "".join(adict[id]["tags"]) and not "暂无" in "".join(adict[id]["tags"])]
|
||||
|
||||
|
||||
def AutoAssignTagNotoLaTeX(newlist,adict): #根据题库中已有的单元挂钩和字符串相似比对, 给newlist中的每一个ID在可能的情况下自动适配单元号码, 可能有误, 需人工审核, 返回(LaTeX代码的body(从\begin{enumerate}到\end{enumerate}的部分),题号和单元号码的对应)组成的二元tuple
|
||||
output = "\\begin{enumerate}\n\n"
|
||||
tagrecord = ""
|
||||
treateddict = treat_dict(adict)
|
||||
for id in newlist:
|
||||
samelist = adict[id]["same"]
|
||||
relatedlist = adict[id]["related"]
|
||||
if not samelist == []:
|
||||
unittags = [i for i in adict[samelist[0]]["tags"] if "单元" in i]
|
||||
elif not relatedlist == []:
|
||||
unittags = [i for i in adict[relatedlist[0]]["tags"] if "单元" in i]
|
||||
else:
|
||||
simgroup = stringmaxsim(treateddict[id]["content"],treateddict,10)
|
||||
unittags_raw = {}
|
||||
for g in simgroup:
|
||||
rid,sim = g
|
||||
if not rid == id and sim > 0.75:
|
||||
for t in [i for i in adict[rid]["tags"] if "单元" in i]:
|
||||
if t in unittags_raw:
|
||||
unittags_raw[t] += 1
|
||||
else:
|
||||
unittags_raw[t] = 1
|
||||
if len(unittags_raw) == 0:
|
||||
unittags = []
|
||||
else:
|
||||
unittags = [max(unittags_raw, key = lambda x: unittags_raw[x])]
|
||||
tagnumbers = ""
|
||||
for u in unittags:
|
||||
tagnumbers += str(getUnitNumber(u))
|
||||
output += f"\\item ({id})[{tagnumbers}] {adict[id]['content']}\n\n"
|
||||
tagrecord += f"{id}\t{tagnumbers}\n"
|
||||
output += "\\end{enumerate}\n\n"
|
||||
return (output,tagrecord)
|
||||
|
||||
|
||||
def UnitRectoMetadataText(data): #把data中的单元对应变为metadata.txt中的单元对应文本
|
||||
lines = [l for l in data.split("\n") if l.strip() != ""]
|
||||
output = "tags\n\n"
|
||||
for l in lines:
|
||||
id,unitno = l.split("\t")
|
||||
units = ""
|
||||
if not len(unitno.strip()) == 0:
|
||||
for n in unitno:
|
||||
units += f"{getUnit(int(n))}\n"
|
||||
output += f"{id.zfill(6)}\n"
|
||||
output += f"{units}\n\n"
|
||||
return output
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("数据库工具, import用.")
|
||||
Reference in New Issue