tag = input("POS/Affixes? -> ")
while tag!= "POS" and tag !="Affixes":
    print("wrong input")
    tag = input("POS/Affixes? -> ")

backoff = input("DefaultTagger as backoff? J/N-> ")
if backoff =="J":
    backoff = DefaultTagger('n')
else:
    backoff = None

print("\nCalculating Brill & Wu Complementarity\n\nAfter the programme finished, please look for \
'Results\CompareBrillWu_Regex"+tone+tag+".txt'  and 'Results\Disagreement_BrillWuHtml_Regex"+tone+tag+".txt' in your current working directory.\n")


bambara = create_reader(tone, tag)          

hmm = indivHMM(bambara)
hmmtagged = hmm.tag_sents([untag(i) for i in bambara.test_sents])
hmm_acc = hmm.evaluate(bambara.test_sents)
hmm_err = round((1 - (hmm_acc)),4)

crf = indivCRF(bambara, tone, tag)
crftagged = crf.tag_sents([untag(i) for i in bambara.test_sents]) 
crf_acc = crf.evaluate(bambara.test_sents)
crf_err = round((1-(crf_acc)),4)

tnt = indivTnT(bambara, backoff)
tnttagged = tnt.tag_sents([untag(i) for i in bambara.test_sents])
tnt_acc = tnt.evaluate(bambara.test_sents)
tnt_err = round((1-(tnt_acc)),4)
Пример #2
0
def backoff_evaluation(tone, tag):
    '''Calculates various backoff-combinations'''
    
    bambara = create_reader(tone, tag)
    print("Calculating Backoff-Combinations...\n")

    unidef = backoff_tagger([2,1,0], bambara,option_tones=tone, option_tag=tag)
    print("unidef acc: ", unidef.evaluate(bambara.test_sents))
    print("hallo")
    
    unidef = backoff_tagger([0], bambara,option_tones=tone, option_tag=tag)
    print("unidef acc: ", unidef.evaluate(bambara.test_sents))

    uniregdef = backoff_tagger([5,0],bambara, option_tones=tone, option_tag=tag)
    print("uniregdef acc: ", uniregdef.evaluate(bambara.test_sents))

    unidicdef = backoff_tagger([6,0], bambara,option_tones=tone, option_tag=tag)
    print("unidicdef acc: ", unidicdef.evaluate(bambara.test_sents))

    unibidef = backoff_tagger([1,0], bambara,option_tones=tone, option_tag=tag)
    print("unibidef acc: ", unibidef.evaluate(bambara.test_sents))

    unibidicdef = backoff_tagger([6,1,0], bambara,option_tones=tone, option_tag=tag)
    print("unibidicdef acc: ", unibidicdef.evaluate(bambara.test_sents))

    uniaffixdef = backoff_tagger([8,0],bambara,option_tones=tone, option_tag=tag)
    print("uniaffixdef acc: ", uniaffixdef.evaluate(bambara.test_sents))

    uniaffixregdef = backoff_tagger([5,8,0],bambara,option_tones=tone, option_tag=tag)
    print("uniaffixregdef acc: ", uniaffixregdef.evaluate(bambara.test_sents))

    uniaffixdicdef = backoff_tagger([6,8,0],bambara,option_tones=tone, option_tag=tag)
    print("uniaffixdicdef acc: ", uniaffixdicdef.evaluate(bambara.test_sents))

    uniaffixdicdef = backoff_tagger([5,6,8,0],bambara,option_tones=tone, option_tag=tag)
    print("uniaffixdicregdef acc: ", uniaffixdicdef.evaluate(bambara.test_sents))


    bidef = backoff_tagger([1],bambara, option_tones=tone, option_tag=tag)
    print("bief acc: ", bidef.evaluate(bambara.test_sents))

    biregdef = backoff_tagger([5,1],bambara,option_tones=tone, option_tag=tag)
    print("biregdef acc: ", biregdef.evaluate(bambara.test_sents))

    bidicdef = backoff_tagger([6,1], bambara,option_tones=tone, option_tag=tag)
    print("bidicdef acc: ", bidicdef.evaluate(bambara.test_sents))

    biunidef = backoff_tagger([0,1], bambara,option_tones=tone, option_tag=tag)
    print("biunidef acc: ", biunidef.evaluate(bambara.test_sents))

    biunidicdef = backoff_tagger([6,0,1], bambara,option_tones=tone, option_tag=tag)
    print("biunidicdef acc: ", biunidicdef.evaluate(bambara.test_sents))

    biaffixdef = backoff_tagger([8,1],bambara,option_tones=tone, option_tag=tag)
    print("biaffixdef acc: ", biaffixdef.evaluate(bambara.test_sents))

    biaffixregdef = backoff_tagger([5,8,1],bambara,option_tones=tone, option_tag=tag)
    print("biaffixregdef acc: ", biaffixregdef.evaluate(bambara.test_sents))

    biaffixdicdef = backoff_tagger([6,8,1],bambara,option_tones=tone, option_tag=tag)
    print("biaffixdicdef acc: ", biaffixdicdef.evaluate(bambara.test_sents))

    biaffixdicdef = backoff_tagger([5,6,8,1],bambara,option_tones=tone, option_tag=tag)
    print("biaffixdicregdef acc: ", biaffixdicdef.evaluate(bambara.test_sents))

    tridef = backoff_tagger([2], bambara,option_tones=tone, option_tag=tag)
    print("tridef acc: ", tridef.evaluate(bambara.test_sents))

    triregdef = backoff_tagger([5,2],bambara,option_tones=tone, option_tag=tag)
    print("triregdef acc: ", triregdef.evaluate(bambara.test_sents))

    tridic = backoff_tagger([6,2],bambara,option_tones=tone, option_tag=tag)
    print("tridic acc: ", tridic.evaluate(bambara.test_sents))

    tribiuni = backoff_tagger([0,1,2],bambara,option_tones=tone, option_tag=tag)
    print("tribiuni acc: ", tribiuni.evaluate(bambara.test_sents))

    tribiunidic = backoff_tagger([6,0,1,2],bambara,option_tones=tone, option_tag=tag)
    print("tribiunidic acc: ", tribiunidic.evaluate(bambara.test_sents))

    triaffix = backoff_tagger([8,2],bambara,option_tones=tone, option_tag=tag)
    print("triaffix acc: ", triaffix.evaluate(bambara.test_sents))

    triaffixreg = backoff_tagger([5,8,2],bambara,option_tones=tone, option_tag=tag)
    print("triaffixreg acc: ", triaffixreg.evaluate(bambara.test_sents))

    triaffixdic = backoff_tagger([6,8,2],bambara,option_tones=tone, option_tag=tag)
    print("triaffixdic acc: ", triaffixdic.evaluate(bambara.test_sents))

    triaffixdicreg = backoff_tagger([5,6,8,2],bambara,option_tones=tone, option_tag=tag)
    print("triaffixdicregdef acc: ", triaffixdicreg.evaluate(bambara.test_sents))


    tntdef = backoff_tagger([9],bambara,option_tones=tone, option_tag=tag)
    print("tntdef acc: ", tntdef.evaluate(bambara.test_sents))

    tntreg = backoff_tagger([5,9],bambara,option_tones=tone, option_tag=tag)
    print("tntreg acc: ", tntreg.evaluate(bambara.test_sents))

    tntdic = backoff_tagger([6,9],bambara,option_tones=tone, option_tag=tag)
    print("tntdic acc: ", tntdic.evaluate(bambara.test_sents))

    tntbiuni = backoff_tagger([0,1,9],bambara,option_tones=tone, option_tag=tag)
    print("tntbiuni acc: ", tntbiuni.evaluate(bambara.test_sents))

    tntaffix = backoff_tagger([8,9],bambara,option_tones=tone, option_tag=tag)
    print("tntaffix acc: ", tntaffix.evaluate(bambara.test_sents))

    tntaffixdic = backoff_tagger([6,8,9],bambara,option_tones=tone, option_tag=tag)
    print("tntaffixdic acc: ", tntaffixdic.evaluate(bambara.test_sents))

    tntaffixdic = backoff_tagger([5,6,8,9],bambara,option_tones=tone, option_tag=tag)
    print("tntaffixdicregdef acc: ", tntaffixdic.evaluate(bambara.test_sents))

    tntcrf = backoff_tagger([4,9],bambara,option_tones=tone, option_tag=tag)
    print("tntcrf acc"+tone+" "+tag+": ", tntcrf.evaluate(bambara.test_sents))

    tnthmm = backoff_tagger([10,9], bambara, option_tones=tone, option_tag=tag)
    print("tnthmm acc: ", tnthmm.evaluate(bambara.test_sents))

    print("Calculating precision of individual taggers...\n")
    indivDefault(bambara)
    indivUnigram(bambara,backoff=None)
    indivBigram(bambara,backoff=None)
    indivTrigram(bambara,backoff=None)
    indivAffix(bambara, affix_length=-4, backoff=None)
    indivTnT(bambara, backoff=None)
    indivRegexp(bambara, tag, tone, backoff=None)
    indivDic(bambara, tone)
    indivHMM(bambara)
    indivCRF(bambara)