src.scheduler package

Submodules

src.scheduler.convert module

Convert course data JSON to a logic language file (as a knowledge graph).

convert_course_data_to_clingo

Converts a JSON file to a Clingo file.

convert_course_data_to_ergo

Converts a JSON file to an ERGO file.

src.scheduler.convert.convert_course_data(json_file, output_file=None, repeatable_courses=None, method='clingo')[source]

Converts a JSON file to a logic language file (Clingo or ErgoAI).

Parameters:
  • json_file (Union[KnowledgeBase, KnowledgeGraph, str]) – Input JSON file (KnowledgeBase or KnowledgeGraph object) to be converted to a logic language file.

  • output_file (Optional[str]) – Output filename. If not specified, then a new file of the same name is created, with a ‘.lp’ or ‘.ergo’ file extension. Defaults to None.

  • repeatable_courses (Optional[List[Tuple[str, str, str]]]) – List of tuples of other courses that are repeatable. Each tuple should have exactly 3 elements: course_id, times_repeatable, max_credits. Defaults to None.

  • method – Method to use for converting/preprocessing data. Input should be either “clingo” or “ergoai” Defaults to “clingo”.

Raises:

ValueError – If the input method is not supported.

Return type:

str

Returns:

Output knowledge base file path.

src.scheduler.convert.convert_course_data_to_clingo(json_file, output_file=None, repeatable_courses=None)[source]

Converts a JSON file to a Clingo file.

Usage example:
>>> from src.scheduler.convert import convert_course_data_to_clingo
>>> clingo_file = convert_course_data_to_clingo("cse_courses.json")
>>> print(clingo_file)
cse_courses.lp
Parameters:
  • json_file (Union[KnowledgeBase, KnowledgeGraph, str]) – Input JSON file (KnowledgeBase or KnowledgeGraph object) to be converted to Clingo file.

  • output_file (Optional[str]) – Output filename. If not specified, then a new file of the same name is created, with a ‘.lp’ file extension. Defaults to None.

  • repeatable_courses (Optional[List[Tuple[str, str, str]]]) – List of tuples of other courses that are repeatable. Each tuple should have exactly 3 elements: course_id, times_repeatable, max_credits. Defaults to None.

Return type:

str

Returns:

Output Clingo knowledge base file path.

src.scheduler.convert.convert_course_data_to_ergo(json_file, output_file=None)[source]

Converts a JSON file to an ERGO file.

Note

  • If a JSON file needs to be converted to an ERGO file, this function MUST be called first before calling query_ergoai().

  • If a KnowledgeBase or KnowledgeGraph object is passed, then the object is updated with the ERGO file path.

Warning

  • This function can only be once per session. If you need to convert multiple JSON files to ERGO files, you must start a new session each time, otherwise the current session will crash.

Usage example:
>>> from src.scheduler.convert import convert_course_data_to_ergo
>>> ergo_file = convert_course_data_to_ergo("cse_courses.json")
>>> print(ergo_file)
cse_courses.ergo
Parameters:
Return type:

str

Returns:

Path to the output ERGO file.

src.scheduler.download module

Module to download/scrape files from Stony Brook University’s Solar System.

procure_course_data

Procures course data from Stony Brook University's Solar System for a select major.

src.scheduler.download.procure_course_data(url, major, output=None, headless=True, verbose=False, wait_time=10)[source]

Procures course data from Stony Brook University’s Solar System for a select major. If the output file exists, then this function will simply return a KnowledgeBase object.

Usage example:
>>> from src.scheduler.download import procure_course_data
>>> url = "https://prod.ps.stonybrook.edu/psc/csprodg/EMPLOYEE/CAMP/c/COMMUNITY_ACCESS.SSS_BROWSE_CATLG.GBL?"
>>> kg = procure_course_data(url, "CSE", output="cse_courses.json")
>>> print(kg.json)
cse_courses.json
>>> kg = procure_course_data(url, "CSE", "cse_courses.json")
>>> print(kg.json)
cse_courses.json
Parameters:
  • url (Union[str, KnowledgeBase]) – URL of Stony Brook University course catalog as string or KnowledgeBase object.

  • major (str) – Major, represented as a three-letter code (e.g. “CSE”).

  • output (Optional[str]) – Output filename for the JSON file. Defaults to None.

  • headless (bool) – Do not open brower. Defaults to True.

  • verbose (bool) – Print output to screen. Defaults to False.

  • wait_time (int) – Maximum wait time (in seconds) for each click operation. Defaults to 10.

Return type:

KnowledgeGraph

Returns:

KnowledgeBase object containing course information that corresponds to a set of output JSON, and CSV files.

src.scheduler.query module

Executes queries of some knowledge base.

query

Executes queries for some knowledge base.

src.scheduler.query.query(knowledge, method='clingo', verbose=False, num_models=None, configuration='handy', parallel_mode=None, query=None)[source]

Executes queries for some knowledge base.

Danger

  • ErgoAI queries are not fully supported.

Usage example:
>>> from src.scheduler.query import query
>>> result = query(knowledge="cse_courses.lp", method="clingo", verbose=True, query="cse_reqs.lp.")
>>> print(result)
...
>>> result = query(knowledge="cse_courses.ergo", method="ergoai", query="?X[Credits->3].")
>>> print(result)
...
Parameters:
  • knowledge (Union[KnowledgeBase, KnowledgeGraph, str]) – Input knowledge base/graph file (or KnowledgeBase or KnowledgeGraph object) to be queried.

  • method (str) – Method to use for querying the knowledge base. Options are "clingo" or "ergoai". Defaults to "clingo".

  • verbose (bool) – Print output to screen. Defaults to False.

  • num_models (Optional[int]) – Number of models to generate for Clingo queries. Defaults to None.

  • configuration (str) – Configuration for Clingo queries. Options are "handy" or "competition". Defaults to "handy".

  • parallel_mode (Optional[int]) – Parallel mode, maximum number of threads. Defaults to None.

  • query (Union[str, Tuple[str], None]) – Query or query file paths to be passed to Clingo or ErgoAI. Clingo can take multiple input files as a tuple of strings. ErgoAI can only take string inputs. Input must be a string or a tuple of strings. Defaults to None.

Raises:

ValueError – If the input method is not supported.

Return type:

str

Returns:

Results of the query.

Module contents