Skip to content

Commit

Permalink
Try9
Browse files Browse the repository at this point in the history
  • Loading branch information
steveraysteveray committed Sep 19, 2023
1 parent 8052d88 commit 6263d03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions add-base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ def add_base_if_missing(file_path):
with open(file_path, 'r') as f:
lines = f.readlines()

# Insert the @base declaration before line #4
if "@base" not in lines[3]: # Checking to ensure it's not already added
lines.insert(3, f"@base <{base_uri}> .\n")
# Find the line number of the first occurrence of '@prefix'
prefix_line_number = next((i for i, line in enumerate(lines) if line.startswith("@prefix")), None)

if prefix_line_number is not None:
# Check if @base is already in the file before the first @prefix
if all("@base" not in line for line in lines[:prefix_line_number]):
lines.insert(prefix_line_number, f"@base <{base_uri}> .\n")
else:
# If no @prefix is found, just append at the end (or handle in some other manner)
lines.append(f"@base <{base_uri}> .\n")

with open(file_path, 'w') as f:
f.writelines(lines)
Expand Down
2 changes: 1 addition & 1 deletion file1.shapes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<https://example/file1>
a owl:Ontology ;
owl:imports <http://datashapes.org/dash> ;
owl:versionInfo "Created with TopBraid Composer" ;
owl:versionInfo "Created with TopBraid Composer" ;
.
file1:DestinationClass_1
a file1:Location ;
Expand Down

0 comments on commit 6263d03

Please sign in to comment.