Esempio n. 1
0
 def __init__(self):
     self.user = User()
     self.hsk = HskVocab()
     self.cat = Category()
     self.hlp = HanziLevelProject()
     self.cedict = Cedict()
     self.sentence = SpoonFed()
Esempio n. 2
0
    def __init__(self):
        self.user = User()
        self.logger = Logger('anki.log.yaml')

        self.to_unsuspend = []
        for sentence in self.user.load_user_sentence():
            self.to_unsuspend.append(sentence)

        with Logger('anki.log.yaml') as log:
            log_dict = log.load()
            self.to_unsuspend = [item for item in self.to_unsuspend
                                 if item not in log_dict.get('to_unsuspend', [])]
            self.logger.save(to_unsuspend=self.to_unsuspend)
Esempio n. 3
0
    def __init__(self):
        self.user = User()
        self.ref = {
            'hsk': HskVocab(),
            'category': Category(),
            'hlp': HanziLevelProject(),
            'dict': Cedict(),
            'sentence': SpoonFed()
        }

        self.vocabs = []
        used_vocab = []
        # for vocab in self.user.sentence_to_vocab():
        for vocab in self.user.load_user_vocab():
        # for vocab in set(chain(self.user.sentence_to_vocab(), self.user.load_user_vocab())):
            lookup = self.ref['dict'].get(vocab)
            simplified = lookup.get('simplified', '')
            vocab = simplified if simplified else vocab

            if vocab not in used_vocab:
                used_vocab.append(vocab)
                if re.search(r'[\u2E80-\u2FD5\u3400-\u4DBF\u4E00-\u9FCC]', vocab):
                    self.vocabs.append((vocab, self.to_note(vocab)))
                else:
                    print('Skipped', vocab)

        self.sentences = []
        for sentence in self.user.load_user_sentence():
            self.sentences.append((sentence, self.to_tags(sentence, 'sentence')))

        hanzi_list = list(set(re.findall(r'[\u2E80-\u2FD5\u3400-\u4DBF\u4E00-\u9FCC]',
                                         ''.join([entry for entry, content in chain(self.vocabs, self.sentences)]))))
        self.hanzi = [(hanzi, self.to_tags(hanzi, 'hanzi')) for hanzi in hanzi_list]

        self.tags = {
            'hanzi': [],
            'vocab': [],
            'sentence': []
        }
        for _, note in self.vocabs:
            self.tags['vocab'].extend(note['tags'])
        for _, tags in self.sentences:
            self.tags['sentence'].extend(tags)
        for _, tags in self.hanzi:
            self.tags['hanzi'].extend(tags)
Esempio n. 4
0
    def __init__(self):
        self.user = User()
        self.hsk = HskVocab()
        self.cat = Category()
        self.hlp = HanziLevelProject()
        self.cedict = Cedict()
        self.sentence = SpoonFed()

        self.to_unsuspend = list()
        self.to_add = list()
        all_vocabs = chain(self.user.sentence_to_vocab(), self.user.load_user_vocab())
        used_vocab = []
        for i, vocab in enumerate(all_vocabs):
            lookup = self.cedict.get(vocab)
            simplified = lookup.get('simplified', '')
            vocab = simplified if simplified else vocab

            if vocab not in used_vocab:
                used_vocab.append(vocab)
                if re.search(r'[\u2E80-\u2FD5\u3400-\u4DBF\u4E00-\u9FCC]', vocab):
                    if self.hsk.what_level(vocab):
                        self.to_unsuspend.append(vocab)
                    else:
                        self.to_add.append(vocab)
                else:
                    print("Skipped:", vocab)

        with Logger('anki.log.yaml') as log:
            log_dict = log.load()
            self.to_add = [item for item in self.to_add if item not in log_dict.get('to_add', [])]
            self.to_unsuspend = [item for item in self.to_unsuspend
                                 if item not in log_dict.get('to_unsuspend', [])]
            log.save(**{
                'to_add': self.to_add,
                'to_unsuspend': self.to_unsuspend
            })