File size: 1,090 Bytes
9497a3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pandas as pd
from app.analysis import detect_query_type, count_keyword_rows, THANKS_KEYWORDS, COMPLAINT_KEYWORDS


def test_detect_query_type_thanks():
    t = "讻诪讛 诪砖转诪砖讬诐 讻转讘讜 转讜讚讛 注诇 讛砖讬专讜转"
    qtype, target = detect_query_type(t)
    assert qtype == "count_thanks"


def test_detect_query_type_complaint():
    t = "讻诪讛 讗谞砖讬诐 诪讚讜讜讞讬诐 注诇 转拽诇讛 讘诪注专讻转"
    qtype, target = detect_query_type(t)
    assert qtype == "count_complaint"


def test_count_keyword_rows_counts_thanks():
    df = pd.DataFrame({"Text": ["转讜讚讛 注诇 讛砖讬专讜转", "诇讗 讟讜讘", "转讜讚讛 专讘讛!", "砖讚专讜讙 谞讞诪讚"]})
    cnt = count_keyword_rows(df, THANKS_KEYWORDS, text_column="Text")
    assert cnt == 2


def test_count_keyword_rows_counts_complaints():
    df = pd.DataFrame({"Text": ["讗讬谉 砖讙讬讗讛", "转讬拽讜谉 谞讚专砖", "讬砖 转拽诇讛", "谞讻砖诇 讘注讘讜讚讛"]})
    # Notice: keywords are Hebrew complaint variants; expect matches >=1
    cnt = count_keyword_rows(df, COMPLAINT_KEYWORDS, text_column="Text")
    assert cnt >= 1