Fix OS examples annotated by Yitao
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import csv
|
||||
import json
|
||||
import functools
|
||||
import json
|
||||
import operator
|
||||
import re
|
||||
import sqlite3
|
||||
from numbers import Number
|
||||
from typing import Callable, Any, Union
|
||||
from typing import Dict, List, Pattern
|
||||
@@ -14,13 +15,14 @@ from rapidfuzz import fuzz
|
||||
|
||||
from .utils import _match_record, _match_value_to_rule
|
||||
|
||||
import sqlite3
|
||||
|
||||
def check_include_exclude(result: str, rules: Dict[str, List[str]]) -> float:
|
||||
print(result, rules)
|
||||
include = rules.get("include", [])
|
||||
exclude = rules.get("exclude", [])
|
||||
return all(r in result for r in include) and all(r not in result for r in exclude)
|
||||
|
||||
|
||||
def exact_match(result, rules) -> float:
|
||||
expect = rules["expected"]
|
||||
print(result, expect)
|
||||
@@ -36,6 +38,7 @@ def fuzzy_match(result, rules) -> float:
|
||||
|
||||
return fuzz.ratio(result, expect) / 100.
|
||||
|
||||
|
||||
def check_csv(result: str, rules: Dict[str, List[Dict[str, str]]]) -> float:
|
||||
"""
|
||||
Args:
|
||||
@@ -140,10 +143,10 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
return 0.
|
||||
|
||||
if "text" in rules:
|
||||
match_func: Callable[[str], Number] = functools.partial( operator.eq if rules["exact"]\
|
||||
else (lambda a, b: fuzz.ratio(a, b)/100.)
|
||||
, rules["text"]
|
||||
)
|
||||
match_func: Callable[[str], Number] = functools.partial(operator.eq if rules["exact"] \
|
||||
else (lambda a, b: fuzz.ratio(a, b) / 100.)
|
||||
, rules["text"]
|
||||
)
|
||||
match_score: Number = 0
|
||||
for elm in elements:
|
||||
match_score = max(match_score, match_func(elm.text or None))
|
||||
@@ -152,6 +155,7 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
|
||||
return float(match_score)
|
||||
|
||||
|
||||
# def check_existence(result: str, *args) -> float:
|
||||
# return 1. - (result is None)
|
||||
|
||||
@@ -160,6 +164,7 @@ def run_sqlite3(result: str, rules: Dict[str, Any]) -> float:
|
||||
cursor: sqlite3.Cursor = connection.execute(rules["sql"])
|
||||
return float(cursor.fetchone()[0] or 0)
|
||||
|
||||
|
||||
def check_json(result: str, rules: Dict[str, List[Dict[str, Union[List[str], str]]]]) -> float:
|
||||
"""
|
||||
Args:
|
||||
@@ -200,4 +205,3 @@ def check_json(result: str, rules: Dict[str, List[Dict[str, Union[List[str], str
|
||||
value = value[k]
|
||||
metric = metric and not _match_value_to_rule(value, r)
|
||||
return metric
|
||||
|
||||
|
||||
Reference in New Issue
Block a user