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
470ef76f
Commit
470ef76f
authored
6 years ago
by
Simon Will
Browse files
Options
Downloads
Patches
Plain Diff
Add script for extracting meters from Hypotactic
parent
c3aab459
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
scripts/extract_meters.py
+59
-0
59 additions, 0 deletions
scripts/extract_meters.py
with
59 additions
and
0 deletions
scripts/extract_meters.py
0 → 100644
+
59
−
0
View file @
470ef76f
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import
argparse
from
collections
import
defaultdict
import
json
import
allzweckmesser
as
azm
def
main
(
hypotactic_dir
,
outfile
):
corpus
=
azm
.
corpus
.
HypotacticCorpus
.
from_directory
(
hypotactic_dir
)
poem_meters
=
defaultdict
(
lambda
:
[
set
(),
0
])
line_meters
=
defaultdict
(
lambda
:
[
set
(),
0
])
for
document
in
corpus
.
documents
:
print
(
'
Processing {}
'
.
format
(
document
.
title
))
has_poems
=
False
for
poem
in
document
.
get_poems
():
has_poems
=
True
meters
=
[
c
for
c
in
poem
.
attrs
[
'
class
'
]
if
c
!=
'
poem
'
]
for
meter
in
meters
:
poem_meters
[
meter
][
0
].
add
(
document
.
title
)
poem_meters
[
meter
][
1
]
+=
1
line_meters
[
meter
][
0
].
add
(
document
.
title
)
line_meters
[
meter
][
1
]
+=
len
(
poem
.
find_all
(
name
=
'
div
'
,
class_
=
'
line
'
))
if
not
has_poems
:
for
line
in
document
.
get_lines
():
meters
=
[
c
for
c
in
line
.
attrs
[
'
class
'
]
if
c
!=
'
line
'
]
for
meter
in
meters
:
line_meters
[
meter
][
0
].
add
(
document
.
title
)
line_meters
[
meter
][
1
]
+=
1
print
(
'
Meters: {}
'
.
format
(
set
(
poem_meters
.
keys
()).
union
(
line_meters
.
keys
())))
for
pair
in
poem_meters
.
values
():
pair
[
0
]
=
list
(
pair
[
0
])
for
pair
in
line_meters
.
values
():
pair
[
0
]
=
list
(
pair
[
0
])
with
open
(
outfile
,
'
w
'
)
as
f
:
obj
=
{
'
poem_meters
'
:
poem_meters
,
'
line_meters
'
:
line_meters
}
json
.
dump
(
obj
,
f
,
indent
=
2
)
def
parse_args_and_main
():
d
=
'
Extract occurring meters from a Hypotactic corpus
'
parser
=
argparse
.
ArgumentParser
(
description
=
d
)
parser
.
add_argument
(
'
hypotactic_dir
'
,
help
=
'
Top level directory of the Hypotactic corpus
'
)
parser
.
add_argument
(
'
outfile
'
,
help
=
'
File to save the lines in
'
)
args
=
parser
.
parse_args
()
main
(
**
vars
(
args
))
if
__name__
==
'
__main__
'
:
parse_args_and_main
()
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