-
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. |
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've requested a few changes here. It's a lot of code to review and I wish we could have done it in more pieces.
I think it would help to have a lot more comments because the specialized knowledge you are acquiring is not clear from the code (and may never be from the code alone). On the other hand, there may be value in more modularity/functions that help describe things instead of comments, in some places.
XML_to_SON/grammar_parser_test.py
Outdated
'silver': [192, 192, 192]} | ||
self.highlight_str = self.make_basic_son() | ||
|
||
def highlight_maker(self, name, word, color='blue'): |
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 we can add bold
and italic
as function parameters and then use it to set the right characteristics of a rule
XML_to_SON/grammar_parser_test.py
Outdated
# highlight_str += highlight_maker('brack_open', '{', 'red') | ||
# highlight_str += highlight_maker('brack_close', '}', 'red') | ||
# highlight_str += highlight_maker('square_open', '[', 'lime') | ||
# highlight_str += highlight_maker('square_close', ']', 'lime') |
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.
Did you comment these out? Might be good to put them back in.
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.
These were commented out by Jin Whan. I uncommented it to add them to the highlighter, but the items don't get highlighted. I tried multiple times to see if I was doing something wrong, but it appears that they are not recognized as elements that can be highlighted.
XML_to_SON/grammar_parser_test.py
Outdated
highlight_str += '''rule("Quoted string") { | ||
pattern = """'[^']*'|"[^"]*"""" | ||
bold = true | ||
foreground { | ||
red = 255 | ||
green = 130 | ||
blue = 0 | ||
} | ||
background { | ||
red = 255 | ||
green = 130 | ||
blue = 0 | ||
alpha = 25 | ||
} | ||
} | ||
|
||
rule("equal"){ | ||
pattern="=" | ||
background{ | ||
red=192 | ||
green=192 | ||
blue=192 | ||
} | ||
} | ||
|
||
rule("Comment") { | ||
pattern = "%.*" | ||
italic = true | ||
foreground { | ||
red = 0 | ||
green = 128 | ||
blue = 0 | ||
} | ||
} | ||
|
||
''' |
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.
Can't we use the highlight_maker
function for these? especially if we extend it to support italics and add more colors to the color list
XML_to_SON/grammar_parser_test.py
Outdated
replacement_text = generate_child_exactly_one_line('facility') | ||
node.text = node.text.replace('@Facility_REFS@', replacement_text) | ||
return f"[{' '.join(facilities)}]", {} |
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.
Seems like this could be a little function since we reuse it in all three cases.
XML_to_SON/grammar_parser_test.py
Outdated
new_region_config.update(region_config) | ||
final_json["simulation"]["region"]["config"][region_name] = new_region_config | ||
|
||
for agent_type, agent_list in zip(['facility', 'region'], [processed_facilities, processed_regions]): |
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.
It might be safer/more readable to manually bind/zip these since there will only ever be two:
for agent_type, agent_list in zip(['facility', 'region'], [processed_facilities, processed_regions]): | |
for agent_type, agent_list in [ ('facility, processed_facilities), ('region', processed_regions) ]: |
…highlighter class and some other modularity/function issues.
Improved automatic template generation for autocompletion mechanism. Current code also saves output files on user's specified directory.