Example #1
0
def getNgramTaggerAccuracy(n, trainingSet, testingSet):
    # trains and returns the accuracy of the NgramTagger given a value of n

    # get untagged sentences and gold POS tags
    testingUntaggedSentences = [[taggedWord[0] for taggedWord in sentence] for sentence in testingSet]
    testingGoldPOSTags = [[taggedWord[1] for taggedWord in sentence] for sentence in testingSet]

    # train tagger
    ngramTagger = NgramTagger(n, trainingSet)

    # test tagger and get predicted POS tags
    ngramTaggedSentences = ngramTagger.tag_sents(testingUntaggedSentences)
    ngramTaggedSentencesPOSTags = [[taggedWord[1] for taggedWord in sentence] for sentence in ngramTaggedSentences]

    # calculate and return accuracy
    return calculateAccuracy(testingGoldPOSTags, ngramTaggedSentencesPOSTags)
Example #2
0
def getNgramTaggerAccuracy(n, trainingSet, testingSet):
    # trains and returns the accuracy of the NgramTagger given a value of n

    # get untagged sentences and gold POS tags
    testingUntaggedSentences = [[taggedWord[0] for taggedWord in sentence]
                                for sentence in testingSet]
    testingGoldPOSTags = [[taggedWord[1] for taggedWord in sentence]
                          for sentence in testingSet]

    # train tagger
    ngramTagger = NgramTagger(n, trainingSet)

    # test tagger and get predicted POS tags
    ngramTaggedSentences = ngramTagger.tag_sents(testingUntaggedSentences)
    ngramTaggedSentencesPOSTags = [[taggedWord[1] for taggedWord in sentence]
                                   for sentence in ngramTaggedSentences]

    # calculate and return accuracy
    return calculateAccuracy(testingGoldPOSTags, ngramTaggedSentencesPOSTags)