Example #1
0
 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
Example #2
0
 def __init__(self, name):
   self.isVerb = False
   if re.match('.*\*$', name.strip()):
     name = name[:-1]
   if not utilities.sanitize(name).istitle():
     type = utilities.sanitize(name).split()[-1]
   else:
     type = None
   Concept.__init__(self, name, type)
Example #3
0
    def getFields(self):
        """Returns a dictionary of all the fields, stripped and sanitized"""
        fields = {}
        fields['title'] = str(self.ui.titleLineEdit.text()).strip()
        fields['title'] = sanitize(fields['title'])
        fields['titleOfMusical'] = str(self.ui.titleOfMusicalLineEdit.text()).strip()
        fields['titleOfMusical'] = sanitize(fields['titleOfMusical'])
        fields['composerArranger'] = str(self.ui.composerLineEdit.text()).strip()
        fields['composerArranger'] = sanitize(fields['composerArranger'])
        # Don't need to sanitize a timeEdit
        fields['performanceTime'] = str(self.ui.performanceTimeEdit.time().toString("m:ss"))

        return fields
Example #4
0
 def classNumberLineEdit_edited(self):
     """Checks if the class number is valid and fills in the class name"""
     classNumber = str(self.ui.classNumberLineEdit.text()).strip()
     classNumber = sanitize(classNumber)
     classNumber = classNumber.upper()
     self.ui.classNumberLineEdit.setText(classNumber)
     result = dbInteractionInstance.findClassName(classNumber)
     if result is not None:
         self.ui.classNameLineEdit.setText(result)
     else:
         self.ui.classNameLineEdit.clear()
Example #5
0
 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
Example #6
0
 def classify(self, term1, term2=None):
     if re.match("^!", term1):
         return False
     if term2:
         if re.match("^!", term2):
             return False
     if not term2:
         if not self.isVerb:
             if not utilities.sanitize(term1).istitle():
                 self.classify(term1, utilities.sanitize(term1).split()[-1])
         child = self.name
         parent = term1
     else:
         child = term1
         parent = term2
     if child == parent:
         return
     child = utilities.sanitize(child)
     parent = utilities.sanitize(parent)
     if not self.isA(child, parent) and not parent.istitle():
         Concept.taxonomy.case_sensitive = True
         Concept.taxonomy.append(child, type=parent)
         Concept.taxonomy.case_sensitive = False
Example #7
0
 def isA(self, term1, term2=None):
     if not term2:
         if not self.name:
             return False
         childTerms = self.synonyms()
         parent = term1
     else:
         childTerms = self.synonyms(term1)
         parent = term2
     if parent == "thing":
         return True
     if parent in childTerms:
         return True
     existingParents = set()
     for child in childTerms:
         child = utilities.sanitize(child)
         parent = utilities.sanitize(parent)
         if child.istitle() or parent.istitle():
             Concept.taxonomy.classifiers = []
             Concept.taxonomy.case_sensitive = True
         if not getattr(self, "isVerb", False):
             existingParents |= set(map(str, Concept.taxonomy.parents(child, recursive=True)))
         else:
             existingParents |= set(map(str, Concept.taxonomy.parents(child, recursive=True, pos="VB")))
         if child.istitle() or parent.istitle():
             if Concept.bootstrapVocabulary:
                 Concept.taxonomy.classifiers.append(Concept.wordnetClassifier)
             Concept.taxonomy.case_sensitive = False
             temp = set()
             for term in existingParents:
                 if not utilities.sanitize(term).istitle():
                     temp |= set(map(str, Concept.taxonomy.parents(utilities.sanitize(term), recursive=True)))
             existingParents |= temp
     for term in self.synonyms(parent):
         if utilities.sanitize(term) in existingParents:
             return True
     return False