Skip to content

Commit

Permalink
Simplify prefix generation for a URL, and fix the bug in the generati…
Browse files Browse the repository at this point in the history
…on where a URI uses a fragment to split identifiers. (#236)
  • Loading branch information
ashleysommer authored Jun 28, 2024
1 parent 212ac34 commit 4f43cf8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions prez/services/curie_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ def generate_new_prefix(uri):
Generates a new prefix for a uri
"""
parsed_url = urlparse(uri)
to_generate_prefix_from = ""
if bool(parsed_url.fragment):
ns = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}#"
to_generate_prefix_from = parsed_url.fragment.lower()
else:
ns = f'{parsed_url.scheme}://{parsed_url.netloc}{"/".join(parsed_url.path.split("/")[:-1])}/'
split_path = parsed_url.path.split("/")
if len(split_path) > 1:
to_generate_prefix_from = split_path[-2].lower()
if to_generate_prefix_from:
ns = f'{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path.rsplit("/", 1)[0]}/'

split_prefix_path = ns[:-1].rsplit('/', 1)
if len(split_prefix_path) > 1:
to_generate_prefix_from = split_prefix_path[-1].lower()
# attempt to just use the last part of the path prior to the fragment or "identifier"
if len(to_generate_prefix_from) <= 6:
proposed_prefix = to_generate_prefix_from
Expand Down

0 comments on commit 4f43cf8

Please sign in to comment.