def NL2ResultA(sentence): # natural language to internal language ''' Принимает объект предложения и возвращает его уже, но с анализами ''' GrammarNazi = {} # Анализируем предложение #BS.FWrite("- "*10 + BS.getTime() + " -"*10 + "\n\n") sentence, GrammarNazi['getMorphA'] = getMorphA(sentence) #BS.safeResults(sentence, u"Морфологический анализ") #BS.safeUnknown(list_res) sentence, GrammarNazi['getPostMorphA'] = getPostMorphA(sentence) #BS.safeResults(list_res, u"Промежуточный анализ") sentence, GrammarNazi['getSyntA'] = getSyntA(sentence) #BS.safeResults(list_res, u"Синтаксический анализ") print GrammarNazi return sentence, GrammarNazi
index, GN = _getPostMorphA(index, sentence) GrammarNazi.extend(GN) index += 1 # удаляем служебные части речи sentence.delByCharacteristic('POSpeech', 'preposition') pr(sentence) return sentence, GrammarNazi if __name__ == '__main__': from MorphologicalAnalysis import getMorphA import BeautySafe as BS #sentence = 'montru miajn kursojn de rusia dolaro' sentence = '' BS.FWrite('----'+BS.getTime()+'\n') list_res = getMorphA(sentence) BS.safeResults(list_res, 'MorphA') BS.safeUnknown(list_res) tree = getPostMorphA(list_res) BS.FWrite('\n '+sentence+'\n') sentence = '' for k, v in tree.items(): sentence += v['word'] + ' ' BS.FWrite(' '+sentence+'\n\n') BS.safeResults(tree, 'PostMorphA') print 'Ready! :)'