Skip to content

Commit

Permalink
hxl-spec (#16) hxlm.core.hdp.project._recursive_resource_parsing() draft
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Mar 30, 2021
1 parent 1306d6c commit 3d2ba52
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hxlm/core/hdp/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class HDPIndex:
resource: ResourceWrapper
"""The ResourceWrapper from this item"""

hsilos: List['HSiloWrapper']

# ∂
hdp: InitVar[list] = []
"""List of HDP indexes files"""
Expand Down
2 changes: 2 additions & 0 deletions hxlm/core/hdp/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
HDPIndex
)

__all__ = ['convert_resource_to_hdpindex', 'is_index_hdp']

# TODO: move this to ontology
HDP_INDEX_ALLOWED = (
'∫', # ∫, ∬, ∭
Expand Down
43 changes: 43 additions & 0 deletions hxlm/core/hdp/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@
HDPRaw
)

from hxlm.core.hdp.index import (
# convert_resource_to_hdpindex,
is_index_hdp
)
from hxlm.core.hdp.raw import (
convert_resource_to_hdpraw,
is_raw_hdp_item_syntax,
ResourceWrapper
)

Expand Down Expand Up @@ -99,6 +104,12 @@ def __init__(self, entrypoint: Any, user_l10n: L10NContext):
self._parse_entrypoint(entrypoint)

def _parse_entrypoint(self, entrypoint: Any):
"""Generic parser for the initial entrypoint
Args:
entrypoint (Any): Anything that hxlm.core.io.util.get_entrypoint
is able to undestand.
"""
# TODO: at the moment, we're only parsing the raw input, but it should
# be loaded as an Silo

Expand All @@ -114,6 +125,7 @@ def _parse_entrypoint(self, entrypoint: Any):
self._log.append('_parse_entrypoint failed: input [' +
str(entrypoint) + '] ResourceWrapper log [ ' +
str(self._entrypoint.log) + ']')

hdpraw1 = self._parse_resource(self._entrypoint)

if hdpraw1.failed:
Expand All @@ -122,6 +134,37 @@ def _parse_entrypoint(self, entrypoint: Any):
str(entrypoint) + '] HDPRaw log [ ' +
str(hdpraw1.log) + ']')

def _recursive_resource_parsing(
self,
resource: ResourceWrapper) -> 'HDPProject':
"""Method to do recursive parsing of files.
While the simplest case (load a simple HDP file) may already have more
than one HSilo, the fact that we allow HDPIndex files have
_interesting_ usages, in special because both for performance and
privacy of the user, full automated parsing may not be the default
case
Returns:
[HDPProject]: An instance of this class itself
"""
# TODO: _recursive_hdp_parsing is an draft and should be implemented.
if resource.failed:
self.ok = False
self._log.append('resource.failed: [' + str(resource) + ']')
elif is_index_hdp(resource.content):
print('TODO: is_index_hdp')

elif is_raw_hdp_item_syntax(resource.content):
print('TODO: is_index_hdp')
else:
self.ok = False
self._log.append(
'resource ¬ (is_index_hdp | is_raw_hdp_item_syntax) ['
+ str(resource) + ']')

return self

def _parse_resource(self, resource: ResourceWrapper) -> bool:
hdpraw = convert_resource_to_hdpraw(resource)
self.hdpraw.append(hdpraw)
Expand Down

0 comments on commit 3d2ba52

Please sign in to comment.