From d87a9eaeae91e4ff6b84c825dc8fc2a32c3a129c Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:40:15 -0400 Subject: [PATCH] Revert "Remove parse" (#24) * Revert "Remove parse" This reverts commit 7d3caf8c1e09a68d832b25a2ff3866fda2e7a1c1. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pygeoapi_plugins/provider/sparql.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pygeoapi_plugins/provider/sparql.py b/pygeoapi_plugins/provider/sparql.py index fabbc3d..bbca140 100644 --- a/pygeoapi_plugins/provider/sparql.py +++ b/pygeoapi_plugins/provider/sparql.py @@ -315,7 +315,7 @@ def _combine(self, properties, results): for k, v in results.items(): # Join query results by key values = [ - item.get('value') if isinstance(item, dict) else item + self.parse(item.get('value') if isinstance(item, dict) else item) for item in (v if isinstance(v, list) else [v]) ] # Return item or list of items @@ -398,6 +398,23 @@ def delete(self, identifier): def __repr__(self): return f' {self.data}' + @staticmethod + def parse(value: str) -> list: + """ + Parse a string by splitting it on commas. + + :param value: `str` to be parsed. + + :returns: A `list` of strings if commas are present, + otherwise the original string. + """ + if '|' in value: + return value.split('|') + elif ', ' in value: + return value.split(', ') + else: + return value + @staticmethod def combine_lists(dict_data: dict): """