Skip to content

Commit

Permalink
Create update_alias_register.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ghobona committed Dec 6, 2023
1 parent 084f34b commit b294314
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions incubation/geosparql/second_attempt/update_alias_register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os, re
import rdflib
import requests
from rdflib.namespace import DC, DCTERMS, DOAP, FOAF, SKOS, OWL, RDF, RDFS, VOID, XMLNS, XSD

'''
pip3 install rdflib
pip3 install requests
'''

fout = open('/Users/gobehobona/Documents/GitHub/NamingAuthority/incubation/geosparql/20231206_url_statuses.csv','w')


path = "/Users/gobehobona/Documents/GitHub/NamingAuthority/incubation/geosparql/second_attempt/triples_to_add"

g = rdflib.Graph()

for dirpath, subdirs, files in os.walk(path):
for name in files:
if name.endswith(".ttl"):
print(os.path.join(dirpath, name))
g.parse(os.path.join(dirpath, name))


#g.serialize(destination="/Users/gobehobona/Documents/GitHub/NamingAuthority/incubation/geosparql/20231206_insert_aliases.nt",format="nt")


#g1 = rdflib.Graph()
#g1.parse("file:///Users/gobehobona/Documents/GitHub/NamingAuthority/incubation/geosparql/20231206_insert_aliases.nt")


knows_query = """
SELECT DISTINCT ?subject {
?subject ?predicate ?object
FILTER (isURI(?subject) && STRSTARTS(str(?subject), str('http://www.opengis.net/def/') ) )
}"""

all_def_uris = []

qres = g.query(knows_query)
for row in qres:
all_def_uris.append(f"{row.subject}")

for subject in all_def_uris:
print(subject)
r = requests.head(str(subject))
if r.status_code == 303:
r2 = requests.head(r.headers['Location'])
if not(r2.status_code==200):
fout.write(str(r2.status_code)+","+str(r.headers['Location']).replace('&_mediatype=text/turtle','').replace('http://defs.opengis.net/vocprez/object?uri=','')+"\n")


fout.close()

0 comments on commit b294314

Please sign in to comment.