Пример #1
0
class CtrlHeuristic:
    def __init__(self):
        self.h = Heuristic()
        self.t = Text()
        self.o = Order()

    def execute(self, textL):
        arrayResult = {
            Constant.HERUGLON_NAMES[Constant.HERUGLON_PREPOSITION]: 0,
            Constant.HERUGLON_NAMES[Constant.HERUGLON_VERB]: 0,
            Constant.HERUGLON_NAMES[Constant.HERUGLON_VERB_SUBJUNCTIVE]: 0,
            Constant.HERUGLON_NAMES[Constant.HERUGLON_NUMBER_PRETTY]: 0,
            "Vocabulary": None
        }

        listPrettyNumber = {}
        arrayPharagrap = self.t.getWords(textL)
        vocabulary = {}

        for word in arrayPharagrap:
            class_word = self.h.classify(word)
            class_word_type = class_word['type']

            if (class_word_type == Constant.HERUGLON_UNKNOWN):
                pass

            vocabulary[word] = word

            if (class_word_type == Constant.HERUGLON_NUMBER):
                pass

            if (class_word_type == Constant.HERUGLON_NUMBER_PRETTY):
                listPrettyNumber[word] = word
            elif (class_word_type == Constant.HERUGLON_VERB):
                arrayResult[Constant.HERUGLON_NAMES[
                    Constant.HERUGLON_VERB]] += 1
            elif (class_word_type == Constant.HERUGLON_VERB_SUBJUNCTIVE):
                arrayResult[Constant.HERUGLON_NAMES[
                    Constant.HERUGLON_VERB]] += 1
                arrayResult[Constant.HERUGLON_NAMES[
                    Constant.HERUGLON_VERB_SUBJUNCTIVE]] += 1
            elif (class_word_type == Constant.HERUGLON_PREPOSITION):
                arrayResult[Constant.HERUGLON_NAMES[
                    Constant.HERUGLON_PREPOSITION]] += 1

        arrayResult[Constant.HERUGLON_NAMES[
            Constant.HERUGLON_NUMBER_PRETTY]] = len(listPrettyNumber)

        listWords = self.o.prepare(vocabulary.keys())
        listOrderVocabulary = self.o.do(listWords)
        arrayResult['Vocabulary'] = listOrderVocabulary

        return arrayResult
Пример #2
0
 def test_text(self):
     textL = 'shoce pq podciy nfwh phfer epgdc dgsloqe do rhfl qhmoixw cmfur qdrulxogji whc ermjdhsx py en ycoienqm wjuln dwuch qinhmjul mjxdqfrnlg iygsex qihmu grewyluhfs ucf us xclpedqmi yrx qinexwo qx rqwwxflpdn rsogxd cpqmxj lgchqdin fdw nwcrus coj nj qplfjnwidg fwdmslqn cwj hysucxdqm ms hdmwpeigxweo sqflo ycqlinro ghu hgecdfj mw xrpmyenq fgixsr fpwcnguieh fclgj ghepqyd jxhwe cejfugn ujxqhihncrl mlceo udr fm ocxfsjdng sfoqmd pdoymnwxei spqinedf ql ncsepfl icmqsdj chwjlg yiq ifl syejrqdlwnepmcg xlmnfqry ghlyopuncw qx iw sionpux cop dmqpchuyf ojxfqhernm ignpeyf rseoyl emjocsildrfimdy mwd oewgjfr uo irmcunfgx ylduwpsnh xrdng gcxr ng prfmjicud srdueqhgiy nmodwsqijh dcnql'
     list_ = textL.split()
     O = Order()
     self.assertEqual(O.do(O.prepare(list_)),['sqflo', 'spqinedf', 'sfoqmd', 'syejrqdlwnepmcg', 'shoce', 'srdueqhgiy', 'sionpux', 'xclpedqmi', 'xlmnfqry', 'xrpmyenq', 'xrdng', 'ocxfsjdng', 'oewgjfr', 'ojxfqhernm', 'cop', 'coj', 'cmfur', 'cwj', 'cpqmxj', 'chwjlg', 'cejfugn', 'qx', 'qx', 'qplfjnwidg', 'qhmoixw', 'ql', 'qdrulxogji', 'qinhmjul', 'qinexwo', 'qihmu', 'ncsepfl', 'nmodwsqijh', 'nwcrus', 'nfwh', 'nj', 'ng', 'ms', 'mw', 'mwd', 'mlceo', 'mjxdqfrnlg', 'whc', 'wjuln', 'podciy', 'pq', 'py', 'phfer', 'prfmjicud', 'pdoymnwxei', 'fclgj', 'fm', 'fwdmslqn', 'fpwcnguieh', 'fdw', 'fgixsr', 'ycoienqm', 'ycqlinro', 'ylduwpsnh', 'yrx', 'yiq', 'hysucxdqm', 'hdmwpeigxweo', 'hgecdfj', 'en', 'emjocsildrfimdy', 'epgdc', 'ermjdhsx', 'lgchqdin', 'jxhwe', 'rsogxd', 'rseoyl', 'rqwwxflpdn', 'rhfl', 'do', 'dcnql', 'dmqpchuyf', 'dwuch', 'dgsloqe', 'gcxr', 'ghepqyd', 'ghlyopuncw', 'ghu', 'grewyluhfs', 'us', 'uo', 'ucf', 'ujxqhihncrl', 'udr', 'icmqsdj', 'iw', 'ifl', 'iygsex', 'irmcunfgx', 'ignpeyf'])