NikosKprl commited on
Commit
c7ea26b
·
verified ·
1 Parent(s): c0eee34

Update ✨Entity Linking Application✨.py

Browse files
Files changed (1) hide show
  1. ✨Entity Linking Application✨.py +13 -7
✨Entity Linking Application✨.py CHANGED
@@ -15,6 +15,12 @@ from openai import OpenAI
15
  import sys
16
  from googlesearch import search
17
 
 
 
 
 
 
 
18
  folder_path = '/home/user/app/qids_folder'
19
 
20
  if not os.path.exists(folder_path):
@@ -55,24 +61,24 @@ async def fetch_json(url, session):
55
  return await response.json()
56
 
57
  async def combination_method(name, session):
58
- async with aiohttp.ClientSession() as session:
59
  data = set()
60
  new_name = name.split()
61
  x = itertools_combinations(new_name, 2)
62
  for i in x:
63
  new_word = (i[0] + " " + i[1])
64
- url = f"{new_word} site:en.wikipedia.org"
65
  s = search(url, num_results = 12, lang="en")
66
  for i in s:
67
  data.add(i.split("/")[-1])
68
  return data
69
 
70
  async def single_method(name, session):
71
- async with aiohttp.ClientSession() as session:
72
  data = set()
73
  new_name = name.replace("-", " ").replace("/", " ").split()
74
  for i in new_name:
75
- url = f"{i} site:en.wikipedia.org"
76
  s = search(url, num_results = 12, lang="en")
77
  for i in s:
78
  data.add(i.split("/")[-1])
@@ -83,8 +89,8 @@ async def mains(name, single, combi):
83
  disam_data = set()
84
  qids = set()
85
 
86
- async with aiohttp.ClientSession() as session:
87
- url = f"{name} site:en.wikipedia.org"
88
  s = search(url, num_results = 30, lang="en")
89
  for i in s:
90
  data.add(i.split("/")[-1])
@@ -172,7 +178,7 @@ def cleaner(text):
172
  return text
173
 
174
  async def retriever(qid):
175
- async with aiohttp.ClientSession() as session:
176
  list_with_sent = []
177
 
178
  query_label = f"""SELECT ?subjectLabel
 
15
  import sys
16
  from googlesearch import search
17
 
18
+
19
+ headers = {
20
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
21
+ }
22
+
23
+
24
  folder_path = '/home/user/app/qids_folder'
25
 
26
  if not os.path.exists(folder_path):
 
61
  return await response.json()
62
 
63
  async def combination_method(name, session):
64
+ async with aiohttp.ClientSession(headers=headers) as session:
65
  data = set()
66
  new_name = name.split()
67
  x = itertools_combinations(new_name, 2)
68
  for i in x:
69
  new_word = (i[0] + " " + i[1])
70
+ url = f"{new_word} site:en.wikipedia.org inurl:/wiki/ -inurl:?"
71
  s = search(url, num_results = 12, lang="en")
72
  for i in s:
73
  data.add(i.split("/")[-1])
74
  return data
75
 
76
  async def single_method(name, session):
77
+ async with aiohttp.ClientSession(headers=headers) as session:
78
  data = set()
79
  new_name = name.replace("-", " ").replace("/", " ").split()
80
  for i in new_name:
81
+ url = f"{i} site:en.wikipedia.org inurl:/wiki/ -inurl:?"
82
  s = search(url, num_results = 12, lang="en")
83
  for i in s:
84
  data.add(i.split("/")[-1])
 
89
  disam_data = set()
90
  qids = set()
91
 
92
+ async with aiohttp.ClientSession(headers=headers) as session:
93
+ url = f"{name} site:en.wikipedia.org inurl:/wiki/ -inurl:?"
94
  s = search(url, num_results = 30, lang="en")
95
  for i in s:
96
  data.add(i.split("/")[-1])
 
178
  return text
179
 
180
  async def retriever(qid):
181
+ async with aiohttp.ClientSession(headers=headers) as session:
182
  list_with_sent = []
183
 
184
  query_label = f"""SELECT ?subjectLabel