Skip to content

Commit

Permalink
Fixed issue with json lists
Browse files Browse the repository at this point in the history
  • Loading branch information
eiglesias34 committed Jul 31, 2024
1 parent a72269f commit 647af2a
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions rdfizer/rdfizer/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,27 +936,23 @@ def string_substitution_json(string, pattern, row, term, ignore, iterator):
return None
print('Aborting...')
sys.exit(1)

elif "." in match:
if "[*]" in match:
if match.split("[*]")[0] in row:
child_list = row[match.split("[*]")[0]]
match = match.split(".")[1:]
object_list = []
for child in child_list:
if "." in match:
match = match.split(".")[1:]
if len(match) > 1:
if len(match) > 1:
value = child[match[0]]
for element in match:
if element in value:
value = value[element]
else:
if match[0] in child:
value = child[match[0]]
for element in match:
if element in value:
value = value[element]
else:
if match[0] in child:
value = child[match[0]]
else:
value = None
else:
value = child
value = None
if value is not None:
if (type(value).__name__) != "str":
if (type(value).__name__) != "float":
Expand Down Expand Up @@ -1003,9 +999,39 @@ def string_substitution_json(string, pattern, row, term, ignore, iterator):
return None
else:
if match in row:
value = row[match]
value = row[match]
else:
return None
if "[*]" in match:
object_list = []
child_list = row[match.split("[*]")[0]]
for value in child_list:
if value is not None:
if (type(value).__name__) != "str":
if (type(value).__name__) != "float":
value = str(value)
else:
value = str(math.ceil(value))
else:
if re.match(r'^-?\d+(?:\.\d+)$', value) is not None:
value = str(math.ceil(float(value)))
if re.search("^[\s|\t]*$", value) is None:
if "http" not in value:
value = encode_char(value)
new_string = new_string[:start + offset_current_substitution] + value.strip() + new_string[ end + offset_current_substitution:]
offset_current_substitution = offset_current_substitution + len(value) - (end - start)
if "\\" in new_string:
new_string = new_string.replace("\\", "")
count = new_string.count("}")
i = 0
new_string = " " + new_string
while i < count:
new_string = "{" + new_string
i += 1
object_list.append(new_string)
new_string = string
offset_current_substitution = 0
else:
return None

if value is not None:
if (type(value).__name__) != "str":
Expand Down Expand Up @@ -1044,7 +1070,7 @@ def string_substitution_json(string, pattern, row, term, ignore, iterator):
child_list = row[match.split("[*]")[0]]
object_list = []
for child in child_list:
if "." in match
if "." in match:
match = match.split(".")[1:]
if len(match) > 1:
value = child[match[0]]
Expand Down

0 comments on commit 647af2a

Please sign in to comment.