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
fe5d9a9c
Commit
fe5d9a9c
authored
6 years ago
by
Victor Zimmermann
Browse files
Options
Downloads
Plain Diff
Resolve conflict
parents
fe6d70a7
0dbec5ef
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
allzweckmesser/meters.py
+16
-8
16 additions, 8 deletions
allzweckmesser/meters.py
allzweckmesser/model.py
+59
-2
59 additions, 2 deletions
allzweckmesser/model.py
with
75 additions
and
10 deletions
allzweckmesser/meters.py
+
16
−
8
View file @
fe5d9a9c
...
@@ -3,20 +3,28 @@
...
@@ -3,20 +3,28 @@
import
re
import
re
from
.model
import
Reading
from
.model
import
Reading
,
Position
def
caesurae_together
(
positions
,
reward
):
def
caesurae_together
(
position
_spec
s
,
reward
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
# TODO: Check if caesurae occur.
for
spec
in
position_specs
:
return
reward
position
=
Position
.
after
(
spec
[
0
],
reading
,
meter
,
spec
[
1
])
if
not
position
.
word_boundary
:
return
0
else
:
return
reward
return
get_reward
return
get_reward
def
bridge
(
position
,
reward
):
def
bridge
(
position
,
reward
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
def
get_reward
(
meter
:
Meter
,
reading
:
Reading
):
# TODO: Check if bridge occurs.
position
=
Position
.
after
(
position_spec
[
0
],
reading
,
meter
,
return
reward
position_spec
[
1
])
if
position
.
word_boundary
:
return
0
else
:
return
reward
return
get_reward
return
get_reward
...
@@ -32,7 +40,7 @@ class Meter:
...
@@ -32,7 +40,7 @@ class Meter:
self
.
short_name
=
short_name
self
.
short_name
=
short_name
def
match_reading
(
self
,
reading
:
Reading
):
def
match_reading
(
self
,
reading
:
Reading
):
return
re
.
match
(
self
.
schema
,
reading
.
get_
syllable_
schema
())
return
re
.
match
(
self
.
schema
,
reading
.
get_schema
())
def
get_rewards
(
self
,
reading
:
Reading
):
def
get_rewards
(
self
,
reading
:
Reading
):
return
sum
(
cond
(
reading
)
for
cond
in
self
.
conditions
)
return
sum
(
cond
(
reading
)
for
cond
in
self
.
conditions
)
...
@@ -45,7 +53,7 @@ ALL_METERS = [
...
@@ -45,7 +53,7 @@ ALL_METERS = [
conditions
=
{
conditions
=
{
caesurae_together
([(
'
mora
'
,
6
,
'
Trithemimeral
'
),
caesurae_together
([(
'
mora
'
,
6
,
'
Trithemimeral
'
),
(
'
mora
'
,
14
,
'
Hephthemimeral
'
)],
2
),
(
'
mora
'
,
14
,
'
Hephthemimeral
'
)],
2
),
caesurae_together
([(
'
mora
'
,
10
,
'
Penthemimeral
'
)],
1
),
caesurae_together
([(
'
mora
'
,
10
,
'
Penthemimeral
'
)],
2
),
caesurae_together
([(
'
mora
'
,
16
,
'
Bucolic Diaeresis
'
)],
1
),
caesurae_together
([(
'
mora
'
,
16
,
'
Bucolic Diaeresis
'
)],
1
),
bridge
((
'
mora
'
,
15
,
'
Hermann’s Bridge
'
),
1
)
bridge
((
'
mora
'
,
15
,
'
Hermann’s Bridge
'
),
1
)
},
},
...
...
This diff is collapsed.
Click to expand it.
allzweckmesser/model.py
+
59
−
2
View file @
fe5d9a9c
...
@@ -57,6 +57,7 @@ def minimal(full_dict:dict):
...
@@ -57,6 +57,7 @@ def minimal(full_dict:dict):
#print(result_dict)
#print(result_dict)
return
result_dict
return
result_dict
class
Syllable
:
class
Syllable
:
def
__init__
(
self
,
syllable
:
str
,
span
:
List
[
int
],
idx
:
int
,
def
__init__
(
self
,
syllable
:
str
,
span
:
List
[
int
],
idx
:
int
,
...
@@ -345,6 +346,17 @@ class Reading:
...
@@ -345,6 +346,17 @@ class Reading:
return
reading
return
reading
def
get_schema
(
self
):
schema_list
=
[]
for
token
in
self
.
tokens
:
for
syllable
in
token
.
syllables
:
if
syllable
.
syllable_length
==
1
:
schema_list
.
append
(
'
⏑
'
)
elif
syllable
.
syllable_length
==
2
:
schema_list
.
append
(
'
–
'
)
# If length == 0, don’t append a symbol.
return
''
.
join
(
schema_list
)
def
to_dict
(
self
):
def
to_dict
(
self
):
features
=
dict
()
features
=
dict
()
...
@@ -356,7 +368,6 @@ class Reading:
...
@@ -356,7 +368,6 @@ class Reading:
return
minimal
(
features
)
return
minimal
(
features
)
def
to_json
(
self
):
def
to_json
(
self
):
return
json
.
dumps
(
self
.
to_dict
())
return
json
.
dumps
(
self
.
to_dict
())
...
@@ -433,4 +444,50 @@ class Verse:
...
@@ -433,4 +444,50 @@ class Verse:
return
s
.
format
(
verse
=
self
.
text
,
reading_num
=
len
(
self
.
readings
),
return
s
.
format
(
verse
=
self
.
text
,
reading_num
=
len
(
self
.
readings
),
readings
=
readings_str
)
readings
=
readings_str
)
class
Position
:
def
__init__
(
self
,
reading
:
Reading
,
mora
:
int
,
word_boundary
:
bool
,
token
:
Token
,
syllable
:
Syllable
,
meter
:
'
.meters.Meter
'
=
None
,
element
:
int
=
None
):
self
.
reading
=
reading
self
.
mora
=
mora
self
.
word_boundary
=
word_boundary
self
.
meter
=
meter
self
.
element
=
element
@classmethod
def
after_mora
(
cls
,
reading
:
Reading
,
mora
:
int
)
->
'
Position
'
:
morae
=
0
position
=
None
for
token
in
reading
.
tokens
:
for
i
,
syllable
in
enumerate
(
token
.
syllables
):
word_boundary
=
i
==
0
if
morae
==
mora
:
position
=
cls
(
reading
=
reading
,
mora
=
mora
,
token
=
token
,
syllable
=
syllable
,
word_boundary
=
word_boundary
,
meter
=
meter
)
else
:
morae
+=
syllable
.
syllable_length
return
position
@classmethod
def
after_element
(
cls
,
reading
:
Reading
,
meter
:
'
.meters.Meter
'
,
element
:
int
)
->
'
Position
'
:
# TODO: Implement this.
pass
@classmethod
def
after
(
cls
,
type
:
str
,
reading
:
Reading
,
position_number
:
int
,
meter
:
'
.meters.Meter
'
)
->
'
Position
'
:
if
type
==
'
mora
'
:
return
cls
.
after_mora
(
*
args
,
reading
,
position_number
)
elif
type
==
'
element
'
:
return
cls
.
after_element
(
*
args
,
reading
,
meter
,
position_number
)
else
:
raise
ValueError
(
'
The after type has to be
"
mora
"
or
"
element
"
, but is {!r}
'
.
format
(
spec
)
)
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