File size: 32,279 Bytes
0c3992e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/dfs/scratch0/shirwu/anaconda3/envs/torch2/lib/python3.8/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading dataset from external data\n",
      "Load cached graph with meta link types ['brand']\n"
     ]
    }
   ],
   "source": [
    "from src.benchmarks.get_qa_dataset import get_qa_dataset\n",
    "from src.benchmarks.get_semistruct import get_semistructured_data\n",
    "\n",
    "dataset_name = 'amazon'\n",
    "\n",
    "qa_dataset = get_qa_dataset(dataset_name)\n",
    "kb = get_semistructured_data(dataset_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load QA dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Query: Looking for a user-friendly fly fishing knot guide with clear, easy-to-understand illustrations. Ideally, it should be logically organised for easy learning and effective in teaching dependable knot tying techniques. It would be a bonus if it complements the Anglers Accessories Gehrke's Gink that I frequently use. Any recommendations?\n",
      "Query ID: 30\n",
      "Answer:\n",
      " Lake Products THREE-in-One Knot Tying Tool Fly Fishing\n",
      "EZ Tie Blood Knot Tying Tool\n",
      "BenchMaster Pocket Guide - Fly Fishing - Fishing\n"
     ]
    }
   ],
   "source": [
    "# Get one qa pair, we masked out metadata to avoid answer leaking\n",
    "query, q_id, answer_ids, _ = qa_dataset[1]\n",
    "print('Query:', query)\n",
    "print('Query ID:', q_id)\n",
    "print('Answer:\\n', '\\n'.join([kb[aid].title for aid in answer_ids]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of training examples: 5910\n",
      "Number of validation examples: 1548\n",
      "Number of test examples: 1642\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'train': tensor([3885, 4522, 2110,  ..., 6839, 3967, 2814]),\n",
       " 'val': tensor([1550, 1486, 6591,  ..., 5606, 1204, 3792]),\n",
       " 'test': tensor([2905, 3863, 4651,  ..., 3891, 7631, 4472])}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We provide official random split for training, validation and test\n",
    "print('Number of training examples:', len(qa_dataset.get_subset('train')))\n",
    "print('Number of validation examples:', len(qa_dataset.get_subset('val')))\n",
    "print('Number of test examples:', len(qa_dataset.get_subset('test')))\n",
    "\n",
    "# Alternatively, you can get the split indices\n",
    "qa_dataset.get_idx_split()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load Knowledge Base"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('brand', 'has_brand', 'product'),\n",
       " ('product', 'also_buy', 'product'),\n",
       " ('product', 'also_view', 'product'),\n",
       " ('product', 'has_brand', 'brand')]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# You can see part of the knowledge base schema here\n",
    "kb.get_tuples()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['product', 'brand'], ['also_buy', 'also_view', 'has_brand'])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Similarly, you can get the node and relation types \n",
    "kb.node_type_lst(), kb.rel_type_lst()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of nodes: 1032407\n",
      "Number of edges: 6455692\n"
     ]
    }
   ],
   "source": [
    "print('Number of nodes:', kb.num_nodes())\n",
    "print('Number of edges:', kb.num_edges())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'product': ['title',\n",
       "  'dimensions',\n",
       "  'weight',\n",
       "  'description',\n",
       "  'features',\n",
       "  'reviews',\n",
       "  'Q&A'],\n",
       " 'brand': ['brand_name']}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We include the attributes in node's textual information as part of the schema\n",
    "# Note that some nodes may not have all attributes while some may have additional attributes\n",
    "kb.node_attr_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- product: Lake Products THREE-in-One Knot Tying Tool Fly Fishing\n",
      "- brand: Lake\n",
      "- description: NEW & IMPROVED - Replaces the Two-in-One Knot Tying Tool - still ties many over 14 different knots, but now adds a magnetic hook threader; made of Delron and stainless steel; instruction book included.Precision machined contact firmly grips any fishing line, without causing damageUp and down spring action with stainless steel springThe body is manufactured of strong, lightweight Acetel Delrin for years of reliable serviceStainless Steel Shaft, head and loop will not rust or corrodeAttachment loop to clip onto clothing\n",
      "- features: \n",
      "#1: Precision machined contact firmly grips any fishing line, without causing damage\n",
      "#2: Up and down spring action with stainless steel spring\n",
      "#3: The body is manufactured of strong, lightweight Acetel Delrin for years of reliable service\n",
      "#4: Stainless Steel Shaft, head and loop will not rust or corrode\n",
      "#5: Attachment loop to clip onto clothing\n",
      "- reviews: \n",
      "#9:\n",
      "summary: Works Great\n",
      "text: \"Due to an injury, I have no finger dexterity in either hand and cannot feel the fishing line while holding it between my thumb and finger.  It would literally take me about 15 minutes to tie a hook or swivel to my line and was extremely frustrating. This tool allows me to tie the knot in 15 seconds. It really works well and I recommend it.\"\n",
      "#3:\n",
      "summary: It works\n",
      "text: \"I got this last night and decided to give it a try. Size 16 nymph, small tippet, no reading glasses (don't laugh, you'll get there), and light gloves. Threaded the fly and tied a cinch knot with no issues several times. It does a lot more, but this alone made it worth it. Ever tried tying on a fly with cold fingers or low light? The only downside is I wish there was a color difference in the v slot where the line threads in. Not a big enough deal to make a difference in opinion.\"\n",
      "#4:\n",
      "summary: Excellent\n",
      "text: \"There are three curses to advancing years: (1) Fingers shake a bit more, (2) eyes don't see the small stuff as well in low light, and (3) we're still as irresponsible as we ever were--can't seem to stop ourselves from doing something stupid like getting up at 3:30 am to stand freezing in a stream, fingers shaking and eyes blurring even more from the chill.\n",
      "\n",
      "But this nice little gadget lets me tie even #22 flies onto a leader with ease. (And I couldn't really tie those on even when I was 25!) Using this tool to thread the tiniest hook eyes onto a leader may sometimes take a little concentration (must use a leader size appropriate for the hook eye, after all), but threading isn't the main thing we need--invariably our problem is tying the knot itself, without crushing the hackle, burying the hook into our finger, or losing the fly in the river during the attempt to hand-tie the knot. With this tool, in 8 or 10 seconds a secure clinch knot is done. Zero chance of losing the fly, having to start over, or foul language. I now find it easy to make the decision whether to try a different fly, because changing flies costs me almost no fishing time.\n",
      "\n",
      "The tool ties securely to a cord on the vest and is just plain there when (constantly) needed. The knots are as clean & compact and good as a knot can be. One time I did not have this tool with me, and I lost 20 minutes of my last fishing hour changing flies a couple of times.\n",
      "\n",
      "As long as I can get the fly threaded (this thing does often help with that too, although no tool is perfect for the very smallest of hook eyes on a bushy fly), then with this tool the job of tying the knot is a done deal.\n",
      "\n",
      "Also, I've found that Lake Products is very responsive and has a great customer service ethic. They really stand behind their product. I'm very happy with this little gizmo.\n",
      "\n",
      "- Michael Vorhis\n",
      ".....Author of OPEN DISTANCE deep sea/aviation thriller\n",
      ".....Author of ARCHANGEL suspense thriller\n",
      ".....Fly fisherman\"\n",
      "#2:\n",
      "summary: Excellent tool. Does what it says.\n",
      "text: \"Hard to imagine an easier toot to use to tie Surgeon's Knots, Clinch and improved Climnch knots which are alll that I really need on a day to day basis. Its hook threader works like a charm for the size 16 midges i typically use.\"\n",
      "#86:\n",
      "summary: Consider alternatives\n",
      "text: \"This device is supposed to tie a variety of knots and help you thread small hooks.  The material quality seems good with the body made from a tough plastic (think cutting board) and the metal parts (including spring) made from stainless.  I already thought the price was unreasonably high and was more disappointed when I tried to thread size 18 flies with great difficulty.  The threader is no panacea for resolving this problem, but for slightly larger hooks, it seems to work ok.  It looks like someone removed the mold marks with a pocket knife and a power sander.  Smooth, but crude.\n",
      "\n",
      "While the knot tier works well for tying clinch knots, I found that a pair of forceps, especially ones with a curved tip actually work better, and you probably already have those in your tackle box.  There are several good YouTube videos on how to use them.\"\n",
      "#6:\n",
      "summary: it works\n",
      "text: \"I have trouble seeing the sting at twilight due to my need for reading glasses ( which I use sunglass bifocals). THis product helps for threading hooks and tying knots.\"\n",
      "#7:\n",
      "summary: It works\n",
      "text: \"Showed and impressed other fly club members. I got 2, one for rigging and one for changes on the water.\"\n",
      "#1:\n",
      "summary: Makes tying knots much easier.\n",
      "text: \"As a 68 year old my vision isn't as good as it was.  I use the improved clinch knot the most and using the tip to pull the tag end through your loop eliminates the need for my reading glasses.  Also tying nail or albright knots using the double slotted end is much easier.\"\n",
      "#8:\n",
      "summary: worthless for smaller hooks\n",
      "text: \"Took a chance based on other reviews, but this product is worthless when it comes to threading smaller hooks, particular down-turned eyes in sizes 16 or smaller.\"\n",
      "#26:\n",
      "summary: Great product\n",
      "text: \"Replaced a heavier brass tyer with this one and it works great. Before this product I had the brass tyer and a nail knot tool in my pack now I only have this one freeing up space hanging from a retracter. Don't hesitate to purchase one, you will not be disappointed\"\n",
      "#23:\n",
      "summary: Might be a great product, but there's a good chance you'll never ...\n",
      "text: \"Might be a great product, but there's a good chance you'll never know because of the poor instructions that are provided with the tool. The major issues here are the small sizes of the font and diagrams, which makes it next to impossible to decrypt. I looked for a pdf of the knot typing manual on the seller's website and there is none, only an instructional video for an additional $5 or the same replacement manual for $3. Instruction on the use an application of a new tool is 90% of its value, and the seller must do a better job at this.\"\n",
      "#67:\n",
      "summary: My favorite thing in my fishing kit\n",
      "text: \"Love this thing.  I have several of these for various tackle boxes.  I got this in the yellow color for when I put it down.  The booklet that comes with this is professional and easy to understand.  It is a great attention device as you are sitting in the doctor's office and practicing knot tying.  Fly fishing to whatever.\n",
      "Note: Fly fishing purists use this when no one is looking.\"\n",
      "#14:\n",
      "summary: Almost ready to give up on fly fishing.\n",
      "text: \"So I was fly-fishing on the river and nothing was biting. So I decided to try a different fly. AftER about five minutes of trying and messing with the fly threader I purchased on a auction site. I pulled the tippet up off of the thread to learn the tippet wasn't in the hook eye, and seeing my fly pop up and drop in the river. I just lost another $1.50 fly and that was my last one. So I decided to try this threader before I quit fly fishing. Not only has this threader work for me everytime. But it's also a knot tyer. So now I can change flies in about a minute, instead of the 20 minutes it did before. This thread has a ring to clip to my lanyard, or to my zinger for easy access. Wish I would have purchased years ago. I might have done more fishing! Yes! I would recommend this to anyone!\"\n",
      "#48:\n",
      "summary: Helpful but not perfect\n",
      "text: \"It's very helpful for 64-year-old hands that struggle with tiny tippet and leader, but the design of the tip could be better. It can get tangled in the tip as line/tippet are drawn through loops. Maybe I just need some more practice, but it's been a challenge.\"\n",
      "#89:\n",
      "summary: Tool for Many Uses; Handy Item (Versatile)\n",
      "text: \"Although its not a solution for all problems encountered with threading lines through the eyes of hooks, flies, & lures, etc., the Lake Products 3-in-1 Knot Tying Tool has proven beneficial (for me) to carry it along each fishing outing.  There are some limitations to what it can help to accomplish.  For example, you cannot thread a line of large diameter through the eye of a smaller fly.  The 6X tippet or smaller diameters (7X, 8X, etc.) are required for the smaller flies.  Larger diameter tippets greater than 6X (5X, 4X, 3X, etc.) can be threaded into medium and large flies.  I was skeptical at first (and sometimes still don't accomplish all tasks that I would like to) but it has been tremendously helpful with knot tying as well.  Tying tippet-knots that create leader at the end of fly line is much simpler and quicker, and so is the knot thats needed once the line is threaded through the eye of the hook/fly.  The magnet that holds the fly is relatively strong to secure the fly while threading the eye.  Those who struggle with focusing (poor vision) will especially find it helpful.  Ive found it a worthwhile purchase and would recommend it to a friend.  At times, it has been my only method of achieving certain tasks.\"\n",
      "#88:\n",
      "summary: HANDY DANDY LAKE PRODUCT KNOT TYING TOOL\n",
      "text: \"all i can say about this product is its the best for old eyes and crooked hands. use it at least three times a week, would recommend\"\n",
      "#45:\n",
      "summary: Good to have if you're having trouble seeing small things.\n",
      "text: \"Very easy to use - once you read the instructions.  Not intuitive but works as documented.  Getting older and eyesight is diminishing so I bought a second one as a spare.\"\n",
      "#5:\n",
      "summary: Three in one tool.\n",
      "text: \"This tool is perfect for my failing eyesight and arthritic fingers.  Just what I needed.  The fisherman's magic wand for stiff and cold fingers\"\n",
      "#71:\n",
      "summary: Best invention ever.\n",
      "text: \"This tool is great. It speeds up my tying 100% and allows me to tie small flies on tiny tippets without much trouble. It definitely is worth every penny for an older man with arthritis and fading eyesight.\"\n",
      "#70:\n",
      "summary: easy to use tool\n",
      "text: \"Simpe to use and I carry it on all my fishing trips. sure makes it a lot easier to thread flies and tie them on the line\"\n",
      "#69:\n",
      "summary: The Best\n",
      "text: \"Makes it so easy with my shaky hands\"\n",
      "#68:\n",
      "summary: Great tool for all fly knots\n",
      "text: \"Helpful tool.  Really helps threading fly for these over 50 eyes\"\n",
      "#73:\n",
      "summary: Five Stars\n",
      "text: \"Great tool!\"\n",
      "#72:\n",
      "summary: Five Stars\n",
      "text: \"As expected\"\n",
      "#64:\n",
      "summary: Still learning to tie knots, and learn all the ...\n",
      "text: \"Still learning to tie knots, and learn all the different knots you can do with this tool. should prove to be very helpful\"\n",
      "#65:\n",
      "summary: Great Tool for all fishermen\n",
      "text: \"Does what it says it does if you follow the instruction booklet which is well written.  I tied 5X and 6X tippet together with ease...this is a versatile tool and NOT just for Clinch Knots or improved Clinch Knots which it does with ease.\"\n",
      "#74:\n",
      "summary: Three Stars\n",
      "text: \"GREAT IDEA - BUT STILL TRICKY IF YOUR HANDS SHAKE ANDPOOR EYE SIGHT\"\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Each node has textual information\n",
    "print(kb.get_doc_info(answer_ids[0], add_rel=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The neighbors of the answer node are: 222\n"
     ]
    }
   ],
   "source": [
    "# Each node can be linked to other nodes\n",
    "neighbor_lst = kb.get_neighbor_nodes(answer_ids[0], edge_type='*')\n",
    "print('The neighbors of the answer node are:', len(neighbor_lst))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Counter({'product': 221, 'brand': 1})\n"
     ]
    }
   ],
   "source": [
    "# Count the number of each type\n",
    "from collections import Counter\n",
    "neighbor_types = [kb.get_node_type_by_id(neighbor) for neighbor in neighbor_lst]\n",
    "print(Counter(neighbor_types))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Take PrimeKG as another example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading dataset from external data\n",
      "Loaded from data/primekg/processed!\n"
     ]
    }
   ],
   "source": [
    "dataset_name = 'primekg'\n",
    "\n",
    "qa_dataset = get_qa_dataset(dataset_name)\n",
    "kb = get_semistructured_data(dataset_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('What drugs target the CYP3A4 enzyme and are used to treat strongyloidiasis?',\n",
       " 1,\n",
       " [15450],\n",
       " None)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qa_dataset[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- name: Ivermectin\n",
      "- type: drug\n",
      "- source: DrugBank\n",
      "- details:\n",
      "  - description: Ivermectin is a broad-spectrum anti-parasite medication. It was first marketed under the name Stromectol® and used against worms (except tapeworms), but, in 2012, it was approved for the topical treatment of head lice infestations in patients 6 months of age and older, and marketed under the name Sklice™ as well. Ivermectin is mainly used in humans in the treatment of onchocerciasis, but is also effective against other worm infestations (such as strongyloidiasis, ascariasis, trichuriasis and enterobiasis).\n",
      "  - half_life: 16 hours (also reported at 22-28 hours)\n",
      "  - indication: For the treatment of intestinal (i.e., nondisseminated) strongyloidiasis due to the nematode parasite <i>Strongyloides stercoralis</i>. Also for the treatment of onchocerciasis (river blindness) due to the nematode parasite <i>Onchocerca volvulus</i>. Can be used to treat scabies caused by <i>Sarcoptes scabiei</i>.\n",
      "  - mechanism_of_action: Ivermectin binds selectively and with high affinity to glutamate-gated chloride ion channels in invertebrate muscle and nerve cells of the microfilaria. This binding causes an increase in the permeability of the cell membrane to chloride ions and results in hyperpolarization of the cell, leading to paralysis and death of the parasite. Ivermectin also is believed to act as an agonist of the neurotransmitter gamma-aminobutyric acid (GABA), thereby disrupting GABA-mediated central nervous system (CNS) neurosynaptic transmission. Ivermectin may also impair normal intrauterine development of O. volvulus microfilariae and may inhibit their release from the uteri of gravid female worms.\n",
      "  - protein_binding: 93%\n",
      "  - pharmacodynamics: Ivermectin is a semisynthetic, anthelminitic agent. It is an avermectin which a group of pentacyclic sixteen-membered lactone (i.e. a macrocyclic lactone disaccharide) derived from the soil bacterium Streptomyces avermitilis. Avermectins are potent anti-parasitic agents. Ivermectin is the most common avermectin. It is a broad spectrum antiparasitic drug for oral administration. It is sometimes used to treat human onchocerciasis (river blindness). It is the mixture of 22,23-dihydro-avermectin B1a (at least 90%) and 22,23-dihydro-avermectin B1b (less than 10%).\n",
      "  - state: Ivermectin is a solid.\n",
      "  - atc_1: Ivermectin is anatomically related to antiparasitic products, insecticides and repellents and dermatologicals.\n",
      "  - atc_2: Ivermectin is in the therapeutic group of anthelmintics and other dermatological preparations.\n",
      "  - atc_3: Ivermectin is pharmacologically related to antinematodal agents and other dermatological preparations.\n",
      "  - atc_4: The chemical and functional group of  is avermectines and other dermatologicals.\n",
      "  - category: Ivermectin is part of Agents Causing Muscle Toxicity ; Agrochemicals ; Anthelmintics ; Anti-Bacterial Agents ; Anti-Infective Agents ; Antinematodal Agents ; Antiparasitic Agents ; Antiparasitic Products, Insecticides and Repellents ; Avermectines ; BCRP/ABCG2 Substrates ; Compounds used in a research, industrial, or household setting ; Cytochrome P-450 CYP3A Inducers ; Cytochrome P-450 CYP3A Inhibitors ; Cytochrome P-450 CYP3A Substrates ; Cytochrome P-450 CYP3A4 Inducers ; Cytochrome P-450 CYP3A4 Inducers (strength unknown) ; Cytochrome P-450 CYP3A4 Substrates ; Cytochrome P-450 Enzyme Inducers ; Cytochrome P-450 Enzyme Inhibitors ; Cytochrome P-450 Substrates ; Dermatologicals ; Insecticides ; Lactones ; OATP1B1/SLCO1B1 Inhibitors ; OATP1B3 inhibitors ; P-glycoprotein inducers ; P-glycoprotein inhibitors ; P-glycoprotein substrates ; Pediculicides ; Pesticides ; Polyketides ; Scabicides and Pediculicides ; Toxic Actions.\n",
      "  - group: Ivermectin is approved and investigational and vet_approved.\n",
      "  - molecular_weight: The molecular weight is 1736.18.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(kb.get_doc_info(15450, add_rel=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- relations:\n",
      "\n",
      "  enzyme: {gene/protein: (CYP3A4),}\n",
      "  target: {gene/protein: (GABRB3, GLRA3),}\n",
      "  transporter: {gene/protein: (ABCC2, ABCG2, ABCC1, ABCB1, SLCO1B1, SLCO1B3),}\n",
      "  contraindication: {disease: (filariasis, loiasis),}\n",
      "  indication: {disease: (onchocerciasis, strongyloidiasis),}\n",
      "  synergistic_interaction: {drug: (Beclomethasone dipropionate, Betamethasone, Triamcinolone, Diethylstilbestrol, Liothyronine, Liotrix, Genistein, Ubidecarenone, Torasemide, Nelfinavir, Lovastatin, Ziprasidone, Phenytoin, Metoprolol, Dicoumarol, Conjugated estrogens, Etonogestrel, Desogestrel, Gefitinib, Meperidine, Duloxetine, Chlorpromazine, Raloxifene, Zidovudine, Ritonavir, Erlotinib, Ciprofloxacin, Nortriptyline, Methotrexate, Cephalexin, Clonidine, Enalapril, Medroxyprogesterone acetate, Chloroquine, Imatinib, Testosterone, Stavudine, Estrone, Tamoxifen, Warfarin, Lamivudine, Norethisterone, Irinotecan, Estradiol, Propofol, Clofazimine, Terbinafine, Tacrolimus, Quinidine, Repaglinide, Salmeterol, Phenprocoumon, Fexofenadine, Isoniazid, Norgestimate, Ethinylestradiol, Isotretinoin, Doxorubicin, Letrozole, Sulfamethoxazole, Fenofibrate, Rifampicin, Benzylpenicillin, Atazanavir, Atorvastatin, Rosuvastatin, Amiodarone, Captopril, Saquinavir, Dexamethasone, Gemfibrozil, Clomipramine, Fosphenytoin, Colchicine, Digitoxin, Acenocoumarol, Topiroxostat, Quercetin, Estrone sulfate, Dronedarone, Vandetanib, Cenobamate, Rufinamide, Simeprevir, Prucalopride, (R)-warfarin, Vismodegib, Pitavastatin, Rilpivirine, Ulipristal, Vemurafenib, Palbociclib, Nintedanib, Tenofovir alafenamide, Grazoprevir, Vinflunine, Pitolisant, Acalabrutinib, Istradefylline, Fostemsavir, Neratinib, Revefenacin, Dacomitinib, Glasdegib, Abemaciclib, Gilteritinib, Copanlisib, Darolutamide, Pexidartinib, Testosterone enanthate, Estradiol acetate, Estradiol benzoate, Estradiol cypionate, Estradiol dienanthate, Estradiol valerate, Tenofovir, Ripretinib, Elexacaftor, Niacin, Clofibrate, Metoclopramide, Cholic Acid, Ethanol, Dronabinol, Montelukast, Zafirlukast, Etoposide, Ifosfamide, Trabectedin, Propylthiouracil, Cannabidiol, Medical Cannabis, Nabiximols, Risedronic acid, Bumetanide, Drospirenone, Progesterone, Bempedoic acid, Mefloquine, Ranitidine, Vitamin D, Tucatinib, Cimetidine, Busulfan, Cobimetinib, Ticlopidine, Cytarabine, Caffeine, Theophylline, Omeprazole, Lansoprazole, Paclitaxel, Docetaxel, Dasatinib, Norelgestromin, Methyldopa, Carbimazole, Cyproterone acetate, Norgestrel, Nizatidine, Procainamide, Thiotepa, Sumatriptan, Safinamide, Procarbazine, Ethyl biscoumacetate, Cyclosporine, Erythromycin, Sildenafil, Indinavir, Terfenadine, Levonorgestrel, Amlodipine, Sorafenib, Cerivastatin, Teniposide, Haloperidol, Lercanidipine, Cyclophosphamide, Vincristine, Carbamazepine, Cisapride, Astemizole, Simvastatin, Mycophenolate mofetil, Mifepristone, Sirolimus, Triazolam, Buprenorphine, Fluvastatin, Pimozide, Sunitinib, Trastuzumab emtansine, Romidepsin, Temsirolimus, Ambrisentan, Midostaurin, Axitinib, Gestodene, Cabazitaxel, Hydroxyprogesterone caproate, Crizotinib, Ponatinib, Idelalisib, Cobicistat, Olaparib, Daclatasvir, Paritaprevir, Asunaprevir, Isavuconazole, Letermovir, Rucaparib, Bortezomib, Venlafaxine, Vinorelbine, Zolpidem, Prochlorperazine, Vinblastine, Doxazosin, Bicalutamide, Rabeprazole, St. John's Wort, Everolimus, Zuclopenthixol, Fusidic acid, Nilotinib, Pazopanib, Panobinostat, Netupitant, Dasabuvir, Rolapitant, Ixazomib, Lasmiditan, Elagolix, Fedratinib, Levosalbutamol, Ipecac, Enasidenib, Remdesivir, Tacrine, Trimethoprim, Albendazole, Norfloxacin, Hesperetin, Leflunomide, Ofloxacin, Aminophylline, Dovitinib, Eltrombopag, Teriflunomide, Pomalidomide, Tasimelteon, Osimertinib, Capmatinib, Abametapir, Voxilaprevir, Lorazepam, Phentermine, Dofetilide, Azithromycin, Pantoprazole, Methysergide, Cabergoline, Vindesine, Dihydroergotamine, Megestrol acetate, Caspofungin, Bosentan, Amphotericin B, Ergotamine, Ethynodiol diacetate, Conivaptan, Ezetimibe, Levacetylmethadol, Mestranol, Bezafibrate, Pranlukast, Roflumilast, Ixabepilone, Tolvaptan, Lacosamide, Bosutinib, Fosaprepitant, Lomitapide, Brentuximab vedotin, Ruxolitinib, Linagliptin, Regorafenib, Dabrafenib, Vorapaxar, Suvorexant, Ceritinib, Dienogest, Sonidegib, Tianeptine, Norethynodrel, Dihydroergocornine, Selexipag, Venetoclax, Velpatasvir, Gestrinone, Nomegestrol, Ribociclib, Ebastine, Baricitinib, Apalutamide, Duvelisib, Entrectinib, Fostamatinib, Alpelisib, Erdafitinib, Brigatinib, Siponimod, Lynestrenol, 9-aminocamptothecin, Lefamulin, Tazemetostat, Methylprednisone, Dihydroergocristine, Diphenadione, Dihydroergocryptine, Chlormadinone, Quingestanol, Demegestone, Etynodiol, Glecaprevir, Nomegestrol acetate, (S)-Warfarin, Ivosidenib, Norethindrone enanthate, Zanubrutinib, Mevastatin, Valsartan, Coumarin, Avatrombopag, Fluindione, Cladribine, Telmisartan, Digoxin, Famciclovir, Naltrexone, Raltegravir, Pibrentasvir, Minocycline, Sulfasalazine, Cholecystokinin, Eprosartan, Fimasartan, Dinoprostone, Iloprost, Ciprofibrate, Fenofibric acid, Somatotropin, Allylestrenol, Naringenin, Daidzin, Leuprolide, Nafarelin, Baclofen, Temocapril, Isosorbide, Tafamidis, Alectinib, Eluxadoline, Afatinib, Atrasentan, Pravastatin, Infliximab, Phenindione, Ouabain, Pamidronic acid, Alendronic acid, Ibandronate, Cholesterol, Levamisole, Elacridar, Lonidamine, Taurocholic acid, Metreleptin, Gossypol, Octylphenoxy polyethoxyethanol, p-Coumaric acid, Novobiocin, Penicillamine, Gimatecan, Gadoxetic acid, Technetium Tc-99m mebrofenin, Ganciclovir, Sincalide, Daptomycin, Lactulose, Acipimox, Mebeverine, 4-hydroxycoumarin, Trestolone, Cloprostenol, Triptolide, Clorindione, Ormeloxifene, Tioclomarol, Norgestrienone, Picosulfuric acid, BCG vaccine, Typhoid vaccine, Vibrio cholerae CVD 103-HgR strain live antigen, Etofibrate, Simfibrate, Ronifibrate, Aluminium clofibrate, Clofibride, Emetine),}\n",
      "  side_effect: {effect/phenotype: (Edema, Inflammatory abnormality of the skin, Hyperhidrosis, Keratitis, Abdominal distention, Fever, Pain, Seizure, Headache, Dyspnea, Tremor, Encephalopathy, Vomiting, Abdominal pain, Lymphadenopathy, Hematuria, Back pain, Myalgia, Tachycardia, Hepatitis, Respiratory distress, Arthralgia, Blindness, Vertigo, Lethargy, Fatigue, Palpebral edema, Pruritus, Cough, Confusion, Eosinophilia, Chest pain, Bowel incontinence, Facial edema, Coma, Leukopenia, Nausea, Apathy, Dry skin, Excessive daytime somnolence, Difficulty standing, Poor appetite, Peripheral edema),}\n"
     ]
    }
   ],
   "source": [
    "print(kb.get_rel_info(15450))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.17"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}