Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

python-3.x - 仅在以* CHI开头的行上用@s:eng标记文本文件中的所有英语单词:(Tag all English words in text files with @s:eng only on lines starting with *CHI:)

I am trying to write a Python script to tag all English words only on lines that start with *CHI: with "@s:eng" at the end of the word but the code does not seem to work.

(我试图编写一个Python脚本,以仅在以* CHI:开头的行上标记所有英文单词,并在该单词的末尾加上“ @s:eng”,但该代码似乎无法正常工作。)

Currently, the code looks like this:

(当前,代码如下所示:)

import re

with open("transcript 0623.cha", encoding='utf8') as f:

    text = f.read()

    new_text = re.sub("A-Za-z", "A-Za-z@s:eng", text)
    with open("transcript 0623_out.cha", "w", encoding='utf8') as result:
        result.write(new_text)

Can you suggest how I can improve the code?

(您能建议我如何改善代码吗?)

The sample contents of transcript 0623 are as follows:

(成绩单0623的样本内容如下:)

@Begin
@Languages: zho , eng
@Participants:  TEA Teacher , CHI Child
@ID:    zho,|change_me_later|TEA|||||Teacher|||
@ID:    zho,|change_me_later|CHI|||||Child|||
@Transcriber:   CKX
@Activities:    Storytelling
@Comment:   child used the malay word sayang
*TEA:   ok ,   来   ,   开始   .
*CHI:   呃   ,   the   boy@s   .
*TEA:   嗯   .
*CHI:   have a frog@s .
*TEA:   ok .
*TEA:   ok do you know what is boy in chinese ?
*TEA:   can you help me tell the story in chinese ?
*TEA:   ok then do you know what is a frog in chinese ?
*TEA:   ok , come .
*TEA:   go to the next page .
*CHI:   when the boy sleeping , then the frog come out@s .
*TEA:   ok .
*TEA:   还有 吗   ?
*CHI:   the cat also sleeping@s .
*TEA:   ok .
*TEA:   do you know what is cat in chinese ?
*TEA:   嗯   ,   what   is   it   ?
*CHI:   猫   .
*TEA:   ok .
*TEA:   so can you use your chinese for cat to help me tell the story ?
*TEA:   嗯   ?
*CHI:   猫   睡觉   .
*TEA:   啊   ,   很   好   .
*TEA:   还有   吗   ?
*CHI:   frog come out@s .
*TEA:   ok .
*TEA:   很   好   .
*TEA:   还有   吗   ?
*CHI:   next one@s .
*TEA:   ok .
*CHI:   the boy wake up@s .
*CHI:   and , the frog is gone@s .
*TEA:   嗯   .
*CHI:   then , maybe , the frog went out the window@s .
*TEA:   嗯   ,   ok   .
*CHI:   the boy is looking for the frog@s .
*TEA:   嗯   .
*CHI:   the cat is looking for the frog@s .
*TEA:   ok   what   is   cat   in   chinese   again   ?
*CHI:   what@s ?
*TEA:   what is cat in chinese again ?
*CHI:   猫   .
*TEA:   嗯   .
*TEA:   ok can you use the chinese word for cat to tell me the story again ?
*TEA:   嗯   ?
*CHI:   猫   looking   for   the@s   .
*TEA:   啊   .
*CHI:   for the@s .
*TEA:   嗯   .
*CHI:   frog@s .
*TEA:   ok .
*TEA:   very good .
*TEA:   anything else ?
*TEA:   ok .
*CHI:   the@s   猫   go   in@s   .
*CHI:   and put the bottle in here@s .
*TEA:   嗯   .
*CHI:   the boy has do this@s .

*TEA:   嗯   .
*CHI:   the cat fall down@s .
*TEA:   ok   what   is   cat   in   chinese   again   ?
*CHI:   猫   fall   down@s   .
*TEA:   嗯   .
*CHI:   and get the bottle@s .
*CHI:   get the bottle@s .
*TEA:   ok .
*TEA:   very good .
*TEA:   ok anything else ?
*TEA:   anything else ?
*TEA:   ok .
*CHI:   the   boy   go   and   sayang   the   cat@s   .
*TEA:   嗯   .
*TEA:   what is cat in chinese ?
*CHI:   the , the boy go and sayang the@s 猫 .
*TEA:   啊   ,   ok   .
*TEA:   very good .
*CHI:   and then the bottle break@s .
*TEA:   ok .
*TEA:   very good .
*TEA:   anything else ?
*TEA:   come .
*TEA:   ok this whole thing is together .
*CHI:   the boy is calling for the frog@s .
*TEA:   嗯   .
*CHI:   the cat is looking underneath the table@s .
*TEA:   ok   what   is   cat   in   chinese   again   ?
*CHI:   the@s 猫 looking for the frog underneath@s .
*TEA:   嗯   ,   ok   .
*CHI:   they looking inside the hole if the frog is here@s .
*TEA:   嗯   .
*TEA:   anything else ?
*CHI:   then the boy is here@s .
*TEA:   啊 , ok very good .
*TEA:   anything else ?
*CHI:   the boy fall down into the water@s .
*CHI:   and the cat also@s .
*CHI:   and then the log break@s .
*TEA:   嗯   .
*TEA:   do you know what is water in chinese ?
*TEA:   what is it ?
*CHI:   水   .
*TEA:   ok can you tell me the story again with the word , with the , with
    the chinese word for water ?
*TEA:   嗯   ?
*CHI:   the boy fall down@s .
*CHI:   and   the@s   猫   too@s   .
*CHI:   and   both   of   them   fall   in   the@s   水   .
*TEA:   ok , very good .
*CHI:   and then they all get wet@s .
*TEA:   嗯   .
*TEA:   ok .
*CHI:   they found some water on the log@s .
*TEA:   嗯   .
*CHI:   they found so many frogs@s .
*TEA:   嗯   .
*CHI:   and is this the frog that they have@s ?
*TEA:   嗯   .
*TEA:   ok .
*CHI:   then they say bye bye .
*TEA:   嗯   .
*TEA:   you know how to say bye bye in chinese ?
*CHI:   再见   .
*TEA:   ok .
*TEA:   can you repeat this part again in chinese ?
*CHI:   and   then   the   boy   and   the   cat   and   the   frog
    say@s   再见   .
*TEA:   ok   what   is   cat   in   chinese   again   ?
*CHI:   猫   .
*TEA:   啊   .
*TEA:   can you repeat the whole thing ?
*CHI:   the boy and the@s 猫 and the , and the frog@s .
*TEA:   嗯   .
*CHI:   say@s   再见   .
*TEA:   ok .
*TEA:   very good .
*TEA:   thank you for telling me the story ok ?
@End 

Thank you.

(谢谢。)

  ask by Toh An translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...