|
|
(One intermediate revision by the same user not shown) |
Line 21: |
Line 21: |
| Error: <span id="decline_error"/> | | Error: <span id="decline_error"/> |
| </div> | | </div> |
− | <script type="text/javascript">
| |
− | function decline_submit(form) {
| |
− | try {
| |
− | document.getElementById('decline_success').style.display = '';
| |
− | document.getElementById('decline_failure').style.display = 'none';
| |
− | document.getElementById('decline_result').innerHTML = decline(
| |
− | form.noun.value,
| |
− | form.case_.value,
| |
− | form.number.value);
| |
− | } catch(error) {
| |
− | document.getElementById('decline_failure').style.display = '';
| |
− | document.getElementById('decline_success').style.display = 'none';
| |
− | document.getElementById('decline_error').innerHTML = error.message;
| |
− | }
| |
− | }
| |
− |
| |
− | function decline(noun, case_, number) {
| |
− | var m;
| |
− | noun = noun.replace(/$\s+|\s+$/g, '');
| |
− |
| |
− | if (!noun) {
| |
− | throw new Error("You must specify a noun.");
| |
− | }
| |
− |
| |
− | if (m = /^(.*)(a|am|ae|as|arum|is)$/.exec(noun)) {
| |
− | return accent(m[1]+{
| |
− | singular: {
| |
− | nominative: 'a',
| |
− | vocative: 'a',
| |
− | accusative: 'am',
| |
− | genitive: 'ae',
| |
− | dative: 'ae',
| |
− | ablative: 'a',
| |
− | },
| |
− | plural: {
| |
− | nominative: 'ae',
| |
− | vocative: 'ae',
| |
− | accusative: 'as',
| |
− | genitive: 'arum',
| |
− | dative: 'is',
| |
− | ablative: 'is',
| |
− | }
| |
− | }[number][case_]);
| |
− | } else {
| |
− | throw new Error("That doesn't look like a first declension noun.");
| |
− | }
| |
− | }
| |
− |
| |
− | function accent(word) {
| |
− | var syllables = [],
| |
− | s;
| |
− | // Remove any accents
| |
− | word = word.replace(/\u0301/g, '');
| |
− |
| |
− | // Break the word into syllables
| |
− | while (word) {
| |
− | if (s = /(?:[bcdfghijklmnpqrstxvyz]+)?[aeiouv]+[bcdfghjklmnpqrstxyz]*$/.exec(word)) {
| |
− | syllables.unshift(s[0]);
| |
− | word = word.substr(0, word.length-s[0].length)
| |
− | continue;
| |
− | }
| |
− | throw new Error("I got stuck trying to find syllables: "+syllables+" "+word);
| |
− | }
| |
− |
| |
− | return syllables.join('');
| |
− |
| |
− | }
| |
− |
| |
− | </script>
| |
| </html> | | </html> |