[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Case tagging and python
From:       chrispoliquin () gmail ! com
Date:       2008-07-31 20:21:45
Message-ID: e71d6c32-c616-46bf-b7ed-6c12c2a9413e () z66g2000hsc ! googlegroups ! com
[Download RAW message or body]


I second the idea of just using the islower(), isupper(), and
istitle() methods.
So, you could have a function - let's call it checkCase() - that
returns a string with the tag you want...

def checkCase(word):

    if word.islower():
    	tag = 'nocap'
    elif word.isupper():
	tag = 'allcaps'
    elif word.istitle():
	tag = 'cap'

    return tag

Then let's take an input file and pass every word through the
function...

f = open(path:to:file, 'r')
corpus_text = f.read()
f.close()

tagged_corpus = ''
all_words = corpus_text.split()

for w in all_words:
  tagtext = checkCase(w)
  tagged_corpus = tagged_corpus + ' ' + w + '/' + tagtext

output_file = open(path:to:file, 'w')
output_file.write(tagged_corpus)
print 'All Done!'



Also, if you're doing natural language processing in Python, you
should get NLTK.

--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic