#!/usr/bin/env python # -*- coding: utf-8 -*- """ Zad 4. Napisz funkcje oov(text, vocab), która zwraca listę wyrazów (bez duplikatów), które występują w tekście text i nie występują w liście znanych wyrazów vocab. Argumenty funkcji text i vocab to odpowiednio łańcuch znakowy i lista łańuchów znakowych. Wszystkie wyrazy należy zmienić na małe litery. (OOV = out of vocabulary) (W pythonie istnieje struktura danych tak jak 'set', która przechowuje elementy bez powtórzeń.) """ def oov(text, vocab): text_list = text.casefold().replace("(", "").replace(",", "").replace("[", "").replace(" "," ").split(" ") set_text = set(text_list) string_vocab = str() for i in vocab: string_vocab +=i.lower()+" " vocab_list = string_vocab.replace(",", "").split(" ") return list(set(text_list) - set(vocab_list)) def tests(f): inputs = [("this is a string , which i will use for string testing", [',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])] outputs = [['string', 'testing', 'use']] for input, output in zip(inputs, outputs): if set(f(*input)) != set(output): return "ERROR: {}!={}".format(f(*input), output) break return "TESTS PASSED" if __name__ == "__main__": print(tests(oov))