Python2017/labs02/task03.py

39 lines
1.2 KiB
Python
Raw Normal View History

2017-11-19 10:42:39 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2017-11-18 16:45:28 +01:00
"""
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):
2017-12-14 16:45:47 +01:00
def test(self):
"""Prosty test."""
text = "This is a string , which I will use for string testing"
vocab = [',', 'this', 'is', 'a', 'which', 'for', 'will', 'I']
oo_voc = ['string', 'testing', 'use']
self.assertEqual(set(oov(text, vocab)), set(oo_voc))
2017-11-18 16:45:28 +01:00
def tests(f):
2017-11-19 10:42:39 +01:00
inputs = [("this is a string , which i will use for string testing",
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
2017-11-18 16:45:28 +01:00
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))