diff options
Diffstat (limited to 'gn3/db')
-rw-r--r-- | gn3/db/rdf.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gn3/db/rdf.py b/gn3/db/rdf.py index 3e8d513..21a5121 100644 --- a/gn3/db/rdf.py +++ b/gn3/db/rdf.py @@ -5,6 +5,9 @@ This module is a collection of functions that handle SPARQL queries. """ from typing import Tuple from string import Template +from urllib.parse import unquote +from urllib.parse import urlparse + from SPARQLWrapper import JSON, SPARQLWrapper from pymonad.maybe import Just from gn3.monads import MonadicDict @@ -37,6 +40,14 @@ def sparql_query( return (MonadicDict(),) +def strip_url(string: str) -> str: + """Get the last item after a '/" from a URL""" + if string.startswith("http"): + url = urlparse(string) + return unquote(url.path).rpartition("/")[-1] + return string + + def get_dataset_metadata( sparql_conn: SPARQLWrapper, name: str ) -> MonadicDict: |