Jean-François Sudre1 (15 August 1787 – 3 October 1862) had a unique thought in 1817: if people of different cultures can appreciate the same music, why not develop music itself into an international language? The constructed language that he devised based on this idea — which he called Solresol — enjoyed a brief spell of popularity, reaching its pinnacle with Boleslas Gajewski's 1902 posthumous publication of Grammaire du Solrésol.
Solresol is a musical language based on the principles of solfège, a music education method used to teach the pitch and sight singing. Theoretically, Solresol communication can be done through speaking, singing, flags of different color — even painting. Solresol words are made up of from one to five syllables or notes. Each of these may be one of only seven basic phonemes that correspond to the seven familiar notes of the solfeggio scale: do, re, mi, fa, sol, la, si. These phonemes have been used to compose a vocabulary of 2600 roots.
Like other constructed languages with a priori vocabulary, longer Solresol words are divided into categories of meaning, based on their first syllable. Words beginning with sol have meanings related to arts and sciences. Words that begin with solsol are related to sickness and medicine. Related words thus share initial syllables. For example, doremi means day, dorefa means week, doresol means month and doredo the concept of time itself. A unique feature of Solresol is that meanings are negated by reversing the syllables in words. For instance fala means good or tasty, and lafa means bad.
The teaching of sign languages to the deaf was discouraged between 1880 and 1991 in France, contributing to Solresol's descent into obscurity. After a few years of popularity, Solresol nearly vanished in the face of more successful languages, such as Volapük2 and Esperanto3. There is still a small community of Solresol enthusiasts scattered across the world, better able to communicate with one another now than previously thanks to the Internet. For example, in the Steven Spielberg movie Close Encounters of the Third Kind4 the aliens use Solresol to communicate with the human race.
Watch the learning clip about test-driven development5 to see how you can make use of doctests. This will allow you to understand the last two statements in the skeleton of the source code that is given in the assignment.
You are given the following skeleton of the source code that must lead to the solution of this exercise.
def isSolresol(word):
"""
Returns a Boolean value that indicates whether or not the given word meets
the grammar rules of Solresol.
>>> isSolresol('doresol')
True
>>> isSolresol('doreso')
False
>>> isSolresol('salami')
False
"""
def shorthand(word):
"""
Returns the shorthand notation of the given Solresol word.
>>> shorthand('fala')
'fl'
>>> shorthand('doremi')
'drm'
>>> shorthand('doresol')
'drso'
"""
def opposite(word):
"""
Returns the opposite of the given Solresol word.
>>> opposite('fala')
'lafa'
>>> opposite('doremi')
'miredo'
>>> opposite('doresol')
'solredo'
"""
if __name__ == '__main__':
import doctest
print(doctest.testmod())
Your task is to implement the three functions in this code fragment, so that the functions meet the following descriptions.
Write a function isSolresol that takes a string argument. The function must return a boolean value that indicates whether or not the given string represents a word that matches the grammar rules of Solresol. Solresol words are made up of from one to five syllables that each may be one of the seven notes of the solfeggio scale: do, re, mi, fa, sol, la, si (written using lowercase letters).
Write a function shorthand that takes a Solresol word as its argument. The function must return the shorthand notation of the given word. The syllables of Solresol words are abbreviated in the following way: d[o], r[e], m[i], f[a], so[l], l[a] and s[i].
Write a function opposite that takes a Solresol word as its argument. The function must return the opposite of the given word, which is formed by reversing the syllables in the word.
You may assume that all arguments passed to the functions shorthand and opposite represent words that match the grammar rules of Solresol, as defined in the description of the function isSolresol.
>>> isSolresol('doresol')
True
>>> isSolresol('doreso')
False
>>> isSolresol('salami')
False
>>> shorthand('fala')
'fl'
>>> shorthand('doremi')
'drm'
>>> shorthand('doresol')
'drso'
>>> opposite('fala')
'lafa'
>>> opposite('doremi')
'miredo'
>>> opposite('doresol')
'solredo'