"""Compare two local routing rules with a fixed set of labelled tasks."""
import argparse
import json
from pathlib import Path
def choose(task, candidates):
task = task.lower()
for candidate in candidates:
groups = candidate["requires"]
if all(any(word in task for word in group) for group in groups):
return candidate["name"]
return None
def grade(tasks, candidates):
counts = dict(correct=0,missed=0,unexpected=0,wrong=0)
trials = []
for entry in tasks:
actual = choose(entry["request"],candidates)
expected = entry["skill"]
if actual == expected:
outcome = "correct"
elif actual is None:
outcome = "missed"
elif expected is None:
outcome = "unexpected"
else:
outcome = "wrong"
counts[outcome] += 1
trials.append({"request":entry["request"],"expected":expected,"chosen":actual,"outcome":outcome})
return {"counts":counts,"trials":trials}
if __name__ == "__main__":
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument("dataset",type=Path)
files=json.loads(parser.parse_args().dataset.read_text(encoding="utf8"))
print(json.dumps({name:grade(files["tasks"],files[name]) for name in ("broad","specific")}))
本例需在 Windows、Python 3.12。各实验所需工具和版本见下载包 README。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows、Python 3.12。各实验所需工具和版本见下载包 README。
入口文件:projects/skills-reuse/grade_descriptions.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
grade_descriptions.py,或下载右侧课程工程包。 - 确认本地已准备 Windows、Python 3.12。各实验所需工具和版本见下载包 README。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联3章) · 含当前章节或实例 · mbskycom202612a350.zip
课程关联工程包(登记关联39章) · 含当前章节或实例 · mbskycom202612a331.zip