Skip to content

Commit

Permalink
rename existing function to dataset_names
Browse files Browse the repository at this point in the history
ids are something different in LiDP now
  • Loading branch information
khider committed Feb 18, 2023
1 parent dc53141 commit 5329553
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions pylipd/lipd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LiPD:
lipd = LiPD()
lipd.load(["https://lipdverse.org/data/LCf20b99dfe8d78840ca60dfb1f832b9ec/1_0_1//Nunalleq.Ledger.2018.lpd"])
ts_list = lipd.get_timeseries(lipd.get_all_dataset_ids())
ts_list = lipd.get_timeseries(lipd.get_all_dataset_names())
for dsid, tsos in ts_list.items():
for tso in tsos:
Expand Down Expand Up @@ -80,7 +80,7 @@ def load_from_dir(self, dir_path, collection_id=None):
lipd = LiPD()
lipd.load_from_dir("../examples/data")
print(lipd.get_all_dataset_ids())
print(lipd.get_all_dataset_names())
'''
if not os.path.isdir(dir_path):
print(f"Directory {dir_path} does not exist")
Expand Down Expand Up @@ -127,7 +127,7 @@ def load(self, lipdfiles, collection_id=None):
"https://lipdverse.org/data/LCf20b99dfe8d78840ca60dfb1f832b9ec/1_0_1/Nunalleq.Ledger.2018.lpd"
])
print(lipd.get_all_dataset_ids())
print(lipd.get_all_dataset_names())
'''
if type(lipdfiles) is not list:
lipdfiles = [lipdfiles]
Expand Down Expand Up @@ -181,7 +181,7 @@ def set_endpoint(self, endpoint):
lipd_remote = LiPD()
lipd_remote.set_endpoint("https://linkedearth.graphdb.mint.isi.edu/repositories/LiPDVerse2")
lipd_remote.load_remote_datasets(["Ocn-MadangLagoonPapuaNewGuinea.Kuhnert.2001", "MD98_2181.Stott.2007", "Ant-WAIS-Divide.Severinghaus.2012"])
print(lipd_remote.get_all_dataset_ids())
print(lipd_remote.get_all_dataset_names())
'''
self.remote = True
Expand Down Expand Up @@ -302,14 +302,22 @@ def query(self, query, result="sparql"):

return result, result_df

def load_remote_datasets(self, dsids):
# def whatArchive(self):

# archive_query = """PREFIX le: <http://linked.earth/ontology#>
# select ?archiveType (count(distinct ?archiveType) as ?count) where {
# ?ds a le:Dataset .
# ?ds le:hasUrl ?url
# }"""

def load_remote_datasets(self, dsnames):
'''Loads remote datasets into cache if a remote endpoint is set
Parameters
----------
dsids : array
array of dataset id strings
dsnames : array
array of dataset names
Examples
--------
Expand All @@ -325,16 +333,16 @@ def load_remote_datasets(self, dsids):
lipd_remote = LiPD()
lipd_remote.set_endpoint("https://linkedearth.graphdb.mint.isi.edu/repositories/LiPDVerse2")
lipd_remote.load_remote_datasets(["Ocn-MadangLagoonPapuaNewGuinea.Kuhnert.2001", "MD98_2181.Stott.2007", "Ant-WAIS-Divide.Severinghaus.2012"])
print(lipd_remote.get_all_dataset_ids())
print(lipd_remote.get_all_dataset_names())
'''
if not self.remote or not self.endpoint:
raise Exception("No remote endpoint")

if dsids == None or len(dsids) == 0:
raise Exception("No dataset ids to cache")
dsidstr = (' '.join('<' + NSURL + "/" + dsid + '>' for dsid in dsids))
if dsnames == None or len(dsnames) == 0:
raise Exception("No dataset names to cache")
dsnamestr = (' '.join('<' + NSURL + "/" + dsname + '>' for dsname in dsnames))
print("Caching datasets from remote endpoint..")
qres = self.query(f"SELECT ?s ?p ?o ?g WHERE {{ GRAPH ?g {{ ?s ?p ?o }} VALUES ?g {{ {dsidstr} }} }}")
qres = self.query(f"SELECT ?s ?p ?o ?g WHERE {{ GRAPH ?g {{ ?s ?p ?o }} VALUES ?g {{ {dsnamestr} }} }}")

# Reinitialize graph
self.initialize_graph()
Expand All @@ -350,7 +358,7 @@ def get_timeseries(self, dsids):
----------
dsids : array
array of dataset id strings
array of dataset id or name strings
Examples
--------
Expand Down Expand Up @@ -426,7 +434,7 @@ def get_lipd(self, dsid):
converter = RDFToLiPD()
return converter.convert(dsid, self.graph)

def get_all_dataset_ids(self):
def get_all_dataset_names(self):
query = f"""
SELECT ?dsname WHERE {{
?ds a le:Dataset .
Expand Down
2 changes: 1 addition & 1 deletion pylipd/tests/test_LiPD.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_get_timeseries_t0(self):
if __name__=="__main__":
lipd = LiPD()
lipd.load(url)
ts_list=lipd.get_timeseries(lipd.get_dataset_ids())
ts_list=lipd.get_timeseries(lipd.get_dataset_names())

class TestLiPDquery():

Expand Down

0 comments on commit 5329553

Please sign in to comment.