natural.text
¶
-
class
natural.text.
Alphabet
(mapping)¶ Bases:
natural.text.Spelling
Helper class for (spelling) alphabets.
-
static
from_pair
(keys, values)¶ Returns a new
Alphabet()
object for the translation items specified inkeys
andvalues
.
-
transform
(letter)¶
-
static
-
natural.text.
code
(sentence, pad=u' ', format='army')¶ Transform a sentence using the code spelling alphabet, multiple international code alphabets are supported.
format description army US (international) army code alphabet faa Federal Aviation Administration code alphabet, as described in “ICAO Phonetics in the FAA ATC Manual, §2-4-16” icao International Civil Aviation Organization, as described in “Annex 10 to the Convention on International Civil Aviation, Volume II (Fifth edition, 1995), Chapter 5, 38–40” itu International Telecommunication Union Roman alphabet, as described in “ITU Phonetic Alphabet and Figure Code” morse International morse code, as described in “International Morse code Recommendation ITU-R M.1677-1”, http://itu.int/ word International Civil Aviation Organization, as described in “Annex 10 to the Convention on International Civil Aviation, Volume II (Fifth edition, 1995), Chapter 5, 38–40” Parameters: - sentence – input sentence
- pad – default
None
(reside to per-alphabet defaults) - format – default
army
>>> code('Python') 'PAH pah YANG kee TANG go HO tell OSS car NOH vem ber' >>> code('Python', format='faa') 'PAHPAH YANGKEY TANGGO HOHTELL OSSCAH NOVEMBER' >>> code('Python', format='icao') 'PAH PAH YANG KEY TANG GO HOH TELL OSS CAH NO VEM BER' >>> code('Python', format='itu') 'PAH PAH YANG KEY TANG GO HOH TELL OSS CAH NO VEM BER' >>> code('Python', format='morse') '.--. -.-- - .... --- -.' >>> code('Python', format='word') 'papa yankee tango hotel oscar november'
-
natural.text.
morse
(sentence, pad=u' ')¶ Wrapper for
code()
.>>> morse('Python') '.--. -.-- - .... --- -.'
-
natural.text.
nato
(sentence, pad=' ', format='telephony')¶ Transform a sentence using the NATO spelling alphabet.
Parameters: - sentence – input sentence
- pad – default
u' '
- format – default
telephony
, optionstelephony
orphonetic
>>> nato('Python') 'papa yankee tango hotel oscar november' >>> nato('Python', format='phonetic') 'pah-pah yang-key tang-go hoh-tel oss-cah no-vem-ber'
-
natural.text.
pronounce
(sentence, pad=u' ')¶ Transform a sentence using the pronounciations of the international code spelling alphabet. This function is subject to change its behaviour to support internationalised pronounciations of letters.
Parameters: - sentence – input sentence
- pad – default
u' '
>>> pronounce('abc') 'ælfɑ ˈbrɑːˈvo ˈtʃɑːli'
-
natural.text.
spell
(sentence, pad=' ')¶ Transform a sentence using the localised spelling alphabet.
Parameters: - sentence – input sentence
- pad – default
u' '
>>> spell('Python') 'Paris Yokohama Tripoli Havanna Oslo New York'