Skip to content

Commit

Permalink
#387 handling case where something is just one line and not in anothe…
Browse files Browse the repository at this point in the history
…r nest
  • Loading branch information
ecwood committed Jul 27, 2024
1 parent 6db935f commit 7b4ac97
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions misc-tools/owlparser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import argparse
import datetime

COMMENT = "!--"
XML_TAG = "?xml"
Expand Down Expand Up @@ -29,6 +30,9 @@ def get_args():
arg_parser.add_argument('inputFile', type=str)
return arg_parser.parse_args()

def date():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

def convert_line(line):
tag = ""
attributes = dict()
Expand Down Expand Up @@ -240,16 +244,20 @@ def divide_into_lines(input_file_name):
if line_type != LINE_TYPE_IGNORE:
curr_nest.append(line_parsed)

output_nest = (line_type in [LINE_TYPE_ENTRY, LINE_TYPE_ENTRY_WITH_ATTR, LINE_TYPE_ENTRY_ONLY_ATTR] and len(curr_nest_tags) == 0)

if line_type in [LINE_TYPE_START_NEST, LINE_TYPE_START_NEST_WITH_ATTR]:
curr_nest_tags.append(tag)
elif line_type == LINE_TYPE_END_NEST:
popped_curr_nest_tag = curr_nest_tags.pop()
assert popped_curr_nest_tag == tag
if len(curr_nest_tags) == 0:
nest_dict, _ = convert_nest(curr_nest, 0)
print(json.dumps(nest_dict, indent=4))
curr_nest = list()
curr_nest_tag = str()
output_nest = True
if output_nest:
nest_dict, _ = convert_nest(curr_nest, 0)
print(json.dumps(nest_dict, indent=4))
curr_nest = list()
curr_nest_tag = str()

curr_str = ""

Expand All @@ -262,4 +270,7 @@ def divide_into_lines(input_file_name):
args = get_args()
input_file_name = args.inputFile

divide_into_lines(input_file_name)
print("File:", input_file_name)
print("Start Time:", date())
divide_into_lines(input_file_name)
print("End Time:", date())

0 comments on commit 7b4ac97

Please sign in to comment.