graphdoc.data.local module

class graphdoc.data.local.LocalDataHelper(schema_directory_path: str | ~pathlib._local.Path | None = None, categories: ~typing.Type[~enum.Enum] = <enum 'SchemaCategory'>, ratings: ~typing.Type[~enum.Enum] = <enum 'SchemaRating'>, categories_ratings: ~typing.Callable = <function SchemaCategoryRatingMapping.get_rating>)[source]

Bases: object

A helper class for loading data from a directory.

Parameters:
  • schema_directory_path (Union[str, Path] Defaults to the path to the schemas in the graphdoc package.) – The path to the directory containing the schemas

  • categories (Type[Enum]) – The categories of the schemas. Defaults to SchemaCategory.

  • ratings (Type[Enum]) – The ratings of the schemas. Defaults to SchemaRating.

  • categories_ratings – A callable that maps categories to ratings. Defaults to SchemaCategoryRatingMapping.get_rating.

schema_objects_from_folder(category: str, rating: int, folder_path: str | Path) dict[str, SchemaObject][source]

Load schemas from a folder, keeping the difficulty tag.

Parameters:
  • category (str) – The category of the schemas

  • rating (int) – The rating of the schemas

  • folder_path (Union[str, Path]) – The path to the folder containing the schemas

Returns:

A dictionary of schemas

Return type:

dict[str, SchemaObject]

schema_objects_from_folder_of_folders(folder_paths: ~typing.Type[~enum.Enum] | None = <enum 'SchemaCategoryPath'>) Dict[str, SchemaObject] | None[source]

Load a folder of folders containing schemas, keeping the difficulty tag.

Parameters:

folder_paths (Optional[Type[Enum]]) – Enum class defining folder paths, defaults to SchemaCategoryPath. Must have a get_path method.

Returns:

Dictionary of loaded schemas

Return type:

Union[Dict[str, SchemaObject], None]

folder_to_dataset(category: str, folder_path: str | Path, parse_objects: bool = True, type_mapping: dict[type, str] | None = None) Dataset[source]

Load a folder of schemas, keeping the difficulty tag.

Parameters:
  • category (str) – The category of the schemas

  • folder_path (Union[str, Path]) – The path to the folder containing the schemas

  • parse_objects (bool) – Whether to parse the objects from the schemas

  • type_mapping (Optional[dict[type, str]]) – A dictionary mapping types to strings

Returns:

A dataset containing the schemas

Return type:

Dataset

folder_of_folders_to_dataset(folder_paths: ~typing.Type[~enum.Enum] = <enum 'SchemaCategoryPath'>, parse_objects: bool = True, type_mapping: dict[type, str] | None = None) Dataset[source]

Load a folder of folders containing schemas, keeping the difficulty tag.

Parameters:
  • folder_paths (Type[Enum]) – Enum class defining folder paths, defaults to SchemaCategoryPath. Must have a get_path method.

  • parse_objects (bool) – Whether to parse the objects from the schemas

  • type_mapping (Optional[dict[type, str]]) – A dictionary mapping graphql-ast node values to strings

Returns:

A dataset containing the schemas

Return type:

Dataset