Skip to content

Commit 8d28435

Browse files
committed
- added example_input.py as an example for the disallow() entity
- added example_input.py as an example for the disallow() entity - added test case for example_input - updated disallow() entities
1 parent 459c9e8 commit 8d28435

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

examples/example_input.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
import os.path, sys
4+
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
5+
from lara import parser, entities
6+
7+
''' Basic Chatbot that just prints out replies '''
8+
9+
if __name__ == "__main__":
10+
11+
user = input('Kérlek add meg a neved: ')
12+
13+
disallow = entities.disallow()
14+
if parser.Intents(disallow).match_set(user):
15+
print('Sajnálom, de ezt a nevet nem választhatod, mert obszcén kifejezést tartalmaz!')
16+
else:
17+
print('Szervusz',user)

lara/entities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def emoji():
157157
def disallow():
158158
return {
159159
"obscene" : [{"stem":"(fel|le|meg|r[aá]|ki|be|oda|[oö]s+ze|bele|hoz+[aá])?bas*z+d?\s?(at)?(hat)?(us|a[dk]?|n?[aá][kl]|[aá]?t[aáo][lkm]?|ot+|ni|n[aá]n?[dlkm]?|va|meg)?","wordclass":"regex","exc":[{"stem":"megye"}]},{"stem":"((l[oó]|agy)?fasz|fas+z+op[oó]|geci\w*|kurv[aá]([eé]let|an+yj?[aá])?|(be)?fos|ribanc|(be)?szar|buzi|k[oö]cs[oö]g|pin[aá]|pics[aá]|p[oö]cs|p[eé]nisz|(kurva)?any[aá]d)([oö]?k)?r?[aáeoö]?(\w{0,2}[aeoöőu][dnklt]*)?(n[ae]k)?\b","wordclass":"regex","boundary":False},{"stem":"((mother)?f\s?u\s?c\s?k|shit(as{2})?|bitch|pus{2}y|cunt|fag(g?[eo]t)?|penis|blowjob|but{2}(plug|head)?|as{2}|arse|homo|gay|dyke|cock|dick(pic)?)(e?s|ing|e?r)?","wordclass":"regex"}],
160-
"racist" : [{"stem":"(fek[aá]|nig+(er|a)|n[aá]ci|cig[oó]|cig[aá]n+y|gypsy|dzsip[oó]|zsidr?[ó])[aáeégklnmstv]*","wordclass":"regex"}],
161-
"erotic" : [{"stem":"(sz?ex|an[aá]l|vagina|p[eé]nisz?|creampie|cum|sperma?|fuck|homo(kos|sexu[aá]l(is)?)?|milf|bisexual|gay|dild[oó]|vibr[aá]tor|fel+atio|blow\s?job|whore|geci|pus{2}y|pics[aá]|pin[aá]|fasz|pis{2}|boner|dick(pic)?|x{3,}|hentai|catgirl|ec+hi|yaoi|loli|shot[aá]|\w*porn[oó]?(film)?)[aáeéioöőuüdgklmnprstvz]*","wordclass":"regex"}],
160+
"racist" : [{"stem":"(fek[aá]|nig+(er|a)|n[aá]ci|cig[oó]|cig[aá]n+y|gypsy|dzsip[oó]|zsidr?[ó])[aáeégklnmstv]*","wordclass":"regex","boundary":False}],
161+
"erotic" : [{"stem":"(sz?ex|an[aá]l|[bv]agina|[bp][eé][np]isz?|creampie|cum|sperma?|fuck|homo(kos|sexu[aá]l(is)?)?|milf|bisexual|gay|dild[oó]|vibr[aá]tor|fel+atio|blow\s?job|whore|geci|pus{2}y|pics[aá]|pin[aá]|fasz|pis{2}|boner|dick(pic)?|x{3,}|hentai|catgirl|ec+hi|yaoi|loli|shot[aá]|\w*porn[oó]?(film)?)[aáeéioöőuüdgklmnprstvz]*","wordclass":"regex","boundary":False},{"stem":"maki verem"}],
162162
"unpleasant" : [{"stem":"AIDS","wordclass":"noun"},{"stem":"HIV","ignorecase":False},{"stem":"Hitler","wordclass":"noun"},{"stem":"(Sz?t[aá]lin|Len+in)\w*","wordclass":"regex"},{"stem":"pedof[ií]l(i[aá])?[aokltv]*","wordclass":"regex"},{"stem":"(fur{2}y|bestiality|yif{2}y?)[aáeégklnmstv]*","wordclass":"regex"}],
163163
}
164164

tests/test_examples.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88
])
99
def test_entities(entity):
1010
file = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'examples/', entity+'.py')
11-
if os.path.isfile(file) :
11+
if os.path.isfile(file):
1212
event = subprocess.Popen("python "+file, stdin=None, stdout=None, stderr=subprocess.PIPE).communicate()[1]
1313
if event:
1414
raise Exception(event.decode('utf-8'))
1515
else:
16-
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file)
16+
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file)
17+
18+
@pytest.mark.parametrize("input_str", [
19+
"Teszt Elek"
20+
])
21+
def test_entities_input(input_str):
22+
file = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'examples/example_input.py')
23+
if os.path.isfile(file):
24+
event = subprocess.Popen("python "+file, stdin=subprocess.PIPE, stdout=None, stderr=subprocess.PIPE).communicate(input=input_str.encode())[1]
25+
if event:
26+
raise Exception(event.decode('utf-8'))
27+
else:
28+
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), file)
29+

0 commit comments

Comments
 (0)