NikosKprl commited on
Commit
d3859f5
·
verified ·
1 Parent(s): 0289859

Update ✨Entity Linking Application✨.py

Browse files
Files changed (1) hide show
  1. ✨Entity Linking Application✨.py +16 -10
✨Entity Linking Application✨.py CHANGED
@@ -55,11 +55,14 @@ async def combination_method(name, session):
55
  x = itertools_combinations(new_name, 2)
56
  for i in x:
57
  new_word = (i[0] + " " + i[1])
58
- url = f"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={new_word}&srlimit=5&srprop=&srenablerewrites=True&srinfo=suggestion&format=json"
59
- json_suggestion = await fetch_json(url, session)
60
- results = json_suggestion.get('query', {}).get('search')
61
- for i in results:
62
- data.add(i.get('title'))
 
 
 
63
  return data
64
 
65
  async def single_method(name, session):
@@ -67,11 +70,14 @@ async def single_method(name, session):
67
  data = set()
68
  new_name = name.replace("-", " ").replace("/", " ").split()
69
  for i in new_name:
70
- url = f"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={i}&srlimit=10&srprop=&srenablerewrites=True&srinfo=suggestion&format=json"
71
- json_suggestion = await fetch_json(url, session)
72
- results = json_suggestion.get('query', {}).get('search')
73
- for i in results:
74
- data.add(i.get('title'))
 
 
 
75
  return data
76
 
77
  async def mains(name, single, combi):
 
55
  x = itertools_combinations(new_name, 2)
56
  for i in x:
57
  new_word = (i[0] + " " + i[1])
58
+ url = f"https://www.google.com/search?q={new_word} site:en.wikipedia.org inurl:/wiki/ -inurl:? -inurl:Category: -inurl:File: -inurl:Special: -inurl:Help:&num=5"
59
+ html = requests.get(url, headers=headers)
60
+ soup = BeautifulSoup(html.text, "html.parser")
61
+ elements_with_href = soup.find_all(href=True)
62
+ href_links = [element['href'] for element in elements_with_href]
63
+ for link in href_links:
64
+ if link.startswith('https://en.wikipedia.org/wiki/'):
65
+ data.add(link.split("/")[-1])
66
  return data
67
 
68
  async def single_method(name, session):
 
70
  data = set()
71
  new_name = name.replace("-", " ").replace("/", " ").split()
72
  for i in new_name:
73
+ url = f"https://www.google.com/search?q={i} site:en.wikipedia.org inurl:/wiki/ -inurl:? -inurl:Category: -inurl:File: -inurl:Special: -inurl:Help:&num=5"
74
+ html = requests.get(url, headers=headers)
75
+ soup = BeautifulSoup(html.text, "html.parser")
76
+ elements_with_href = soup.find_all(href=True)
77
+ href_links = [element['href'] for element in elements_with_href]
78
+ for link in href_links:
79
+ if link.startswith('https://en.wikipedia.org/wiki/'):
80
+ data.add(link.split("/")[-1])
81
  return data
82
 
83
  async def mains(name, single, combi):