Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Allzweckmesser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Messerschleifer
Allzweckmesser
Commits
17b94014
Commit
17b94014
authored
6 years ago
by
Simon Will
Browse files
Options
Downloads
Patches
Plain Diff
Add methods for filtering on meters to corpus.py
parent
426c377f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
allzweckmesser/corpus.py
+23
-5
23 additions, 5 deletions
allzweckmesser/corpus.py
with
23 additions
and
5 deletions
allzweckmesser/corpus.py
+
23
−
5
View file @
17b94014
...
...
@@ -91,6 +91,18 @@ class HypotacticDocument:
if
all
(
fil
(
line
)
for
fil
in
line_filters
)
)
def
get_lines_with_meter
(
self
,
meters
):
filters
=
[
lambda
tag
:
any
((
meter
in
tag
.
attrs
[
'
class
'
])
for
meter
in
meters
)]
if
self
.
root
.
find
(
name
=
'
div
'
,
class_
=
'
poem
'
):
yield
from
(
line
for
poem
in
self
.
get_poems
(
filters
)
for
line
in
poem
.
find_all
(
name
=
'
div
'
,
class_
=
'
line
'
)
)
else
:
self
.
get_lines
(
filters
)
class
HypotacticCorpus
:
...
...
@@ -121,12 +133,14 @@ class HypotacticCorpus:
)
def
get_lines_with_meter
(
self
,
meters
):
filters
=
[
lambda
line
:
any
((
meter
in
line
.
attrs
[
'
class
'
])
for
meter
in
meters
)]
yield
from
self
.
get_lines
(
filters
)
yield
from
(
line
for
doc
in
self
.
documents
for
line
in
doc
.
get_lines_with_meter
(
meters
)
)
def
save_lines
(
self
,
file_handle
,
lines
,
title
=
'
Saved Poems
'
,
base_html
=
BASE_HTML
):
base_html
=
BASE_HTML
,
pretty
=
False
):
soup
=
BeautifulSoup
(
base_html
,
self
.
parser
)
title_tag
=
soup
.
new_tag
(
'
title
'
)
...
...
@@ -139,4 +153,8 @@ class HypotacticCorpus:
latin
.
append
(
line
)
soup
.
find
(
name
=
'
body
'
).
append
(
latin
)
file_handle
.
write
(
soup
.
prettify
())
if
pretty
:
output
=
soup
.
prettify
()
else
:
output
=
str
(
soup
)
file_handle
.
write
(
output
)
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