Skip to content

Commit

Permalink
get the properties attached to variable in LiPDSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
khider committed Jul 29, 2024
1 parent 8c82257 commit f0022a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pylipd/globals/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@
}
"""

## At the LiPDSeries level

QUERY_LiPDSERIES_PROPERTIES="""
SELECT DISTINCT ?p WHERE {
?uri ?p ?v .}
"""

QUERY_DATASET_PROPERTIES="""
PREFIX le: <http://linked.earth/ontology#>
Expand Down
33 changes: 32 additions & 1 deletion pylipd/lipd_series.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
'''
Expand Down

0 comments on commit f0022a2

Please sign in to comment.