Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
web-openccg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ease-ph
DeepLanguageUnderstanding
web-openccg
Commits
e08d45c0
Unverified
Commit
e08d45c0
authored
6 years ago
by
Sebastian Höffner
Browse files
Options
Downloads
Patches
Plain Diff
Using blueprint for redirection.
parent
4c07d897
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/ccgapp.py
+16
-43
16 additions, 43 deletions
app/ccgapp.py
app/templates/base.html
+2
-2
2 additions, 2 deletions
app/templates/base.html
app/templates/form.html
+1
-1
1 addition, 1 deletion
app/templates/form.html
with
19 additions
and
46 deletions
app/ccgapp.py
+
16
−
43
View file @
e08d45c0
...
...
@@ -2,49 +2,12 @@ import json
import
os
import
uuid
from
flask
import
Flask
,
render_template
,
request
,
redirect
from
werkzeug.wsgi
import
DispatcherMiddleware
from
flask
import
Blueprint
,
Flask
,
render_template
,
request
,
redirect
import
wccg
def
create_redirecting_app
(
to
):
"""
Creates a dummy flask app which redirects to
'
to
'
for the root url.
"""
app
=
Flask
(
'
redirector
'
)
@app.route
(
'
/
'
)
def
index
():
return
redirect
(
to
,
code
=
301
)
return
app
def
create_app
():
"""
Initializes the Flask app.
Reads the environment variable APPLICATION_ROOT and creates a
DispatcherMiddleware if it is set to something different than /.
This allows to mount the app in a subdirectory.
"""
app
=
Flask
(
__name__
)
app
.
config
[
'
APPLICATION_ROOT
'
]
=
os
.
environ
.
get
(
'
APPLICATION_ROOT
'
,
'
/
'
)
if
app
.
config
[
'
APPLICATION_ROOT
'
]
!=
'
/
'
:
if
app
.
config
[
'
APPLICATION_ROOT
'
].
endswith
(
'
/
'
):
app
.
config
[
'
APPLICATION_ROOT
'
]
=
app
.
config
[
'
APPLICATION_ROOT
'
][:
-
1
]
redirector
=
create_redirecting_app
(
app
.
config
[
'
APPLICATION_ROOT
'
])
mounts
=
{
app
.
config
[
'
APPLICATION_ROOT
'
]:
app
.
wsgi_app
}
app
.
wsgi_app
=
DispatcherMiddleware
(
redirector
,
mounts
)
app
.
logger
.
info
(
'
APPLICATION_ROOT=%s
'
,
app
.
config
[
'
APPLICATION_ROOT
'
])
return
app
app
=
create_app
()
bp
=
Blueprint
(
'
openccg
'
,
__name__
,
template_folder
=
'
templates
'
)
def
create_response
(
sentence
):
...
...
@@ -66,12 +29,11 @@ def create_response(sentence):
'
uuid
'
:
str
(
uuid
.
uuid4
())
}
response
.
update
(
content
)
response
.
update
(
graphs
.
create_graphs
(
response
[
'
json_parses
'
]))
return
response
@
ap
p.route
(
'
/parse
'
,
methods
=
[
'
POST
'
])
@
b
p.route
(
'
/parse
'
,
methods
=
[
'
POST
'
])
def
parse
():
"""
Handles parse requests.
...
...
@@ -98,12 +60,12 @@ def parse():
return
json
.
dumps
(
response
),
response
[
'
http_status
'
]
@
ap
p.route
(
'
/use
'
)
@
b
p.route
(
'
/use
'
)
def
use
():
return
render_template
(
'
use.html
'
)
@
ap
p.route
(
'
/
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@
b
p.route
(
'
/
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
index
():
"""
This method shows a minimal user interface.
"""
if
request
.
method
==
'
POST
'
:
...
...
@@ -116,5 +78,16 @@ def index():
return
render_template
(
'
form.html
'
,
sentence
=
sentence
,
response
=
response
)
app
=
Flask
(
__name__
)
@app.route
(
'
/
'
)
def
redirect_to_blueprint
():
return
redirect
(
'
openccg
'
,
301
)
app
.
register_blueprint
(
bp
,
url_prefix
=
'
/openccg
'
)
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
,
host
=
'
0.0.0.0
'
)
This diff is collapsed.
Click to expand it.
app/templates/base.html
+
2
−
2
View file @
e08d45c0
...
...
@@ -9,8 +9,8 @@
</head>
<body>
<header>
<a
href=
"{{ url_for('index') }}"
class=
"logo"
>
Web OpenCCG
</a>
<a
href=
"{{ url_for('use') }}"
class=
"button"
>
API
</a>
<a
href=
"{{ url_for('
openccg.
index') }}"
class=
"logo"
>
Web OpenCCG
</a>
<a
href=
"{{ url_for('
openccg.
use') }}"
class=
"button"
>
API
</a>
<a
href=
"https://github.com/shoeffner/web-openccg"
class=
"button"
>
Source
</a>
<a
href=
"http://openccg.sourceforge.net/"
class=
"button"
>
OpenCCG
</a>
</header>
...
...
This diff is collapsed.
Click to expand it.
app/templates/form.html
+
1
−
1
View file @
e08d45c0
...
...
@@ -59,7 +59,7 @@
{% endblock head %}
{% block content %}
<form
action=
"{{ url_for('index') }}"
method=
"POST"
>
<form
action=
"{{ url_for('
openccg.
index') }}"
method=
"POST"
>
<div
class=
"input-group fluid"
>
<input
type=
"text"
name=
"sentence"
value=
"{{ sentence or '' }}"
placeholder=
"Take the cup off the table."
/>
<input
type=
"submit"
value=
"Go!"
/>
...
...
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