def ancestors(self, name=None): if not name: names = self.synonyms() else: names = self.synonyms(name) response = set() for name in names: name = utilities.sanitize(name) if name.istitle(): Concept.taxonomy.classifiers = [] Concept.taxonomy.case_sensitive = True if not getattr(self, "isVerb", False): response |= set(utilities.unicodeDecode(Concept.taxonomy.parents(name, recursive=True))) else: response |= set(utilities.unicodeDecode(Concept.taxonomy.parents(name, recursive=True, pos="VB"))) if name.istitle(): if Concept.bootstrapVocabulary: Concept.taxonomy.classifiers.append(Concept.wordnetClassifier) Concept.taxonomy.case_sensitive = False temp = set() for term in response: if not utilities.sanitize(term).istitle(): temp |= set( utilities.unicodeDecode(Concept.taxonomy.parents(utilities.sanitize(term), recursive=True)) ) response |= temp return response
def descendants(self, name=None): if not name: names = self.synonyms() else: names = self.synonyms(name) response = set() for name in names: name = utilities.sanitize(name) if name.istitle(): return if not getattr(self, "isVerb", False): firstPass = utilities.unicodeDecode(Concept.taxonomy.children(name, recursive=False)) else: firstPass = utilities.unicodeDecode(Concept.taxonomy.children(name, recursive=False, pos="VB")) for thing in firstPass: if utilities.sanitize(thing).istitle(): continue else: response |= set(utilities.unicodeDecode(self.descendants(thing))) response |= set(firstPass) return response