-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress on xml to son parser #5
base: main
Are you sure you want to change the base?
Conversation
…Current code also saves output files on user's specified directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a lot of comments here. I think it looks OK so far, but anticipate a big review when it's closer to being done.
XML_to_SON/grammar_parser_test.py
Outdated
@@ -137,28 +208,45 @@ def handle_choice_element(node): | |||
def process_schema_from_mjson(xml_string, element_name): | |||
root = ET.fromstring(xml_string) | |||
processed_content = process_node(root) | |||
|
|||
return {element_name: processed_content} | |||
|
|||
def integrate_detailed_schemas(final_json, processed_facilities, processed_regions, processed_institutions): | |||
for facility_name, facility_config in processed_facilities.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given all the repetition here, you could instead do:
for agent_type, agent_list in zip(['facility', 'institution', 'region'],
[processed_facilities, processed_instutitions, processed_regions]):
if agent_type in final_json["simulation"]:
for agent_name, agent_config in agent_list.items():
if agent_name in final_json["simulation"][agent_type]["config"]["ChildAtMostOne"]:
new_agent_config = {"InputTmpl": f'"{agent_name}", "MaxOccurs": 1}
new_agent_config.update(agent_config)
final_json["simulation"][agent_type]["config"][agent_name] = new_agent_config
XML_to_SON/grammar_parser_test.py
Outdated
child_indent = base_indent + tab | ||
|
||
matching_keys = [key for key in annotations.keys() if key.endswith(key_name)] | ||
matching_keys = [key for key in annotations.keys() if key.split(":")[-2] == key_name.split("_")[-3] and key.split(":")[-1] == key_name.split("_")[-1]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will be more readable if we define the following with variables first:
key_name.split("_")[-3]
key_name.split("_")[-1]
…as to reduce repetition.
Done! I reduced the repetition (very nice structure), and added variables to improve readability. |
Improved automatic template generation for autocompletion mechanism. Current code also saves output files on user's specified directory.