return classes class PersonClassifier(BaseClassifier): def is_person(self, symbol): # TODO : test the precision of this method of determining is_person infoboxes = get_infoboxes(symbol) for ibx in infoboxes: if ibx.wikipedia_class() == 'wikipedia-person' or \ ibx.get('birth-date'): return True from wikipediabase.resolvers import PersonResolver if PersonResolver().birth_date(symbol, 'birth-date'): return True return False def classify(self, symbol, fetcher=None): if fetcher: self.fetcher = fetcher classes = [] if self.is_person(symbol): classes += ['wikibase-person'] return classes WIKIBASE_CLASSIFIERS = subclasses(BaseClassifier)
return self.val is None def val_str(self): return u'nil' class LispNumber(_LispLiteral): def should_parse(self): return isinstance(self.val, Number) def val_str(self): return str(self.val) WIKIBASE_LISP_TYPES = subclasses(LispType, instantiate=False) def lispify(obj, typecode=None, infobox_attr=None): """ Return a Lisp-like encoded string. infobox_attr is the name of the infobox attribute where obj came from """ if isinstance(obj, LispType): return obj for T in WIKIBASE_LISP_TYPES: t = T(obj, typecode, infobox_attr=infobox_attr) if t.valid:
def title(self, symbol, fetcher=None): fetcher = fetcher or WIKIBASE_FETCHER html = fetcher.html_source(symbol) match = re.search(TITLE_REGEX, html) if match: return match.group(1) def induce(self, symbol, fetcher=None): synonyms = [] fetcher = fetcher or WIKIBASE_FETCHER title = self.title(symbol, fetcher=fetcher) if title: sym = string_reduce(symbol) if title != sym: synonyms.extend(lexical_synonyms(title)) return synonyms class LexicalInducer(BaseInducer): """ Induce just the lexicals of the symbol """ def induce(self, symbol): return lexical_synonyms(symbol) WIKIBASE_INDUCERS = subclasses(BaseInducer)