Skip to content

Commit

Permalink
Fix on Mapper on loading file(s)
Browse files Browse the repository at this point in the history
Change-Id: Id49ab71917d1efed3886ffa6eccb9dc1c09e11c2
  • Loading branch information
pafonta committed Feb 5, 2020
1 parent 0e91d85 commit 77d8f0e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions kgforge/core/archetypes/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ def map(self, data: Any, mapping: Mapping) -> Union[Resource, List[Resource]]:
# Data could be loaded from a directory, a file, a collection or an object.
if isinstance(data, str):
path = Path(data)
reader = self.reader()
if path.is_dir():
# Could be optimized by overriding the method in the specialization.
records = []
for x in path.iterdir():
with x.open() as f:
record = reader(f)
record = self.reader(f)
records.append(record)
return self._map_many(records, mapping)
else:
with path.open() as f:
record = reader(f)
record = self.reader(f)
return self._map_one(record, mapping)
elif isinstance(data, (Sequence, Iterator)):
# NB: Do not use 'Iterable' for checking type because a Dict is an Iterable.
Expand Down

0 comments on commit 77d8f0e

Please sign in to comment.