蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行描述选择评测并列出错误类型

PYTHONWindows、Python 3.12。各实验所需工具和版本见下载包 README。grade_descriptions.py
grade_descriptions.py40 行
"""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

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 grade_descriptions.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows、Python 3.12。各实验所需工具和版本见下载包 README。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Skills(技能)

课程关联工程包(登记关联3章) · 含当前章节或实例 · mbskycom202612a350.zip

下载课程关联工程包:Skills(技能)

课程关联工程包(登记关联39章) · 含当前章节或实例 · mbskycom202612a331.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习