deal with re

master
bill 6 months ago
parent 1af680b561
commit 2d5db639fb

@ -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

@ -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

Loading…
Cancel
Save