예제 #1
0
 def findWordsFromFragment(self, text):
     # Replace lists of radical names (ex. "{woman,roof}") with the actual possible kanjis
     for radicalList in re.findall("{.*?}", text):
         splitted = radicalList[1:-1].lower().replace("、", ",").split(",")
         text = text.replace(radicalList, "[" + "|".join(lookup.getKanjiFromRadicals(splitted)) + "]")
         
     # return list(sorted(filter(lambda x: re.search("^" + text + "$", x) is not None, self.dictionaryJ2E.keys())))
     
     query = """
         select lemma
           from edict_lemmas l
          where lemma REGEXP '{0}' 
          union all
         select lemmatitle
           from kotobank_lemmas kl
          where lemmatitle REGEXP '{0}'
         """.format(text.replace("'", "\'"))
         
     return [x[0] for x in self.connection.execute(query).fetchall()]
예제 #2
0
 def populateList(self, fullList):
     kanjis = lookup.getKanjiFromRadicals(self.txtRadicalsInput.text().lower().replace("、", ",").split(","))
     # Sorting first by ord() value and then by stroke count, I ensure that kanji
     # with the same stoke count will always be ordered in a consistent way (by ord() value)
     kanjis = sorted(kanjis, key=ord)
     kanjis = sorted(kanjis, key=kanjidic.getStrokeCount)
     
     if self.spnStrokeCount.value() > 0:
         kanjis = list(filter(lambda x: kanjidic.getStrokeCount(x) == self.spnStrokeCount.value(), kanjis))
     
     self.lstOutput.clear()
     if fullList:
         self.lstOutput.addItems(kanjis)
     else:
         self.lstOutput.addItems(kanjis[:100])
         if len(kanjis) > 100:
             self.lstOutput.addItem("...")
     if len(kanjis) > 0:
         self.lstOutput.item(0).setSelected(True)
         if not fullList:
             # it's true when i click the "..." item, i want the scrollbar stay as it is
             self.lstOutput.scrollToTop()