|
a |
|
b/wrapper_functions/demo.py |
|
|
1 |
from EHRKit import EHRKit |
|
|
2 |
|
|
|
3 |
if __name__ == '__main__': |
|
|
4 |
print("Welcome to LILY-EHRKit. Here's a complete run-through of all EHRKit text processing functions.") |
|
|
5 |
|
|
|
6 |
# initialize EHRKit object |
|
|
7 |
kit = EHRKit() |
|
|
8 |
|
|
|
9 |
print("========== Start of SciSpacy Functions ==========") |
|
|
10 |
|
|
|
11 |
print('\n\n') |
|
|
12 |
print('Abbreviations') |
|
|
13 |
|
|
|
14 |
record = "Spinal and bulbar muscular atrophy (SBMA) is an " \ |
|
|
15 |
"inherited motor neuron disease caused by the expansion" \ |
|
|
16 |
"of a polyglutamine tract within the androgen receptor (AR)." \ |
|
|
17 |
"SBMA can be caused by this easily." |
|
|
18 |
|
|
|
19 |
kit.update_and_delete_main_record(record) |
|
|
20 |
print(kit.get_abbreviations()) |
|
|
21 |
|
|
|
22 |
print('\n\n') |
|
|
23 |
print('Hyponyms') |
|
|
24 |
|
|
|
25 |
record = "Keystone plant species such as fig trees are good for the soil." |
|
|
26 |
|
|
|
27 |
kit.update_and_delete_main_record(record) |
|
|
28 |
print(kit.get_hyponyms()) |
|
|
29 |
|
|
|
30 |
print('\n\n') |
|
|
31 |
print('Linked entities') |
|
|
32 |
|
|
|
33 |
record = "Spinal and bulbar muscular atrophy (SBMA) is an " \ |
|
|
34 |
"inherited motor neuron disease caused by the expansion" \ |
|
|
35 |
"of a polyglutamine tract within the androgen receptor (AR)." \ |
|
|
36 |
"SBMA can be caused by this easily." |
|
|
37 |
|
|
|
38 |
kit.update_and_delete_main_record(record) |
|
|
39 |
print(kit.get_linked_entities()) |
|
|
40 |
|
|
|
41 |
print('\n\n') |
|
|
42 |
print('Named entities') |
|
|
43 |
|
|
|
44 |
record = """ |
|
|
45 |
Myeloid derived suppressor cells (MDSC) are immature |
|
|
46 |
myeloid cells with immunosuppressive activity. |
|
|
47 |
They accumulate in tumor-bearing mice and humans |
|
|
48 |
with different types of cancer, including hepatocellular |
|
|
49 |
carcinoma (HCC). |
|
|
50 |
""" |
|
|
51 |
|
|
|
52 |
kit.update_and_delete_main_record(record) |
|
|
53 |
print(kit.get_named_entities()) |
|
|
54 |
|
|
|
55 |
print("========== End of SciSpacy Functions ==========") |
|
|
56 |
print('\n\n') |
|
|
57 |
|
|
|
58 |
# translation |
|
|
59 |
print("========== Start of Translation ==========") |
|
|
60 |
|
|
|
61 |
# reference: https://qbi.uq.edu.au/brain/brain-anatomy/what-neuron |
|
|
62 |
record = "Neurons (also called neurones or nerve cells) are the fundamental units of the brain and nervous system, " \ |
|
|
63 |
"the cells responsible for receiving sensory input from the external world, for sending motor commands to " \ |
|
|
64 |
"our muscles, and for transforming and relaying the electrical signals at every step in between. More than " \ |
|
|
65 |
"that, their interactions define who we are as people. Having said that, our roughly 100 billion neurons do" \ |
|
|
66 |
" interact closely with other cell types, broadly classified as glia (these may actually outnumber neurons, " \ |
|
|
67 |
"although it’s not really known)." |
|
|
68 |
|
|
|
69 |
kit.update_and_delete_main_record(record) |
|
|
70 |
print(kit.get_translation('French')) |
|
|
71 |
|
|
|
72 |
print("========== End of Translation ==========") |
|
|
73 |
|
|
|
74 |
# segmentation |
|
|
75 |
print("========== Start of Sentencizer ==========") |
|
|
76 |
|
|
|
77 |
record = "Neurons (also called neurones or nerve cells) are the fundamental units of the brain and nervous system, " \ |
|
|
78 |
"the cells responsible for receiving sensory input from the external world, for sending motor commands to " \ |
|
|
79 |
"our muscles, and for transforming and relaying the electrical signals at every step in between. More than " \ |
|
|
80 |
"that, their interactions define who we are as people. Having said that, our roughly 100 billion neurons do" \ |
|
|
81 |
" interact closely with other cell types, broadly classified as glia (these may actually outnumber neurons, " \ |
|
|
82 |
"although it’s not really known)." |
|
|
83 |
|
|
|
84 |
kit.update_and_delete_main_record(record) |
|
|
85 |
|
|
|
86 |
print('Using stanza') |
|
|
87 |
print(kit.get_sentences('stanza')) |
|
|
88 |
|
|
|
89 |
print('Using PyRush') |
|
|
90 |
print(kit.get_sentences('pyrush')) |
|
|
91 |
|
|
|
92 |
print('Using SciSpacy') |
|
|
93 |
print(kit.get_sentences('scispacy')) |
|
|
94 |
|
|
|
95 |
print("========== End of Sentencizer ==========") |
|
|
96 |
|
|
|
97 |
# clustering |
|
|
98 |
print("========== Start of Clustering ==========") |
|
|
99 |
|
|
|
100 |
record = "Neurons (also called neurones or nerve cells) are the fundamental units of the brain and nervous system, " \ |
|
|
101 |
"the cells responsible for receiving sensory input from the external world, for sending motor commands to " \ |
|
|
102 |
"our muscles, and for transforming and relaying the electrical signals at every step in between. More than " \ |
|
|
103 |
"that, their interactions define who we are as people. Having said that, our roughly 100 billion neurons do" \ |
|
|
104 |
" interact closely with other cell types, broadly classified as glia (these may actually outnumber neurons, " \ |
|
|
105 |
"although it’s not really known)." |
|
|
106 |
|
|
|
107 |
# reference: https://www.investopedia.com/terms/n/neuralnetwork.asp |
|
|
108 |
cand1 = "A neural network is a series of algorithms that endeavors to recognize underlying relationships in a set of " \ |
|
|
109 |
"data through a process that mimics the way the human brain operates. In this sense, neural networks refer to " \ |
|
|
110 |
"systems of neurons, either organic or artificial in nature." |
|
|
111 |
|
|
|
112 |
# reference: https://medlineplus.gov/druginfo/meds/a682878.html |
|
|
113 |
cand2 = "Prescription aspirin is used to relieve the symptoms of rheumatoid arthritis (arthritis caused by swelling " \ |
|
|
114 |
"of the lining of the joints), osteoarthritis (arthritis caused by breakdown of the lining of the joints), " \ |
|
|
115 |
"systemic lupus erythematosus (condition in which the immune system attacks the joints and organs and causes " \ |
|
|
116 |
"pain and swelling) and certain other rheumatologic conditions (conditions in which the immune system " \ |
|
|
117 |
"attacks parts of the body)." |
|
|
118 |
|
|
|
119 |
# reference: https://www.medicalnewstoday.com/articles/161255 |
|
|
120 |
cand3 = "People can buy aspirin over the counter without a prescription. Everyday uses include relieving headache, " \ |
|
|
121 |
"reducing swelling, and reducing a fever. Taken daily, aspirin can lower the risk of cardiovascular events, " \ |
|
|
122 |
"such as a heart attack or stroke, in people with a high risk. Doctors may administer aspirin immediately" \ |
|
|
123 |
" after a heart attack to prevent further clots and heart tissue death." |
|
|
124 |
|
|
|
125 |
kit.update_and_delete_main_record(record) |
|
|
126 |
kit.replace_supporting_records([cand1, cand2, cand3]) |
|
|
127 |
print(kit.get_clusters()) |
|
|
128 |
|
|
|
129 |
print("========== End of Clustering ==========") |
|
|
130 |
|
|
|
131 |
# similar documents |
|
|
132 |
print("========== Start of Similar Documents ==========") |
|
|
133 |
|
|
|
134 |
record = "Neurons (also called neurones or nerve cells) are the fundamental units of the brain and nervous system, " \ |
|
|
135 |
"the cells responsible for receiving sensory input from the external world, for sending motor commands to " \ |
|
|
136 |
"our muscles, and for transforming and relaying the electrical signals at every step in between. More than " \ |
|
|
137 |
"that, their interactions define who we are as people. Having said that, our roughly 100 billion neurons do" \ |
|
|
138 |
" interact closely with other cell types, broadly classified as glia (these may actually outnumber neurons, " \ |
|
|
139 |
"although it’s not really known)." |
|
|
140 |
|
|
|
141 |
# reference: https://www.investopedia.com/terms/n/neuralnetwork.asp |
|
|
142 |
cand1 = "A neural network is a series of algorithms that endeavors to recognize underlying relationships in a set of " \ |
|
|
143 |
"data through a process that mimics the way the human brain operates. In this sense, neural networks refer to " \ |
|
|
144 |
"systems of neurons, either organic or artificial in nature." |
|
|
145 |
|
|
|
146 |
# reference: https://medlineplus.gov/druginfo/meds/a682878.html |
|
|
147 |
cand2 = "Prescription aspirin is used to relieve the symptoms of rheumatoid arthritis (arthritis caused by swelling " \ |
|
|
148 |
"of the lining of the joints), osteoarthritis (arthritis caused by breakdown of the lining of the joints), " \ |
|
|
149 |
"systemic lupus erythematosus (condition in which the immune system attacks the joints and organs and causes " \ |
|
|
150 |
"pain and swelling) and certain other rheumatologic conditions (conditions in which the immune system " \ |
|
|
151 |
"attacks parts of the body)." |
|
|
152 |
|
|
|
153 |
# reference: https://www.medicalnewstoday.com/articles/161255 |
|
|
154 |
cand3 = "People can buy aspirin over the counter without a prescription. Everyday uses include relieving headache, " \ |
|
|
155 |
"reducing swelling, and reducing a fever. Taken daily, aspirin can lower the risk of cardiovascular events, " \ |
|
|
156 |
"such as a heart attack or stroke, in people with a high risk. Doctors may administer aspirin immediately" \ |
|
|
157 |
" after a heart attack to prevent further clots and heart tissue death." |
|
|
158 |
|
|
|
159 |
kit.update_and_delete_main_record(record) |
|
|
160 |
kit.replace_supporting_records([cand1, cand2, cand3]) |
|
|
161 |
print(kit.get_similar_documents(3)) |
|
|
162 |
|
|
|
163 |
print("========== End of Similar Documents ==========") |
|
|
164 |
|
|
|
165 |
""" UNDER CONSTRUCTION """ |
|
|
166 |
""" stanza functions """ |
|
|
167 |
# print dependencies |
|
|
168 |
record = "A neural network is a series of algorithms that endeavors to recognize underlying relationships in a set of " \ |
|
|
169 |
"data through a process that mimics the way the human brain operates. In this sense, neural networks refer to " \ |
|
|
170 |
"systems of neurons, either organic or artificial in nature." |
|
|
171 |
|
|
|
172 |
kit.update_and_delete_main_record(record) |
|
|
173 |
kit.get_dependency() |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|