Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
DHParser
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
badw-it
DHParser
Commits
c94ebe9f
Commit
c94ebe9f
authored
Feb 08, 2018
by
di68kap
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- MLW automatische Verdichtung
parent
13309219
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
271 additions
and
37 deletions
+271
-37
DHParser/parse.py
DHParser/parse.py
+2
-1
DHParser/syntaxtree.py
DHParser/syntaxtree.py
+4
-4
examples/MLW/Beispiele/facitergula/MLW.css
examples/MLW/Beispiele/facitergula/MLW.css
+26
-7
examples/MLW/Beispiele/facitergula/fascitergula.mlw
examples/MLW/Beispiele/facitergula/fascitergula.mlw
+2
-1
examples/MLW/Beispiele/imperium/MLW.css
examples/MLW/Beispiele/imperium/MLW.css
+8
-2
examples/MLW/CSS/MLW.css
examples/MLW/CSS/MLW.css
+26
-7
examples/MLW/MLW.ebnf
examples/MLW/MLW.ebnf
+1
-1
examples/MLW/MLWCompiler.py
examples/MLW/MLWCompiler.py
+52
-13
examples/MLW/VERALTET/MLW.css
examples/MLW/VERALTET/MLW.css
+147
-0
examples/MLW/verarbeite_Beispiele.py
examples/MLW/verarbeite_Beispiele.py
+3
-1
No files found.
DHParser/parse.py
View file @
c94ebe9f
...
...
@@ -1991,7 +1991,8 @@ class Compiler:
all those node types for which no compiler method `on_XXX` has
been defined."""
if
node
.
children
:
node
.
result
=
tuple
(
self
.
compile
(
nd
)
for
nd
in
node
.
children
)
result
=
tuple
(
self
.
compile
(
nd
)
for
nd
in
node
.
children
)
node
.
result
=
result
return
node
def
compile
(
self
,
node
:
Node
)
->
Any
:
...
...
DHParser/syntaxtree.py
View file @
c94ebe9f
...
...
@@ -216,8 +216,8 @@ class Node(collections.abc.Sized):
stage and never during or after the AST-transformation.
"""
__slots__
=
[
'_result'
,
'children'
,
'_errors'
,
'_len'
,
'_pos'
,
'parser'
,
'error_flag'
]
__slots__
=
[
'_result'
,
'children'
,
'_errors'
,
'_len'
,
'_pos'
,
'parser'
,
'error_flag'
,
'_xml_attr'
]
def
__init__
(
self
,
parser
,
result
:
ResultType
,
leafhint
:
bool
=
False
)
->
None
:
"""
...
...
@@ -550,8 +550,8 @@ class Node(collections.abc.Sized):
"""Returns the opening string for the representation of `node`."""
txt
=
[
'<'
,
node
.
tag_name
]
# s += ' pos="%i"' % node.pos
if
hasattr
(
self
,
'_xml_attr'
):
txt
.
extend
(
' %s="%s"'
%
(
k
,
v
)
for
k
,
v
in
self
.
xml_attr
.
items
())
if
hasattr
(
node
,
'_xml_attr'
):
txt
.
extend
(
' %s="%s"'
%
(
k
,
v
)
for
k
,
v
in
node
.
xml_attr
.
items
())
if
src
:
txt
.
append
(
' line="%i" col="%i"'
%
line_col
(
line_breaks
,
node
.
pos
))
if
showerrors
and
node
.
errors
:
...
...
examples/MLW/Beispiele/facitergula/MLW.css
View file @
c94ebe9f
...
...
@@ -41,12 +41,18 @@ FLEX + FLEX:before {
}
LemmaVariante
{
display
:
block
;
}
LemmaVariante
+
LemmaVariante
:before
{
content
:
"
,
"
;
LemmaVariante
:after
{
content
:
"
("
attr
(
verdichtung
)
")
"
;
}
/* LemmaVariante + LemmaVariante:before {
content: ", ";
} */
Bedeutung
{
display
:
block
;
margin-top
:
0.5em
;
...
...
@@ -59,22 +65,22 @@ U1Bedeutung {
U2Bedeutung
{
display
:
block
;
margin-left
:
2
em
;
margin-left
:
1
em
;
}
U3Bedeutung
{
display
:
block
;
margin-left
:
3
em
;
margin-left
:
1
em
;
}
U4Bedeutung
{
display
:
block
;
margin-left
:
4
em
;
margin-left
:
1
em
;
}
U5Bedeutung
{
display
:
block
;
margin-left
:
5
em
;
margin-left
:
1
em
;
}
Interpretamente
{
...
...
@@ -113,7 +119,7 @@ Stelle {
}
BelegText
{
color
:
dark
goldenrod
;
color
:
dark
slateblue
;
}
BelegText
:before
{
...
...
@@ -124,12 +130,25 @@ BelegText:after {
content
:
"”"
;
}
Sonderbelege
{
font-style
:
italic
;
}
Sonderbelege
:before
{
content
:
" ("
}
Sonderbelege
:after
{
content
:
") "
}
Zusatz
{
font-style
:
italic
;
}
Verweis
{
color
:
blue
;
text-decoration
:
underline
;
}
pfad
:after
{
...
...
examples/MLW/Beispiele/facitergula/fascitergula.mlw
View file @
c94ebe9f
...
...
@@ -13,6 +13,7 @@ GRAMMATIK
-us, -i m.: {=> ibi_1}
-um, -i n.: {=> ibi_2}
SCHREIBWEISE
script.:
vizreg-: {=> ibi_3}
...
...
@@ -22,7 +23,7 @@ SCHREIBWEISE
BEDEUTUNG
LAT pannus, faciale, sudarium
DEU Gesichts
-tuch, Schweiß-
tuch, Tuch {usu liturg.}{de re v. {=> eintrag/ibi_X}}
DEU Gesichts
tuch, Schweiß
tuch, Tuch {usu liturg.}{de re v. {=> eintrag/ibi_X}}
* Catal.: thes. Germ.; 28,11 (post 851) "-um III".
* Form.: Sangall.; {@ibi_2} 39 p. 421,16
...
...
examples/MLW/Beispiele/imperium/MLW.css
View file @
c94ebe9f
...
...
@@ -41,12 +41,18 @@ FLEX + FLEX:before {
}
LemmaVariante
{
display
:
block
;
}
LemmaVariante
+
LemmaVariante
:before
{
content
:
"
,
"
;
LemmaVariante
:after
{
content
:
"
("
attr
(
verdichtung
)
")
"
;
}
/* LemmaVariante + LemmaVariante:before {
content: ", ";
} */
Bedeutung
{
display
:
block
;
margin-top
:
0.5em
;
...
...
examples/MLW/CSS/MLW.css
View file @
c94ebe9f
...
...
@@ -41,12 +41,18 @@ FLEX + FLEX:before {
}
LemmaVariante
{
display
:
block
;
}
LemmaVariante
+
LemmaVariante
:before
{
content
:
"
,
"
;
LemmaVariante
:after
{
content
:
"
("
attr
(
verdichtung
)
")
"
;
}
/* LemmaVariante + LemmaVariante:before {
content: ", ";
} */
Bedeutung
{
display
:
block
;
margin-top
:
0.5em
;
...
...
@@ -59,22 +65,22 @@ U1Bedeutung {
U2Bedeutung
{
display
:
block
;
margin-left
:
2
em
;
margin-left
:
1
em
;
}
U3Bedeutung
{
display
:
block
;
margin-left
:
3
em
;
margin-left
:
1
em
;
}
U4Bedeutung
{
display
:
block
;
margin-left
:
4
em
;
margin-left
:
1
em
;
}
U5Bedeutung
{
display
:
block
;
margin-left
:
5
em
;
margin-left
:
1
em
;
}
Interpretamente
{
...
...
@@ -113,7 +119,7 @@ Stelle {
}
BelegText
{
color
:
dark
goldenrod
;
color
:
dark
slateblue
;
}
BelegText
:before
{
...
...
@@ -124,12 +130,25 @@ BelegText:after {
content
:
"”"
;
}
Sonderbelege
{
font-style
:
italic
;
}
Sonderbelege
:before
{
content
:
" ("
}
Sonderbelege
:after
{
content
:
") "
}
Zusatz
{
font-style
:
italic
;
}
Verweis
{
color
:
blue
;
text-decoration
:
underline
;
}
pfad
:after
{
...
...
examples/MLW/MLW.ebnf
View file @
c94ebe9f
...
...
@@ -36,7 +36,7 @@ LemmaWort = LAT_WORT
LemmaVarianten = LemmaVariante { [";" | ","] [ZW] LemmaVariante } [ ABS Zusatz ]
LemmaVariante = LAT_WORT
[Zusatz]
# Ist eine Lemma immer ein einzelnes Wort?
LemmaVariante = LAT_WORT # Ist eine Lemma immer ein einzelnes Wort?
## GRAMMATIK-POSITION ##
...
...
examples/MLW/MLWCompiler.py
View file @
c94ebe9f
...
...
@@ -95,14 +95,14 @@ class MLWGrammar(Grammar):
LemmaVarianten = LemmaVariante { [";" | ","] [ZW] LemmaVariante } [ ABS Zusatz ]
LemmaVariante = LAT_WORT
[Zusatz]
# Ist eine Lemma immer ein einzelnes Wort?
LemmaVariante = LAT_WORT # Ist eine Lemma immer ein einzelnes Wort?
## GRAMMATIK-POSITION ##
GrammatikPosition = ZWW "GRAMMATIK" [LZ] §Grammatik { ABS GrammatikVariante }
Grammatik = wortart §ABS flexion [
";"] [
genus]
Grammatik = wortart §ABS flexion [
[";"]
genus]
wortart = nomen | verb | adverb | adjektiv | praeposition
nomen = "nomen" | "n."
...
...
@@ -122,7 +122,7 @@ class MLWGrammar(Grammar):
neutrum = "neutrum" | "n."
GrammatikVariante = [wortart ABS] flexion [
";"] [
genus] DPP Beleg { FORTSETZUNG Beleg } # Beleg { SEM Beleg }
GrammatikVariante = [wortart ABS] flexion [
[";"]
genus] DPP Beleg { FORTSETZUNG Beleg } # Beleg { SEM Beleg }
...
...
@@ -326,7 +326,7 @@ class MLWGrammar(Grammar):
flexion
=
Forward
()
genus
=
Forward
()
wortart
=
Forward
()
source_hash__
=
"8
5e451ba51497e7812801dc7a7062bf2
"
source_hash__
=
"8
8fa777691b17d758426d918e5dbdaa5
"
parser_initialization__
=
"upon instantiation"
COMMENT__
=
r
'(?:\/\/.*)|(?:\/\*(?:.|\n)*?\*\/)'
WHITESPACE__
=
r
'[\t ]*'
...
...
@@ -449,7 +449,7 @@ class MLWGrammar(Grammar):
EtymologieBesonderheit
=
Synonym
(
EINZEILER
)
EtymologieVariante
=
Alternative
(
LAT
,
Series
(
GRI
,
Option
(
EtymologieBesonderheit
),
Option
(
Series
(
Token
(
"ETYM"
),
Etymologie
)),
DPP
,
Beleg
))
EtymologiePosition
=
Series
(
ZWW
,
Token
(
"ETYMOLOGIE"
),
Option
(
LZ
),
OneOrMore
(
EtymologieVariante
))
GrammatikVariante
=
Series
(
Option
(
Series
(
wortart
,
ABS
)),
flexion
,
Option
(
Token
(
";"
)),
Option
(
genus
),
DPP
,
Beleg
,
ZeroOrMore
(
Series
(
FORTSETZUNG
,
Beleg
)))
GrammatikVariante
=
Series
(
Option
(
Series
(
wortart
,
ABS
)),
flexion
,
Option
(
Series
(
Option
(
Token
(
";"
)),
genus
)
),
DPP
,
Beleg
,
ZeroOrMore
(
Series
(
FORTSETZUNG
,
Beleg
)))
neutrum
=
Alternative
(
Token
(
"neutrum"
),
Token
(
"n."
))
femininum
=
Alternative
(
Token
(
"femininum"
),
Token
(
"f."
))
maskulinum
=
Alternative
(
Token
(
"maskulinum"
),
Token
(
"m."
))
...
...
@@ -464,9 +464,9 @@ class MLWGrammar(Grammar):
verb
=
Alternative
(
Token
(
"verb"
),
Token
(
"v."
))
nomen
=
Alternative
(
Token
(
"nomen"
),
Token
(
"n."
))
wortart
.
set
(
Alternative
(
nomen
,
verb
,
adverb
,
adjektiv
,
praeposition
))
Grammatik
=
Series
(
wortart
,
ABS
,
flexion
,
Option
(
Token
(
";"
)),
Option
(
genus
),
mandatory
=
1
)
Grammatik
=
Series
(
wortart
,
ABS
,
flexion
,
Option
(
Series
(
Option
(
Token
(
";"
)),
genus
)
),
mandatory
=
1
)
GrammatikPosition
=
Series
(
ZWW
,
Token
(
"GRAMMATIK"
),
Option
(
LZ
),
Grammatik
,
ZeroOrMore
(
Series
(
ABS
,
GrammatikVariante
)),
mandatory
=
3
)
LemmaVariante
=
S
eries
(
LAT_WORT
,
Option
(
Zusatz
)
)
LemmaVariante
=
S
ynonym
(
LAT_WORT
)
LemmaVarianten
=
Series
(
LemmaVariante
,
ZeroOrMore
(
Series
(
Option
(
Alternative
(
Token
(
";"
),
Token
(
","
))),
Option
(
ZW
),
LemmaVariante
)),
Option
(
Series
(
ABS
,
Zusatz
)))
LemmaWort
.
set
(
Synonym
(
LAT_WORT
))
gesichert
=
Token
(
"$"
)
...
...
@@ -628,6 +628,30 @@ def get_transformer() -> TransformationFunc:
#
#######################################################################
def
lemma_verdichtung
(
lemma
,
variante
):
# finde den ersten Unterschied von links
l
=
0
while
l
<
min
(
len
(
lemma
),
len
(
variante
))
and
lemma
[
l
]
==
variante
[
l
]:
l
+=
1
# finde den ersten Unterschied von rechts
r
=
1
while
r
<=
min
(
len
(
lemma
),
len
(
variante
))
and
lemma
[
-
r
]
==
variante
[
-
r
]:
r
+=
1
r
-=
1
l
-=
1
# beginne 1 Zeichen vor dem ersten Unterschied
if
l
<=
1
:
l
=
0
# einzelne Buchstaben nicht abtrennen
r
-=
1
# beginne 1 Zeichen nach dem letzten Unterschied
if
r
<=
1
:
r
=
0
# einzelne Buchstaben nicht abtrennen
# gib Zeichenkette der Unterschide ab dem letzten gemeinsamen (von links) bzw.
# ab dem ersten gemeinsamen (von rechts) Buchstaben mit Trennstrichen zurück
return
((
'-'
if
l
>
0
else
''
)
+
variante
[
l
:(
-
r
)
or
None
]
+
(
'-'
if
r
>
0
else
''
))
class
MLWCompiler
(
Compiler
):
"""Compiler for the abstract-syntax-tree of a MLW source file.
"""
...
...
@@ -643,6 +667,7 @@ class MLWCompiler(Compiler):
def
__init__
(
self
,
grammar_name
=
"MLW"
,
grammar_source
=
""
):
super
(
MLWCompiler
,
self
).
__init__
(
grammar_name
,
grammar_source
)
assert
re
.
match
(
'\w+\Z'
,
grammar_name
)
self
.
lemmawort
=
""
def
on_VerweisKern
(
self
,
node
):
if
node
.
children
[
0
].
parser
.
name
==
"FREITEXT"
:
...
...
@@ -684,6 +709,15 @@ class MLWCompiler(Compiler):
self
.
ergänze_Zähler
(
node
,
5
)
return
self
.
fallback_compiler
(
node
)
def
on_LemmaWort
(
self
,
node
):
assert
not
node
.
children
self
.
lemmawort
=
node
.
result
return
node
def
on_LemmaVariante
(
self
,
node
):
assert
not
node
.
children
node
.
xml_attr
[
'verdichtung'
]
=
lemma_verdichtung
(
self
.
lemmawort
,
node
.
result
)
return
node
def
get_compiler
(
grammar_name
=
"MLW"
,
grammar_source
=
""
)
->
MLWCompiler
:
global
thread_local_MLW_compiler_singleton
...
...
@@ -732,6 +766,16 @@ HTML_LEAD_OUT = """
</html>
"""
def
write_as_html
(
file_name
,
tree
,
show
=
False
):
out_name
=
os
.
path
.
splitext
(
file_name
)[
0
]
+
'.html'
with
open
(
out_name
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
HTML_LEAD_IN
)
f
.
write
(
tree
.
as_xml
())
f
.
write
(
HTML_LEAD_OUT
)
if
show
:
webbrowser
.
open
(
out_name
)
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
>
1
:
file_name
,
log_dir
=
sys
.
argv
[
1
],
''
...
...
@@ -746,12 +790,7 @@ if __name__ == "__main__":
print
(
'
\n
Leider hat es ein paar Fehler gegeben :-(
\n
'
)
sys
.
exit
(
1
)
else
:
out_name
=
file_name
[:
-
4
]
+
'.html'
with
open
(
out_name
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
HTML_LEAD_IN
)
f
.
write
(
result
.
as_xml
())
f
.
write
(
HTML_LEAD_OUT
)
webbrowser
.
open
(
out_name
)
write_as_html
(
file_name
,
result
,
show
=
True
)
print
(
"Das Einlesen war erfolgreich :-)"
)
else
:
print
(
"Aufruf: MLWCompiler.py [--debug] FILENAME"
)
examples/MLW/VERALTET/MLW.css
0 → 100644
View file @
c94ebe9f
Lemma
{
display
:
block
;
font-weight
:
bold
;
margin-bottom
:
0.5rem
;
}
LemmaVarianten
{
display
:
block
;
color
:
darkgrey
;
}
GrammatikPosition
,
SchreibweisenPosition
,
StrukturPosition
,
GebrauchsPosition
,
MetrikPosition
,
VerwechselungsPosition
,
BedeutungsPosition
{
display
:
block
;
margin-top
:
0.5em
;
}
Kategorie
{
display
:
block
;
}
Besonderheit
,
Gegenstand
{
font-style
:
italic
;
}
Besonderheit
:after
,
Gegenstand
:after
{
content
:
": "
}
Grammatik
{
display
:
block
;
margin-bottom
:
0.5rem
;
}
GrammatikVariante
{
display
:
block
;
}
FLEX
+
FLEX
:before
{
content
:
", "
;
}
LemmaVariante
{
}
LemmaVariante
+
LemmaVariante
:before
{
content
:
", "
;
}
Bedeutung
{
display
:
block
;
margin-top
:
0.5em
;
}
U1Bedeutung
{
display
:
block
;
margin-left
:
1em
;
}
U2Bedeutung
{
display
:
block
;
margin-left
:
2em
;
}
U3Bedeutung
{
display
:
block
;
margin-left
:
3em
;
}
U4Bedeutung
{
display
:
block
;
margin-left
:
4em
;
}
U5Bedeutung
{
display
:
block
;
margin-left
:
5em
;
}
Interpretamente
{
display
:
block
;
}
LateinischerAusdruck
,
DeutscherAusdruck
{
font-weight
:
bold
;
}
LateinischerAusdruck
+
LateinischerAusdruck
:before
,
DeutscherAusdruck
+
DeutscherAusdruck
:before
{
content
:
", "
}
LateinischeBedeutung
+
DeutscheBedeutung
:before
{
content
:
" -- "
}
Bedeutungskategorie
{
display
:
block
;
font-weight
:
bold
;
}
Bedeutungskategorie
:after
{
content
:
": "
;
}
BelegQuelle
{
font-variant
:
small-caps
;
}
Stelle
{
}
BelegText
{
color
:
darkgoldenrod
;
}
BelegText
:before
{
content
:
"“"
;
}
BelegText
:after
{
content
:
"”"
;
}
Zusatz
{
font-style
:
italic
;
}
Verweis
{
color
:
blue
;
}
pfad
:after
{
content
:
"/"
}
Stellenverzeichnis
{
display
:
none
;
}
ArtikelVerfasser
{
display
:
block
;
margin-top
:
1em
;
font-style
:
italic
;
}
\ No newline at end of file
examples/MLW/verarbeite_Beispiele.py
View file @
c94ebe9f
...
...
@@ -18,7 +18,8 @@ if not recompile_grammar('MLW.ebnf', force=False): # recompiles Grammar only if
sys
.
exit
(
1
)
from
MLWCompiler
import
get_preprocessor
,
get_grammar
,
get_transformer
,
get_compiler
from
MLWCompiler
import
get_preprocessor
,
get_grammar
,
get_transformer
,
get_compiler
,
\
write_as_html
def
tst_func
():
for
root
,
dirs
,
files
in
os
.
walk
(
'Beispiele'
):
...
...
@@ -47,6 +48,7 @@ def tst_func():
else
:
if
os
.
path
.
isfile
(
raw_name
+
'.messages'
):
os
.
remove
(
raw_name
+
'.messages'
)
write_as_html
(
raw_name
,
result
)
print
(
"
\n
Parsing of %s successfull :-)
\n
"
%
entry
)
def
cpu_profile
(
func
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment