Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon_data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Franck Dary
macaon_data
Commits
0574caf5
Commit
0574caf5
authored
2 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Improved conllu2latex
parent
df79cf1d
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/conllu2latex.py
+70
-47
70 additions, 47 deletions
scripts/conllu2latex.py
with
70 additions
and
47 deletions
scripts/conllu2latex.py
+
70
−
47
View file @
0574caf5
...
...
@@ -67,35 +67,40 @@ def getLayout(sentence, text) :
ranges
=
[
ranges
[
i
]
for
i
in
range
(
len
(
ranges
))
if
i
not
in
multis
]
for
i
in
range
(
len
(
ranges
))
:
if
ranges
[
i
][
0
]
!=
-
1
:
continue
start
=
0
if
i
>
0
:
start
=
ranges
[
i
-
1
][
1
]
+
1
j
=
i
while
ranges
[
j
][
0
]
==
-
1
:
j
+=
1
end
=
ranges
[
j
][
0
]
-
1
size
=
end
-
start
+
1
each
=
size
//
(
j
-
i
)
for
k
in
range
(
j
-
i
)
:
ranges
[
i
+
k
][
0
]
=
start
+
k
*
each
ranges
[
i
+
k
][
1
]
=
ranges
[
i
+
k
][
0
]
+
each
-
1
i
=
j
for
i
in
range
(
len
(
ranges
)
-
1
)
:
if
ranges
[
i
][
1
]
!=
ranges
[
i
+
1
][
0
]
-
1
:
if
ranges
[
i
][
1
]
-
ranges
[
i
][
0
]
<=
ranges
[
i
+
1
][
1
]
-
ranges
[
i
+
1
][
0
]
:
ranges
[
i
][
1
]
=
ranges
[
i
+
1
][
0
]
-
1
else
:
ranges
[
i
+
1
][
0
]
=
ranges
[
i
][
1
]
+
1
end
=
ranges
[
i
][
-
1
]
if
end
+
1
in
range
(
len
(
text
))
and
text
[
end
+
1
]
==
"
"
:
ranges
[
i
][
-
1
]
+=
1
# for i in range(len(ranges)) :
# if ranges[i][0] != -1 :
# continue
# start = 0
# if i > 0 :
# start = ranges[i-1][1]+1
# j = i
# while ranges[j][0] == -1 :
# j += 1
# end = ranges[j][0]-1
# size = end-start +1
# each = size // (j-i)
# for k in range(j-i) :
# ranges[i+k][0] = start + k*each
# ranges[i+k][1] = ranges[i+k][0]+each-1
# i = j
#
# for i in range(len(ranges)-1) :
# if ranges[i][1] != ranges[i+1][0]-1 :
# if ranges[i][1]-ranges[i][0] <= ranges[i+1][1]-ranges[i+1][0] :
# ranges[i][1] = ranges[i+1][0]-1
# else :
# ranges[i+1][0] = ranges[i][1]+1
return
sentence
,
ranges
################################################################################
################################################################################
def
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
nodes
,
reduce
,
breakSize
,
mask
=
[
None
,
None
],
hsep
=
True
)
:
def
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
nodes
,
reduce
,
breakSize
,
mask
=
[
None
,
None
],
hsep
=
True
,
isCenter
=
lambda
_
:
False
,
isColored
=
lambda
_
:
False
,
colSizes
=
None
,
title
=
None
)
:
if
mask
[
0
]
not
in
[
None
,
"
incr
"
,
"
seq
"
]
:
print
(
"
ERROR : invalid mask
'
%s
'"
%
mask
,
file
=
sys
.
stderr
)
...
...
@@ -113,15 +118,23 @@ def produceTabular(sentence, ranges, text, columns, nodes, reduce, breakSize, ma
partSizes
=
[
-
ranges
[
parts
[
partId
][
0
]][
0
]
+
ranges
[
parts
[
partId
][
-
1
]][
1
]
+
1
for
partId
in
range
(
len
(
parts
))]
curLine
=
-
1
colsep
=
"
|
"
if
hsep
else
""
for
partId
in
range
(
len
(
parts
))
:
if
partId
!=
0
:
print
(
"
\\
vspace{7pt}
\n
"
)
print
(
"
\\
begin{tabular}{|l|%s|}
"
%
(
colsep
.
join
([
"
c
"
]
*
partSizes
[
partId
])))
colsDef
=
colsep
.
join
([
"
c
"
]
*
partSizes
[
partId
])
print
(
"
\\
begin{tabular}{|@{\hskip 4pt}l@{\hskip 3pt}|@{\hskip 3pt}%s|}
"
%
(
colsDef
))
if
title
is
not
None
:
print
(
"
\multicolumn{%d}{c}{\large %s}
\\\\
"
%
(
partSizes
[
partId
]
+
1
,
title
))
print
(
"
\cline{1-%d}
\n
"
%
(
partSizes
[
partId
]
+
1
))
for
i
in
range
(
len
(
columns
))[::
-
1
]
:
curLine
+=
1
curCol
=
-
1
print
(
"
\\
texttt{
\\
textbf{
\\
footnotesize{%s}}}
"
%
columns
[
i
].
lower
(),
end
=
"
&
\n
"
)
for
j
in
parts
[
partId
]
:
curCol
+=
1
if
columns
[
i
]
==
"
EOS
"
:
value
=
"
yes
"
if
j
==
parts
[
partId
][
-
1
]
and
partId
==
len
(
parts
)
-
1
else
"
no
"
else
:
...
...
@@ -150,10 +163,23 @@ def produceTabular(sentence, ranges, text, columns, nodes, reduce, breakSize, ma
values
[
k
]
=
"
\\
texttt{%s}
"
%
(
values
[
k
])
cellContent
=
"
\\\\
"
.
join
(
values
)
tcolsep
=
colsep
if
j
!=
parts
[
partId
][
-
1
]
else
"
|
"
color
=
""
if
isColored
((
curLine
,
curCol
))
:
color
=
r
"
\cellcolor{green!15}
"
if
isCenter
((
curLine
,
curCol
))
:
color
=
r
"
\cellcolor{blue!30}
"
if
nodes
:
print
(
"
\multicolumn{%d}{c%s}{\makecell[cc]{
\\
tabnode{%s}}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
if
colSizes
is
not
None
:
cellSize
=
colSizes
[
curCol
]
if
cellSize
>
0
:
cellSize
=
"
%dpt
"
%
(
3
+
cellSize
*
5.5
)
print
(
"
\multicolumn{%d}{c%s}{%s\makecell[cb]{\parbox{%s}{%s}}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
color
,
cellSize
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
else
:
print
(
"
\multicolumn{%d}{c%s}{%s\makecell[cb]{%s}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
color
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
else
:
print
(
"
\multicolumn{%d}{c%s}{%s\makecell[cb]{%s}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
color
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
else
:
print
(
"
\multicolumn{%d}{c%s}{\makecell[c
c]
{%s}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
print
(
"
\multicolumn{%d}{c%s}{\makecell[c
b
{%s}}
"
%
(
ranges
[
j
][
1
]
-
ranges
[
j
][
0
]
+
1
,
tcolsep
,
cellContent
),
end
=
"
&
\n
"
if
j
!=
parts
[
partId
][
-
1
]
else
""
)
if
nodes
and
i
!=
0
:
print
(
"
\\\\
%s
\n
"
%
(
"
[-0.1cm]
"
if
i
==
1
else
"
[%scm]
"
%
(
breakSize
)))
else
:
...
...
@@ -323,35 +349,32 @@ def drawPaths(sentence, ranges, text, columns, hsep, isSeq) :
################################################################################
def
drawFeatures
(
sentence
,
ranges
,
text
,
columns
)
:
print
(
r
"""
\makeatletter
\@ifundefined{tabnode}{%
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node[minimum height=0.5cm] (\arabic{nodecount}) {#1};}%
\newcounter{nodecount}%
}{}
\makeatother
\setcounter{nodecount}{0}
"""
)
print
(
r
"
\tikzstyle{every picture}+=[remember picture,baseline]
"
)
print
(
r
"
\tikzstyle{every node}+=[inner sep=0pt,anchor=base]
"
)
nbLines
=
len
(
sentence
[
0
])
nbCols
=
len
(
sentence
)
center
=
(
nbLines
//
2
,
nbCols
//
2
)
isCenter
=
lambda
lc
:
lc
==
center
isColored
=
lambda
lc
:
lc
[
0
]
>=
center
[
0
]
and
lc
[
1
]
<=
center
[
1
]
colSizes
=
[
max
(
map
(
len
,
elem
))
for
elem
in
sentence
]
print
(
r
"
\begin{figure}
"
)
print
(
"
\\
tabcolsep=0.10mm
"
)
print
(
r
"
\centering
"
)
print
(
"
\\
setlength{
\\
tabcolsep}{0.00mm}
"
)
print
(
r
"
\resizebox{\textwidth}{!}{
"
)
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
seq
"
,
center
),
hsep
=
""
)
print
(
r
"
\quad
"
,
end
=
""
)
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
seq
"
,
center
),
hsep
=
""
)
isColored
=
lambda
lc
:
lc
[
0
]
>=
center
[
0
]
and
lc
[
1
]
<=
center
[
1
]
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
seq
"
,
center
),
hsep
=
""
,
isCenter
=
isCenter
,
isColored
=
isColored
,
colSizes
=
colSizes
,
title
=
r
"
Passé-Bas (\palo)
"
)
print
(
r
"
\quad
"
,
end
=
""
)
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
incr
"
,
center
),
hsep
=
""
)
print
(
""
)
drawRectanglePalo
(
1
,
nbLines
,
nbCols
)
drawRectangleFulo
(
nbLines
*
nbCols
+
1
,
nbLines
,
nbCols
)
drawRectanglePahi
(
2
*
nbLines
*
nbCols
+
1
,
nbLines
,
nbCols
)
print
(
"
}
"
)
isColored
=
lambda
lc
:
lc
[
0
]
>=
center
[
0
]
and
lc
[
1
]
<=
center
[
1
]
or
lc
[
0
]
>
center
[
0
]
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
seq
"
,
center
),
hsep
=
""
,
isCenter
=
isCenter
,
isColored
=
isColored
,
colSizes
=
colSizes
,
title
=
r
"
Futur-Bas (\fulo)
"
)
print
(
"
\n
}
\n
"
)
print
(
r
"
\vspace*{0.25cm}
"
)
print
(
r
"
\resizebox{0.5\textwidth}{!}{
"
)
isColored
=
lambda
lc
:
lc
[
1
]
<
center
[
1
]
or
lc
[
1
]
==
center
[
1
]
and
lc
[
0
]
>
center
[
0
]
produceTabular
(
sentence
,
ranges
,
text
,
columns
,
True
,
True
,
"
0.1
"
,
mask
=
(
"
incr
"
,
center
),
hsep
=
""
,
isCenter
=
isCenter
,
isColored
=
isColored
,
colSizes
=
colSizes
,
title
=
"
Passé-Haut (\pahi)
"
)
print
(
"
\n
}
"
)
print
(
r
"
\caption{Caption.}
"
)
print
(
r
"
\label{fig:a}
"
)
...
...
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