Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
msx-tool
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
FoodInformatics
msx-tool
Commits
b8b1ec04
Commit
b8b1ec04
authored
4 years ago
by
Jim Hoekstra
Browse files
Options
Downloads
Patches
Plain Diff
the graph layout changes when submitting a new term, but not when adding or removing associations
parent
5302388b
No related branches found
No related tags found
1 merge request
!6
MSX-27
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dash_app/app.py
+17
-14
17 additions, 14 deletions
dash_app/app.py
dash_app/graph.py
+2
-1
2 additions, 1 deletion
dash_app/graph.py
dash_app/words.py
+2
-1
2 additions, 1 deletion
dash_app/words.py
with
21 additions
and
16 deletions
dash_app/app.py
+
17
−
14
View file @
b8b1ec04
...
@@ -16,7 +16,8 @@ external_stylesheets = [
...
@@ -16,7 +16,8 @@ external_stylesheets = [
]
]
app
=
dash
.
Dash
(
name
=
__name__
,
external_stylesheets
=
external_stylesheets
,
url_base_pathname
=
'
/msx/
'
)
app
=
dash
.
Dash
(
name
=
__name__
,
external_stylesheets
=
external_stylesheets
,
url_base_pathname
=
'
/msx/
'
,
suppress_callback_exceptions
=
True
)
graph
=
Graph
()
graph
=
Graph
()
graph
.
fill_with_associations
(
'
fruit
'
)
graph
.
fill_with_associations
(
'
fruit
'
)
cyto_graph
=
graph
.
get_graph
(
'
msx-graph
'
)
cyto_graph
=
graph
.
get_graph
(
'
msx-graph
'
)
...
@@ -32,14 +33,14 @@ app.layout = html.Div(children=[
...
@@ -32,14 +33,14 @@ app.layout = html.Div(children=[
html
.
H2
(
children
=
'
Term:
'
),
html
.
H2
(
children
=
'
Term:
'
),
]),
]),
html
.
Div
(
className
=
'
col-9
'
,
children
=
[
html
.
Div
(
className
=
'
col-9
'
,
children
=
[
dcc
.
Input
(
id
=
'
base-word-input
'
,
value
=
'
fruit
'
,
type
=
'
text
'
,
className
=
'
form-control form-control-lg
'
),
dcc
.
Input
(
id
=
'
base-word-input
'
,
value
=
''
,
type
=
'
text
'
,
className
=
'
form-control form-control-lg
'
),
]),
]),
html
.
Div
(
className
=
'
col-2
'
,
children
=
[
html
.
Div
(
className
=
'
col-2
'
,
children
=
[
html
.
Button
(
id
=
'
base-word-submit
'
,
n_clicks_timestamp
=
0
,
children
=
'
Submit Term
'
,
className
=
'
btn btn-success btn-lg
'
)]),
html
.
Button
(
id
=
'
submit-word-button
'
,
n_clicks_timestamp
=
0
,
children
=
'
Submit Term
'
,
className
=
'
btn btn-success btn-lg
'
)]),
])
])
]),
]),
html
.
Br
(),
html
.
Br
(),
cyto_graph
,
html
.
Div
(
id
=
'
msx-graph-div
'
,
children
=
[
cyto_graph
])
,
html
.
Div
(
children
=
[
html
.
Div
(
children
=
[
html
.
Div
(
className
=
'
row
'
,
children
=
[
html
.
Div
(
className
=
'
row
'
,
children
=
[
html
.
Div
(
className
=
'
col-3
'
,
children
=
[
html
.
Div
(
className
=
'
col-3
'
,
children
=
[
...
@@ -64,27 +65,29 @@ server.config['SECRET_KEY'] = os.environ['MSX_SECRET_KEY']
...
@@ -64,27 +65,29 @@ server.config['SECRET_KEY'] = os.environ['MSX_SECRET_KEY']
@app.callback
(
@app.callback
(
Output
(
component_id
=
'
msx-graph
'
,
component_property
=
'
autoRefreshLayout
'
),
Output
(
component_id
=
'
msx-graph
'
,
component_property
=
'
elements
'
),
Output
(
component_id
=
'
msx-graph
'
,
component_property
=
'
elements
'
),
Input
(
component_id
=
'
base-word-submit
'
,
component_property
=
'
n_clicks_timestamp
'
),
Input
(
component_id
=
'
add-word-button
'
,
component_property
=
'
n_clicks_timestamp
'
),
Input
(
component_id
=
'
add-word-button
'
,
component_property
=
'
n_clicks_timestamp
'
),
Input
(
component_id
=
'
remove-word-button
'
,
component_property
=
'
n_clicks_timestamp
'
),
Input
(
component_id
=
'
remove-word-button
'
,
component_property
=
'
n_clicks_timestamp
'
),
Input
(
component_id
=
'
submit-word-button
'
,
component_property
=
'
n_clicks_timestamp
'
),
State
(
component_id
=
'
msx-graph
'
,
component_property
=
'
tapNodeData
'
),
State
(
component_id
=
'
msx-graph
'
,
component_property
=
'
tapNodeData
'
),
State
(
component_id
=
'
add-word-input
'
,
component_property
=
'
value
'
),
State
(
component_id
=
'
base-word-input
'
,
component_property
=
'
value
'
),
State
(
component_id
=
'
base-word-input
'
,
component_property
=
'
value
'
),
State
(
component_id
=
'
add-word-input
'
,
component_property
=
'
value
'
)
)
)
def
select_node
(
submit_button_ts
,
add_button_ts
,
remove_button_ts
,
graph_selected
,
base_word
,
add_word
):
def
graph_elements_callback
(
add_button_ts
,
remove_button_ts
,
submit_button_ts
,
graph_selected
,
add_word
,
base_word
):
if
remove_button_ts
>
submit_button_ts
and
remove_button_ts
>
add_button_ts
:
if
submit_button_ts
>
remove_button_ts
and
submit_button_ts
>
add_button_ts
:
graph
.
fill_with_associations
(
base_word
)
graph_elements
=
graph
.
get_graph_elements
()
return
True
,
graph_elements
if
remove_button_ts
>
add_button_ts
:
if
graph_selected
is
not
None
:
if
graph_selected
is
not
None
:
graph
.
remove_node
(
graph_selected
[
'
label
'
])
graph
.
remove_node
(
graph_selected
[
'
label
'
])
if
submit_button_ts
>
add_button_ts
and
submit_button_ts
>
remove_button_ts
:
if
add_button_ts
>
remove_button_ts
:
if
base_word
is
not
None
and
base_word
!=
''
:
graph
.
fill_with_associations
(
base_word
)
if
add_button_ts
>
submit_button_ts
and
add_button_ts
>
remove_button_ts
:
if
add_word
is
not
None
and
add_word
!=
''
:
if
add_word
is
not
None
and
add_word
!=
''
:
graph
.
add_node
(
add_word
)
graph
.
add_node
(
add_word
)
graph
.
add_edge
(
graph
.
get_base_word
(),
add_word
)
graph
.
add_edge
(
graph
.
get_base_word
(),
add_word
)
graph_elements
=
graph
.
get_graph_elements
()
graph_elements
=
graph
.
get_graph_elements
()
return
graph_elements
return
False
,
graph_elements
This diff is collapsed.
Click to expand it.
dash_app/graph.py
+
2
−
1
View file @
b8b1ec04
...
@@ -73,7 +73,8 @@ class Graph:
...
@@ -73,7 +73,8 @@ class Graph:
def
get_graph
(
self
,
component_id
):
def
get_graph
(
self
,
component_id
):
elements
=
self
.
get_graph_elements
()
elements
=
self
.
get_graph_elements
()
return
cyto
.
Cytoscape
(
id
=
component_id
,
return
cyto
.
Cytoscape
(
id
=
component_id
,
layout
=
{
'
name
'
:
'
cose
'
,
'
animate
'
:
False
},
autoRefreshLayout
=
True
,
layout
=
{
'
name
'
:
'
cose
'
,
'
animate
'
:
True
},
style
=
{
'
width
'
:
'
100%
'
,
'
height
'
:
'
550px
'
},
style
=
{
'
width
'
:
'
100%
'
,
'
height
'
:
'
550px
'
},
elements
=
elements
,
elements
=
elements
,
userZoomingEnabled
=
False
,
userZoomingEnabled
=
False
,
...
...
This diff is collapsed.
Click to expand it.
dash_app/words.py
+
2
−
1
View file @
b8b1ec04
...
@@ -8,7 +8,7 @@ class AssociatedWords:
...
@@ -8,7 +8,7 @@ class AssociatedWords:
self
.
N_RESULTS
=
10
self
.
N_RESULTS
=
10
print
(
"
\n
Word2Vec model is loading.This can take a couple of minutes.
"
)
print
(
"
\n
Word2Vec model is loading.This can take a couple of minutes.
"
)
self
.
model
=
api
.
load
(
'
glove-twitter-200
'
)
self
.
model
=
api
.
load
(
'
glove-twitter-200
'
)
print
(
"
\n
Word2Vec model is ready. Enjoy!!!
"
)
print
(
"
Word2Vec model is ready. Enjoy!!!
\n
"
)
self
.
base_word
=
None
self
.
base_word
=
None
self
.
gensim_result
=
None
self
.
gensim_result
=
None
...
@@ -18,6 +18,7 @@ class AssociatedWords:
...
@@ -18,6 +18,7 @@ class AssociatedWords:
def
set_base_word
(
self
,
word
):
def
set_base_word
(
self
,
word
):
self
.
base_word
=
word
self
.
base_word
=
word
self
.
gensim_result
=
self
.
model
.
most_similar
(
self
.
base_word
,
topn
=
self
.
N_RESULTS
)
self
.
gensim_result
=
self
.
model
.
most_similar
(
self
.
base_word
,
topn
=
self
.
N_RESULTS
)
# self.gensim_result = [('apple', 1.0), ('banana', 1.0), ('strawberry', 1.0)]
self
.
filter_results
()
self
.
filter_results
()
def
filter_results
(
self
):
def
filter_results
(
self
):
...
...
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