Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
geopyck
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alice Brenon
geopyck
Commits
25558a3e
Commit
25558a3e
authored
1 year ago
by
Alice Brenon
Browse files
Options
Downloads
Patches
Plain Diff
Add a method to map over the content of a corpus
parent
96e294f8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GEODE/Store/Corpus.py
+19
-0
19 additions, 0 deletions
GEODE/Store/Corpus.py
with
19 additions
and
0 deletions
GEODE/Store/Corpus.py
+
19
−
0
View file @
25558a3e
...
...
@@ -67,6 +67,25 @@ class TSVIndexed(Corpus):
if
where
is
None
or
where
(
*
row
):
yield
projector
(
*
row
)
"""
A map over the content of a corpus with filter-capability
Positional arguments
:param function f: the function to apply on each text of the corpus. It must
accept a `row` as input (i.e. a `dict` containing the primary key for the
text and its content associated to the `column_name` attribute of the
corpus on which this method is called) and returning the transformed content
(or `None` if the text shouldn
'
t be kept)
:return: a generator over the transformed corpus, skipping elements for
which `f` returns `None`)
"""
def
map_content
(
self
,
f
):
for
row
in
self
.
get_all
():
newContent
=
f
(
row
)
if
newContent
is
not
None
:
yield
{
**
row
,
self
.
column_name
:
newContent
}
class
SelfContained
(
TSVIndexed
):
"""
A class to handle the dataset TSV normalised path used in the project and loading the
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment