Esempio n. 1
0
def test_ngram(request, ng):
    obj = DTrie()
    prev_letter = ""
    # per-line processor - remove spaces
    for char in get_letters("".join(re.split("\s+", ng)).lower()):
        if (prev_letter.isalpha() and char.isalpha()) or (
                utf8.is_tamil_unicode(prev_letter) and utf8.is_tamil_unicode(char)
        ):
            bigram = "".join([prev_letter, char])
            obj.add(bigram)  # update previous
        prev_letter = char
    actual = obj.getAllWordsAndCount()
    json_string = json.dumps(actual, ensure_ascii=False)
    # creating a Response object to set the content type and the encoding
    response = HttpResponse(json_string, content_type="application/json; charset=utf-8")
    return response
def test_ngram(request,ng):
    obj = DTrie()
    prev_letter = u''
    # per-line processor - remove spaces
    for char in get_letters(u"".join(re.split('\s+',ng)).lower()):
        if (prev_letter.isalpha() and char.isalpha()) or ( utf8.is_tamil_unicode(prev_letter) and utf8.is_tamil_unicode(char)):
            bigram = u"".join([prev_letter,char])
            obj.add(bigram) # update previous
        prev_letter = char
    actual = obj.getAllWordsAndCount()
    json_string = json.dumps(actual,ensure_ascii = False)
    #creating a Response object to set the content type and the encoding
    response = HttpResponse(json_string,content_type="application/json; charset=utf-8" )
    return response