How to use the pycantonese.tone function in pycantonese

To help you get started, we’ve selected a few pycantonese examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jacksonllee / pycantonese / test_corpus.py View on Github external
for word in stringlist:
        try:
            print unicode(word, encoding='utf-8')
        except:
            print repr(word)

def final_tone(corpus, what_final_tone):
    final = what_final_tone[: -1]
    tone = what_final_tone[-1]
    return pc.search_jp(corpus, [(final, 2), (tone, 3)], 'type')

##----------------------------------------------------------------------------##
## sample usage of PyCantonese

print '\nFind all words with a specific tone (e.g., tone 4):'
tone4 = pc.tone(currentCorpus, '4', 'type')
print 'There are %d matching words, e.g.:' % (len(tone4))
printListUTF8(tone4[: 5]) # 5 results

print '\nFind all words with a specific onset/initial (e.g., \'b\'):'
b = pc.onset(currentCorpus, 'b', 'type') # the function initial() is the same
print 'There are %d matching words, e.g.:' % (len(b))
printListUTF8(b[: 5]) # 5 results

print '\nFind all words with a specific nucleus (e.g., \'aa\'):'
aa = pc.nucleus(currentCorpus, 'aa', 'type')
print 'There are %d matching words, e.g.:' % (len(aa))
printListUTF8(aa[: 5]) # 5 results

print '\nFind all words with a specific coda (e.g., \'ng\'):'
ng = pc.coda(currentCorpus, 'ng', 'type')
print 'There are %d matching words, e.g.:' % (len(ng))