from io import open
from conllu import parse_incr


file_list = [
"agr_adj_noun.conllu",
"agr_spg.conllu",
"agr_spn.conllu",
"agr_svn_obj-rel-clause.conllu",
"agr_svn_suj-rel-clause.conllu",
"agr_svp.conllu",
#"agr_svn.conllu",

"center_embedding.conllu",
"center_embedding_pairs_w_modifier.conllu",


"gss-subordination.conllu",
"gss-subordination-pp.conllu",
"gss-subordination-subj-rel-clause.conllu",
"gss-subordination-w-mod.conllu",

#"licensing_subj_neg_belief.conllu",
"licensing-npi.conllu",
#"licensing_subj_neg_belief-w-mod.conllu",
"licensing_subj_wish.conllu",

#"ldd-cleft.conllu",
#"ldd-cleft-w-mods.conllu",
"ldd-filler-gap-3stembed.conllu",
#"ldd-filler-gap-4stembed.conllu",
    "ldd-filler-gap-hierarchy.conllu",
"ldd-filler-gap-obj-extraction.conllu",
"ldd-filler-gap-subj-extraction.conllu",
]


for file in file_list:
    print("#####################")
    print(file)
    print("#####################")
    data_file = open(file, "r", encoding="utf-8")
    dico_pos_list = {}
    for tokenlist in parse_incr(data_file):
        pos_list = ""
        l = 0
        for token in tokenlist:
            l += 1
            pos_list += str(l)
            pos_list += ':'

#            print(token["form"], token["upos"])
#            print("feats = ", token["feats"])

#            if token["upos"] == "PRON" and token["feats"] == "PronType=Rel" :
            if token["upos"] == "gogo":# or token["upos"] == "ADP":
                pos_list += token["form"]
            else :
                pos_list += token["upos"]
            pos_list += " "
        if pos_list not in dico_pos_list :
            dico_pos_list[pos_list] = 1
        else:
            dico_pos_list[pos_list] += 1
#    for pos_list in dico_pos_list.keys().sort():

#    for pos_list in sorted(dico_pos_list.keys(), key=dico_pos_list.get):
    for pos_list in sorted(dico_pos_list.items()):
#        print("pos list =", pos_list)
        print(dico_pos_list[pos_list[0]], pos_list[0])
#        print(pos_list)
#    print("total number of patterns : ", len(dico_pos_list))
