Skip to content

Commit a2e0ad0

Browse files
committed
improved logic
1 parent 921cb4b commit a2e0ad0

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

trove/render/simple_csv.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
CardsearchParams,
1414
ValuesearchParams,
1515
)
16-
from trove.util.propertypath import Propertypath
16+
from trove.util.propertypath import Propertypath, GLOB_PATHSTEP
1717
from trove.vocab import mediatypes
1818
from trove.vocab import osfmap
1919
from trove.vocab.namespaces import TROVE
@@ -77,14 +77,14 @@ def first_page(self) -> dict[str, dict]:
7777
def _column_paths(self) -> Iterator[Propertypath]:
7878
_pathlists: list[Iterable[Propertypath]] = []
7979
if self.trove_params is not None: # hacks
80+
if GLOB_PATHSTEP in self.trove_params.attrpaths_by_type:
81+
_pathlists.append(self.trove_params.attrpaths_by_type['*'])
8082
if isinstance(self.trove_params, ValuesearchParams):
8183
_expected_card_types = set(self.trove_params.valuesearch_type_iris())
8284
elif isinstance(self.trove_params, CardsearchParams):
8385
_expected_card_types = set(self.trove_params.cardsearch_type_iris())
8486
else:
8587
_expected_card_types = set()
86-
if '*' in self.trove_params.attrpaths_by_type:
87-
_pathlists.append(self.trove_params.attrpaths_by_type['*'])
8888
for _type_iri in sorted(_expected_card_types, key=len):
8989
try:
9090
_pathlist = self.trove_params.attrpaths_by_type[_type_iri]
@@ -94,7 +94,15 @@ def _column_paths(self) -> Iterator[Propertypath]:
9494
_pathlists.append(_pathlist)
9595
if not _pathlists:
9696
_pathlists.append(osfmap.DEFAULT_TABULAR_SEARCH_COLUMN_PATHS)
97-
return itertools.chain.from_iterable(_pathlists)
97+
return self.iter_unique(itertools.chain.from_iterable(_pathlists))
98+
99+
@staticmethod
100+
def iter_unique(iterable):
101+
_seen = set()
102+
for _item in iterable:
103+
if _item not in _seen:
104+
_seen.add(_item)
105+
yield _item
98106

99107
def _iter_card_pages(self):
100108
assert not self._started

trove/util/trove_params.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from trove.util.propertypath import (
1616
PropertypathSet,
1717
Propertypath,
18-
parse_propertypath,
18+
parse_propertypath, GLOB_PATHSTEP,
1919
)
2020
from trove.util import queryparams as _qp
2121
from trove.vocab.namespaces import namespaces_shorthand
@@ -108,20 +108,19 @@ def _gather_attrpaths(cls, queryparams: _qp.QueryparamDict, shorthand: rdf.IriSh
108108
f'expected "fields[TYPE]" (with exactly one non-empty bracketed segment)'
109109
f' (got "{_param_name}")'
110110
)
111-
if _typenames == '*':
112-
wildcard_paths.extend(
113-
parse_propertypath(_path_value, shorthand)
114-
for _path_value in _qp.split_queryparam_value(_param_value)
115-
)
116111
else:
117112
for _type in _qp.split_queryparam_value(_typenames):
118-
_type_iri = shorthand.expand_iri(_type)
119-
_requested[_type_iri].extend(
120-
parse_propertypath(_path_value, shorthand)
121-
for _path_value in _qp.split_queryparam_value(_param_value)
113+
_type_key = (
114+
GLOB_PATHSTEP
115+
if _type == GLOB_PATHSTEP
116+
else shorthand.expand_iri(_type)
117+
)
118+
_requested[_type_key].extend(
119+
(
120+
parse_propertypath(_path_value, shorthand)
121+
for _path_value in _qp.split_queryparam_value(_param_value)
122+
)
122123
)
123-
if wildcard_paths:
124-
_requested['*'].extend(wildcard_paths)
125124
_attrpaths = _attrpaths.with_new(freeze(_requested))
126125
return _attrpaths
127126

0 commit comments

Comments
 (0)