From 2d5db639fb0a0f4efd506e8d9485b5881a7ed290 Mon Sep 17 00:00:00 2001 From: bill Date: Thu, 30 Nov 2023 23:48:21 +0000 Subject: [PATCH] deal with re --- mongodb/source/autograder.py | 19 +++++++++++++------ neo4j/source/autograder.py | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mongodb/source/autograder.py b/mongodb/source/autograder.py index a1dc2c8..54ebbb8 100644 --- a/mongodb/source/autograder.py +++ b/mongodb/source/autograder.py @@ -1,14 +1,15 @@ import pymongo, json -print('ver: 1.1') +print('ver: 1.5') # dbprep fsroot = '/autograder/source/' datasets = ['congress', 'bills'] db = pymongo.MongoClient('mongodb://127.0.0.1')['test'] + def postproc_str(data : str): # relaxed str matching import re - data = re.sub(r'[\s|_]', '', data.lower()) + data = re.sub(r'[\s|_|.]', '', data.lower()) return re.sub(r'sponser', 'sponsor', data) def comparator(a, b): @@ -40,7 +41,7 @@ def comparator(a, b): return cmp(f'{a}', f'{b}') case _: return cmp(hash(type(a)), hash(type(b))) - + def postproc_iter(data): from collections.abc import Iterable from functools import cmp_to_key @@ -63,13 +64,17 @@ def postproc_iter(data): except Exception as e: # fail proof print(e) return data - + def evaluate(query : str): import re - query = re.sub(r'(\$?[\d\w_]+)\s*:', r'"\1" :', query) - query = re.sub(r'[\r|\n]|.\s*pretty\s*\(\s*\)', '', query).strip() + query = re.sub(r'//[^\n]*', '', query) + query = re.sub(r'(\$?[\d\w_]+)[\s\r\n]*:', r'"\1" :', query) + query = re.sub(r'[\r\n]|.\s*pretty\s*\(\s*\)|.\s*sort\s*\([^\)]*\)', '', query).strip() + query = re.sub(r'.\s*aggregate\s*\(\s*([^\[^\s][^\)]*)\)', r'.aggregate([\1])', query) + if query.endswith(';'): query = query[:-1] + true = True return postproc_iter(list(eval(query))) if query else None for d in datasets: @@ -106,6 +111,8 @@ def grade78(ans, i): a[ak] = t if a not in sol: return False + else: + sol.remove(a) except Exception as e: print(e) return False diff --git a/neo4j/source/autograder.py b/neo4j/source/autograder.py index ecf25a4..23805ba 100644 --- a/neo4j/source/autograder.py +++ b/neo4j/source/autograder.py @@ -1,4 +1,5 @@ import neo4j, json +print('ver: 1.3') # dbprep fsroot = '/autograder/source/' @@ -7,7 +8,7 @@ db = neo4j.GraphDatabase.driver('bolt://localhost:7687', auth = ('neo4j', '4Sfz5 def postproc_str(data : str): # relaxed str matching import re - return re.sub(r'[\s|_]', '', data.lower()) + return re.sub(r'[\s|_|.]', '', data.lower()) def comparator(a, b): cmp = lambda x, y: 1 if x < y else -1 if x > y else 0