forked from knowledge-learning/ehealthkd-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
89 lines (63 loc) · 2.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pandas as pd
import streamlit as st
from kdtools.conceptnet import ConceptNet, ConceptNetEncoder
tab = st.sidebar.selectbox("Tab", ["hello", "cnet", "cnet_encoder"])
if tab == "hello":
"# Hello"
"Choose a tag in the sidebar!!!"
elif tab == "cnet":
"# ConceptNet"
cnet = ConceptNet()
"## Head "
st.table(cnet().sample(5))
st.show(cnet.unknown_rels)
st.show(cnet.SYMMETRIC_RELS)
st.show(cnet.ASYMMETRIC_RELS)
possible_languages = cnet.possible_languages()
possible_pos = cnet.possible_pos()
st.sidebar.subheader("Relation")
rel = st.sidebar.selectbox("Label", [None] + cnet.relations())
st.sidebar.subheader("Source")
source = st.sidebar.text_input("Text", key="Source Text")
source = source if source.strip() else None
source_language = st.sidebar.multiselect(
"Language", possible_languages, key="Source Language", default=["es"]
)
source_language = source_language if source_language else None
source_pos = st.sidebar.multiselect("Pos", possible_pos, key="Source Pos")
source_pos = source_pos if source_pos else None
st.sidebar.subheader("Head")
head = st.sidebar.text_input("Text", key="Head Text", value="asthma")
head = head if head.strip() else None
head_language = st.sidebar.multiselect(
"Language", possible_languages, key="Head Language", default=["en"]
)
head_language = head_language if head_language else None
head_pos = st.sidebar.multiselect("Pos", possible_pos, key="Head Pos")
head_pos = head_pos if head_pos else None
selected = cnet(
rel=rel,
source=source,
head=head,
source_language=source_language,
head_language=head_language,
source_pos=source_pos,
head_pos=head_pos,
)
try:
st.table(selected.sample(5))
except ValueError:
st.table(selected.head())
elif tab == "cnet_encoder":
"# ConceptNet Encoder"
mode = st.sidebar.selectbox("Mode", ["simple", "deep"])
if mode == 'deep':
import es_core_news_md
nlp = es_core_news_md.load()
else:
nlp = None
encoder = ConceptNetEncoder.from_clustered_entities([["asma", "asthma"]], mode, nlp=nlp)
st.show(encoder._relations)
st.show(len(encoder))
st.show(encoder("asma", "asthma"))
st.show(encoder("asma", "gato"))