Skip to content

Commit 40f9d79

Browse files
committed
hxlm (#11): re-enabled hdpcli --non-urn & hdpcli --verum-urn
1 parent 6859bd8 commit 40f9d79

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

hxlm/core/bin/hdpcli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def make_args_urnresolver(self):
519519

520520
parser.add_argument(
521521
'--non-urn',
522-
help='(draft) Filter by except URN pattern. ' +
522+
help='Filter by except URN pattern. ' +
523523
'Use values based on strings defined on HDP file.',
524524
action='store',
525525
default=None,
@@ -623,7 +623,7 @@ def make_args_urnresolver(self):
623623

624624
parser.add_argument(
625625
'--verum-urn',
626-
help='(draft) Filter by URN pattern. ' +
626+
help='Filter by URN pattern.' +
627627
'Use values based on strings defined on HDP file.',
628628
action='store',
629629
default=None,

hxlm/core/model/hdp.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import os
12+
import re
1213
from urllib.request import urlopen
1314

1415
from typing import (
@@ -123,7 +124,7 @@ def _get_hsilo_urn(self, hsilo_object: dict,
123124
suffix = ''
124125
if container_item_index > 0:
125126
suffix = '-' + str(container_item_index)
126-
return ('urn:oo:hsilo:' + domain_base + ':' +
127+
return ('urn:hdp:oo:hsilo:' + domain_base + ':' +
127128
container_base + suffix)
128129

129130
def _update(self, hdp_rules: Union[List, dict],
@@ -178,6 +179,13 @@ def _get_filtered(self, hdp_filters: dict = None) -> dict:
178179
if self._debug:
179180
print('HDP._get_filtered hdp_filters', hdp_filters)
180181

182+
if 'verum_urn' in hdp_filters:
183+
filtered = self._get_filtered_urn(
184+
filtered, hdp_filters['verum_urn'])
185+
if 'non_urn' in hdp_filters:
186+
filtered = self._get_filtered_urn(
187+
filtered, hdp_filters['non_urn'], False)
188+
181189
if 'verum_grupum' in hdp_filters:
182190
filtered = self._get_filtered_grupum(
183191
filtered, hdp_filters['verum_grupum'])
@@ -229,6 +237,52 @@ def _get_filtered_grupum(self, hdp_current: dict,
229237
# or grupum not in hdpgroup.hsilo.grupum):
230238
return hdp_result
231239

240+
def _get_filtered_urn(self, hdp_current: dict,
241+
urn_regex: str, present: bool = True) -> dict:
242+
"""Filter (present/absent) urn_regex on hdp_current subnamespace
243+
244+
Args:
245+
hdp_current (dict): HDP current internal representation
246+
urn_regex (str): urn (group) to filter
247+
present (bool, optional): If the grupum must be present (True) or
248+
is an inverse filter (absent). Defaults to True.
249+
250+
Returns:
251+
dict: Filtered result
252+
"""
253+
if self._debug:
254+
print('HDP._get_filtered_urn', urn_regex, present, hdp_current)
255+
256+
if len(hdp_current) == 0:
257+
return hdp_current
258+
259+
hdp_result = deepcopy(hdp_current)
260+
261+
try:
262+
pattern = re.compile(urn_regex)
263+
264+
for hdpns in hdp_current:
265+
# print('ooooi', hdpns, pattern,
266+
# re.search(pattern, hdpns), present)
267+
# print('ooooi2', re.search(pattern, hdpns) is not None)
268+
if re.search(pattern, hdpns) is not None:
269+
if present:
270+
continue
271+
else:
272+
if not present:
273+
continue
274+
275+
deleteditem = hdp_result.pop(hdpns, None)
276+
if self._debug:
277+
print('HDP._get_filtered_urn deleteditem', deleteditem)
278+
except Exception as e:
279+
print("HDP._get_filtered_urn:An exception occurred", e)
280+
print('Did the regex is valid? urn_regex [ ' + urn_regex + ' ]')
281+
print('ABORTING')
282+
return False
283+
284+
return hdp_result
285+
232286
def _prepare(self, hdp_entry_point: str, is_startup: bool = False) -> bool:
233287

234288
if self._debug:

tests/manual-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ hdpcli --export-to-hxl-json-processing-specs https://raw.githubusercontent.com/E
2121
hdpcli https://raw.githubusercontent.com/EticaAI/HXL-Data-Science-file-formats/main/tests/hxl-processing-specs/hxl-processing-specs-test-01.hdp.yml
2222
hdpcli tests/hrecipe/hello-world.hrecipe.hdp.yml --non-grupum hello-world
2323
hdpcli tests/hrecipe/hello-world.hrecipe.hdp.yml --verum-grupum hello-world
24+
hdpcli tests/hrecipe/yemen-01.hrecipe.hdp.yml --verum-urn yemen
25+
hdpcli tests/hrecipe/hello-world.hrecipe.hdp.yml --verum-urn hello-world --verum-grupum hello-world
26+
2427

2528
# To inspect the result (pretty print)
2629
hdpcli --export-to-hxl-json-processing-specs tests/hxl-processing-specs/hxl-processing-specs-test-01.hdp.yml

0 commit comments

Comments
 (0)