Χρήστης:Flubot/Κινέζικα ουσιαστικά

Από Βικιλεξικό
Μετάβαση στην πλοήγηση Πήδηση στην αναζήτηση

Διαβάζει τα κινεζικά ουσιαστικά από αρχείο xml και κάνει κατάλογο λημμάτων με μεταφράσεις Π.χ.

不在场证明: * το άλλοθι</text>

乌拉诺斯: * ο θεός Ουρανός (μυθολογία)</text>

乌鸦座: * Κόραξ (αστερισμός)</text>

乍得: * Τσαντ</text>

fin = sys.stdin

page_tag = re.compile('<page>')
title_content = re.compile('<title>([^:]+):(.+)<\/title>')
title_tag = re.compile('<title>')
title_capture = re.compile('<title>(.*)<\/title>')
page_tag_end = re.compile('<\/page>')
pagnm=re.compile('\'\'\'\{\{PAGENAME\}\}\'\'\'')
pagnm2=re.compile('\{\{ξεν\|zh\|\{\{PAGENAME\}\}\}\}')
set_string = re.compile('set')

eof=0
transl_header=""
while not eof:
    line = fin.readline()
    if line == "":
       eof = 1
    elif page_tag.search(line):
	namespace=""
	title=""
	transl=""
	transl_header=""
    elif title_tag.search(line):
           result = title_content.search(line)
           if result:
	       namespace=result.group(1)
	       title=result.group(2)
	   else:
               result = title_capture.search(line)
               if result:
	         namespace="main"
	         title=result.group(1)
    elif pagnm.search(line) or pagnm2.search(line):
	transl_header="set"
    elif set_string.search(transl_header):
	transl=line
	transl_header=""
    elif page_tag_end.search(line):
	print "[[%s]]: %s" % (title, transl)
fin.close()