aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-06-02 21:29:43 +0300
committerBonfaceKilz2023-06-02 21:44:19 +0300
commitea0dd0dc21a659105f25f22fc8624849890de99e (patch)
tree575dac87e1e7ec3b113bc69c165e120e64beda62
parentdfc43506047d9fbb25f5ce5328f6743da891ca97 (diff)
downloadgenenetwork3-ea0dd0dc21a659105f25f22fc8624849890de99e.tar.gz
Create a function for stripping the last bit from a URL
* gn3/db/rdf.py: Import unquote and urlparse. (strip_url): New function. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/db/rdf.py11
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: