コード例 #1
0
ファイル: main.py プロジェクト: virajds/NLPWordCounter
def main(path=None, words=None, paragraph=None):
    """Main entry point for count words command line app.

    path :: Full path to the text file Dir ("String" - Unix format file path)

    words :: List of word specially should look for ("String" - Comma separated word list).
    Will count everything other than stop words, if not passed

    paragraph :: Paragraph to pass as a variable. Will use the file Dir if not passed.
    """
    count_words(path, words, paragraph)
コード例 #2
0
    def test_count_words_3(self):
        count_data = count_words(path=None,
                                 words="⅞",
                                 paragraph="½⅓¼⅕⅙⅐⅛⅑ ⅔⅖ ¾⅗ ⅘ ⅚⅝ ⅞")

        self.assertEqual(count_data[0][1], 1)
        self.assertEqual(count_data[0][0], "⅞")
コード例 #3
0
def read_file(file_name, number_of_words_to_print, return_json, json_name):
    try:
        file = open(file_name, "r")
        file_contents = file.read()
    except:
        print("An error was ecountered trying to open the file you specified.")
        return
    word_counts = count_words(file_contents)
    print_top_words(word_counts, number_of_words_to_print)
    if return_json:
        json_file_name = file_name.replace(".txt",
                                           "") + "_" + json_name + ".json"
        create_json(word_counts, json_file_name)
コード例 #4
0
    def test_count_words_1(self):
        count_data = count_words(
            path=None,
            words=None,
            paragraph="Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
            "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
            "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi "
            "ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit "
            "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur "
            "sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
            "mollit anim id est laborum.")

        self.assertEqual(count_data[0][1], 2)
        self.assertEqual(count_data[0][0], "Dolor")
コード例 #5
0
 def test_count_words_5(self):
     count_data = count_words(path="ExampleDocs/Test Docs/",
                              words=None,
                              paragraph=None)
コード例 #6
0
 def test_count_words_4(self):
     count_data = count_words(path="ExampleDocs/Test Docs/",
                              words="Government",
                              paragraph=None)
コード例 #7
0
def count_words_test_template(input_str, comparison_dict):
    count_words_result = count_words(input_str)
    assert count_words_result == comparison_dict
コード例 #8
0
 def test_count_v2(self):
     self.assertEqual(count_words(os.getcwd(), 'привет'), 4)
コード例 #9
0
 def test_count_v1(self):
     self.assertEqual(count_words(os.getcwd(), 'тест'), 3)
コード例 #10
0
 def test_count_v3(self):
     self.assertEqual(count_words(os.getcwd(), 'письмо'), 3)
コード例 #11
0
ファイル: getPerception.py プロジェクト: dwallach1/Public_Eye
def call_word_counter():
    """
	make tuples of each word and their associated count and store it in a .csv file
	the work of this function is done in wordCounter.py
	"""
    wordCounter.count_words(words)