Пример #1
0
def get_lv_for_modules(modules: "list of modules (URI)",
					optional: "set this to True to get get only optional units"=False,
					mandatory: "set this to True to get get only lectures"=False) \
					-> "list of courses for given modules":
	"""Returns information about the courses to a given module.
	
	These contain information like the course-name, appointed time, location and trainer.	
	"""
	ret = {modul : list() for modul in modules}
	wrapper.resetQuery()
	query = """
	SELECT distinct ?LV, ?LVlabel, ?LVdayOfWeek, ?LVbeginsAt, ?LVendsAt, ?LVservedBy, ?modul, ?LVlocation
	WHERE {
		?unit od:relatedModule ?modul.
		FILTER( ?modul IN ( %s
			))
		?unit od:containsKurs ?kurs.
		?kurs od:containsLV ?LV.
		?LV rdf:type <http://od.fmi.uni-leipzig.de/model/LV>
		FILTER REGEX(?LV, ".*%s.*")
		?LV rdfs:label ?LVlabel.
		?LV od:beginsAt ?LVbeginsAt.
		?LV od:endsAt ?LVendsAt.
		?LV od:servedBy ?LVservedBy.
		?LV od:dayOfWeek ?LVdayOfWeek.
		?LV rdf:type ?typ.
		?LV od:locatedAt ?LVlocationURI.
		?LVlocationURI rdfs:label ?LVlocation.
		FILTER(?typ != <http://od.fmi.uni-leipzig.de/model/LV>)
		""" % (", \n".join(["<%s>" % modul for modul in modules]), time_conversion.semester())
	if optional:
		query += """
		FILTER(?typ = <http://od.fmi.uni-leipzig.de/model/Praktikum> || ?typ = <http://od.fmi.uni-leipzig.de/model/Uebung> )"""
	if mandatory:
		query += """
		FILTER(?typ != <http://od.fmi.uni-leipzig.de/model/Praktikum> && ?typ != <http://od.fmi.uni-leipzig.de/model/Uebung> )"""
	query += """
		?typ rdfs:label ?typLabel.
	}"""
	wrapper.setQuery(query)
	results = wrapper.query().convert()
	for result in results["results"]["bindings"]:
		ret[result["modul"]["value"]].append((result["LV"]["value"],
							result["LVlabel"]["value"],
							result["LVdayOfWeek"]["value"],
							result["LVbeginsAt"]["value"],
							result["LVendsAt"]["value"],
							get_trainer(result["LVservedBy"]["value"]),
							result["LVlocation"]["value"]))
	return ret
Пример #2
0
def module_finder(
		study_course: "course of studies"=None,
		semester: "semester"=None
		) -> "list of all modules of a chosen course of study":
	"""Returns a list of modules.

	Returns either all listed modules in the database or,
	if a course of study or a semester is given, the recommended ones
	"""
	wrapper.resetQuery()
	query = """
	SELECT distinct ?modulLabel, ?modul
	WHERE {"""
	if study_course is not None:
		query += """
		?semesterStudyCourse od:toStudiengang <%s>.
		""" % study_course
	if semester is not None:
		query += """
		?semesterStudyCourse rdfs:label ?semesterStudyCourseLabel.
		FILTER REGEX(?semesterStudyCourseLabel, ".*%s")
		""" % semester
	if semester is not None or study_course is not None:
		query += """
		?modul od:toStudiengangSemester ?semesterStudyCourse.
		"""
	query += """
		?modul rdfs:label ?modulLabel.
		?unit od:relatedModule ?modul.
		?unit od:containsKurs ?kurs.
		?kurs od:containsLV ?LV.
		?LV rdf:type <http://od.fmi.uni-leipzig.de/model/LV>
		FILTER REGEX(?LV, ".*%s.*")
	} ORDER BY ASC(?modulLabel)""" % time_conversion.semester()

	wrapper.setQuery(query)
	results = wrapper.query().convert()
	return [(result["modul"]["value"], result["modulLabel"]["value"])
		for result in results["results"]["bindings"]]
Пример #3
0
def get_lv_for_modules(
		modules: "list of modules (URI)",
		optional: "set this to True to get get only optional units"=False,
		mandatory: "set this to True to get get only lectures"=False
		) -> "module:lv:(label, weekday, begin, end, by, location":
	"""finds information about the modules lvs"""

	from multiprocessing.pool import ThreadPool
	ret = {modul: dict() for modul in modules}
	ret = dict()
	querys = list()
	for modul in modules:
		query = """
		SELECT distinct ?LV, ?LVlabel, ?LVdayOfWeek, ?LVbeginsAt, ?LVendsAt, ?LVservedBy, ?LVlocation
		WHERE {
			?unit od:relatedModule <%s>.
			?unit od:containsKurs ?kurs.
			?kurs od:containsLV ?LV.
			?LV rdf:type <http://od.fmi.uni-leipzig.de/model/LV>
			FILTER REGEX(?LV, ".*%s.*")
			?LV rdfs:label ?LVlabel.
			?LV od:beginsAt ?LVbeginsAt.
			?LV od:endsAt ?LVendsAt.
			?LV od:servedBy ?LVservedBy.
			?LV od:dayOfWeek ?LVdayOfWeek.
			?LV rdf:type ?typ.
			?LV od:locatedAt ?LVlocationURI.
			?LVlocationURI rdfs:label ?LVlocation.
			FILTER(?typ != <http://od.fmi.uni-leipzig.de/model/LV>)
			""" % (modul, time_conversion.semester())
		if optional:
			query += """
			FILTER(?typ = <http://od.fmi.uni-leipzig.de/model/Praktikum> || ?typ = <http://od.fmi.uni-leipzig.de/model/Uebung> )"""
		if mandatory:
			query += """
			FILTER(?typ != <http://od.fmi.uni-leipzig.de/model/Praktikum> && ?typ != <http://od.fmi.uni-leipzig.de/model/Uebung> )"""
		query += """
			?typ rdfs:label ?typLabel.
		}"""
		querys.append(query)

	def execute_query(query):
		my_wrapper = SPARQLWrapper("http://od.fmi.uni-leipzig.de:8892/sparql", returnFormat=JSON)
		my_wrapper.resetQuery()
		my_wrapper.setQuery(query)
		results = my_wrapper.query().convert()
		ret = dict()
		for result in results["results"]["bindings"]:
			uri = result["LV"]["value"]
			by = get_trainer(result["LVservedBy"]["value"])
			if uri in ret:
				ret[uri][4] += " & " + by
			else:
				titel = result["LVlabel"]["value"]
				day = result["LVdayOfWeek"]["value"]
				begin = result["LVbeginsAt"]["value"]
				end = result["LVendsAt"]["value"]
				loc =result["LVlocation"]["value"]
				ret[uri] = [titel, day, begin, end, by, loc]
		return {uri: tuple(ret[uri]) for uri in ret}

	# increase 8 to moar for even moooar paralelz
	p = ThreadPool(8)
	modul_infos = p.map(execute_query, querys)
	return {module: modul_info for module, modul_info in zip(modules, modul_infos)}