Exemplo n.º 1
0
def detected():
    bWords = {}
    if request.method == "POST":
        formData = request.form
        inputtextarea = formData['inputtextarea']
        sentence = str(inputtextarea).strip()
        wordTokenizer = word_tokenizer().tokenize(sentence)
        #file1 = open("wordlist.txt", "a+", encoding='utf-8')  # write mode
        for i in range(len(wordTokenizer)):
            # bWords.append(BengaliWord(wordTokenizer[i]))
            bWords[i] = BengaliWord(wordTokenizer[i]).__dict__
            #file1.write(str(wordTokenizer[i]) + "\n")
        #print(bWords[0])
        #file1.close()
        #print(my_trie.search("চীন"))
        #comp = my_trie.printAutoSuggestions(bWords[0]['word'])
        # print(comp)
        # if comp == -1:
        #     print("No other strings found with this prefix\n")
        # elif comp == 0:
        #     print("No string found with this prefix\n")

        wordListWithErrorLeveledOnIt = error_detector(my_trie, bWords).error_generator()
        # wordListWithErrorLeveledOnItInJSONFormat = json.dumps(wordListWithErrorLeveledOnIt)
        wordListJson = JsonBuilder(wordListWithErrorLeveledOnIt)
    #return render_template('detection.html', result=wordListWithErrorLeveledOnIt, inputtextarea=inputtextarea)
    # return render_template('detection.html', result= wordListWithErrorLeveledOnIt[0].words, inputtextarea=inputtextarea)
    #return wordListWithErrorLeveledOnItInJSONFormat
    return wordListJson.return_json()
Exemplo n.º 2
0
 def test_builder_pretty_simple(self):
     print "A simple Builder Test with KeyValues in prittyprint"
     a_builder = JsonBuilder(1)
     a_builder.keyvalue("a_key", "a_value").keyvalue("b_key",
                                                     "b_value").close()
     x = a_builder.build()
     self.assertEquals(
         '[{\n    "a_key": "a_value",\n    "b_key": "b_value"\n}]', x)
     print x
Exemplo n.º 3
0
 def test_builder_simple(self):
     print "A simple Builder Test with KeyValues"
     a_builder = JsonBuilder(0)
     a_builder.keyvalue("a_key", "a_value").keyvalue("b_key",
                                                     "b_value").close()
     x = a_builder.build()
     self.assertEquals("[{\"a_key\": \"a_value\",\"b_key\": \"b_value\"}]",
                       x)
     print x
Exemplo n.º 4
0
 def test_builder_pretty_advanced(self):
     print "An advanced Builder Test with KeyValues and Lists in prittyprint"
     a_builder = JsonBuilder(1)
     a_builder.keyvalue("a_key", "a_value").keyvalue(
         "b_key", "b_value").list("a_list").keyvalue("a_lkey",
                                                     "alvalue").closeAll()
     x = a_builder.build()
     self.assertEquals(
         '[{\n    "a_key": "a_value",\n    "b_key": "b_value",\n    "a_list": [\n        {\n            "a_lkey": "alvalue"\n        }\n    ]\n}]',
         x)
     print x
Exemplo n.º 5
0
 def test_builder_advanced(self):
     print "An advanced Builder Test with KeyValues and Lists"
     a_builder = JsonBuilder(0)
     a_builder.keyvalue("a_key", "a_value").keyvalue(
         "b_key", "b_value").list("a_list").keyvalue("a_lkey",
                                                     "alvalue").closeAll()
     x = a_builder.build()
     self.assertEquals(
         '[{"a_key": "a_value","b_key": "b_value","a_list": [{"a_lkey": "alvalue"}]}]',
         x)
     print x
Exemplo n.º 6
0
    def doFile(self, listOfSets, pretty, path):
        builder = JsonBuilder(pretty)
        if (listOfSets is not None and 0 < len(listOfSets)):
            for propset in listOfSets:
                self.__do(builder, propset)
            builder.closeAll()
            content = builder.build()

            self.__writeFile(path, content)

        else:
            print "Empty List, did Nothing"
Exemplo n.º 7
0
 def test_builder_classtest(self):
     print "A simple Classmatching Test"
     a_builder = JsonBuilder(0)
     a_keyvalue = KeyValue("a", "b")
     a_list = List("a", 0)
     print a_builder._classtest(a_keyvalue)
     print a_builder._classtest(a_list)
     self.assertEquals("kv", a_builder._classtest(a_keyvalue))
     self.assertEquals("list", a_builder._classtest(a_list))
Exemplo n.º 8
0
    def test_jsonBuilder(self):
        item1 = Item("id", 1)
        item1.append("lastName", "Muster")
        item1.append("firstName", "Max")

        item2 = Item("id", 2)
        item2.append("lastName", "Müller")
        item2.append("firstName", "Ute")

        builder = JsonBuilder()
        builder.append(item1)
        builder.append(item2)

        director = Director(builder)
        json = director.construct()
        self.assertEqual(
            '{{"id":"1", "lastName":"Muster", "firstName":"Max"},{"id":"2", "lastName":"Müller", "firstName":"Ute"}}',
            json)
Exemplo n.º 9
0
    def doPrint(self, listOfSets, pretty):
        builder = JsonBuilder(pretty)

        if (listOfSets is not None and 0 < len(listOfSets)):
            for propset in listOfSets:
                self.__do(builder, propset)
            builder.closeAll()
            print builder.build()

        else:
            print "Empty List, did Nothing"
Exemplo n.º 10
0
 def test_builder_create(self):
     a_builder = JsonBuilder(1)
     self.assertEquals(a_builder.pretty, 1)
Exemplo n.º 11
0
 def test_builder_close_only(self):
     print "A Builder Test with Close-Elements only"
     a_builder = JsonBuilder(0)
     a_builder.close().close().close()
     x = a_builder.build()
     print x
Exemplo n.º 12
0
 def test_builder_empty(self):
     print "A Builder Test with no Elements"
     a_builder = JsonBuilder(0)
     x = a_builder.build()
     self.assertEquals('[]', x)
     print x