示例#1
0
def main():
	if len(sys.argv)>1:
		path=sys.argv[1]
	else:
		path= 'out'

	flist=path+'/*.txt'
	processDir(flist)
	wordcount.wordcount(path)
	bigram.bigramBuild(path)
    def test_wordcount(self):
        # Define the file paths.
        input_path = "./tweet_input/tweets.txt"
        output_path = "./tweet_output/ft1.txt"
        golden_path = "./tweet_output/wordcount_golden.txt"

        print "Running wordcount on input %s and writing output to %s" % (input_path, output_path)
        wordcount(input_path, output_path)
        
        # Read the contents of the output and golden files.
        with open(golden_path, "r") as f: golden=f.read()
        with open(output_path, "r") as f: out=f.read()

        # Check that the output and golden files are identical.
        self.assertEqual(golden, out)
示例#3
0
 def test_word_occurance9(self):
     self.assertDictEqual({
         'hello': 1,
         'world': 1
     },
                          wordcount('hello\tworld'),
                          msg='should not count tabs')
示例#4
0
 def test_word_occurance8(self):
     self.assertDictEqual({
         'hello': 1,
         'world': 1
     },
                          wordcount('hello\nworld'),
                          msg='should not count multilines')
示例#5
0
 def test_word_occurance0(self):
     self.assertDictEqual({
         'hello': 1,
         'world': 1
     },
                          wordcount('hello  world'),
                          msg='should count multiple spaces as one')
示例#6
0
 def test_word_occurance2(self):
     self.assertDictEqual({
         'one': 1,
         'of': 1,
         'each': 1
     },
                          wordcount("one of each"),
                          msg='should count one of each')
示例#7
0
 def test_word_occurance5(self):
     self.assertDictEqual({
         'testing': 2,
         1: 1,
         2: 1
     },
                          wordcount('testing 1 2 testing'),
                          msg='should include numbers')
示例#8
0
 def test_word_occurance6(self):
     self.assertDictEqual({
         'go': 1,
         'Go': 1,
         'GO': 1
     },
                          wordcount('go Go GO'),
                          msg='should respect case')
示例#9
0
 def test_word_occurance7(self):
     self.assertDictEqual(
         {
             "¡Hola!": 1,
             "¿Qué": 1,
             "tal?": 1,
             "Привет!": 1
         },
         wordcount('¡Hola! ¿Qué tal? Привет!'),
         msg='should count international characters properly')
示例#10
0
def test_wordcount_2():
    blob = ''
    with open ('sample_texts/textfile1.txt', 'r') as f:
        blob += f.read()

    with open ('sample_texts/textfile2.txt', 'r') as f:
        blob = blob + ' ' + f.read()

    assert wordcount.wordcount(blob) == ['this', 'is', 'a', 'test', 'file',
                                         '1', '2', '3', '4', '5']
示例#11
0
 def test_word_occurance3(self):
     self.assertDictEqual(
         {
             'one': 1,
             'fish': 4,
             'two': 1,
             'red': 1,
             'blue': 1
         },
         wordcount("one fish two fish red fish blue fish"),
         msg='should count multiple occurrences')
示例#12
0
文件: test_wc.py 项目: inpho/uroc
    def testTotalCount(self):
        """
        Testing to see if the reduce function returns an accurate count of the
        total number of words in all articles.
        """
        articleList = []
        for string in self.strings:
            articleList.append(wordcount.wordcount(string))

        theList = []
        for string in self.theTwentyFive:
            theList.append(wordcount.wordcount(string))

        emptyCount = wordcount.wordcount(self.emptyString)
        wcBulkDict = wordcount.reduce(articleList)
        wcTheDict = wordcount.reduce(theList)

        self.assertEqual(sum(emptyCount.values()), 0)
        self.assertEqual(sum(wcBulkDict.values()), 65)
        self.assertEqual(sum(wcTheDict.values()), 25)
示例#13
0
 def test_word_occurance4(self):
     self.assertDictEqual(
         {
             'car': 1,
             ":": 2,
             'carpet': 1,
             'as': 1,
             'java': 1,
             'javascript!!&@$%^&': 1
         },
         wordcount('car : carpet as java : javascript!!&@$%^&'),
         msg='should include punctuation')
示例#14
0
文件: test_wc.py 项目: inpho/uroc
    def testBulkCount(self):
        """
        Testing to see if the reduce function can count the occurrence of a word
        over a list of articles.
        """
        articleList = []
        for string in self.strings:
            articleList.append(wordcount.wordcount(string))

        wcBulkDict = wordcount.reduce(articleList)

        self.assertEqual(wcBulkDict["bureaucracy"], 1)
        self.assertEqual(wcBulkDict["bureaucracy."], 1)
        self.assertEqual(wcBulkDict["bureaucracy;"], 0)
        self.assertEqual(wcBulkDict["The"], 1)
        self.assertEqual(wcBulkDict["the"], 8)
        self.assertEqual(wcBulkDict["You"], 1)
        self.assertEqual(wcBulkDict["you"], 3)
        self.assertEqual(wcBulkDict["to"], 4)
        self.assertEqual(wcBulkDict["be"], 3)
示例#15
0
文件: test_wc.py 项目: inpho/uroc
    def testCount(self):
        """
        Testing to see if wordcount can count the number of occurrences of a word in
        an article.
        """
        wcDict = wordcount.wordcount(self.emptyString)
        self.assertEqual(wcDict["what"], 0)

        wcDict = wordcount.wordcount(self.string1)
        self.assertEqual(wcDict["what"], 2)

        wcDict = wordcount.wordcount(self.string2)
        self.assertEqual(wcDict["to"], 3)

        wcDict = wordcount.wordcount(self.string3)
        self.assertEqual(wcDict["what"], 0)

        wcDict = wordcount.wordcount(self.string4)
        self.assertEqual(wcDict["bureaucracy"], 1)
        self.assertEqual(wcDict["bureaucracy."], 1)

        wcDict = wordcount.wordcount(self.string5)
        self.assertEqual(wcDict["bureaucracy."], 0)
        self.assertEqual(wcDict["the"], 5)
示例#16
0
def test_wordcount_single() -> None:
    assert wordcount("ΝΙΨΟΝΑΝΟΜΗΜΑΤΑΜΗΜΟΝΑΝΟΨΙΝ") == 1
示例#17
0
def test_wordcount_multi() -> None:
    assert wordcount("Nipson anomemata me monan opsin") == 5
示例#18
0
def test_wordcount_empty() -> None:
    assert wordcount("") == 0
示例#19
0
 def test_single(self):
     self.assertEqual(wordcount("ΝΙΨΟΝΑΝΟΜΗΜΑΤΑΜΗΜΟΝΑΝΟΨΙΝ"), 1)
示例#20
0
def test_wordcount_1():
    with open ('sample_texts/huckleberry.txt', 'r') as f:
        assert wordcount.wordcount(f.read()) == [
            'and', 'the', 'i', 'a', 'to', 'it', 't', 'was', 'he', 'of'
        ]
示例#21
0
 def test_check_wordcount(self): 
     with self.assertRaises(AttributeError):
         wordcount(1)
示例#22
0
文件: bot.py 项目: Aloha137/Homework
def count_words(bot, update, args):
    print('Вызван /wordcount')
    bot.sendMessage(update.message.chat_id, wordcount(args))
示例#23
0
 def test_wordcount_fail(self):
     self.assertEqual(wordcount.wordcount('this sentence definitely doesn\'t have 50 words'), 50)
示例#24
0
 def test_wordcount3(self):
     result = wordcount.wordcount("Oneword")
     self.assertEqual(result, 1)
示例#25
0
 def test_empty(self):
     self.assertEqual(wordcount(""), 0)
示例#26
0
 def test_multi(self):
     self.assertEqual(wordcount("Nipson anomemata me monan opsin"), 5)
示例#27
0
 def test_wordcount_good(self):
     self.assertEqual(wordcount.wordcount('This sentence has five words.'), 5)
     self.assertEqual(wordcount.wordcount('       This   one has 4.     '), 4)
     self.assertEqual(wordcount.wordcount('don\'t count apostrophes?'), 3)
     self.assertEqual(wordcount.wordcount('tabs?\tlet\'s see'), 3)
示例#28
0
 def test_wordcount(self):
     self.assertDictEqual({'foo': 2, 'bar': 1}, wordcount('foo bar foo  '))
示例#29
0
 def test_wordcount4(self):
     result = wordcount.wordcount(fail)
     self.assertEqual(result, 3)
示例#30
0
def test_wordcount_good():
    assert wordcount.wordcount('This sentence has five words.') == 5
    assert wordcount.wordcount('       This   one has 4.     ') == 4
    assert wordcount.wordcount('don\'t count apostrophes?') == 3
    assert wordcount.wordcount('tabs?\tlet\'s see') == 3
示例#31
0
 def test_word_occurance1(self):
     self.assertDictEqual({'word': 1},
                          wordcount('word'),
                          msg='should count one word')
示例#32
0
 def test_wordcount5(self):
     result = wordcount.wordcount(1234)
     self.assertEqual(result, 3)
示例#33
0
 def test_wordcount6(self):
     result = wordcount.wordcount("M a n y w o r d s")
     self.assertEqual(result, 9)
示例#34
0
 def test_wordcount1(self):
     result = wordcount.wordcount("Should be four words")
     self.assertEqual(result, 4)
We cannot approve of this doctrine in one place unless we are willing to apply it everywhere.  If there is poison in the blood of the hand it will ultimately reach the heat.  It is equally true that forcible Christianity, if planted under the American flag in the far-away Orient, will sooner or later be transplanted upon American soil.

If true Christianity consists in carrying out in our daily lives the teachings of Christ, who will say that we are commanded to civilize with dynamite and proselyte with the sword?  He who would declare the divine will must prove his authority either by Holy Writ or by evidence of a special dispensation.

Imperialism finds no warrant in the Bible.  The command, “Go ye into all the world and preach the gospel to every creature,” has no Gatling gun attachment.  When Jesus visited a village of Samaria and the people refused to receive him, some of the disciples suggested that fire should be called down from Heaven to avenge the insult; but the Master rebuked them and said:  “Ye know not what manner of spirit ye are of; for the Son of Man is not come to destroy men’s lives, but to save them.”  Suppose he had said: “We will thrash them until they understand who we are,” how different would have been the history of Christianity!  Compare, if you will, the swaggering, bullying, brutal doctrine of imperialism with the golden rule and the commandment, “Thou shalt love thy neighbor as thyself.”

Love not force, was the weapon of the Nazarene; sacrifice for others, not the exploitation of them, was His method of reaching the human heart.  A missionary recently told me that the Stars and Stripes once saved his life because his assailant recognized our flag as a flag that had no blood upon it.

Let it be known that our missionaries are seeking souls instead of sovereignty; let be it known that instead of being the advance guard of conquering armies, they are going forth to help and uplift, having their loins girt about with the truth and their feet shod with the preparation of the gospel of peace, wearing the breastplate of righteousness and carrying the sword of the spirit; let it be known that they are citizens of a nation which respects the rights of the citizens of other nations as carefully as it protects the rights of its own citizens, and the welcome given to our missionaries will be more cordial than the welcome extended to the missionaries of any other nation.

The argument made by some that it was unfortunate for the nation that it had anything to do with the Philippine Islands, but that the naval victory at Manila made the permanent acquisition of those islands necessary, is also unsound. We won a naval victory at Santiago, but that did not compel us to hold Cuba.

The shedding of American blood in the Philippine Islands does not make it imperative that we should retain possession forever; American blood was shed at San Juan and El Caney, and yet the President has promised the Cubans independence. The fact that the American flag floats over Manila does not compel us to exercise perpetual sovereignty over the islands; the American flag floats over Havana to-day, but the President has promised to haul it down when the flag of the Cuban Republic is ready to rise in its place.  Better a thousand times that our flag in the Orient give way to a flag representing the idea of self-government than that the flag of this Republic should become the flag of an empire.

There is an easy, honest, honorable solution of the Philippine question. It is set forth in the Democratic platform and it is submitted with confidence to the American people.  This plan I unreservedly indorse.  If elected, I will convene Congress in extraordinary session as soon as inaugurated and recommend an immediate declaration of the nation’s purpose, first, to establish a stable form of government in the Philippine Islands, just as we are now establishing a stable form of government in Cuba; second, to give independence to the Filipinos as we have promised to give independence to the Cubans; third, to protect the Filipinos from outside interference while they work out their destiny, just as we have protected the republics of Central and South America, and are, by the Monroe doctrine, pledged to protect Cuba.

A European protectorate often results in the plundering of the ward by the guardian.  An American protectorate gives to the nation protected the advantage of our strength, without making it he victim of our greed.  For three-quarters of a century the Monroe doctrine has been a shield to neighboring republics and yet it has imposed no pecuniary burden upon us. After the Filipinos had aided us in the war against Spain, we could not leave them to be the victims of the ambitious designs of European nations, and since we do not desire to make them a part of us or to hold them as subjects, we propose the only alternative, namely, to give them independence and guard them against molestation from without.

When our opponents are unable to defend their position by argument they fall back upon the assertion that is destiny, and insist that we must submit to it, no matter how much it violates our moral percepts and our principles of government. This is a complacent philosophy.  It obliterates the distinction between right and wrong and makes individuals and nations the helpless victims of circumstance.

Destiny is the subterfuge of the invertebrate, who, lacking the courage to oppose error, seeks some plausible excuse for supporting it.  Washington said that the destiny of the republican form of government was deeply, if not finally, staked on the experiment entrusted to the American people.  How different Washington’s definition of destiny from the Republican definition!

The Republicans say that this nation is in the hands of destiny; Washington believed that not only the destiny of our own nation but the destiny of the republican form of government throughout the world was entrusted to American hands.  Immeasurable responsibility!  The destiny of this Republic is in the hands of its own people, and upon the success of the experiment here rests the hope of humanity.  No exterior force can disturb this Republic, and no foreign influence should be permitted to change its course.  What the future has in store for this nation no one has authority to declare, but each individual has his own idea of the nation’s mission, and he owes it to his country as well as to himself to contribute as best he may to the fulfillment of that mission.

Mr. Chairman and Gentlemen of the Committee: I can never fully discharge the debt of gratitude which I owe to my countrymen for the honors which they have so generously bestowed upon me; but, sirs, whether it be my lot to occupy the high office for which the convention has named me, or to spend the remainder of my days in private life, it shall be my constant ambition and my controlling purpose to aid in realizing the high ideals of those whose wisdom and courage and sacrifices brought the Republic into existence.

I can conceive of a national destiny surpassing the glories of the present and the past -- a destiny which meets the responsibility of today and measures up to the possibilities of the future. Behold a republic, resting securely upon the foundation stones quarried by revolutionary patriots from the mountain of eternal truth -- a republic applying in practice and proclaiming to the world the self-evident propositions that all men are created equal; that they are endowed with inalienable rights; that governments are instituted among men to secure these rights, and that governments derive their just powers from the consent of the governed. Behold a republic in which civil and religion liberty stimulate all to earnest endeavor and in which the law restrains every hand uplifted for a neighbor's injury -- a republic in which every citizen is a sovereign, but in which no one cares to wear a crown. Behold a republic standing erect while empires all around are bowed beneath the weight of their own armaments -- a republic whose flag is loved while other flags are only feared. Behold a republic increasing in population, in wealth, in strength and in influence, solving the problems of civilization and hastening the coming of an universal brotherhood -- a republic which shakes thrones and dissolves aristocracies by its silent example and gives light and inspiration to those who sit in darkness. Behold a republic gradually but surely becoming the supreme moral factor in the world's progress and the accepted arbiter of the world's disputes -- a republic whose history, like the path of the just, "is as the shining light that shineth more and more unto the perfect day."
"""

counted_words = wordcount.wordcount(text)
wordcount.create_csv(counted_words, 'wjb_imperialism')
示例#36
0
 def test_wordcount2(self):
     result = wordcount.wordcount("Two words")
     self.assertEqual(result, 2)
示例#37
0
server_address = ('localhost', 8000)
print >> sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)

# Listen for incoming connections
sock.listen(1)

while True:
    # Wait for a connection
    print >> sys.stderr, 'waiting for a connection'
    connection, client_address = sock.accept()

    try:
        print >> sys.stderr, 'connection from', client_address

        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(4096)
            if data:
                command_list = pickle.loads(data)
                wordc = wc.wordcount(command_list[1], command_list[2])
                print "Word Count of " + command_list[2] + " is " + str(wordc)
                connection.sendall(str(wordc))
            else:
                print "No data from " + str(client_address)
                break

    finally:
        # Clean up the connection
        connection.close()
示例#38
0
def test_wordcount_exceptions():
    with pytest.raises(TypeError):
        assert wordcount.wordcount(234)