-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
182 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,184 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"> **How to Run This Notebook**\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to \"Java (java)\". Refresh the browser before running any subsequent code. You can also run this notebook locally if you have the IJava kernel for Jupyter installed." | ||
] | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/sualeh/What-a-Character/blob/java/Notebooks/2_java_unicode_case_conversions.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "98uz_z16iWPq" | ||
}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"> **How to Run This Notebook**\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to \"Java (java)\". Refresh the browser before running any subsequent code. You can also run this notebook locally if you have the IJava kernel for Jupyter installed." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "lxcct87EiWPr" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Prepare Google Colab for IJava Kernel\n", | ||
"\n", | ||
"%%sh\n", | ||
"# Install java kernel\n", | ||
"wget -q https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip\n", | ||
"unzip -q ijava-1.3.0.zip\n", | ||
"python install.py\n", | ||
"\n", | ||
"# Install proxy for the java kernel\n", | ||
"wget -qO- https://gist.github.com/SpencerPark/e2732061ad19c1afa4a33a58cb8f18a9/archive/b6cff2bf09b6832344e576ea1e4731f0fb3df10c.tar.gz | tar xvz --strip-components=1\n", | ||
"python install_ipc_proxy_kernel.py --kernel=java --implementation=ipc_proxy_kernel.py" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "GNc5zEadiWPs" | ||
}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "S01vqm4viWPs" | ||
}, | ||
"source": [ | ||
"# Unicode Case Conversions\n", | ||
"\n", | ||
"Uppercasing or lowercasing a character may result in more than one character. Also, depending on the position of a character in a word, you can get a different uppercase or lowercase character." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "qoL_A4jkiWPs" | ||
}, | ||
"source": [ | ||
"## Lower Case\n", | ||
"\n", | ||
"In Greek, the word for dog in lowercase is \"σκύλος\". Notice that the first and last letter are both sigma." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "bCJPp8QJiWPs" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"final String greekWord = \"ΣΚΎΛΟΣ\"; // dog\n", | ||
"final String greekUpper = greekWord.toUpperCase();\n", | ||
"final String greekLower = greekUpper.toLowerCase();\n", | ||
"\n", | ||
"System.out.format(\"Greek \\\"dog\\\" - \\\"%s\\\" - length %d%n\",\n", | ||
" greekWord,\n", | ||
" greekWord.length());\n", | ||
"System.out.format(\"Converted to uppercase - \\\"%s\\\"%n\",\n", | ||
" greekUpper);\n", | ||
"System.out.format(\"Converted to lowercase - \\\"%s\\\"%n\",\n", | ||
" greekLower);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "zzmw32CyiWPt" | ||
}, | ||
"source": [ | ||
"## Upper Case\n", | ||
"\n", | ||
"[**U+1E9E LATIN CAPITAL LETTER SHARP S**](http://unicode.org/versions/Unicode5.1.0/#Tailored_Casing_Operations)\n", | ||
"\n", | ||
"In particular, capital sharp s is intended for typographical representations of signage and uppercase titles, and other environments where users require the sharp s to be preserved in uppercase. Overall, such usage is rare. In contrast, standard German orthography uses the string \"SS\" as uppercase mapping for small sharp s. Thus, with the default Unicode casing operations, capital sharp s will lowercase to small sharp s, but not the reverse: small sharp s uppercases to \"SS\". In those instances where the reverse casing operation is needed, a tailored operation would be required.\n", | ||
"\n", | ||
"When the German word \"straße\" is converted to uppercase \"STRASSE\", notice that the string lengths are different." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "RhNr09lOiWPt" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"final String germanWord = \"straße\"; // street\n", | ||
"final String germanUpper = germanWord.toUpperCase();\n", | ||
"final String germanLower = germanUpper.toLowerCase();\n", | ||
"\n", | ||
"System.out.format(\"German \\\"street\\\" - \\\"%s\\\" - length %d%n\",\n", | ||
" germanWord,\n", | ||
" germanWord.length());\n", | ||
"System.out.format(\"Converted to uppercase - \\\"%s\\\" - length %d%n\",\n", | ||
" germanUpper,\n", | ||
" germanUpper.length());\n", | ||
"System.out.format(\"Converted to lowercase - \\\"%s\\\" - length %d%n\",\n", | ||
" germanLower,\n", | ||
" germanLower.length());" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "97uJhUn_iWPt" | ||
}, | ||
"source": [ | ||
"## Incorrect Character Conversions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "yVaWHFk3iWPt" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"final char germanChar = 'ß';\n", | ||
"final char germanCharUpper = Character.toUpperCase(germanChar);\n", | ||
"System.out.format(\"%s becomes %s in uppercase%n\",\n", | ||
" germanChar,\n", | ||
" germanCharUpper);\n", | ||
"System.out.format(\"Same char? %b\", germanChar == germanCharUpper);" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Java", | ||
"language": "java", | ||
"name": "java" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "java", | ||
"file_extension": ".jshell", | ||
"mimetype": "text/x-java-source", | ||
"name": "java", | ||
"pygments_lexer": "java", | ||
"version": "17.0.6+9-LTS-190" | ||
}, | ||
"colab": { | ||
"provenance": [], | ||
"include_colab_link": true | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Prepare Google Colab for IJava Kernel\n", | ||
"\n", | ||
"%%sh\n", | ||
"# Install java kernel\n", | ||
"wget -q https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip\n", | ||
"unzip -q ijava-1.3.0.zip\n", | ||
"python install.py\n", | ||
"\n", | ||
"# Install proxy for the java kernel\n", | ||
"wget -qO- https://gist.github.com/SpencerPark/e2732061ad19c1afa4a33a58cb8f18a9/archive/b6cff2bf09b6832344e576ea1e4731f0fb3df10c.tar.gz | tar xvz --strip-components=1\n", | ||
"python install_ipc_proxy_kernel.py --kernel=java --implementation=ipc_proxy_kernel.py" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Unicode Case Conversions\n", | ||
"\n", | ||
"Uppercasing or lowercasing a character may result in more than one character. Also, depending on the position of a character in a word, you can get a different uppercase or lowercase character." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Lower Case\n", | ||
"\n", | ||
"In Greek, the word for dog in lowercase is \"σκύλος\". Notice that the first and last letter are both sigma." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"final String greekWord = \"ΣΚΎΛΟΣ\"; // dog\n", | ||
"final String greekUpper = greekWord.toUpperCase();\n", | ||
"final String greekLower = greekUpper.toLowerCase();\n", | ||
"\n", | ||
"System.out.format(\"Greek \\\"dog\\\" - \\\"%s\\\" - length %d%n\",\n", | ||
" greekWord,\n", | ||
" greekWord.length());\n", | ||
"System.out.format(\"Converted to uppercase - \\\"%s\\\"%n\",\n", | ||
" greekUpper);\n", | ||
"System.out.format(\"Converted to lowercase - \\\"%s\\\"%n\",\n", | ||
" greekLower);" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Upper Case\n", | ||
"\n", | ||
"[**U+1E9E LATIN CAPITAL LETTER SHARP S**](http://unicode.org/versions/Unicode5.1.0/#Tailored_Casing_Operations)\n", | ||
"\n", | ||
"In particular, capital sharp s is intended for typographical representations of signage and uppercase titles, and other environments where users require the sharp s to be preserved in uppercase. Overall, such usage is rare. In contrast, standard German orthography uses the string \"SS\" as uppercase mapping for small sharp s. Thus, with the default Unicode casing operations, capital sharp s will lowercase to small sharp s, but not the reverse: small sharp s uppercases to \"SS\". In those instances where the reverse casing operation is needed, a tailored operation would be required.\n", | ||
"\n", | ||
"When the German word \"straße\" is converted to uppercase \"STRASSE\", notice that the string lengths are different." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"final String germanWord = \"straße\"; // street\n", | ||
"final String germanUpper = germanWord.toUpperCase();\n", | ||
"final String germanLower = germanUpper.toLowerCase();\n", | ||
"\n", | ||
"System.out.format(\"German \\\"street\\\" - \\\"%s\\\" - length %d%n\",\n", | ||
" germanWord,\n", | ||
" germanWord.length());\n", | ||
"System.out.format(\"Converted to uppercase - \\\"%s\\\" - length %d%n\",\n", | ||
" germanUpper,\n", | ||
" germanUpper.length());\n", | ||
"System.out.format(\"Converted to lowercase - \\\"%s\\\" - length %d%n\",\n", | ||
" germanLower,\n", | ||
" germanLower.length());" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Incorrect Character Conversions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"final char germanChar = 'ß';\n", | ||
"final char germanCharUpper = Character.toUpperCase(germanChar);\n", | ||
"System.out.format(\"%s becomes %s in uppercase%n\",\n", | ||
" germanChar,\n", | ||
" germanCharUpper);\n", | ||
"System.out.format(\"Same char? %b\", germanChar == germanCharUpper);" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Java", | ||
"language": "java", | ||
"name": "java" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "java", | ||
"file_extension": ".jshell", | ||
"mimetype": "text/x-java-source", | ||
"name": "java", | ||
"pygments_lexer": "java", | ||
"version": "17.0.6+9-LTS-190" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |