-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonparser.py
More file actions
33 lines (25 loc) · 929 Bytes
/
jsonparser.py
File metadata and controls
33 lines (25 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from json import load
from .requirement import Requirement
class JSONParser:
"""A class to retrieve requirements from a JSON file.
The input file must be a list of JSON objects with the following
structure:
{
"scenario": <str>,
"goal": <str>,
"context": <str>,
"actors": <list[str]>,
"resources": <list[str]>,
"episodes": <list[str]>
}
"""
def __init__(self, file_name: str):
"""Initialize the JSONParser object."""
with open(file_name, mode="r", encoding="utf8") as file:
self.data: dict = load(file)
def requirements(self) -> list[Requirement]:
"""Get a list of objects representing each parsed requirement.
Returns:
requirements (list[Requirement]): list of requirements.
"""
return list(map(lambda req: Requirement(req), self.data))