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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
UNL
web-service-demo
Commits
7b2c2d60
Verified
Commit
7b2c2d60
authored
5 years ago
by
David Beniamine
Browse files
Options
Downloads
Patches
Plain Diff
WIP unl.ru connecteur
Template not finished (imported from unl2rdf)
parent
104d4c53
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/app.py
+34
-0
34 additions, 0 deletions
src/app/app.py
src/app/templates/text2unl.html
+110
-0
110 additions, 0 deletions
src/app/templates/text2unl.html
with
144 additions
and
0 deletions
src/app/app.py
+
34
−
0
View file @
7b2c2d60
...
@@ -6,6 +6,7 @@ from flask import render_template
...
@@ -6,6 +6,7 @@ from flask import render_template
import
tempfile
import
tempfile
from
subprocess
import
Popen
,
PIPE
,
STDOUT
from
subprocess
import
Popen
,
PIPE
,
STDOUT
import
os
import
os
import
requests
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -28,6 +29,18 @@ def unl2rdf():
...
@@ -28,6 +29,18 @@ def unl2rdf():
return
render_template
(
'
unl2rdf.html
'
,
unl
=
unl
,
output
=
output
)
return
render_template
(
'
unl2rdf.html
'
,
unl
=
unl
,
output
=
output
)
@app.route
(
'
/text2unl
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
text2unl
():
if
request
.
method
==
'
POST
'
:
text
=
request
.
form
[
'
text
'
]
language
=
request
.
form
[
'
language
'
]
output
=
{
'
unl
'
:
convertTextToUnl
(
text
,
language
)}
else
:
text
=
None
output
=
None
return
render_template
(
'
text2unl.html
'
,
text
=
text
,
output
=
output
)
def
convertUnl
(
unl
,
outputs
):
def
convertUnl
(
unl
,
outputs
):
res
=
{}
res
=
{}
...
@@ -79,3 +92,24 @@ def convertUnl(unl, outputs):
...
@@ -79,3 +92,24 @@ def convertUnl(unl, outputs):
res
[
'
svg
'
]
=
'
Error : no dot file
'
res
[
'
svg
'
]
=
'
Error : no dot file
'
return
res
return
res
def
convertTextToUnl
(
text
,
language
):
url
=
"
http://unl.ru/etap-cgi/etap-cgi-old/cgiunl.exe
"
data
=
{
'
DOMAIN
'
:
'
SPORT
'
,
'
password
'
:
'
guest
'
,
'
TAGERROR
'
:
'
NO
'
,
'
username
'
:
'
UNL_guest
'
,
'
conversion
'
:
'
true
'
,
'
language
'
:
language
,
'
data
'
:
text
,
'
outputmode
'
:
'
text
'
,
'
coding
'
:
'
utf-8
'
,
'
translate
'
:
'
Process
'
}
r
=
requests
.
post
(
url
,
data
)
# Remove garbage before first '['
return
''
.
join
(
r
.
text
.
partition
(
'
[
'
)[
1
:])
This diff is collapsed.
Click to expand it.
src/app/templates/text2unl.html
0 → 100644
+
110
−
0
View file @
7b2c2d60
{% extends "base.html" %}
{% block title %}Text 2 unl demo{% endblock %}
{% block content %}
{% if not text %}
<form
action=
"{{request.path}}"
method=
"POST"
>
<h1>
Enter some text here I will convert it unsing unl.ru for you
</h1>
<div
class=
"form-group row"
>
<div
class=
"col-12 col-md-8"
>
<h2>
Text
</h3>
<textarea
class=
"form-control"
name=
"unl"
cols=
"120"
rows=
"30"
>
The black cat and the white cat are eating.
</textarea>
</div>
<div
class=
"col-4"
>
<h3>
Settings
</h2>
<ul>
<li><label><input
type=
"radio"
name=
"language"
value=
"en"
checked
>
English
</label></li>
<li><label><input
type=
"radio"
name=
"language"
value=
"ru"
>
Russian
</label></li>
</ul>
<button
class=
"btn btn-primary"
type=
"submit"
>
Submit
</button>
</div>
</div>
</form>
{% else %}
<div
class=
"row"
>
{% if output['error'] %}
<div
class=
'col-12 md-6'
>
<h2>
Error
</h2>
<pre>
{{ output['error'] }}
</pre>
</div>
{% endif %}
{% if output['unl'] %}
<div
class=
'col-12 md-6'
>
<h2>
Unl
</h2>
<div
class=
'row justify-content-center'
>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
onclick=
"download('text.ttl', 'svg', 'html',
'image/svg+xml')"
>
Download image
<i
class=
"fas fa-download"
></i></button>
</div>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
onclick=
"download('graph.dot', 'dot', 'text',
'text/plain;charset=utf-8')"
>
Download source
<i
class=
"fas
fa-download"
></i></button>
</div>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
data-toggle=
"collapse"
data-target=
"#svg"
aria-expanded=
"true"
aria-controls=
"svg"
>
Toggle image
</button>
</div>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
data-toggle=
"collapse"
data-target=
"#dotdiv"
aria-expanded=
"false"
aria-controls=
"dotdiv"
>
Toggle source
</button>
</div>
</div>
<div
id=
'svg'
class=
'collapse show'
>
{{ output['svg'] | safe }}
</div>
<div
id=
'dotdiv'
class=
'collapse'
>
<pre>
<code
id=
'dot'
>
{{ output['dot'] }}
</code>
</pre>
</div>
</div>
{% endif %}
{% if output['rdf'] %}
<div
class=
'col-12 md-6'
>
<h2>
RDF
</h2>
<div
class=
'row justify-content-center'
>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
onclick=
"download('out.ttl', 'rdf', 'text', 'application/x-turtle')"
>
Download RDF
<i
class=
"fas fa-download"
></i></button>
</div>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
data-toggle=
"collapse"
data-target=
"#rdf"
aria-expanded=
"true"
aria-controls=
"rdf"
>
Toggle RDF
</button>
</div>
</div>
<pre>
<code
id=
'rdf'
class=
'collapse show'
>
{{ output['rdf'] }}
</code>
</pre>
</div>
{% endif %}
<div
class=
'col-12 md-6'
>
<h2>
UNL
</h2>
<div
class=
'row justify-content-center'
>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
onclick=
"download('in.unl', 'unl', 'text', 'text/plain;charset=utf-8')"
>
Download UNL
<i
class=
"fas fa-download"
></i></button>
</div>
<div
class=
'col-3'
>
<button
class=
"btn btn-primary"
type=
"button"
data-toggle=
"collapse"
data-target=
"#unl"
aria-expanded=
"true"
aria-controls=
"unl"
>
Toggle UNL
</button>
</div>
</div>
<pre>
<code
id=
'unl'
class=
'collapse show'
>
{{ unl }}
</code>
</pre>
</div>
</div>
{% 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