Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d394b1

Browse filesBrowse files
committed
updated notebooks and data
1 parent 8d30d69 commit 3d394b1
Copy full SHA for 3d394b1

10 files changed

+3,757-185,250Lines changed: 3757 additions & 185250 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎notebooks/Abbreviations_extraction.ipynb‎

Copy file name to clipboardExpand all lines: notebooks/Abbreviations_extraction.ipynb
+178-7Lines changed: 178 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@
5959
},
6060
{
6161
"cell_type": "code",
62-
"execution_count": 2,
62+
"execution_count": 1,
6363
"metadata": {},
6464
"outputs": [
6565
{
6666
"data": {
6767
"application/vnd.jupyter.widget-view+json": {
68-
"model_id": "8c987b21d7c04f62b66651fdd555edff",
68+
"model_id": "46a8735bb95a411d9ef2513275e918cb",
6969
"version_major": 2,
7070
"version_minor": 0
7171
},
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 3,
95+
"execution_count": 32,
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
@@ -109,7 +109,7 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": 5,
112+
"execution_count": 33,
113113
"metadata": {},
114114
"outputs": [],
115115
"source": [
@@ -140,15 +140,15 @@
140140
},
141141
{
142142
"cell_type": "code",
143-
"execution_count": 9,
143+
"execution_count": 34,
144144
"metadata": {},
145145
"outputs": [
146146
{
147147
"name": "stdout",
148148
"output_type": "stream",
149149
"text": [
150-
"Processing file: C:\\Users\\damir\\Dropbox\\Develop\\python-tutorial-notebooks\\notebooks\\data\\medline_overview.txt\n",
151-
"({'NLM': 'National Library of Medicine’s', 'MeSH': 'Medical Subject Headings', 'NCBI': 'National Center for Biotechnology Information', 'MEDLARS': 'MEDical Literature Analysis and Retrieval System', 'LSTRC': 'Literature Selection Technical Review Committee'}, {'NLM': 'National Library of Medicine’s', 'MeSH': 'Medical Subject Headings', 'NCBI': 'National Center for Biotechnology Information', 'MEDLARS': 'MEDical Literature Analysis and Retrieval System', 'LSTRC': 'Literature Selection Technical Review Committee'})\n"
150+
"Processing file: C:\\Users\\damir\\Dropbox\\Develop\\python-tutorial-notebooks\\notebooks\\data\\bio_1.txt\n",
151+
"({'ER': 'endoplasmic reticulum'}, {'ER': 'endoplasmic reticulum'})\n"
152152
]
153153
}
154154
],
@@ -157,6 +157,177 @@
157157
"print(abbreviations)"
158158
]
159159
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": 35,
163+
"metadata": {},
164+
"outputs": [],
165+
"source": [
166+
"uri_prefix = \"http://www.indiana.edu/nlplab/bioterminology#\""
167+
]
168+
},
169+
{
170+
"cell_type": "code",
171+
"execution_count": 36,
172+
"metadata": {},
173+
"outputs": [],
174+
"source": [
175+
"from rdflib.namespace import RDF, RDFS, SKOS, OWL, DC, DCTERMS, XSD, TIME, NamespaceManager\n",
176+
"from rdflib import Graph, URIRef, Literal, Namespace"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": 37,
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"dictionary = {}\n",
186+
"for x in abbreviations:\n",
187+
" entry = tuple(x.items())[0]\n",
188+
" dictionary[uri_prefix + \"\".join([ z.title() for z in entry[1].split() ])] = entry\n"
189+
]
190+
},
191+
{
192+
"cell_type": "code",
193+
"execution_count": 38,
194+
"metadata": {},
195+
"outputs": [],
196+
"source": [
197+
"from pprint import pprint\n",
198+
"g = Graph()\n",
199+
"vaem_acronym = URIRef(\"http://www.linkedmodel.org/schema/vaem#acronym\")\n",
200+
"for key in dictionary:\n",
201+
" g.add( (URIRef(key), RDFS.label, Literal(dictionary[key][1])) )\n",
202+
" g.add( (URIRef(key), vaem_acronym, Literal(dictionary[key][0])) )\n"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": 39,
208+
"metadata": {},
209+
"outputs": [],
210+
"source": [
211+
"import spacy\n",
212+
"import pytextrank"
213+
]
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": 50,
218+
"metadata": {},
219+
"outputs": [
220+
{
221+
"data": {
222+
"text/plain": [
223+
"<pytextrank.base.BaseTextRankFactory at 0x22b2e203010>"
224+
]
225+
},
226+
"execution_count": 50,
227+
"metadata": {},
228+
"output_type": "execute_result"
229+
}
230+
],
231+
"source": [
232+
"nlp = spacy.load(\"en_core_web_trf\") # en_core_web_sm\")\n",
233+
"nlp.add_pipe(\"textrank\")"
234+
]
235+
},
236+
{
237+
"cell_type": "code",
238+
"execution_count": 53,
239+
"metadata": {},
240+
"outputs": [],
241+
"source": [
242+
"with open(os.path.join(fc.selected_path, fc.selected_filename), mode='r', encoding='utf-8') as ifp:\n",
243+
" text = ifp.read()"
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": 54,
249+
"metadata": {},
250+
"outputs": [],
251+
"source": [
252+
"doc = nlp(text)"
253+
]
254+
},
255+
{
256+
"cell_type": "markdown",
257+
"metadata": {},
258+
"source": [
259+
"for phrase in doc._.phrases:\n",
260+
" print(phrase.text)\n",
261+
" print(phrase.rank, phrase.count)\n",
262+
" print(phrase.chunks)\n",
263+
" print()"
264+
]
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": 46,
269+
"metadata": {},
270+
"outputs": [
271+
{
272+
"name": "stdout",
273+
"output_type": "stream",
274+
"text": [
275+
"{}\n"
276+
]
277+
}
278+
],
279+
"source": [
280+
"dictionary = {}\n",
281+
"for x in doc._.phrases:\n",
282+
" entry = x.text # tuple(x.items())[0]\n",
283+
" key = URIRef(uri_prefix + \"\".join([ z.title() for z in entry.split() ]))\n",
284+
" # = entry\n",
285+
" # for key in dictionary:\n",
286+
" g.add( (URIRef(key), RDFS.label, Literal(entry)) )\n",
287+
" # g.add( (URIRef(key), vaem_acronym, Literal(dictionary[key][0])) )\n",
288+
"print(dictionary)"
289+
]
290+
},
291+
{
292+
"cell_type": "code",
293+
"execution_count": 63,
294+
"metadata": {},
295+
"outputs": [],
296+
"source": [
297+
"nelabels = {\"ORG\": \"Organization\",\n",
298+
" \"PERSON\": \"Person\"}\n",
299+
"for k in nelabels:\n",
300+
" g.add( ( URIRef(uri_prefix + nelabels[k]), RDF.type, OWL.Class) )\n",
301+
"for ent in doc.ents:\n",
302+
" # print(ent.text, ent.label_)\n",
303+
" if ent.label_ in (\"ORG\", \"PERSON\"):\n",
304+
" key = URIRef(uri_prefix + \"\".join([ z.title() for z in ent.text.split() ]))\n",
305+
" type = nelabels[ent.label_]\n",
306+
" g.add( (key, RDF.type, URIRef(uri_prefix + type)) )\n",
307+
" g.add( (key, RDFS.label, Literal(ent.text)) )\n",
308+
" # print(ent.text, ent.label_)\n"
309+
]
310+
},
311+
{
312+
"cell_type": "code",
313+
"execution_count": 64,
314+
"metadata": {},
315+
"outputs": [
316+
{
317+
"data": {
318+
"text/plain": [
319+
"<Graph identifier=N8793d07f04814241b59925a0d5c3aeae (<class 'rdflib.graph.Graph'>)>"
320+
]
321+
},
322+
"execution_count": 64,
323+
"metadata": {},
324+
"output_type": "execute_result"
325+
}
326+
],
327+
"source": [
328+
"g.serialize(destination=\"data/test_graph.ttl\", format=\"turtle\", encoding=\"utf-8\")"
329+
]
330+
},
160331
{
161332
"attachments": {},
162333
"cell_type": "markdown",
Collapse file

‎notebooks/FrameNet Examples using NLTK.ipynb‎

Copy file name to clipboardExpand all lines: notebooks/FrameNet Examples using NLTK.ipynb
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"**(C) 2019-2020 by [Damir Cavar](http://damir.cavar.me/)**"
14+
"**(C) 2019-2023 by [Damir Cavar](http://damir.cavar.me/)**"
1515
]
1616
},
1717
{
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"**Version:** 0.3, April 2020"
21+
"**Version:** 0.4, September 2023"
2222
]
2323
},
2424
{
@@ -80,7 +80,7 @@
8080
"output_type": "stream",
8181
"text": [
8282
"[nltk_data] Downloading package framenet_v17 to\n",
83-
"[nltk_data] /home/damir/nltk_data...\n",
83+
"[nltk_data] C:\\Users\\damir\\AppData\\Roaming\\nltk_data...\n",
8484
"[nltk_data] Package framenet_v17 is already up-to-date!\n"
8585
]
8686
},
@@ -116,7 +116,7 @@
116116
},
117117
{
118118
"cell_type": "code",
119-
"execution_count": 1,
119+
"execution_count": 2,
120120
"metadata": {},
121121
"outputs": [],
122122
"source": [
@@ -132,7 +132,7 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": 2,
135+
"execution_count": 3,
136136
"metadata": {},
137137
"outputs": [
138138
{
@@ -141,7 +141,7 @@
141141
"1221"
142142
]
143143
},
144-
"execution_count": 2,
144+
"execution_count": 3,
145145
"metadata": {},
146146
"output_type": "execute_result"
147147
}
@@ -159,7 +159,7 @@
159159
},
160160
{
161161
"cell_type": "code",
162-
"execution_count": 3,
162+
"execution_count": 4,
163163
"metadata": {},
164164
"outputs": [
165165
{
@@ -168,7 +168,7 @@
168168
"[<frame ID=239 name=Medical_conditions>, <frame ID=257 name=Medical_instruments>, ...]"
169169
]
170170
},
171-
"execution_count": 3,
171+
"execution_count": 4,
172172
"metadata": {},
173173
"output_type": "execute_result"
174174
}
@@ -28558,7 +28558,7 @@
2855828558
"cell_type": "markdown",
2855928559
"metadata": {},
2856028560
"source": [
28561-
"**(C) 2019-2020 by [Damir Cavar](http://damir.cavar.me/)**"
28561+
"**(C) 2019-2023 by [Damir Cavar](http://damir.cavar.me/)**"
2856228562
]
2856328563
}
2856428564
],
@@ -28578,7 +28578,7 @@
2857828578
"name": "python",
2857928579
"nbconvert_exporter": "python",
2858028580
"pygments_lexer": "ipython3",
28581-
"version": "3.7.6"
28581+
"version": "3.11.5"
2858228582
},
2858328583
"toc": {
2858428584
"base_numbering": 1,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.