master
結愛すみか 7 months ago
parent 2d5db639fb
commit b343bb2468

1
.gitignore vendored

@ -1 +1,2 @@
playground.* playground.*
__pycache__

@ -1,26 +1,23 @@
# You can change these variables to use a different base image, but
# you must ensure that your base image inherits from one of ours.
# You can also override these at build time with --build-arg flags
ARG BASE_REPO=gradescope/autograder-base ARG BASE_REPO=gradescope/autograder-base
ARG TAG=latest ARG TAG=latest
FROM ${BASE_REPO}:${TAG} FROM ${BASE_REPO}:${TAG}
ADD source /autograder/source RUN python3 -m pip install pymongo
RUN cp /autograder/source/run_autograder /autograder/run_autograder RUN curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
RUN export OS_VER=`cat /etc/os-release | grep VERSION_CODENAME` && \
export OS_VER=${OS_VER#*=} && \
printf "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu "${OS_VER}"/mongodb-org/7.0 multiverse\n">/etc/apt/sources.list.d/mongodb.list
# Ensure that scripts are Unix-friendly and executable RUN apt-get update
RUN dos2unix /autograder/run_autograder /autograder/source/setup.sh RUN mkdir -p /data/db
RUN chmod +x /autograder/run_autograder RUN apt install -y mongodb-org
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Do whatever setup was needed in setup.sh, including installing apt packages ADD source /autograder/source
# Cleans up the apt cache afterwards in the same step to keep the image small
RUN apt-get update && \
bash /autograder/source/setup.sh && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# You can also use RUN commands in the Dockerfile to install things RUN cp /autograder/source/run_autograder /autograder/run_autograder
# instead of using a bash script
# The base image defines the CMD and ENTRYPOINT, so don't redefine those RUN dos2unix /autograder/run_autograder
RUN chmod +x /autograder/run_autograder

@ -1,159 +1,184 @@
import pymongo, json import pymongo, json, re
from bson import json_util
print('ver: 1.5') print('ver: 1.5')
# dbprep # dbprep
fsroot = '/autograder/source/' fsroot = '/autograder/source/'
datasets = ['congress', 'bills'] datasets = ['movies', 'comments']
db = pymongo.MongoClient('mongodb://127.0.0.1')['test'] db = pymongo.MongoClient('mongodb://127.0.0.1')['test']
points = (4,4,5,5,8,8,8,8)
def postproc_str(data : str): # relaxed str matching def postproc_str(data : str): # relaxed str matching
import re return re.sub(r'[\s|_|.]', '', data.lower())
data = re.sub(r'[\s|_|.]', '', data.lower())
return re.sub(r'sponser', 'sponsor', data) def postproc_keys(data : str):
if type(data) is not str:
def comparator(a, b): return postproc_iter(data)
cmp = lambda x, y: 1 if x < y else -1 if x > y else 0 _dict = {}
try: data = postproc_str(data)
return cmp(a, b) for k, v in _dict.items():
except Exception: data = re.sub(k, v, data)
from collections.abc import Iterable return data
def itcmp(a: Iterable, b: Iterable):
if len(a) < len(b): def comparator(a, b):
return -1 cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
elif len(a) == len(b): try:
for aa, bb in zip(a, b): return cmp(a, b)
c = comparator(aa, bb) except Exception:
if c != 0: from collections.abc import Iterable
return c def itcmp(a: Iterable, b: Iterable):
else: return 1 if len(a) < len(b):
return 0 return -1
from bson import ObjectId elif len(a) == len(b):
for aa, bb in zip(a, b):
match (a, b): c = comparator(aa, bb)
case (dict(), dict()): if c != 0:
return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()]) return c
case (ObjectId(aa), ObjectId(bb)): else: return 1
return cmp(aa, bb) return 0
case (Iterable(), Iterable()): from bson import ObjectId
return itcmp(a, b)
case _ if type(a) == type(b): match (a, b):
return cmp(f'{a}', f'{b}') case (dict(), dict()):
case _: return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()])
return cmp(hash(type(a)), hash(type(b))) case (ObjectId(aa), ObjectId(bb)):
return cmp(aa, bb)
def postproc_iter(data): case (Iterable(), Iterable()):
from collections.abc import Iterable return itcmp(a, b)
from functools import cmp_to_key case _ if type(a) == type(b):
try: return cmp(f'{a}', f'{b}')
match data: case _:
case str(): return cmp(hash(type(a)), hash(type(b)))
return postproc_str(data)
case dict(): def postproc_iter(data, naive = False):
return { postproc_iter(k):postproc_iter(v) for k, v in data.items() } from collections.abc import Iterable
case Iterable(): # flatten, remove order and empty iterables from functools import cmp_to_key
res = type(data)( try:
sorted( match data:
[postproc_iter(d) for d in data case str():
if not isinstance(d, Iterable) or d] return postproc_str(data)
, key = cmp_to_key(comparator)) case dict():
) return {
return res[0] if len(res) == 1 else res (i if naive else postproc_keys(k)) : postproc_iter(v, naive)
case _: # primitives for i, (k, v) in enumerate(data.items())
return data }
except Exception as e: # fail proof case Iterable(): # flatten, remove order and empty iterables
print(e) res = type(data)(
return data sorted(
[postproc_iter(d, naive) for d in data
if not isinstance(d, Iterable) or d]
def evaluate(query : str): , key = cmp_to_key(comparator))
import re )
query = re.sub(r'//[^\n]*', '', query) return res[0] if len(res) == 1 else res
query = re.sub(r'(\$?[\d\w_]+)[\s\r\n]*:', r'"\1" :', query) case _: # primitives
query = re.sub(r'[\r\n]|.\s*pretty\s*\(\s*\)|.\s*sort\s*\([^\)]*\)', '', query).strip() return data
query = re.sub(r'.\s*aggregate\s*\(\s*([^\[^\s][^\)]*)\)', r'.aggregate([\1])', query) except Exception as e: # fail proof
print(e)
if query.endswith(';'): query = query[:-1] return data
true = True
return postproc_iter(list(eval(query))) if query else None
for d in datasets: def evaluate(query : str):
with open(fsroot + d + '.json', encoding = 'utf-8') as f: if type(query) is not str:
db[d].insert_many(json.load(f)) return tuple(evaluate(q) for q in query)
query = re.sub(r'//[^\n]*', '', query)
from solution import sols query = re.sub(r'(\$?[\d\w_]+)[\s\r\n]*:', r'"\1" :', query)
answers = [evaluate(s) for s in sols] query = re.sub(r'[\r\n]|.\s*pretty\s*\(\s*\)|.\s*sort\s*\([^\)]*\)', '', query).strip()
if not query: return [None] * 2
# grading query = re.sub(r'.\s*aggregate\s*\(\s*([^\[^\s][^\)]*)\)', r'.aggregate([\1])', query)
from os import listdir
from importlib.util import module_from_spec, spec_from_file_location if query.endswith(';'): query = query[:-1]
subroot = '/autograder/submission/' true = True
feedback = '' data = list(eval(query))
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')] return [postproc_iter(data, n) if query else None for n in (True, False)]
grade = 0 for d in datasets:
n_queries = len(sols) with open(fsroot + d + '.json', encoding = 'utf-8') as f:
# ds = re.sub(r'{\s*"\$oid"\s*:\s*("\w*")\s*}', r'ObjectId(\1)', f.read())
def grade78(ans, i): jsonds = '[' + f.read().strip().replace('\n', ',') + ']'
sol = answers[i] db[d].insert_many(json.loads(jsonds, object_hook=json_util.object_hook))
others = ('otherbill', 'otherperson')[i - 6]
if type(ans) != list or len(ans) != len(sol): from solution import sols
return False answers = [evaluate(s) for s in sols]
for a in ans:
if a not in sol: # grading
if type(a) is dict: from os import listdir
try: from importlib.util import module_from_spec, spec_from_file_location
for ak in a.keys(): subroot = '/autograder/submission/'
if ak.startswith(others): feedback = ''
key_others = ak[len(others):] submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
t = a[key_others]
a[key_others] = a[ak] grade = 0
a[ak] = t n_queries = len(sols)
if a not in sol:
return False def grade78(ans, i):
else: sol = answers[i]
sol.remove(a) others = ('otherbill', 'otherperson')[i - 6]
except Exception as e: if type(ans) != list or len(ans) != len(sol):
print(e) return False
return False for a in ans:
else: if a not in sol:
return False if type(a) is dict:
return True try:
for ak in a.keys():
if submissions: if ak.startswith(others):
submission = submissions[0] key_others = ak[len(others):]
t = a[key_others]
for i in range(n_queries): a[key_others] = a[ak]
feedback += f'Query {i + 1}: ' a[ak] = t
try: if a not in sol:
spec = spec_from_file_location('curr', submission) return False
module = module_from_spec(spec) else:
spec.loader.exec_module(module) sol.remove(a)
q = getattr(module, f'query{i + 1}')() except Exception as e:
ans = evaluate(q) print(e)
def eq(i): return False
if i in (6, 7): else:
return grade78(ans, i) return False
else: return True
return ans == answers[i]
if eq(i): wa = rte = False
grade += 1 if submissions:
feedback += 'Correct.\n' submission = submissions[0]
else:
feedback += 'Wrong Answer.\n' for i in range(n_queries):
print('ans: ', ans, '\nsol: ', answers[i]) feedback += f'Query {i + 1}: '
except Exception as e: try:
feedback += 'Runtime Error.\n' spec = spec_from_file_location('curr', submission)
print (e) module = module_from_spec(spec)
else: spec.loader.exec_module(module)
feedback += 'No python file in submission.\n' q = getattr(module, f'query{i + 1}')()
ans = evaluate(q)
# output def eq(i):
results = { _cmp = lambda a, b: any(aa == bb for aa, bb in zip(a, b))
'output': feedback, if type(answers[i]) is tuple:
'score': grade * 100 / n_queries, return any(_cmp(ans, aa) for aa in answers[i])
'max_score': 100, else:
} return _cmp(ans, answers[i])
if eq(i):
with open('/autograder/results/results.json', 'w') as res: grade += points[i]
json.dump(results, res) feedback += 'Correct.\n'
else:
feedback += 'Wrong Answer.\n'
wa = True
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
rte = True
feedback += 'Runtime Error.\n'
print (e)
else:
feedback += 'No python file in submission.\n'
max_score = sum(points)
if rte:
feedback += ('\nPlease check for syntax errors first if you encountered runtime errors.\n' +
'If you believe it\'s a mistake, contact the TA at sun1226@purdue.edu for assistance.')
# output
results = {
'output': feedback,
'score': grade,
'max_score': max_score,
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -8,13 +8,3 @@ cd -
python3 /autograder/source/autograder.py python3 /autograder/source/autograder.py
# files_submitted=$(ls /autograder/submission)
# num_files_submitted=$(ls /autograder/submission/ | wc -l)
# cat > /autograder/results/results.json <<EOF
# {
# "output": "Good job, you passed! Submitted ${num_files_submitted} files: ${files_submitted}",
# "score": 10,
# "max_score": 10
# }
# EOF

@ -1,10 +0,0 @@
apt install -y curl python3 python3-pip
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
export OS_VER=`cat /etc/os-release | grep VERSION_CODENAME` &&\
export OS_VER=${OS_VER#*=} &&\
printf "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu "${OS_VER}"/mongodb-org/7.0 multiverse\n">/etc/apt/sources.list.d/mongodb.list
apt update
apt install -y mongodb-org
mkdir -p /data/db
cd /data
python3 -m pip install pymongo

@ -1,47 +1,77 @@
sols = ['db.bills.find({sponsor_name:"Marco Rubio"}, {_id:0, title: 1, sponsor_name:1, sponsor_state:1})', sols = ['db.movies.find({year: 1928}, {_id: 0, title: 1, plot: 1})',
'db.bills.find({cosponsors:{$gte:3, $lte:5}}, {_id:0, title:1, sponsor_name:1, cosponsors:1})', """db.movies.find({'awards.wins' :{$gt: 200}}, {_id: 0, title: 1, 'awards_wins': '$awards.wins'})""",
'db.bills.find({$or:[{cosponsors:{$gte:3, $lte:5}}, {sponsor_name:"Marco Rubio"}]}, {_id:0, title:1, sponsor_name:1, cosponsors:1})', """db.movies.find({'imdb.votes' :{$gt: 100}, 'imdb.rating':{$gt: 9.0}}, {_id: 0, title: 1, 'imdb.votes': 1, 'imdb.rating':1})""",
'''db.congress.aggregate([ """
{ $match: {"state": "IN"} }, db.movies.aggregate([{$unwind: '$directors'},
{ $group: {_id: "$role_type", count_of_this_role: {$sum:1} } }, {$match: {year: {$gte: 1915, $lte: 1920}}},
{ $sort: {count_of_this_role: -1} }, {$group: {_id: '$directors', count_of_movies: {$sum: 1}}},
{ $project: {_id: 1, count_of_this_role: 1} } { $sort: {count_of_movies: -1} }
])''', ])
'''db.bills.aggregate([ """,
{ $lookup: { """
from: "congress", db.comments.aggregate([
localField: "sponsor_id", { $lookup: {
foreignField: "person.bioguideid", from: "movies",
as:"congressMember"} }, localField: "movie_id",
{ $unwind: "$congressMember" }, foreignField: "_id",
{ $project: {_id: 0, title:1, sponsor_name: 1, "description": "$congressMember.description", "DOB": "$congressMember.person.birthday"} } as:"MovieDetails"}},
])''', { $unwind: "$MovieDetails" },
'''db.bills.aggregate([ {$project: {name:1, "Movie_imdb_rating": "$MovieDetails.imdb.rating"}},
{ $unwind: "$committee_codes" }, {$group: {_id: '$name', count_of_comments: {$sum:1}, average_movie_ratings: {$avg: "$Movie_imdb_rating"}}},
{ $project: {committee_codes: 1} }, {$match: {count_of_comments: {$gt: 250}}}
{ $group: {_id: "$committee_codes", countOfCommittee: {$sum:1} } }, ])
{ $sort: {countOfCommittee: -1} }, """,
])''', ("""
'''db.bills.aggregate([ db.movies.aggregate([
{ $project: {_id: 1, title:1, sponsor_name: 1, sponsor_state:1}}, {$unwind: "$cast"},
{ $lookup: { {$match: {year:1996}},
from: "bills", {$project: {cast: 1}},
localField: "sponsor_state", {$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
foreignField: "sponsor_state", {$match: {CountOfMovies:{$gt: 3}}},
as:"otherBills"} }, { $sort: {CountOfMovies: -1} }
{ $unwind: "$otherBills" }, ])
{ $project: {title: 1, sponsor_name: 1, sponsor_state: 1, otherbill_id: "$otherBills._id", otherbill_title: "$otherBills.title", otherbill_sponsor_name: "$otherBills.sponsor_name", otherbill_sponsor_state: "$otherBills.sponsor_state"}}, """,
{ $match: {$expr: {$lt: ["$_id", "$otherbill_id"]}}} """
])''', db.movies.aggregate([
'''db.congress.aggregate([ {$unwind: "$cast"},
{ $project: {_id: 1, firstname: "$person.firstname", lastname: "$person.lastname", state: 1}}, {$match: {year:1996}},
{ $lookup: { {$project: {cast: 1}},
from: "congress", {$group: {_id: "$cast", CountOfMovies: {$sum:1}}},
localField: "lastname", {$match: {CountOfMovies:{$gte: 3}}},
foreignField: "person.lastname", { $sort: {CountOfMovies: -1} }
as:"otherPersons"} }, ])
{ $unwind: "$otherPersons" }, """),
{ $match: {$expr: {$lt: ["$_id", "$otherPersons._id"]}}}, ("""
{ $project: {_id:1, firstname: 1, lastname: 1, state:1, otherPerson_id: "$otherPersons._id", otherPerson_firstname: "$otherPersons.person.firstname", otherPerson_lastname: "$otherPersons.person.lastname", otherPerson_state: "$otherPersons.state"}}, db.comments.aggregate([
{ $match: {$expr: {$eq: ["$state", "$otherPerson_state"]}}}, { $lookup: {
])'''] from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gt: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
""",
"""
db.comments.aggregate([
{ $lookup: {
from: "movies",
localField: "movie_id",
foreignField: "_id",
as:"MovieDetails"}},
{$unwind: '$MovieDetails'},{$unwind: '$MovieDetails.genres'},
{$group: {_id: {name: '$name', Genres: '$MovieDetails.genres'}, comment_count: {$sum: 1}}},
{$match:{"_id.Genres": "Crime", comment_count:{$gte: 35}}},
{$project: {_id:0, name : "$_id.name", comment_count: 1}}
])
"""),
"""
db.movies.aggregate([
{$unwind: '$cast'},
{$unwind: '$directors'},
{$match: {$expr: {$eq: ["$cast", "$directors"]}}},
{$project: {title:1, directors: 1}}
])
"""]

@ -1,26 +1,22 @@
# You can change these variables to use a different base image, but
# you must ensure that your base image inherits from one of ours.
# You can also override these at build time with --build-arg flags
ARG BASE_REPO=gradescope/autograder-base ARG BASE_REPO=gradescope/autograder-base
ARG TAG=latest ARG TAG=latest
FROM ${BASE_REPO}:${TAG} FROM ${BASE_REPO}:${TAG}
ADD source /autograder/source
RUN cp /autograder/source/run_autograder /autograder/run_autograder
# Ensure that scripts are Unix-friendly and executable RUN curl -fsSL https://debian.neo4j.com/neotechnology.gpg.key | gpg --dearmor -o /usr/share/keyrings/neo4j.gpg
RUN dos2unix /autograder/run_autograder /autograder/source/setup.sh RUN echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" > /etc/apt/sources.list.d/neo4j.list
RUN chmod +x /autograder/run_autograder
# Do whatever setup was needed in setup.sh, including installing apt packages RUN python3 -m pip install neo4j
# Cleans up the apt cache afterwards in the same step to keep the image small RUN apt-get update
RUN apt-get update && \ RUN apt install -y neo4j
bash /autograder/source/setup.sh && \ RUN sed -i '1s/^/server.default_listen_address=0.0.0.0\n/' /etc/neo4j/neo4j.conf
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# You can also use RUN commands in the Dockerfile to install things RUN service neo4j start
# instead of using a bash script RUN neo4j-admin dbms set-initial-password 4Sfz541Lm --require-password-change=false
ADD source /autograder/source
# The base image defines the CMD and ENTRYPOINT, so don't redefine those RUN cp /autograder/source/run_autograder /autograder/run_autograder
RUN dos2unix /autograder/run_autograder
RUN chmod +x /autograder/run_autograder

@ -1 +1 @@
docker build -t sunyinqi0508/neo4j_autograder . && docker push sunyinqi0508/neo4j_autograder docker build -t sunyinqi0508/neo4j_autograder . && docker push sunyinqi0508/neo4j_autograder

@ -1,47 +0,0 @@
CREATE
(gorman:Author {name:"Gorman, Michael"}),
(toner:Author {name:"Toner, Patrick"}),
(koslicki:Author {name:"Koslicki, Kathrin"}),
(fine:Author {name:"Fine, Kit"}),
(roger:Author {name:"Roger, Cat"}),
(beth:Author {name:"Beth, Dog"}),
(art1:Article {doi:"10.5840/ipq20064626", title:"Independence and Substance"}),
(art2:Article {doi:"10.1007/s11098-010-9521-4", title:"Independence Accounts of Substance and Substantial Parts"}),
(art3:Article {doi:"10.1007/s11098-011-9708-3", title:"On Substantial Independence: a Reply to Patrick Toner"}),
(art4:Article {doi:"10.1080/05568640609485174", title:"Substance and Identity-Dependence"}),
(art5:Article {doi:"10.2307/4545221", title:"Ontological Dependence"}),
(art6:Article {doi:"10.2307/4519752", title:"Yet Another Title"}),
(art7:Article {doi:"10.2308/4547590", title:"Seventh Title"}),
(chp1:Chapter {no:9, title:"Substance, Independence, and Unity"}),
(chp2:Chapter {no:10, title:"Chapter on Making Chapters"}),
(ipq:Journal {title:"International Philosophical Quarterly", ISSN:"0019-0365", onlineISSN:"2153-8077"}),
(ps:Journal {title:"Philosophical Studies", ISSN:"0031-8116", onlineISSN:"1573-0883"}),
(pp:Journal {title:"Philosophical Papers", ISSN:"0556-8641", onlineISSN:"1996-8523"}),
(pas:Journal {title:"Proceedings of the Aristotelian Society", ISSN:"0066-7374", onlineISSN:"1467-9264"}),
(hitm:Journal {title:"History in the making", ISSN:"0084-7649", onlineISSN:"1235-7549"}),
(ssj:Journal {title:"Something Something Journal", ISSN:"0420-6729", onlineISSN:"5964-3248"}),
(gorman)-[:WRITES]->(art1)-[:IN {pp:[147,159]} ]->(:Issue {volume:46, issue:2, year:2006, month:6})-[:OF]->(ipq),
(toner)-[:WRITES]->(art2)-[:IN {pp:[37,43]} ]->(:Issue {volume:155, issue:1, year:2011, month:8})-[:OF]->(ps),
(gorman)-[:WRITES]->(art3)-[:IN {pp:[239,297]} ]->(:Issue {volume:159, issue:2, year:2012, month:6})-[:OF]->(ps),
(gorman)-[:WRITES]->(art4)-[:IN {pp:[103,118]} ]->(:Issue {volume:35, issue:1, year:2006, month:3})-[:OF]->(pp),
(fine)-[:WRITES]->(art5)-[:IN {pp:[269,290]} ]->(:Issue {volume:95, year:1995})-[:OF]->(pas),
(roger)-[:WRITES]->(art6)-[:IN {pp:[206,300]} ]->(:Issue {volume:24, year:1996})-[:OF]->(hitm),
(beth)-[:WRITES]->(art7)-[:IN {pp:[0,5]} ]->(:Issue {volume:32, year:1903})-[:OF]->(ssj),
(koslicki)-[:WRITES]->(chp1)-[:IN {pp:[169,195]} ]->(book:Book {title:"Aristotle on Method and Metaphysics", `ISBN-10`:"0230360912", `ISBN-13`:"978-0230360914", year:2013, month:7})<-[:EDITS]-(feser:Author {name:"Feser, Edward"}),
(beth)-[:WRITES]->(chp2)-[:IN {pp:[104,109]} ]->(book2:Book {title:"Book Name is Two", `ISBN-10`:"023546382", `ISBN-13`:"978-0230346584", year:2003, month:9})<-[:EDITS]-(tim:Author {name:"Tim, Bob"}),
(book)<-[:PUBLISHED_BY]-(pub:Publisher {location:"London", name:"Palgrave Macmillan"}),
(book2)<-[:PUBLISHED_BY]-(pub2:Publisher {location:"Madagascar", name:"Alex Lion"}),
(art1)-[:CITES]->(art5),
(art2)-[:CITES]->(art1),
(art2)-[:CITES]->(art4),
(art3)-[:CITES]->(art2),
(art3)-[:CITES]->(art4),
(art5)-[:CITES]->(art6),
(art7)-[:CITES]->(art3),
(art6)-[:CITES]->(art1),
(chp1)-[:CITES]->(art1),
(chp1)-[:CITES]->(art2),
(chp2)-[:CITES]->(art3),
(chp1)-[:CITES]->(art6),
(chp2)-[:CITES]->(art7),
(chp1)-[:CITES]->(art3)

@ -1,126 +1,151 @@
import neo4j, json import neo4j, json, re
print('ver: 1.3') print('ver: 1.33')
# dbprep # dbprep
fsroot = '/autograder/source/' fsroot = '/autograder/source/'
datasets = ['Neo4J_dataset'] datasets = ['databaseCreateQueries']
db = neo4j.GraphDatabase.driver('bolt://localhost:7687', auth = ('neo4j', '4Sfz541Lm')).session() db = neo4j.GraphDatabase.driver('bolt://localhost:7687', auth = ('neo4j', '4Sfz541Lm')).session()
def postproc_str(data : str): # relaxed str matching points = (5,)*10
import re
return re.sub(r'[\s|_|.]', '', data.lower()) def postproc_str(data : str): # relaxed str matching
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 def postproc_keys(data : str):
try: if type(data) is not str:
return cmp(a, b) return postproc_iter(data)
except Exception: _dict = {r'count\(\*\)': 'cnt',
from collections.abc import Iterable r'efamily': 'family',
def itcmp(a: Iterable, b: Iterable): r'sname': 'aname',
if len(a) < len(b): r'size\(continents\)': 'numberofcontinent'}
return -1 data = postproc_str(data)
elif len(a) == len(b): for k, v in _dict.items():
for aa, bb in zip(a, b): data = re.sub(k, v, data)
c = comparator(aa, bb) return data
if c != 0:
return c def comparator(a, b):
else: return 1 cmp = lambda x, y: 1 if x < y else -1 if x > y else 0
return 0 try:
return cmp(a, b)
match (a, b): except Exception:
case (dict(), dict()): from collections.abc import Iterable
return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()]) def itcmp(a: Iterable, b: Iterable):
case (Iterable(), Iterable()): if len(a) < len(b):
return itcmp(a, b) return -1
case _ if type(a) == type(b): elif len(a) == len(b):
return cmp(f'{a}', f'{b}') for aa, bb in zip(a, b):
case _: c = comparator(aa, bb)
return cmp(hash(type(a)), hash(type(b))) if c != 0:
return c
def postproc_iter(data): else: return 1
from collections.abc import Iterable return 0
from functools import cmp_to_key match (a, b):
try: case (dict(), dict()):
match data: return itcmp([*a.keys(), *a.values()], [*b.keys(), *b.values()])
case str(): case (Iterable(), Iterable()):
return postproc_str(data) return itcmp(a, b)
case dict(): case _ if type(a) == type(b):
return { postproc_iter(k):postproc_iter(v) for k, v in data.items() } return cmp(f'{a}', f'{b}')
case Iterable(): # flatten, remove order and empty iterables case _:
res = type(data)( return cmp(hash(type(a)), hash(type(b)))
sorted(
[postproc_iter(d) for d in data def postproc_iter(data, naive = False):
if not isinstance(d, Iterable) or d] from collections.abc import Iterable
, key = cmp_to_key(comparator)) from functools import cmp_to_key
) try:
return res[0] if len(res) == 1 else res match data:
case _: # primitives case str():
return data return postproc_str(data)
except Exception as e: # fail proof case dict():
print(e) return {
return data (i if naive else postproc_keys(k)) : postproc_iter(v, naive)
for i, (k, v) in enumerate(data.items())
def evaluate(query : str): }
query = query.strip() case Iterable(): # flatten, remove order and empty iterables
return postproc_iter(db.run(query).data()) if query else None res = type(data)(
sorted(
while True: [postproc_iter(d, naive) for d in data
try: if not isinstance(d, Iterable) or d]
db.run('RETURN 0') , key = cmp_to_key(comparator))
break )
except: return res[0] if len(res) == 1 else res
continue case _: # primitives
return data
for d in datasets: except Exception as e: # fail proof
with open(fsroot + d + '.txt', encoding = 'utf-8') as f: print(e)
db.run(f.read()) return data
from solution import sols
answers = [evaluate(s) if type(s) is str else tuple(evaluate(k) for k in s) for s in sols ] def evaluate(query : str):
query = query.strip()
# grading return [postproc_iter(db.run(query).data(), n)
from os import listdir if query else None for n in (False, True)]
from importlib.util import module_from_spec, spec_from_file_location
subroot = '/autograder/submission/' while True:
feedback = '' try:
submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')] db.run('RETURN 0')
break
grade = 0 except:
n_queries = len(sols) continue
if submissions: for d in datasets:
submission = submissions[0] with open(fsroot + d + '.txt', encoding = 'utf-8') as f:
db.run(f.read())
for i in range(n_queries):
feedback += f'Query {i + 1}: ' from solution import sols
try: answers = [evaluate(s) if type(s) is str else tuple(evaluate(k) for k in s) for s in sols ]
spec = spec_from_file_location('curr', submission)
module = module_from_spec(spec) # grading
spec.loader.exec_module(module) from os import listdir
q = getattr(module, f'query{i + 1}')() from importlib.util import module_from_spec, spec_from_file_location
def eq(a: list, b): subroot = '/autograder/submission/'
if type(b) is tuple: feedback = ''
return any(eq(a, bb) for bb in b) submissions = [subroot + f for f in listdir(subroot) if f.strip().lower().endswith('.py')]
else: return a == b
ans = evaluate(q) grade = 0
if eq(ans, answers[i]): n_queries = len(sols)
grade += 1 wa = rte = False
feedback += 'Correct.\n'
else: if submissions:
feedback += 'Wrong Answer.\n' submission = submissions[0]
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e: for i in range(n_queries):
feedback += 'Runtime Error.\n' feedback += f'Query {i + 1}: '
print(e) try:
else: spec = spec_from_file_location('curr', submission)
feedback += 'No python file in submission.\n' module = module_from_spec(spec)
spec.loader.exec_module(module)
# output q = getattr(module, f'query{i + 1}')()
results = { def eq(a: list, b):
'output': feedback, if type(b) is tuple:
'score': round(grade * 100 / n_queries, 1), return any(eq(a, bb) for bb in b)
'max_score': 100, else:
} return any(aa == bb for aa, bb in zip(a, b))
ans = evaluate(q)
with open('/autograder/results/results.json', 'w') as res: if eq(ans, answers[i]):
json.dump(results, res) grade += points[i]
feedback += 'Correct.\n'
else:
wa = True
feedback += 'Wrong Answer.\n'
print('ans: ', ans, '\nsol: ', answers[i])
except Exception as e:
rte = True
feedback += 'Runtime Error.\n'
print(e)
else:
feedback += 'No python file in submission.\n'
if rte:
feedback += ('\nPlease check for syntax errors if you encountered runtime errors.\n' +
'If you believe it\'s a mistake, contact the TA at sun1226@purdue.edu for assistance.')
# output
results = {
'output': feedback,
'score': grade,
'max_score': sum(points),
}
with open('/autograder/results/results.json', 'w') as res:
json.dump(results, res)

@ -0,0 +1,488 @@
CREATE (continent1:Continent{name:'North America'})
CREATE (continent2:Continent{name:'South America'})
CREATE (continent3:Continent{name:'Asia'})
CREATE (continent4:Continent{name:'Europe'})
CREATE (continent5:Continent{name:'Australia'})
CREATE (region1:Region{name:'N. Virginia', launched:2006})
CREATE (region2:Region{name:'Oregon', launched:2011})
CREATE (region3:Region{name:'N. California', launched:2009})
CREATE (region4:Region{name:'Ireland', launched:2007})
CREATE (region5:Region{name:'Singapore', launched:2010})
CREATE (region6:Region{name:'Tokyo', launched:2011})
CREATE (region7:Region{name:'Sydney', launched:2012})
CREATE (region8:Region{name:'Sao Paulo', launched:2011})
CREATE (region9:Region{name:'GovCloud', launched:2011})
CREATE (region10:Region{name:'Beijing', launched:2014})
CREATE (availabilityzone1:AvailabilityZone{name:'eu-west-1a'})
CREATE (availabilityzone2:AvailabilityZone{name:'eu-west-1b'})
CREATE (availabilityzone3:AvailabilityZone{name:'eu-west-1c'})
CREATE (availabilityzone4:AvailabilityZone{name:'us-east-1a'})
CREATE (availabilityzone5:AvailabilityZone{name:'us-east-1b'})
CREATE (availabilityzone6:AvailabilityZone{name:'us-east-1c'})
CREATE (availabilityzone7:AvailabilityZone{name:'us-east-1d'})
CREATE (availabilityzone8:AvailabilityZone{name:'us-west-2a'})
CREATE (availabilityzone9:AvailabilityZone{name:'us-west-2b'})
CREATE (availabilityzone10:AvailabilityZone{name:'us-west-2c'})
CREATE (availabilityzone11:AvailabilityZone{name:'us-west-1a'})
CREATE (availabilityzone12:AvailabilityZone{name:'us-west-1c'})
CREATE (availabilityzone13:AvailabilityZone{name:'ap-southeast-1a'})
CREATE (availabilityzone14:AvailabilityZone{name:'ap-southeast-1b'})
CREATE (availabilityzone15:AvailabilityZone{name:'ap-northeast-1a'})
CREATE (availabilityzone16:AvailabilityZone{name:'ap-northeast-1b'})
CREATE (availabilityzone17:AvailabilityZone{name:'ap-northeast-1c'})
CREATE (availabilityzone18:AvailabilityZone{name:'ap-southeast-2a'})
CREATE (availabilityzone19:AvailabilityZone{name:'ap-southeast-2b'})
CREATE (availabilityzone20:AvailabilityZone{name:'sa-east-1a'})
CREATE (availabilityzone21:AvailabilityZone{name:'sa-east-1b'})
CREATE (region1)-[:IS_LOCATED_IN]->(continent1)
CREATE (region2)-[:IS_LOCATED_IN]->(continent1)
CREATE (region3)-[:IS_LOCATED_IN]->(continent1)
CREATE (region4)-[:IS_LOCATED_IN]->(continent4)
CREATE (region5)-[:IS_LOCATED_IN]->(continent3)
CREATE (region6)-[:IS_LOCATED_IN]->(continent3)
CREATE (region7)-[:IS_LOCATED_IN]->(continent5)
CREATE (region8)-[:IS_LOCATED_IN]->(continent2)
CREATE (region9)-[:IS_LOCATED_IN]->(continent1)
CREATE (region10)-[:IS_LOCATED_IN]->(continent3)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone1)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone2)
CREATE (region4)-[:HAS_ISOLATED]->(availabilityzone3)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone4)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone5)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone6)
CREATE (region1)-[:HAS_ISOLATED]->(availabilityzone7)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone8)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone9)
CREATE (region2)-[:HAS_ISOLATED]->(availabilityzone10)
CREATE (region3)-[:HAS_ISOLATED]->(availabilityzone11)
CREATE (region3)-[:HAS_ISOLATED]->(availabilityzone12)
CREATE (region5)-[:HAS_ISOLATED]->(availabilityzone13)
CREATE (region5)-[:HAS_ISOLATED]->(availabilityzone14)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone15)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone16)
CREATE (region6)-[:HAS_ISOLATED]->(availabilityzone17)
CREATE (region7)-[:HAS_ISOLATED]->(availabilityzone18)
CREATE (region7)-[:HAS_ISOLATED]->(availabilityzone19)
CREATE (region8)-[:HAS_ISOLATED]->(availabilityzone20)
CREATE (region8)-[:HAS_ISOLATED]->(availabilityzone21)
CREATE (service1:Service{name:'Amazon Elastic Compute Cloud'})
CREATE (service2:Service{name:'Amazon CloudWatch'})
CREATE (service3:Service{name:'Amazon Virtual Private Cloud'})
CREATE (service4:Service{name:'Amazon Simple Storage Service'})
CREATE (service5:Service{name:'Amazon Elastic Block Store'})
CREATE (service6:Service{name:'Auto Scaling'})
CREATE (service7:Service{name:'Amazon Simple Queue Service'})
CREATE (service8:Service{name:'Amazon Simple Notification Service'})
CREATE (service9:Service{name:'Elastic Load Balancing'})
CREATE (service10:Service{name:'AWS Support'})
CREATE (service11:Service{name:'Amazon DynamoDB'})
CREATE (service12:Service{name:'Amazon Relational Database Service'})
CREATE (service13:Service{name:'Amazon Simple Workflow Service'})
CREATE (service14:Service{name:'Amazon Elastic MapReduce'})
CREATE (service15:Service{name:'AWS Direct Connect'})
CREATE (service16:Service{name:'AWS CloudFormation'})
CREATE (service17:Service{name:'VM Import/Export'})
CREATE (service18:Service{name:'AWS Elastic Beanstalk'})
CREATE (service19:Service{name:'AWS Storage Gateway'})
CREATE (service20:Service{name:'Amazon SimpleDB'})
CREATE (service21:Service{name:'Amazon ElastiCache'})
CREATE (service22:Service{name:'Amazon Elastic Transcoder'})
CREATE (service23:Service{name:'Amazon Redshift'})
CREATE (service24:Service{name:'Amazon CloudSearch'})
CREATE (service25:Service{name:'AWS Import/Export'})
CREATE (service26:Service{name:'Amazon Glacier'})
CREATE (service27:Service{name:'High Performance Computing'})
CREATE (service28:Service{name:'AWS CloudHSM'})
CREATE (service29:Service{name:'AWS CloudTrail'})
CREATE (service30:Service{name:'Amazon Simple Email Service'})
CREATE (service31:Service{name:'AWS Data Pipeline'})
CREATE (service32:Service{name:'Amazon Kinesis'})
CREATE (region1)-[:OFFERS_SERVICE]->(service1)
CREATE (region1)-[:OFFERS_SERVICE]->(service2)
CREATE (region1)-[:OFFERS_SERVICE]->(service3)
CREATE (region1)-[:OFFERS_SERVICE]->(service4)
CREATE (region1)-[:OFFERS_SERVICE]->(service5)
CREATE (region1)-[:OFFERS_SERVICE]->(service6)
CREATE (region1)-[:OFFERS_SERVICE]->(service7)
CREATE (region1)-[:OFFERS_SERVICE]->(service8)
CREATE (region1)-[:OFFERS_SERVICE]->(service9)
CREATE (region1)-[:OFFERS_SERVICE]->(service10)
CREATE (region1)-[:OFFERS_SERVICE]->(service11)
CREATE (region1)-[:OFFERS_SERVICE]->(service12)
CREATE (region1)-[:OFFERS_SERVICE]->(service13)
CREATE (region1)-[:OFFERS_SERVICE]->(service14)
CREATE (region1)-[:OFFERS_SERVICE]->(service15)
CREATE (region1)-[:OFFERS_SERVICE]->(service16)
CREATE (region1)-[:OFFERS_SERVICE]->(service17)
CREATE (region1)-[:OFFERS_SERVICE]->(service18)
CREATE (region1)-[:OFFERS_SERVICE]->(service19)
CREATE (region1)-[:OFFERS_SERVICE]->(service20)
CREATE (region1)-[:OFFERS_SERVICE]->(service21)
CREATE (region1)-[:OFFERS_SERVICE]->(service22)
CREATE (region1)-[:OFFERS_SERVICE]->(service23)
CREATE (region1)-[:OFFERS_SERVICE]->(service24)
CREATE (region1)-[:OFFERS_SERVICE]->(service25)
CREATE (region1)-[:OFFERS_SERVICE]->(service26)
CREATE (region1)-[:OFFERS_SERVICE]->(service27)
CREATE (region1)-[:OFFERS_SERVICE]->(service28)
CREATE (region1)-[:OFFERS_SERVICE]->(service29)
CREATE (region1)-[:OFFERS_SERVICE]->(service30)
CREATE (region1)-[:OFFERS_SERVICE]->(service31)
CREATE (region1)-[:OFFERS_SERVICE]->(service32)
CREATE (region2)-[:OFFERS_SERVICE]->(service1)
CREATE (region2)-[:OFFERS_SERVICE]->(service2)
CREATE (region2)-[:OFFERS_SERVICE]->(service3)
CREATE (region2)-[:OFFERS_SERVICE]->(service4)
CREATE (region2)-[:OFFERS_SERVICE]->(service5)
CREATE (region2)-[:OFFERS_SERVICE]->(service6)
CREATE (region2)-[:OFFERS_SERVICE]->(service7)
CREATE (region2)-[:OFFERS_SERVICE]->(service8)
CREATE (region2)-[:OFFERS_SERVICE]->(service9)
CREATE (region2)-[:OFFERS_SERVICE]->(service10)
CREATE (region2)-[:OFFERS_SERVICE]->(service11)
CREATE (region2)-[:OFFERS_SERVICE]->(service12)
CREATE (region2)-[:OFFERS_SERVICE]->(service13)
CREATE (region2)-[:OFFERS_SERVICE]->(service14)
CREATE (region2)-[:OFFERS_SERVICE]->(service15)
CREATE (region2)-[:OFFERS_SERVICE]->(service16)
CREATE (region2)-[:OFFERS_SERVICE]->(service17)
CREATE (region2)-[:OFFERS_SERVICE]->(service18)
CREATE (region2)-[:OFFERS_SERVICE]->(service19)
CREATE (region2)-[:OFFERS_SERVICE]->(service20)
CREATE (region2)-[:OFFERS_SERVICE]->(service21)
CREATE (region2)-[:OFFERS_SERVICE]->(service22)
CREATE (region2)-[:OFFERS_SERVICE]->(service23)
CREATE (region2)-[:OFFERS_SERVICE]->(service24)
CREATE (region2)-[:OFFERS_SERVICE]->(service25)
CREATE (region2)-[:OFFERS_SERVICE]->(service26)
CREATE (region2)-[:OFFERS_SERVICE]->(service27)
CREATE (region2)-[:OFFERS_SERVICE]->(service28)
CREATE (region2)-[:OFFERS_SERVICE]->(service29)
CREATE (region3)-[:OFFERS_SERVICE]->(service1)
CREATE (region3)-[:OFFERS_SERVICE]->(service2)
CREATE (region3)-[:OFFERS_SERVICE]->(service3)
CREATE (region3)-[:OFFERS_SERVICE]->(service4)
CREATE (region3)-[:OFFERS_SERVICE]->(service5)
CREATE (region3)-[:OFFERS_SERVICE]->(service6)
CREATE (region3)-[:OFFERS_SERVICE]->(service7)
CREATE (region3)-[:OFFERS_SERVICE]->(service8)
CREATE (region3)-[:OFFERS_SERVICE]->(service9)
CREATE (region3)-[:OFFERS_SERVICE]->(service10)
CREATE (region3)-[:OFFERS_SERVICE]->(service11)
CREATE (region3)-[:OFFERS_SERVICE]->(service12)
CREATE (region3)-[:OFFERS_SERVICE]->(service13)
CREATE (region3)-[:OFFERS_SERVICE]->(service14)
CREATE (region3)-[:OFFERS_SERVICE]->(service15)
CREATE (region3)-[:OFFERS_SERVICE]->(service16)
CREATE (region3)-[:OFFERS_SERVICE]->(service17)
CREATE (region3)-[:OFFERS_SERVICE]->(service18)
CREATE (region3)-[:OFFERS_SERVICE]->(service19)
CREATE (region3)-[:OFFERS_SERVICE]->(service20)
CREATE (region3)-[:OFFERS_SERVICE]->(service21)
CREATE (region3)-[:OFFERS_SERVICE]->(service22)
CREATE (region3)-[:OFFERS_SERVICE]->(service24)
CREATE (region3)-[:OFFERS_SERVICE]->(service25)
CREATE (region3)-[:OFFERS_SERVICE]->(service26)
CREATE (region4)-[:OFFERS_SERVICE]->(service1)
CREATE (region4)-[:OFFERS_SERVICE]->(service2)
CREATE (region4)-[:OFFERS_SERVICE]->(service3)
CREATE (region4)-[:OFFERS_SERVICE]->(service4)
CREATE (region4)-[:OFFERS_SERVICE]->(service5)
CREATE (region4)-[:OFFERS_SERVICE]->(service6)
CREATE (region4)-[:OFFERS_SERVICE]->(service7)
CREATE (region4)-[:OFFERS_SERVICE]->(service8)
CREATE (region4)-[:OFFERS_SERVICE]->(service9)
CREATE (region4)-[:OFFERS_SERVICE]->(service10)
CREATE (region4)-[:OFFERS_SERVICE]->(service11)
CREATE (region4)-[:OFFERS_SERVICE]->(service12)
CREATE (region4)-[:OFFERS_SERVICE]->(service13)
CREATE (region4)-[:OFFERS_SERVICE]->(service14)
CREATE (region4)-[:OFFERS_SERVICE]->(service15)
CREATE (region4)-[:OFFERS_SERVICE]->(service16)
CREATE (region4)-[:OFFERS_SERVICE]->(service17)
CREATE (region4)-[:OFFERS_SERVICE]->(service18)
CREATE (region4)-[:OFFERS_SERVICE]->(service19)
CREATE (region4)-[:OFFERS_SERVICE]->(service20)
CREATE (region4)-[:OFFERS_SERVICE]->(service21)
CREATE (region4)-[:OFFERS_SERVICE]->(service22)
CREATE (region4)-[:OFFERS_SERVICE]->(service23)
CREATE (region4)-[:OFFERS_SERVICE]->(service24)
CREATE (region4)-[:OFFERS_SERVICE]->(service25)
CREATE (region4)-[:OFFERS_SERVICE]->(service26)
CREATE (region4)-[:OFFERS_SERVICE]->(service27)
CREATE (region4)-[:OFFERS_SERVICE]->(service28)
CREATE (region4)-[:OFFERS_SERVICE]->(service30)
CREATE (region5)-[:OFFERS_SERVICE]->(service1)
CREATE (region5)-[:OFFERS_SERVICE]->(service2)
CREATE (region5)-[:OFFERS_SERVICE]->(service3)
CREATE (region5)-[:OFFERS_SERVICE]->(service4)
CREATE (region5)-[:OFFERS_SERVICE]->(service5)
CREATE (region5)-[:OFFERS_SERVICE]->(service6)
CREATE (region5)-[:OFFERS_SERVICE]->(service7)
CREATE (region5)-[:OFFERS_SERVICE]->(service8)
CREATE (region5)-[:OFFERS_SERVICE]->(service9)
CREATE (region5)-[:OFFERS_SERVICE]->(service10)
CREATE (region5)-[:OFFERS_SERVICE]->(service11)
CREATE (region5)-[:OFFERS_SERVICE]->(service12)
CREATE (region5)-[:OFFERS_SERVICE]->(service13)
CREATE (region5)-[:OFFERS_SERVICE]->(service14)
CREATE (region5)-[:OFFERS_SERVICE]->(service15)
CREATE (region5)-[:OFFERS_SERVICE]->(service16)
CREATE (region5)-[:OFFERS_SERVICE]->(service17)
CREATE (region5)-[:OFFERS_SERVICE]->(service18)
CREATE (region5)-[:OFFERS_SERVICE]->(service19)
CREATE (region5)-[:OFFERS_SERVICE]->(service20)
CREATE (region5)-[:OFFERS_SERVICE]->(service21)
CREATE (region5)-[:OFFERS_SERVICE]->(service22)
CREATE (region5)-[:OFFERS_SERVICE]->(service23)
CREATE (region5)-[:OFFERS_SERVICE]->(service24)
CREATE (region5)-[:OFFERS_SERVICE]->(service25)
CREATE (region6)-[:OFFERS_SERVICE]->(service1)
CREATE (region6)-[:OFFERS_SERVICE]->(service2)
CREATE (region6)-[:OFFERS_SERVICE]->(service3)
CREATE (region6)-[:OFFERS_SERVICE]->(service4)
CREATE (region6)-[:OFFERS_SERVICE]->(service5)
CREATE (region6)-[:OFFERS_SERVICE]->(service6)
CREATE (region6)-[:OFFERS_SERVICE]->(service7)
CREATE (region6)-[:OFFERS_SERVICE]->(service8)
CREATE (region6)-[:OFFERS_SERVICE]->(service9)
CREATE (region6)-[:OFFERS_SERVICE]->(service10)
CREATE (region6)-[:OFFERS_SERVICE]->(service11)
CREATE (region6)-[:OFFERS_SERVICE]->(service12)
CREATE (region6)-[:OFFERS_SERVICE]->(service13)
CREATE (region6)-[:OFFERS_SERVICE]->(service14)
CREATE (region6)-[:OFFERS_SERVICE]->(service15)
CREATE (region6)-[:OFFERS_SERVICE]->(service16)
CREATE (region6)-[:OFFERS_SERVICE]->(service17)
CREATE (region6)-[:OFFERS_SERVICE]->(service18)
CREATE (region6)-[:OFFERS_SERVICE]->(service19)
CREATE (region6)-[:OFFERS_SERVICE]->(service20)
CREATE (region6)-[:OFFERS_SERVICE]->(service21)
CREATE (region6)-[:OFFERS_SERVICE]->(service22)
CREATE (region6)-[:OFFERS_SERVICE]->(service23)
CREATE (region6)-[:OFFERS_SERVICE]->(service26)
CREATE (region6)-[:OFFERS_SERVICE]->(service27)
CREATE (region7)-[:OFFERS_SERVICE]->(service1)
CREATE (region7)-[:OFFERS_SERVICE]->(service2)
CREATE (region7)-[:OFFERS_SERVICE]->(service3)
CREATE (region7)-[:OFFERS_SERVICE]->(service4)
CREATE (region7)-[:OFFERS_SERVICE]->(service5)
CREATE (region7)-[:OFFERS_SERVICE]->(service6)
CREATE (region7)-[:OFFERS_SERVICE]->(service7)
CREATE (region7)-[:OFFERS_SERVICE]->(service8)
CREATE (region7)-[:OFFERS_SERVICE]->(service9)
CREATE (region7)-[:OFFERS_SERVICE]->(service10)
CREATE (region7)-[:OFFERS_SERVICE]->(service11)
CREATE (region7)-[:OFFERS_SERVICE]->(service12)
CREATE (region7)-[:OFFERS_SERVICE]->(service13)
CREATE (region7)-[:OFFERS_SERVICE]->(service14)
CREATE (region7)-[:OFFERS_SERVICE]->(service15)
CREATE (region7)-[:OFFERS_SERVICE]->(service16)
CREATE (region7)-[:OFFERS_SERVICE]->(service17)
CREATE (region7)-[:OFFERS_SERVICE]->(service18)
CREATE (region7)-[:OFFERS_SERVICE]->(service19)
CREATE (region7)-[:OFFERS_SERVICE]->(service20)
CREATE (region7)-[:OFFERS_SERVICE]->(service21)
CREATE (region7)-[:OFFERS_SERVICE]->(service23)
CREATE (region7)-[:OFFERS_SERVICE]->(service26)
CREATE (region7)-[:OFFERS_SERVICE]->(service28)
CREATE (region8)-[:OFFERS_SERVICE]->(service1)
CREATE (region8)-[:OFFERS_SERVICE]->(service2)
CREATE (region8)-[:OFFERS_SERVICE]->(service3)
CREATE (region8)-[:OFFERS_SERVICE]->(service4)
CREATE (region8)-[:OFFERS_SERVICE]->(service5)
CREATE (region8)-[:OFFERS_SERVICE]->(service6)
CREATE (region8)-[:OFFERS_SERVICE]->(service7)
CREATE (region8)-[:OFFERS_SERVICE]->(service8)
CREATE (region8)-[:OFFERS_SERVICE]->(service9)
CREATE (region8)-[:OFFERS_SERVICE]->(service10)
CREATE (region8)-[:OFFERS_SERVICE]->(service11)
CREATE (region8)-[:OFFERS_SERVICE]->(service12)
CREATE (region8)-[:OFFERS_SERVICE]->(service13)
CREATE (region8)-[:OFFERS_SERVICE]->(service14)
CREATE (region8)-[:OFFERS_SERVICE]->(service15)
CREATE (region8)-[:OFFERS_SERVICE]->(service16)
CREATE (region8)-[:OFFERS_SERVICE]->(service18)
CREATE (region8)-[:OFFERS_SERVICE]->(service19)
CREATE (region8)-[:OFFERS_SERVICE]->(service20)
CREATE (region8)-[:OFFERS_SERVICE]->(service21)
CREATE (region9)-[:OFFERS_SERVICE]->(service1)
CREATE (region9)-[:OFFERS_SERVICE]->(service2)
CREATE (region9)-[:OFFERS_SERVICE]->(service3)
CREATE (region9)-[:OFFERS_SERVICE]->(service4)
CREATE (region9)-[:OFFERS_SERVICE]->(service5)
CREATE (region9)-[:OFFERS_SERVICE]->(service6)
CREATE (region9)-[:OFFERS_SERVICE]->(service7)
CREATE (region9)-[:OFFERS_SERVICE]->(service8)
CREATE (region9)-[:OFFERS_SERVICE]->(service9)
CREATE (region9)-[:OFFERS_SERVICE]->(service10)
CREATE (region9)-[:OFFERS_SERVICE]->(service11)
CREATE (region9)-[:OFFERS_SERVICE]->(service12)
CREATE (region9)-[:OFFERS_SERVICE]->(service13)
CREATE (region9)-[:OFFERS_SERVICE]->(service14)
CREATE (region9)-[:OFFERS_SERVICE]->(service15)
CREATE (region9)-[:OFFERS_SERVICE]->(service16)
CREATE (region9)-[:OFFERS_SERVICE]->(service27)
CREATE (region10)-[:OFFERS_SERVICE]->(service1)
CREATE (region10)-[:OFFERS_SERVICE]->(service2)
CREATE (region10)-[:OFFERS_SERVICE]->(service3)
CREATE (region10)-[:OFFERS_SERVICE]->(service4)
CREATE (region10)-[:OFFERS_SERVICE]->(service5)
CREATE (region10)-[:OFFERS_SERVICE]->(service6)
CREATE (region10)-[:OFFERS_SERVICE]->(service7)
CREATE (region10)-[:OFFERS_SERVICE]->(service8)
CREATE (region10)-[:OFFERS_SERVICE]->(service9)
CREATE (region10)-[:OFFERS_SERVICE]->(service10)
CREATE (region10)-[:OFFERS_SERVICE]->(service11)
CREATE (region10)-[:OFFERS_SERVICE]->(service12)
CREATE (region10)-[:OFFERS_SERVICE]->(service13)
CREATE (region10)-[:OFFERS_SERVICE]->(service14)
CREATE (region10)-[:OFFERS_SERVICE]->(service16)
CREATE (region10)-[:OFFERS_SERVICE]->(service17)
CREATE (region10)-[:OFFERS_SERVICE]->(service19)
CREATE (region10)-[:OFFERS_SERVICE]->(service21)
CREATE (region10)-[:OFFERS_SERVICE]->(service26)
CREATE (instance1:EC2InstanceType{name:'m1.small', family:'general purpose', memory:1.7 })-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance2:EC2InstanceType{name:'m1.medium', family:'general purpose', memory:3.75})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance3:EC2InstanceType{name:'m1.large', family:'general purpose', memory:7.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance4:EC2InstanceType{name:'m1.xlarge', family:'general purpose', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance5:EC2InstanceType{name:'m3.xlarge', family:'general purpose', memory:15 })-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance6:EC2InstanceType{name:'m3.2xlarge', family:'general purpose', memory:30})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance7:EC2InstanceType{name:'c1.medium', family:'Compute optimized', memory:1.7})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance8:EC2InstanceType{name:'c1.xlarge', family:'Compute optimized', memory:7})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance9:EC2InstanceType{name:'c3.large', family:'Compute optimized', memory:3.75})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance10:EC2InstanceType{name:'c3.xlarge', family:'Compute optimized', memory:7.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance11:EC2InstanceType{name:'c3.2xlarge', family:'Compute optimized', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance12:EC2InstanceType{name:'c3.4xlarge', family:'Compute optimized', memory:30})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance13:EC2InstanceType{name:'c3.8xlarge', family:'Compute optimized', memory:60})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance14:EC2InstanceType{name:'cc2.8xlarge', family:'Compute optimized', memory:60.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance15:EC2InstanceType{name:'m2.xlarge', family:'Memory optimized', memory:17.1})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance16:EC2InstanceType{name:'m2.2xlarge', family:'Memory optimized', memory:34.2})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance17:EC2InstanceType{name:'m2.4xlarge', family:'Memory optimized', memory:68.4})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance18:EC2InstanceType{name:'cr1.8xlarge', family:'Memory optimized', memory:244})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance19:EC2InstanceType{name:'hi1.4xlarge', family:'Storage optimized', memory:60.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance20:EC2InstanceType{name:'hs1.8xlarge', family:'Storage optimized', memory:117})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance21:EC2InstanceType{name:'i2.xlarge', family:'Storage optimized', memory:30.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance22:EC2InstanceType{name:'Â i2.2xlarge', family:'Storage optimized', memory:61})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance23:EC2InstanceType{name:'i2.4xlarge ', family:'Storage optimized', memory:122})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance24:EC2InstanceType{name:'i2.8xlarge', family:'Storage optimized', memory:244})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance25:EC2InstanceType{name:'t1.micro', family:'Micro instances', memory:.615})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance26:EC2InstanceType{name:'cg1.4xlarge', family:'GPU instances', memory:22.5})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance27:EC2InstanceType{name:'g2.2xlarge', family:'GPU instances', memory:15})-[:IS_EC2_INSTANCE_TYPE]->(service1)
CREATE (instance27)-[:IS_EC2_INSTANCE_TYPE]->(service2)
CREATE (instance1)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance22)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance11)-[:IS_EC2_INSTANCE_TYPE]->(service3)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service4)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service5)
CREATE (instance17)-[:IS_EC2_INSTANCE_TYPE]->(service5)
CREATE (instance22)-[:IS_EC2_INSTANCE_TYPE]->(service6)
CREATE (instance11)-[:IS_EC2_INSTANCE_TYPE]->(service7)
CREATE (instance1)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service8)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service9)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service2)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance6)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance2)-[:IS_EC2_INSTANCE_TYPE]->(service18)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service19)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service20)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service21)
CREATE (instance4)-[:IS_EC2_INSTANCE_TYPE]->(service22)
CREATE (instance3)-[:IS_EC2_INSTANCE_TYPE]->(service23)
CREATE (instance26)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance5)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance7)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance17)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance10)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service17)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service10)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service11)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service12)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service13)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service14)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service15)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service16)
CREATE (instance25)-[:IS_EC2_INSTANCE_TYPE]->(service17)
//instance 9
CREATE (price1:Price{name:'PriceBook', desc:'region 1 price book', cost_per_hour:0.150})
CREATE (price2:Price{name:'PriceBook', desc:'region 2 pricebook', cost_per_hour:0.150})
CREATE (price3:Price{name:'PriceBook', desc:'region 3 pricebook', cost_per_hour:0.171})
CREATE (region1)-[:CHARGES]->(price1)-[:FOR_INSTANCE]->(instance9)
CREATE (region2)-[:CHARGES]->(price2)-[:FOR_INSTANCE]->(instance9)
CREATE (region3)-[:CHARGES]->(price3)-[:FOR_INSTANCE]->(instance9)
//instance1
CREATE (price4:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.060})
CREATE (region1)-[:CHARGES]->(price4)-[:FOR_INSTANCE]->(instance1)
//instance 10
CREATE (price5:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.300})
CREATE (price6:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.300})
CREATE (price7:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.342})
CREATE (region1)-[:CHARGES]->(price5)-[:FOR_INSTANCE]->(instance10)
CREATE (region2)-[:CHARGES]->(price6)-[:FOR_INSTANCE]->(instance10)
CREATE (region3)-[:CHARGES]->(price7)-[:FOR_INSTANCE]->(instance10)
//instance 11
CREATE (price8:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.600})
CREATE (price9:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.600})
CREATE (price10:Price{name:'PriceBook', desc:'foo', cost_per_hour:0.683})
CREATE (region9)-[:CHARGES]->(price8)-[:FOR_INSTANCE]->(instance11)
CREATE (region2)-[:CHARGES]->(price9)-[:FOR_INSTANCE]->(instance11)
CREATE (region3)-[:CHARGES]->(price10)-[:FOR_INSTANCE]->(instance11)
//instance 12
CREATE (price11:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.200})
CREATE (price12:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.200})
CREATE (price13:Price{name:'PriceBook', desc:'foo', cost_per_hour:1.366})
CREATE (region1)-[:CHARGES]->(price11)-[:FOR_INSTANCE]->(instance12)
CREATE (region2)-[:CHARGES]->(price12)-[:FOR_INSTANCE]->(instance12)
CREATE (region3)-[:CHARGES]->(price13)-[:FOR_INSTANCE]->(instance12)
//instance 13
CREATE (price14:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.400})
CREATE (price15:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.400})
CREATE (price16:Price{name:'PriceBook', desc:'foo', cost_per_hour:2.732})
CREATE (region1)-[:CHARGES]->(price14)-[:FOR_INSTANCE]->(instance13)
CREATE (region2)-[:CHARGES]->(price15)-[:FOR_INSTANCE]->(instance13)
CREATE (region3)-[:CHARGES]->(price16)-[:FOR_INSTANCE]->(instance13)

@ -6,13 +6,3 @@ service neo4j start
python3 /autograder/source/autograder.py python3 /autograder/source/autograder.py
# files_submitted=$(ls /autograder/submission)
# num_files_submitted=$(ls /autograder/submission/ | wc -l)
# cat > /autograder/results/results.json <<EOF
# {
# "output": "Good job, you passed! Submitted ${num_files_submitted} files: ${files_submitted}",
# "score": 10,
# "max_score": 10
# }
# EOF

@ -1,10 +0,0 @@
apt install -y curl python3 python3-pip
curl -fsSL https://debian.neo4j.com/neotechnology.gpg.key | gpg --dearmor -o /usr/share/keyrings/neo4j.gpg
echo "deb [signed-by=/usr/share/keyrings/neo4j.gpg] https://debian.neo4j.com stable latest" > /etc/apt/sources.list.d/neo4j.list
apt update
apt install -y neo4j
sed -i '1s/^/server.default_listen_address=0.0.0.0\n/' /etc/neo4j/neo4j.conf
systemctl enable --now neo4j
neo4j-admin dbms set-initial-password 4Sfz541Lm --require-password-change=false
python3 -m pip install neo4j

@ -1,73 +1,57 @@
sols = [ sols = [
''' '''
MATCH (author:Author)-[:WRITES]->(article:Article) MATCH (region:Region)-[:IS_LOCATED_IN]-(continent:Continent)
RETURN author.name, article.title RETURN region.name, continent.name
''', ''',
(''' '''
match (author:Author)-[:WRITES]->(paper_or_chapter) MATCH (region:Region)-[:HAS_ISOLATED]-(azone:AvailabilityZone)
return author.name, paper_or_chapter.title, labels(paper_or_chapter) RETURN region.name,azone.name
''', ''',
''' '''
MATCH (author:Author)-[:WRITES]->(paper_or_chapter) MATCH(e:EC2InstanceType)
WITH author, paper_or_chapter, labels(paper_or_chapter) as publicationType return e.family, count(*)
WHERE publicationType=["Article"] or publicationType=["Chapter"] ''',
RETURN author.name, paper_or_chapter.title, publicationType '''
'''), MATCH(e:EC2InstanceType)--(p:Price)
(''' with e, p.cost_per_hour/e.memory as price_per_GB
match (author:Author)-[:WRITES|EDITS]->(publication) Order by price_per_GB
return author.name, publication.title, labels(publication) Return e.name, price_per_GB
''', Limit 1
''' ''',
MATCH (author:Author)-[]->(publication) '''
WHERE publication:Article or publication:Chapter or publication:Book match (service:Service)-[:OFFERS_SERVICE]-(region:Region)
RETURN author.name, publication.title, labels(publication) with service, count(region) as number_of_region, collect(region.name) as region_name_collection
'''), where number_of_region > 5
(''' return service.name, number_of_region,region_name_collection
match (author:Author)-[:WRITES|EDITS]->(publication) order by number_of_region desc, service.name asc
return author.name, count(publication) as publication_count ''',
''', '''
''' match (instance:EC2InstanceType)--(price:Price)--(region:Region {name: "N. Virginia"})
MATCH (author:Author)-[]->(publication) where price.cost_per_hour > 1
WHERE publication:Article OR publication:Chapter or publication:Book return instance.name, price.cost_per_hour, region.name
RETURN author.name, count(publication) as publication_count ''',
'''), '''
(''' match(a:Service)--(:Region)--(c:Continent)
match(a:Article)-[in:IN]->(:Issue) with a, count(distinct c) as number_of_continent
where (in.pp[1] - in.pp[0]) <= 10 where number_of_continent = 5
return a.title, (in.pp[1] - in.pp[0] + 1) as NumberOfPages return a.name, number_of_continent
''', ''',
''' '''
MATCH (a:Article)-[e:IN]->(:Issue) match (r:Region)-[:OFFERS_SERVICE]->(s1:Service {name:'AWS Data Pipeline'}), (r)-[:OFFERS_SERVICE]->(s2:Service {name:'Amazon Kinesis'})
WITH a, e.pp[1]-e.pp[0]+1 as NumberOfPages return r.name
WHERE NumberOfPages <=10 ''',
RETURN a.title, NumberOfPages '''
'''), match (r:Region)-[:OFFERS_SERVICE]->(s1:Service {name:'Amazon Simple Email Service'})
''' WHERE NOT (r)-[:OFFERS_SERVICE]->(:Service {name:'AWS Data Pipeline'})
MATCH (p2:Article)<-[]-(a1:Author)-[]->(p1:Article),(p1)-[:CITES]->(p2) return r.name
RETURN a1.name, p1.title, p2.title ''',
''', '''
''' match(a:Service)<-[]-(e:EC2InstanceType {name: 'Â i2.2xlarge'})
MATCH (publication)<-[:CITES]-() where NOT (a)<-[]-(:EC2InstanceType {name: 'c3.2xlarge'})
WITH publication, count(*) as publication_count return a.name, 'offered only on i2.2xlarge' as description
WHERE (publication:Article or publication:Chapter) and publication_count >= 2 union
RETURN publication.title, publication_count match(a:Service)<-[]-(e:EC2InstanceType {name: 'Â i2.2xlarge'})
''', where (a)<-[]-(:EC2InstanceType {name: 'c3.2xlarge'})
(''' return a.name, 'offered on i2.2xlarge and c3.2xlarge' as description
match (journal:Journal)<-[:OF]-(issue:Issue)<-[:IN]-(article:Article)<-[:CITES]-(someOtherPublication) '''
with journal, article, count(someOtherPublication) as citations_count ]
where citations_count > 1
match (article)<-[:WRITES]-(author:Author)
return journal.title, article.title, citations_count, author.name
''',
'''
MATCH (author:Author)-[:WRITES]->(article:Article)-[:IN]->()-[]->(journal:Journal), ()-[e:CITES]->(article:Article)
WITH journal, article, author, count(e) as citation_count
WHERE citation_count >= 2
RETURN journal.title, article.title, citation_count, author.name
'''),
'''
MATCH (a1:Article)-[:IN]->(i1:Issue)-[]->(:Journal)<-[]-(i2:Issue)<-[]-(a2:Article)
WHERE (a1)-[:CITES]->(a2)
RETURN a1.title, i1.issue, a2.title, i2.issue
'''
]

@ -0,0 +1,45 @@
instr = '''Instructions:
Please put the queries under the corresponding functions below.
Running this python file will check if the formatting is okay.
'''
def query1():
return """
"""
def query2():
return """
"""
def query3():
return """
"""
def query4():
return """
"""
def query5():
return """
"""
def query6():
return """
"""
def query7():
return """
"""
def query8():
return """
"""
if __name__ == "__main__":
try:
if all(type(eval(f'query{f}()'))==str for f in range(1,9)):
print('Your submission is valid.')
else:
raise TypeError('Invalid Return Types.')
except Exception as e:
print(f'Your submission is invalid.\n{instr}\n{e}')

@ -0,0 +1,53 @@
instr = '''Instructions:
Please put the queries under the corresponding functions below.
Running this python file will check if the formatting is okay.
'''
def query1():
return """
"""
def query2():
return """
"""
def query3():
return """
"""
def query4():
return """
"""
def query5():
return """
"""
def query6():
return """
"""
def query7():
return """
"""
def query8():
return """
"""
def query9():
return """
"""
def query10():
return """
"""
if __name__ == "__main__":
try:
if all(type(eval(f'query{f}()'))==str for f in range(1,11)):
print('Your submission is valid.')
else:
raise TypeError('Invalid Return Types.')
except Exception as e:
print(f'Your submission is invalid.\n{instr}\n{e}')
Loading…
Cancel
Save