[Tutor] Tutor Digest, Vol 63, Issue 8
Alan Gauld
alan.gauld at btinternet.com
Tue May 5 11:40:06 CEST 2009
Please use a sensible subject and don;t reporst the whole digest.
"Dan Liang" <danliang20 at gmail.com> wrote in message
> Thank you for your help. I have been working on the file, but I still
> have a
> problem doing what I wanted. As a reminder,
Can you tell us what exactly the problem is? It's easier than us
trying to guess.
> #!usr/bin/python
> tags = {
> 'noun-prop': 'noun_prop null null'.split(),
> 'case_def_gen': 'case_def gen null'.split(),
> 'dem_pron_f': 'dem_pron f null'.split(),
> 'case_def_acc': 'case_def acc null'.split(),
> }
>
> TAB = '\t'
>
> def newlyTaggedWord(line):
> (word,tag) = line.split(TAB) # separate parts of line, keeping
> new_tags = tags[tag] # read in dict
> tagging = TAB.join(new_tags) # join with TABs
> return word + TAB + tagging # formatted result
>
> def replaceTagging(source_name, target_name):
> target_file = open(target_name, "w")
> # replacement loop
> for line in open(source_name, "r"):
> new_line = newlyTaggedWord(line) + '\n'
> target_file.write(new_line)
>
> target_file.close()
>
> if __name__ == "__main__":
> source_name = sys.argv[1]
> target_name = sys.argv[2]
> replaceTagging(source_name, target_name)
More information about the Tutor
mailing list