deal with re

master
bill 12 months ago
parent 1af680b561
commit 2d5db639fb

@ -1,14 +1,15 @@
import pymongo, json import pymongo, json
print('ver: 1.1') print('ver: 1.5')
# dbprep # dbprep
fsroot = '/autograder/source/' fsroot = '/autograder/source/'
datasets = ['congress', 'bills'] datasets = ['congress', 'bills']
db = pymongo.MongoClient('mongodb://127.0.0.1')['test'] db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
def postproc_str(data : str): # relaxed str matching def postproc_str(data : str): # relaxed str matching
import re import re
data = re.sub(r'[\s|_]', '', data.lower()) data = re.sub(r'[\s|_|.]', '', data.lower())
return re.sub(r'sponser', 'sponsor', data) return re.sub(r'sponser', 'sponsor', data)
def comparator(a, b): def comparator(a, b):
@ -67,9 +68,13 @@ def postproc_iter(data):
def evaluate(query : str): def evaluate(query : str):
import re import re
query = re.sub(r'(\$?[\d\w_]+)\s*:', r'"\1" :', query) query = re.sub(r'//[^\n]*', '', query)
query = re.sub(r'[\r|\n]|.\s*pretty\s*\(\s*\)', '', query).strip() 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] if query.endswith(';'): query = query[:-1]
true = True
return postproc_iter(list(eval(query))) if query else None return postproc_iter(list(eval(query))) if query else None
for d in datasets: for d in datasets:
@ -106,6 +111,8 @@ def grade78(ans, i):
a[ak] = t a[ak] = t
if a not in sol: if a not in sol:
return False return False
else:
sol.remove(a)
except Exception as e: except Exception as e:
print(e) print(e)
return False return False

@ -1,4 +1,5 @@
import neo4j, json import neo4j, json
print('ver: 1.3')
# dbprep # dbprep
fsroot = '/autograder/source/' 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 def postproc_str(data : str): # relaxed str matching
import re import re
return re.sub(r'[\s|_]', '', data.lower()) return re.sub(r'[\s|_|.]', '', data.lower())
def comparator(a, b): def comparator(a, b):
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0 cmp = lambda x, y: 1 if x < y else -1 if x > y else 0

Loading…
Cancel
Save