Skip to content

Commit

Permalink
Added py file
Browse files Browse the repository at this point in the history
  • Loading branch information
steveraysteveray committed Sep 18, 2023
1 parent 78e8274 commit 83181e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/add-base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import argparse
import rdflib

def find_ontology_base(file_path):
g = rdflib.Graph()
g.parse(file_path, format='turtle')

for s in g.subjects(predicate=rdflib.RDF.type, object=rdflib.OWL.Ontology):
return str(s)
return None

def add_base_if_missing(file_path):
base_uri = find_ontology_base(file_path)
if base_uri is None:
print("No owl:Ontology found in the RDF file!")
return

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")

with open(file_path, 'w') as f:
f.writelines(lines)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Add @base to an RDF Turtle file if it is missing.')
parser.add_argument('file_path', help='Path to the RDF Turtle file.')

args = parser.parse_args()

add_base_if_missing(args.file_path)
2 changes: 1 addition & 1 deletion brick_ontology.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

bacnet:BACnetDevice
a rdfs:Class ;
rdfs:label "BACnet device" ;
rdfs:label "BACnet device" ;
rdfs:subClassOf owl:Thing ;
.
bacnet:EngineeringUnitsEnumerationValue
Expand Down

0 comments on commit 83181e4

Please sign in to comment.