# -*- encoding: iso-8859-1 -*-

"""sucht alle Einträge, die eine runde Klammer hinter dem Lemmaeintrag
haben.
"""

import re, sys
sys.path.append("../")
import classEntry02


def findBrackets(entryList, countBr):

	p = classEntry02.Entry(entryList)	
	f = open ("../../../res/teilergebnisse/02wlBrackets.txt", "a")

	if re.search(".+\(.+\)", " ".join(p.getWl1())):
		f.write("WL1: "+ " ".join(p.getWl1()) + "\n")
		f.write("WL2: "+ " ".join(p.getWl2()) + "\n")		
		f.write("\n")
		countBr += 1
	elif re.search(".+\(.+\)", " ".join(p.getWl2())):
		f.write("WL1: "+ " ".join(p.getWl1()) + "\n")
		f.write("WL2: "+ " ".join(p.getWl2()) + "\n")		
		f.write("\n")
		countBr += 1	
	return countBr


if __name__ == "__main__":
	lexicon = open("../../../res/01WAT.txt")
	wholeEntry = []
	countEntry = 0
	countBr = 0
	line = lexicon.readline()
	while line:
		line = line.strip()
		if re.search("ID:", line):
			if wholeEntry and wholeEntry[0] is not "":
				countEntry += 1
				countBr = findBrackets(wholeEntry, countBr)
			wholeEntry = []
		wholeEntry.append(line)
		line = lexicon.readline()
	countBr = findBrackets(wholeEntry, countBr)
	print "Anzahl der Einträge: ", countEntry
	print "Anzahl der Einträge mit runden Klammern: ", countBr