Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
web-service-demo
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UNL
web-service-demo
Commits
893876ba
Verified
Commit
893876ba
authored
5 years ago
by
David Beniamine
Browse files
Options
Downloads
Patches
Plain Diff
WIP : call jar parser
parent
d208eac0
Branches
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
src/app/app.py
+35
-6
35 additions, 6 deletions
src/app/app.py
src/app/templates/unl2rdf.html
+26
-13
26 additions, 13 deletions
src/app/templates/unl2rdf.html
with
61 additions
and
19 deletions
src/app/app.py
+
35
−
6
View file @
893876ba
from
flask
import
Flask
from
flask
import
request
from
flask
import
render_template
import
tempfile
import
subprocess
import
os
app
=
Flask
(
__name__
)
...
...
@@ -13,13 +17,38 @@ def main():
def
unl2rdf
():
if
request
.
method
==
'
POST
'
:
unl
=
request
.
form
[
'
unl
'
]
rdf
=
convertUnl2Rdf
(
unl
)
# Validate formats list
formats
=
list
(
set
([
'
rdf
'
,
'
dot
'
])
&
set
(
request
.
form
.
getlist
(
'
outputs
'
)))
output
=
convertUnl
(
unl
,
formats
)
else
:
unl
=
None
rdf
=
None
return
render_template
(
'
unl2rdf.html
'
,
unl
=
unl
,
rdf
=
rdf
)
output
=
None
return
render_template
(
'
unl2rdf.html
'
,
unl
=
unl
,
output
=
output
)
def
convertUnl
(
unl
,
outputs
):
with
tempfile
.
NamedTemporaryFile
()
as
temp
:
out_name
=
temp
.
name
with
tempfile
.
NamedTemporaryFile
()
as
in_file
:
in_file
.
write
(
unl
)
unl2rdf_path
=
"
/opt/UnlParser-1.0-SNAPSHOT.jar
"
cmd
=
[
'
java
'
,
'
-jar
'
,
unl2rdf_path
,
'
--input-file
'
,
in_file
.
name
,
'
--output-filename
'
,
out_name
,
'
--output-type
'
,
outputs
]
subprocess
.
run
(
cmd
)
res
=
{}
if
'
rdf
'
in
outputs
:
fname
=
'
{}.rdf
'
.
format
(
out_name
)
with
open
(
'
{}.rdf
'
.
format
(
out_name
),
'
r
'
)
as
f
:
res
[
'
rdf
'
]
=
f
.
read
()
os
.
remove
(
fname
)
if
'
dot
'
in
outputs
:
fname
=
'
{}.dot
'
.
format
(
out_name
)
cmd
=
[
'
dot
'
,
'
-Tsvg
'
,
fname
]
with
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
)
as
proc
:
res
[
'
dot
'
]
=
proc
.
stdout
.
read
()
os
.
remove
(
fname
)
def
convertUnl2Rdf
(
unl
):
# TODO handle text here, do not call bash command or sanitize input first
return
"
Please implement me so I can convert
'
{}
'
to RDF
"
.
format
(
unl
)
return
res
This diff is collapsed.
Click to expand it.
src/app/templates/unl2rdf.html
+
26
−
13
View file @
893876ba
...
...
@@ -2,26 +2,39 @@
{% block title %}UNL 2 RDF demo{% endblock %}
{% block content %}
{% if not unl %}
<h1>
Enter some UNL here I will convert it to RDF for you
</h1>
<div
class=
"form-group"
>
<form
action=
"{{request.path}}"
method=
"POST"
>
<h2>
Enter some UNL here I will convert it for you
</h2>
<textarea
class=
"form-control"
name=
"unl"
cols=
"80"
rows=
"10"
style=
"width: 300px; height: 150px;"
></textarea>
<h2>
Tell me which output(s) you want
</h2>
<ul>
<li><label><input
type=
"checkbox"
name=
"outputs"
value=
"rdf"
checked
>
RDF
</label></li>
<li><label><input
type=
"checkbox"
name=
"outputs"
value=
"dot"
checked
>
Graph (dot)
</label></li>
</ul>
<button
class=
"btn btn-primary"
type=
"submit"
>
Submit
</button>
</form>
</div>
{% else %}
<h2>
UNL
</h2>
<pre>
<code>
{{ unl }}
</code>
</pre>
<h2>
RDF
</h2>
<pre>
<code>
{{ rdf }}
</code>
</pre>
<h2>
UNL
</h2>
<pre>
<code>
{{ unl }}
</code>
</pre>
{% if output['dot'] %}
<h2>
Unl graph
</h2>
{{ output['dot'] }}
{% endif %}
{% if output['rdf'] %}
<h2>
RDF
</h2>
<pre>
<code>
{{ output['rdf'] }}
</code>
</pre>
{% endif %}
{% endif %}
{% endblock %}
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