Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nlreqdataset-unl-enco
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UNL
nlreqdataset-unl-enco
Commits
9ea8564d
Commit
9ea8564d
authored
Jun 17, 2020
by
David Rouquet
Browse files
Options
Downloads
Patches
Plain Diff
Add orig text print before unl graph
parent
e3beb791
No related branches found
No related tags found
No related merge requests found
Pipeline
#205
passed
Jun 17, 2020
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/unlizeXmlNbSample.ipynb
+10
-0
10 additions, 0 deletions
scripts/unlizeXmlNbSample.ipynb
with
10 additions
and
0 deletions
scripts/unlizeXmlNbSample.ipynb
+
10
−
0
View file @
9ea8564d
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
"source": [
"source": [
"import tempfile\n",
"import tempfile\n",
"import os\n",
"import os\n",
"import re\n",
"from subprocess import Popen, PIPE, STDOUT\n",
"from subprocess import Popen, PIPE, STDOUT\n",
"from IPython.core.display import SVG"
"from IPython.core.display import SVG"
]
]
...
@@ -73,6 +74,8 @@
...
@@ -73,6 +74,8 @@
" svgArray = [x+sep for x in protoSvg.split(sep)]\n",
" svgArray = [x+sep for x in protoSvg.split(sep)]\n",
" svgArray.pop()\n",
" svgArray.pop()\n",
" for svg in svgArray :\n",
" for svg in svgArray :\n",
" text = re.search('\\{org.*\\n(.*)\\n.*org\\}',unldata).group(1)\n",
" print(text)\n",
" display(SVG(svg))"
" display(SVG(svg))"
]
]
}
}
...
@@ -94,6 +97,13 @@
...
@@ -94,6 +97,13 @@
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
tempfile
import
tempfile
import
os
import
os
import
re
from
subprocess
import
Popen
,
PIPE
,
STDOUT
from
subprocess
import
Popen
,
PIPE
,
STDOUT
from
IPython.core.display
import
SVG
from
IPython.core.display
import
SVG
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
def
unl2dot
(
text
,
path
):
def
unl2dot
(
text
,
path
):
with
tempfile
.
NamedTemporaryFile
()
as
temp
:
with
tempfile
.
NamedTemporaryFile
()
as
temp
:
out_name
=
os
.
path
.
basename
(
temp
.
name
)
out_name
=
os
.
path
.
basename
(
temp
.
name
)
out_dir
=
os
.
path
.
dirname
(
temp
.
name
)
out_dir
=
os
.
path
.
dirname
(
temp
.
name
)
with
tempfile
.
NamedTemporaryFile
(
mode
=
"
w
"
)
as
in_file
:
with
tempfile
.
NamedTemporaryFile
(
mode
=
"
w
"
)
as
in_file
:
# Remove CRLF and flush output to avoid java errors
# Remove CRLF and flush output to avoid java errors
in_file
.
write
(
text
.
replace
(
"
\r\n
"
,
"
\n
"
))
in_file
.
write
(
text
.
replace
(
"
\r\n
"
,
"
\n
"
))
in_file
.
flush
()
in_file
.
flush
()
# Run java parser
# Run java parser
cmd
=
[
'
java
'
,
'
-jar
'
,
path
,
cmd
=
[
'
java
'
,
'
-jar
'
,
path
,
'
--input-file
'
,
in_file
.
name
,
'
--input-file
'
,
in_file
.
name
,
'
--output-Dir
'
,
out_dir
,
'
--output-file
'
,
out_name
,
'
--output-Dir
'
,
out_dir
,
'
--output-file
'
,
out_name
,
'
--output-type
'
,
'
dot
'
]
'
--output-type
'
,
'
dot
'
]
with
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
STDOUT
)
as
p
:
with
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
STDOUT
)
as
p
:
p
.
wait
()
p
.
wait
()
p
.
stdout
.
flush
()
p
.
stdout
.
flush
()
if
p
.
returncode
!=
0
:
if
p
.
returncode
!=
0
:
print
(
"
Error in unl2rdf:
\n\n
"
+
p
.
stdout
.
read
().
decode
())
print
(
"
Error in unl2rdf:
\n\n
"
+
p
.
stdout
.
read
().
decode
())
print
(
'
UNL;
'
)
print
(
'
UNL;
'
)
print
(
text
)
print
(
text
)
# generate dot output
# generate dot output
fname
=
'
{}/{}.dot
'
.
format
(
out_dir
,
out_name
)
fname
=
'
{}/{}.dot
'
.
format
(
out_dir
,
out_name
)
cmd
=
[
'
dot
'
,
'
-Tsvg
'
,
fname
]
cmd
=
[
'
dot
'
,
'
-Tsvg
'
,
fname
]
with
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
PIPE
)
as
p
:
with
Popen
(
cmd
,
stdout
=
PIPE
,
stderr
=
PIPE
)
as
p
:
p
.
wait
()
p
.
wait
()
if
p
.
returncode
!=
0
:
if
p
.
returncode
!=
0
:
print
(
"
Error creating svg:
\n\n
"
+
p
.
stderr
.
read
().
decode
())
print
(
"
Error creating svg:
\n\n
"
+
p
.
stderr
.
read
().
decode
())
print
(
'
UNL:
'
)
print
(
'
UNL:
'
)
print
(
text
)
print
(
text
)
try
:
try
:
with
open
(
fname
)
as
f
:
with
open
(
fname
)
as
f
:
print
(
'
DOT:
'
)
print
(
'
DOT:
'
)
print
(
f
.
read
())
print
(
f
.
read
())
except
FileNotFoundError
:
except
FileNotFoundError
:
pass
pass
else
:
else
:
svg
=
p
.
stdout
.
read
().
decode
()
svg
=
p
.
stdout
.
read
().
decode
()
os
.
remove
(
fname
)
os
.
remove
(
fname
)
return
svg
return
svg
return
""
return
""
def
displayUnl
(
unldata
)
:
def
displayUnl
(
unldata
)
:
# We generate protoSVG because whent there are several sentences,
# We generate protoSVG because whent there are several sentences,
# a string composed of several concatenated SVG is produced (not a valid SVG).
# a string composed of several concatenated SVG is produced (not a valid SVG).
# We must then split the string to obtain several valid SVG to display.
# We must then split the string to obtain several valid SVG to display.
protoSvg
=
unl2dot
(
unldata
,
"
unl2rdf-app-1.0-SNAPSHOT-jar-with-dependencies.jar
"
)
protoSvg
=
unl2dot
(
unldata
,
"
unl2rdf-app-1.0-SNAPSHOT-jar-with-dependencies.jar
"
)
sep
=
"
</svg>
\n
"
sep
=
"
</svg>
\n
"
svgArray
=
[
x
+
sep
for
x
in
protoSvg
.
split
(
sep
)]
svgArray
=
[
x
+
sep
for
x
in
protoSvg
.
split
(
sep
)]
svgArray
.
pop
()
svgArray
.
pop
()
for
svg
in
svgArray
:
for
svg
in
svgArray
:
text
=
re
.
search
(
'
\{org.*
\n
(.*)
\n
.*org\}
'
,
unldata
).
group
(
1
)
print
(
text
)
display
(
SVG
(
svg
))
display
(
SVG
(
svg
))
```
```
...
...
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