Skip to content

Commit

Permalink
Display co-occurring words
Browse files Browse the repository at this point in the history
  • Loading branch information
memgonzales committed Aug 30, 2023
1 parent 6d67cdd commit 1298aec
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/callbacks/home/api_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ def get_word_embeddings_db(API_URL, word):
except:
return pd.DataFrame()


def get_pca_embeddings(API_URL, sense_id):
try:
res = requests.get(f'{API_URL}/get_pca_embeddings/?sense_id={sense_id}')
res = requests.get(
f'{API_URL}/get_pca_embeddings/?sense_id={sense_id}')
pca_embeddings = res.json()

return pca_embeddings
except:
return None
return None


def get_netsci_word(API_URL, word):
try:
res = requests.get(f'{API_URL}/get_netsci_word/?word={word}')
netsci_word = res.json()

return netsci_word
except:
return None
31 changes: 30 additions & 1 deletion src/callbacks/home/network/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
from dash import Input, Output
from dash import Input, Output, dcc, html
from plotly.graph_objs import *
from dash.exceptions import PreventUpdate
from ..api_query import *
from .util import *


def init_callback(app, API_URL):
@app.callback(
Output('communities-dropdown', 'options'),
Output('communities-dropdown', 'value'),
Input('submitted-word', 'data')
)
def populate_communities_dropdown(word):
if word:
return [{'label': 'Sense ' + str(i + 1), 'value': i} for i in range(get_num_senses(API_URL, word))], 0

raise PreventUpdate

@app.callback(
Output('input-word-network', 'children'),
Input('submitted-word', 'data')
Expand All @@ -20,3 +31,21 @@ def search_word(word):
return [f'No Word Found: {word}']

raise PreventUpdate

@app.callback(
Output('network-cooccurring-words', 'children'),
Input('submitted-word', 'data'),
Input('communities-dropdown', 'value')
)
def display_co_occurring_words(word, sense_id):
for entry in get_netsci_word(API_URL, word):
if entry['sense_id'] == f'ns_{word}_{sense_id}':
cooccurring_words = [dcc.Link(cooccurring_word, href='', style={'text-decoration': 'none'})
for cooccurring_word in entry['community']]

ret_val = []
for cooccurring_word in cooccurring_words:
ret_val.append(cooccurring_word)
ret_val.append(html.Span(' ', className='me-2'))

return ret_val
5 changes: 5 additions & 0 deletions src/callbacks/home/network/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ..api_query import *


def get_num_senses(API_URL, word):
return len(get_netsci_word(API_URL, word))
13 changes: 11 additions & 2 deletions src/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@
html.Div([
'Words that frequently appear together with ',
html.Span(id='input-word-network')
])
], className='mb-2 mt-2'),

dcc.Dropdown(
id='communities-dropdown',
value='Sense 1'
),

html.Br(),

dcc.Loading(html.Div(id='network-cooccurring-words'))
])
])

Expand Down Expand Up @@ -198,7 +207,7 @@

word_plot_modal,

dcc.Loading(dcc.Graph(id="graph-source"))
dcc.Graph(id="graph-source")
])
)
])
Expand Down

0 comments on commit 1298aec

Please sign in to comment.