From f0022a25e1532cf0fe77e7ee603ad9372d9e903e Mon Sep 17 00:00:00 2001 From: khider <11758571+khider@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:38:09 -0700 Subject: [PATCH] get the properties attached to variable in LiPDSeries --- pylipd/globals/queries.py | 6 ++++++ pylipd/lipd_series.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pylipd/globals/queries.py b/pylipd/globals/queries.py index 9196a49..7a99736 100644 --- a/pylipd/globals/queries.py +++ b/pylipd/globals/queries.py @@ -436,6 +436,12 @@ } """ +## At the LiPDSeries level + +QUERY_LiPDSERIES_PROPERTIES=""" + SELECT DISTINCT ?p WHERE { + ?uri ?p ?v .} + """ QUERY_DATASET_PROPERTIES=""" PREFIX le: diff --git a/pylipd/lipd_series.py b/pylipd/lipd_series.py index 1791935..8958800 100644 --- a/pylipd/lipd_series.py +++ b/pylipd/lipd_series.py @@ -1,5 +1,5 @@ from tqdm import tqdm -from .globals.queries import QUERY_FILTER_VARIABLE_NAME, QUERY_VARIABLE, QUERY_DISTINCT_VARIABLE, QUERY_VARIABLE_ESSENTIALS, QUERY_DISTINCT_PROXY, QUERY_FILTER_VARIABLE_PROXY, QUERY_FILTER_VARIABLE_RESOLUTION +from .globals.queries import QUERY_FILTER_VARIABLE_NAME, QUERY_VARIABLE, QUERY_DISTINCT_VARIABLE, QUERY_VARIABLE_ESSENTIALS, QUERY_DISTINCT_PROXY, QUERY_FILTER_VARIABLE_PROXY, QUERY_FILTER_VARIABLE_RESOLUTION, QUERY_LiPDSERIES_PROPERTIES from .utils.multi_processing import multi_load_lipd_series from .utils.rdf_graph import RDFGraph @@ -174,6 +174,37 @@ def get_timeseries_essentials(self): qres_df['values']=qres_df['values'].apply(lambda row : np.array(json.loads(row))) return qres_df + + def get_variable_properties(self): + """ + Get a list of all the properties name associated with the dataset. Useful to write custom queries + + Returns + ------- + clean_list : list + A list of unique variable properties + + Examples + -------- + + .. jupyter-execute:: + + from pylipd.utils.dataset import load_dir + + lipd = load_dir() + S = lipd.to_lipd_series() + l = S.get_variable_properties() + + print(l) + + + """ + + query_list = self.query(QUERY_LiPDSERIES_PROPERTIES)[1].iloc[:,0].values.tolist() + clean_list = [item.split("#")[-1] for item in query_list] + + return clean_list + def filter_by_name(self, name): '''