Thursday, September 27, 2012

Character Count

Ever wonder how people figure out how many different Chinese characters a book has in it? Like how textbooks can say "use this book and you will learn over 350 characters!" or whatever?

The following is a code I wrote in Python that will take any document containing Chinese text and count the number of different Chinese characters in it. It ignores punctuation, whitespace characters, English, and anything that is not a Chinese character. As written right now, it prints out the vocabulary size and the total length of the document. If you want to see the all the Chinese characters strung together, you can un-comment "print chars" in the 5th line from the bottom.

Right now this is just for my own personal use. Kind of an interesting little script I think.

#!/usr/bin/env python
# -*- encoding: utf8 -*-

import re
import nltk
from nltk.probability import FreqDist

f = open('YOURTEXTHERE.txt')
contents = f.read()
unicontents = contents.decode('utf8')
chinese_only = re.findall(ur'[\u4e00-\u9fff]+', unicontents)
stripped_chinese_only = ''.join(chinese_only)
chars = stripped_chinese_only.encode('utf8')
tokens = nltk.word_tokenize(stripped_chinese_only)
fdist1 = FreqDist(tokens)
#print chars

a = len(fdist1.keys())
b = len(tokens)
print "Vocabulary size:", a, "different characters"
print "Length:", b, "total characters"

Sunday, September 16, 2012

Hard Times

Hard times are coming. Will your addiction save you?

When you are dying in a hospital bed, blinded by pain and laying in a pool of your own blood and shit, will you take comfort in the fact that you are a talented musician? When you can't sleep for days because your heart screams at God "Why would you let that happen?", will looking at porn heal your crushed soul? When your marriage shatters, will playing video games help you pick up the pieces? When you are sitting in a darkened room, just you and a razor blade, will being a good athlete stay your hand? When you bury your son, will you wipe away the tears and cling to hope because you know that everyone thinks you tell funny jokes and great stories?

Hard times are coming. How are you preparing your soul for them? What will you do when they get here?

Wednesday, September 05, 2012

Basketball

Women's basketball should be played on a 9 foot basket. Period. Then you could have legitimate jump-shots, players could shoot while being tightly defended, and of course the dunks would be badass. There is no downside.

Don't even try to argue that this is "lowering the bar" or "compromising the game." They already play with a smaller ball than the men's game. This is a simple matter of optimizing the field of play for the players.