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
dea04d9f
Commit
dea04d9f
authored
6 years ago
by
Simon Will
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.cl.uni-heidelberg.de:Messerschleifer/Allzweckmesser
parents
e99aa6be
fe5d9a9c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
allzweckmesser/model.py
+4
-3
4 additions, 3 deletions
allzweckmesser/model.py
allzweckmesser/scanner.py
+65
-14
65 additions, 14 deletions
allzweckmesser/scanner.py
tests/test_model.py
+5
-3
5 additions, 3 deletions
tests/test_model.py
with
74 additions
and
20 deletions
allzweckmesser/model.py
+
4
−
3
View file @
dea04d9f
...
@@ -62,7 +62,7 @@ class Syllable:
...
@@ -62,7 +62,7 @@ class Syllable:
def
__init__
(
self
,
syllable
:
str
,
span
:
List
[
int
],
idx
:
int
,
def
__init__
(
self
,
syllable
:
str
,
span
:
List
[
int
],
idx
:
int
,
syllable_length
:
int
,
vowel_length
:
int
,
syllable_length
:
int
,
vowel_length
:
int
,
phenomena
:
dict
=
dict
()
):
phenomena
:
dict
=
None
):
if
len
(
syllable
)
!=
span
[
1
]
-
span
[
0
]:
if
len
(
syllable
)
!=
span
[
1
]
-
span
[
0
]:
raise
ValueError
(
'
Syllable length does not match syllable span.
'
)
raise
ValueError
(
'
Syllable length does not match syllable span.
'
)
else
:
else
:
...
@@ -71,7 +71,7 @@ class Syllable:
...
@@ -71,7 +71,7 @@ class Syllable:
self
.
id
=
idx
self
.
id
=
idx
self
.
syllable_length
=
syllable_length
self
.
syllable_length
=
syllable_length
self
.
vowel_length
=
vowel_length
self
.
vowel_length
=
vowel_length
self
.
phenomena
=
phenomena
self
.
phenomena
=
phenomena
or
dict
()
@classmethod
@classmethod
def
from_json
(
cls
,
json_file
):
def
from_json
(
cls
,
json_file
):
...
@@ -397,7 +397,7 @@ class Verse:
...
@@ -397,7 +397,7 @@ class Verse:
self
.
text
=
verse
self
.
text
=
verse
self
.
source
=
source
self
.
source
=
source
self
.
readings
=
readings
or
list
()
self
.
readings
=
readings
or
list
()
@classmethod
@classmethod
def
from_plain_verse
(
cls
,
plain_verse
):
def
from_plain_verse
(
cls
,
plain_verse
):
verse
=
cls
(
plain_verse
)
verse
=
cls
(
plain_verse
)
...
@@ -437,6 +437,7 @@ class Verse:
...
@@ -437,6 +437,7 @@ class Verse:
return
json
.
dumps
(
self
.
to_dict
())
return
json
.
dumps
(
self
.
to_dict
())
def
__str__
(
self
):
def
__str__
(
self
):
s
=
'
Verse: {verse}
\n
{reading_num} Readings:
\n
{readings}
'
s
=
'
Verse: {verse}
\n
{reading_num} Readings:
\n
{readings}
'
readings_str
=
'
\n
'
.
join
(
str
(
r
)
for
r
in
self
.
readings
)
readings_str
=
'
\n
'
.
join
(
str
(
r
)
for
r
in
self
.
readings
)
...
...
This diff is collapsed.
Click to expand it.
allzweckmesser/scanner.py
+
65
−
14
View file @
dea04d9f
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
copy
import
copy
import
re
import
re
from
typing
import
Dict
,
List
,
Set
,
Tuple
from
typing
import
Dict
,
List
,
Set
,
Tuple
from
itertools
import
product
from
.db
import
FormAnalysis
from
.db
import
FormAnalysis
from
.model
import
Reading
,
Syllable
,
Token
,
Verse
,
Phenomenon
from
.model
import
Reading
,
Syllable
,
Token
,
Verse
,
Phenomenon
...
@@ -253,32 +254,82 @@ def muta_cum_liquida(verse):
...
@@ -253,32 +254,82 @@ def muta_cum_liquida(verse):
if
syllable
.
span
[
0
]
<=
match
.
start
()
<
syllable
.
span
[
1
]:
if
syllable
.
span
[
0
]
<=
match
.
start
()
<
syllable
.
span
[
1
]:
syllable
.
phenomena
[
'
muta cum liquida
'
]
=
Phenomenon
(
chars
=
match
.
group
(
0
))
syllable
.
phenomena
[
'
muta cum liquida
'
]
=
Phenomenon
(
chars
=
match
.
group
(
0
))
def
positional_lengthening
(
verse
):
pl_regex
=
re
.
compile
(
r
'
[aeiouv](((([bcdfgjklmnprstvwxz]|(qu)),?\s?){2,})|[xz])
'
)
if
re
.
search
(
pl_regex
,
verse
.
text
):
matches
=
re
.
finditer
(
pl_regex
,
verse
.
text
)
for
match
in
matches
:
for
reading
in
verse
.
readings
:
for
token
in
reading
.
tokens
:
for
syllable
in
token
.
syllables
:
def
positional_lengthening
(
verse
):
if
syllable
.
span
[
0
]
<=
match
.
start
()
<
syllable
.
span
[
1
]:
syllable
.
phenomena
[
'
positional lengthening
'
]
=
Phenomenon
(
chars
=
match
.
group
(
1
))
muta_cum_liquida
(
verse
)
pl_regex
=
re
.
compile
(
r
'
[aeiouv]((([bcdfgjklmnprstvwxz]|(qu),?\s?){2,})|[xz])
'
)
def
parse_verse
(
verse
):
match_starts
=
[
match
.
start
()
for
match
in
re
.
finditer
(
pl_regex
,
verse
.
text
)]
"""
Annotates syllable lengths based on positional_lengthening and muta cum liquida
"""
positional_lengthening
(
verse
)
muta_cum_liquida
(
verse
)
new_readings
=
list
()
for
reading
in
verse
.
readings
:
for
reading
in
verse
.
readings
:
syllables
=
[
syllable
for
token
in
reading
.
tokens
syllables
=
[
syllable
for
token
in
reading
.
tokens
for
syllable
in
token
.
syllables
]
for
syllable
in
token
.
syllables
]
lengths
=
str
()
abstract
=
str
()
mcl_count
=
0
for
syllable
in
syllables
:
for
syllable
in
syllables
:
if
'
muta cum liquida
'
in
syllable
.
phenomena
:
if
'
muta cum liquida
'
in
syllable
.
phenomena
:
lengths
+=
'
M
'
abstract
+=
'
{}
'
elif
syllable
.
syllable_length
==
2
:
mcl_count
+=
1
lengths
+=
'
L
'
elif
'
positional lengthening
'
in
syllable
.
phenomena
:
elif
any
([
syllable
.
span
[
0
]
<=
start
<
syllable
.
span
[
1
]
abstract
+=
'
2
'
for
start
in
match_starts
])
:
elif
syllable
.
syllable_length
==
0
:
lengths
+=
'
L
'
abstract
+=
'
0
'
elif
syllable
.
syllable_length
==
1
:
elif
syllable
.
syllable_length
==
1
:
lengths
+=
'
S
'
abstract
+=
'
1
'
elif
syllable
.
syllable_length
==
2
:
print
(
lengths
)
abstract
+=
'
2
'
if
mcl_count
>
0
:
new_abstracts
=
list
()
combinations
=
list
(
product
([
'
1
'
,
'
2
'
],
repeat
=
mcl_count
))
for
combi
in
combinations
:
new_abstracts
.
append
(
abstract
.
format
(
*
combi
))
reading_copies
=
multiply_readings
([
reading
],
(
mcl_count
)
*
2
)
for
i
in
range
(
len
(
new_abstracts
)):
blueprint
=
new_abstracts
[
i
]
new_reading
=
reading_copies
[
i
]
syll_id
=
0
for
token
in
new_reading
.
tokens
:
for
s
in
token
.
syllables
:
if
blueprint
[
syll_id
]
==
"
1
"
:
s
.
syllable_length
=
1
if
'
positional lengthening
'
in
s
.
phenomena
and
'
muta cum liquida
'
in
s
.
phenomena
:
s
.
phenomena
[
'
positional lengthening
'
].
overruled_by
=
'
muta cum liquida
'
elif
blueprint
[
syll_id
]
==
"
2
"
:
s
.
syllable_length
=
2
syll_id
+=
1
new_readings
.
append
(
copy
.
deepcopy
(
new_reading
))
else
:
new_readings
.
append
(
copy
.
deepcopy
(
reading
))
return
new_readings
#for reading in verse.readings:
#for reading in verse.readings:
#for token in reading.tokens:
#for token in reading.tokens:
...
...
This diff is collapsed.
Click to expand it.
tests/test_model.py
+
5
−
3
View file @
dea04d9f
...
@@ -21,10 +21,12 @@ def test_import_json():
...
@@ -21,10 +21,12 @@ def test_import_json():
assert
verse_list_from_model
==
verse_list_from_json
assert
verse_list_from_model
==
verse_list_from_json
azm
.
scanner
.
muta_cum_liquida
(
verse_models
[
0
])
for
verse
in
verse_models
:
parsed_verses
=
azm
.
scanner
.
parse_verse
(
verse
)
for
verse_model
in
verse_models
[:
1
]:
for
verse_model
in
parsed_verses
:
print
(
json
.
dumps
(
json
.
loads
(
verse_model
.
to_json
()),
indent
=
4
,
sort_keys
=
True
))
#print(json.dumps(json.loads(verse_model.to_json()), indent=4, sort_keys=True))
pass
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
test_import_json
()
test_import_json
()
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