mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
feat: Add data file loading utilities to reasoning_gym.data
This commit is contained in:
parent
22538be4c5
commit
746e05aa3d
1 changed files with 38 additions and 0 deletions
|
|
@ -1 +1,39 @@
|
|||
"""Package containing data files used by reasoning_gym"""
|
||||
|
||||
from importlib import resources
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
def get_data_file_path(filename: str) -> Path:
|
||||
"""Get the path to a data file in the package.
|
||||
|
||||
Args:
|
||||
filename: Name of the file in the data directory
|
||||
|
||||
Returns:
|
||||
Path object pointing to the data file
|
||||
|
||||
Example:
|
||||
>>> path = get_data_file_path("pg19362.txt")
|
||||
>>> with open(path) as f:
|
||||
... content = f.read()
|
||||
"""
|
||||
with resources.path('reasoning_gym.data', filename) as data_path:
|
||||
return data_path
|
||||
|
||||
def read_data_file(filename: str) -> str:
|
||||
"""Read the contents of a data file in the package.
|
||||
|
||||
Args:
|
||||
filename: Name of the file in the data directory
|
||||
|
||||
Returns:
|
||||
String contents of the file
|
||||
|
||||
Example:
|
||||
>>> content = read_data_file("pg19362.txt")
|
||||
"""
|
||||
with resources.open_text('reasoning_gym.data', filename) as f:
|
||||
return f.read()
|
||||
|
||||
__all__ = ['get_data_file_path', 'read_data_file']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue