Spaces:
Runtime error
Runtime error
File size: 1,956 Bytes
d0de866 |
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 |
import wikipediaapi
from .utils import Utils
from.rake import Rake
class Subject(Utils, Rake):
def __init__(self, subject, bs_parser="lxml"):
Utils.__init__(self, latin_encoder="latin-1")
Rake.__init__(self)
self.subject = subject
self.bs_parser = bs_parser
self.wikipedia = wikipediaapi.Wikipedia(language='en',
extract_format=wikipediaapi.ExtractFormat.WIKI)
# lazy loaded
self.wikipedia_object = None
def _get_wiki_object(self):
if not self.wikipedia_object:
self.wikipedia_object = self.wikipedia.page(self.subject)
def _get_links(self):
if not self.wikipedia_object:
self._get_wiki_object()
return self.wikipedia_object.links
def _get_url(self):
if not self.wikipedia_object:
self._get_wiki_object()
return self.wikipedia_object.fullurl
def _check_page_exists(self):
if not self.wikipedia_object:
self._get_wiki_object()
return self.wikipedia_object.exists()
def _get_summary(self):
if not self.wikipedia_object:
self._get_wiki_object()
return self.wikipedia_object.summary
def _get_content(self):
if not self.wikipedia_object:
self._get_wiki_object()
return self.wikipedia_object.text
# def _get_html(self):
# if not self.wikipedia_object:
# self._get_wiki_object()
# return self.wikipedia_object.html
def get_meta(self):
if not self.wikipedia_object:
self._get_wiki_object()
self.meta["url"] = self.wikipedia_object.fullurl
self.meta["title"] = self.wikipedia_object.title
def get_top_keywords_with_score_from_rake(self):
return self.get_keyphrases_with_score(self._get_content())
def get_top_keywords_from_rake(self):
return self.get_keyphrases(self._get_content())
|