Skip to content

Commit

Permalink
Add script for fix order of ttl #80
Browse files Browse the repository at this point in the history
  • Loading branch information
maipet committed Aug 9, 2024
1 parent f8d9cc1 commit fe302d5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rpb/ttl_fix_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import re


def format_list_items(unformatted_list):
formatted_list = [i + "\n\n" for i in unformatted_list]
return formatted_list


with open("/rpb-spatial.ttl", "r") as f:
#with open("rpb-spatial_final.ttl", "r") as f:
data = f.read()
test_search = re.findall(r'^:n.*? \.$', data, flags=re.MULTILINE | re.DOTALL)
prefix_matches = re.findall(r'^@prefix.+\.$\n', data, flags=re.MULTILINE)
other_matches = re.findall(r'^(?!:n| |@|\n).*? \.$', data, flags=re.MULTILINE | re.DOTALL)
list_sort = sorted(test_search, key=lambda x: (len(x.split(' ')[0]), x))

result = prefix_matches + format_list_items(other_matches) + format_list_items(list_sort)

with open("rpb-spatial_sorted.ttl", "w") as outfile:
outfile.write("".join(result))

0 comments on commit fe302d5

Please sign in to comment.