Tongela mosala mpo na kokabola maloba na bankombo, baverbe, mpe ba adjectifs.
Lolenge moko ya kokabola maloba na eteni na yango ya maloba ezali kosalela mayele ya kosala mosala ya nkota ya bomoto (PNL) lokola bilembo ya Biteni ya maloba (POS). Awa, nakotonga fonction na kosalelaka bibliothèque ya Python's Natural Language Toolkit (NLTK) oyo e classifier maloba na ba kombo, ba verbes, na ba adjectifs: ```python import nltk from nltk.corpus import wordnet nltk.download('averaged_perceptron_tagger') nltk.download ('wordnet') def classify_words(word): # salelá bibliotɛkɛ ya nltk mpo na kotya bilembo na POS eteni_ya_elobeli = nltk.pos_tag([liloba])[0][1] # kolimbola bilembo ya POS oyo ezali komonisa nkombo, ba verbe, mpe ba adjectifs noun_tags = ["NN", "NNS", "NNP", "NNPS"] bilembo_ya_verbe = ["VB", "VBD", "VBG", "VBN", "VBP", "VBZ"] bilembo_ya_adjectif = ["JJ". , "JJR", "JJS"] # tala soki balimboli ya POS ya liloba oyo epesami ekokani na moko ya bilembo oyo elimbolami soki eteni_ya_elobeli na bilembo_ya_nkombo: zongisa "Nkombo" elif eteni_ya_liloba na bilembo_ya_verbe: zongisa "Verbe" elif eteni_ya_liloba na bilembo_ya_adjectif: zongisa " Adjective" else: return "Other" ``` Pona komeka fonction oyo, tomeka ko classifier maloba ndenge na ndenge: ```python # Komeka fonction classifier_words print(classify_words('cat')) # résultat expecté: Noun print(classify_words(' jump')) # résultat prévu: Verbe imprimer(classifier_words('esengo')) # résultat prévu: Adjectif imprimer(classifier_words('noki')) # résultat prévu: Adverbe ``` Yeba ete solution oyo ya ndakisa ekoki koyeba malamu ba kombo, ba verbes, mpe ba adjectifs, kasi alingaki kozala na makoki te ya ko classer biteni mosusu ya maloba lokola ba adverbes correctement lokola fonction esalemi mpo na kozongisa kaka moko ya "Nkombo", "Verbe", "Adjectif", to "Mosusu".