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
44a86f03
Commit
44a86f03
authored
6 years ago
by
Victor Zimmermann
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.cl.uni-heidelberg.de:Messerschleifer/Allzweckmesser
parents
d152f9e6
be0aa59a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
allzweckmesser/scanner.py
+31
-9
31 additions, 9 deletions
allzweckmesser/scanner.py
tests/test_scanner.py
+21
-21
21 additions, 21 deletions
tests/test_scanner.py
with
52 additions
and
30 deletions
allzweckmesser/scanner.py
+
31
−
9
View file @
44a86f03
...
...
@@ -90,6 +90,28 @@ def tokenize(plain_verse: str) -> List[Token]:
return
tokens
def
blow_up_accented
(
accented
):
matches
=
list
(
re
.
finditer
(
r
'
[_^]{2}
'
,
accented
))
if
matches
:
# Generate blueprint.
blueprint
=
[
accented
[:
matches
[
0
].
start
()]]
for
m
in
matches
:
blueprint
.
append
(
'
{}
'
)
blueprint
=
''
.
join
(
blueprint
)
# Fill blueprint with variants of accented form.
combinations
=
product
([
0
,
1
],
repeat
=
len
(
matches
))
blown_up
=
[]
for
combi
in
combinations
:
format_args
=
[
'
_
'
if
i
==
1
else
'
^
'
for
i
in
combi
]
blown_up
.
append
(
blueprint
.
format
(
*
format_args
))
else
:
# The accented is form is unambiguous.
blown_up
=
[
accented
]
return
blown_up
def
condense_analyses
(
analyses
:
Set
[
FormAnalysis
])
->
Dict
[
str
,
Dict
[
str
,
Set
[
str
]]]:
"""
Condense analyses objects into a nested dict representation.
...
...
@@ -101,13 +123,14 @@ def condense_analyses(
"""
condensed
=
{}
for
a
in
analyses
:
if
a
.
accented
in
condensed
:
if
a
.
lemma
in
condensed
[
a
.
accented
]:
condensed
[
a
.
accented
][
a
.
lemma
].
add
(
a
.
morphtag
)
for
accented
in
blow_up_accented
(
a
.
accented
):
if
accented
in
condensed
:
if
a
.
lemma
in
condensed
[
accented
]:
condensed
[
accented
][
a
.
lemma
].
add
(
a
.
morphtag
)
else
:
condensed
[
accented
][
a
.
lemma
]
=
{
a
.
morphtag
}
else
:
condensed
[
a
.
accented
][
a
.
lemma
]
=
{
a
.
morphtag
}
else
:
condensed
[
a
.
accented
]
=
{
a
.
lemma
:
{
a
.
morphtag
}}
condensed
[
accented
]
=
{
a
.
lemma
:
{
a
.
morphtag
}}
return
condensed
...
...
@@ -337,7 +360,7 @@ def get_syllables(reading):
def
muta_cum_liquida
(
verse
):
mcl_regex
=
re
.
compile
(
r
'
[aeiouv](([bpsckgdt]|(qu)|(qv))
,
?\s?[lrmn])([aeiouv]|[.?!]|$)
'
,
flags
=
re
.
IGNORECASE
)
mcl_regex
=
re
.
compile
(
r
'
[aeiouv](([bpsckgdt]|(qu)|(qv))
[,.!?]
?\s?[lrmn])([aeiouv]|[.?!]|$)
'
,
flags
=
re
.
IGNORECASE
)
if
re
.
search
(
mcl_regex
,
verse
.
text
):
matches
=
re
.
finditer
(
mcl_regex
,
verse
.
text
)
...
...
@@ -352,7 +375,7 @@ def muta_cum_liquida(verse):
def
positional_lengthening
(
verse
):
pl_regex
=
re
.
compile
(
r
'
[aeiouv](((([bcdfgjklmnprstvwxz]|(qu))
,
?\s?){2,})|[xz])
'
,
flags
=
re
.
IGNORECASE
)
pl_regex
=
re
.
compile
(
r
'
[aeiouv](((([bcdfgjklmnprstvwxz]|(qu))
[,.!?]
?\s?){2,})|[xz])
'
,
flags
=
re
.
IGNORECASE
)
if
re
.
search
(
pl_regex
,
verse
.
text
):
matches
=
re
.
finditer
(
pl_regex
,
verse
.
text
)
...
...
@@ -390,7 +413,6 @@ def make_elisions(verse):
return
verse
def
parse_verse
(
verse
):
"""
Annotates syllable lengths based on positional_lengthening and muta cum liquida
...
...
This diff is collapsed.
Click to expand it.
tests/test_scanner.py
+
21
−
21
View file @
44a86f03
...
...
@@ -50,10 +50,30 @@ def test_get_clitic():
assert
azm
.
scanner
.
get_clitic
(
'
querela
'
)
==
(
'
querela
'
,
None
)
def
test_condense_analyses
():
ancilla_analyses
=
{
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fb-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla_
'
),
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fn-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla
'
),
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fv-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla
'
)
}
condensed
=
azm
.
scanner
.
condense_analyses
(
ancilla_analyses
)
assert
isinstance
(
condensed
,
dict
)
assert
all
(
isinstance
(
accented
,
str
)
and
isinstance
(
lemma_to_morphtags
,
dict
)
for
accented
,
lemma_to_morphtags
in
condensed
.
items
())
assert
condensed
==
{
'
ancilla
'
:
{
'
ancilla
'
:
{
'
n-s---fn-
'
,
'
n-s---fv-
'
}},
'
ancilla_
'
:
{
'
ancilla
'
:
{
'
n-s---fb-
'
}}
}
def
test_lemmatize
(
tokenized_verses
,
word_list
):
readings
=
azm
.
scanner
.
lemmatize
(
word_list
,
azm
.
model
.
Reading
(
tokenized_verses
[
0
]))
assert
len
(
readings
)
==
1
assert
len
(
readings
)
==
2
assert
all
(
len
(
r
)
==
len
(
tokenized_verses
[
0
])
for
r
in
readings
)
readings
=
azm
.
scanner
.
lemmatize
(
word_list
,
...
...
@@ -71,23 +91,3 @@ def test_multiply_readings(tokenized_verses):
multiplied_readings
=
azm
.
scanner
.
multiply_readings
(
readings
,
4
)
assert
len
(
multiplied_readings
)
==
4
assert
all
(
len
(
reading
)
==
reading_len
for
reading
in
multiplied_readings
)
def
test_condense_analyses
():
ancilla_analyses
=
{
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fb-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla_
'
),
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fn-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla
'
),
FormAnalysis
(
form
=
'
ancilla
'
,
morphtag
=
'
n-s---fv-
'
,
lemma
=
'
ancilla
'
,
accented
=
'
ancilla
'
)
}
condensed
=
azm
.
scanner
.
condense_analyses
(
ancilla_analyses
)
assert
isinstance
(
condensed
,
dict
)
assert
all
(
isinstance
(
accented
,
str
)
and
isinstance
(
lemma_to_morphtags
,
dict
)
for
accented
,
lemma_to_morphtags
in
condensed
.
items
())
assert
condensed
==
{
'
ancilla
'
:
{
'
ancilla
'
:
{
'
n-s---fn-
'
,
'
n-s---fv-
'
}},
'
ancilla_
'
:
{
'
ancilla
'
:
{
'
n-s---fb-
'
}}
}
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