Created
January 10, 2025 20:46
-
-
Save tonyfast/edf123090edf2f279efd826198b3f537 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "b0adb3c6-e43d-4dcf-8a2d-d72a376d3cc8", | |
"metadata": {}, | |
"source": [ | |
"# summarizing accessibility properties for discoverability vocabulary\n", | |
"\n", | |
"organize the [Schema.org Accessibility Properties for Discoverability Vocabulary](https://www.w3.org/community/reports/a11y-discov-vocab/CG-FINAL-vocabulary-20241209/) into a better shape for developers. developers need to know the valid values for the microdata or json-ld representations of these features." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 146, | |
"id": "62008484-5568-4506-816c-acf1d9dc6946", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<h2>scraping in the document</h2>\n", | |
"<p>lets make a delicious warm bowl BeautifulSoup of with disability related noodles\n", | |
"roasted over a warm cache.</p>\n", | |
"<pre><code>import requests; __import__("requests_cache").install_cache()\n", | |
"soup = bs4.BeautifulSoup(requests.get(url :=\n", | |
"</code></pre>\n", | |
"<p><a href=\"https://www.w3.org/community/reports/a11y-discov-vocab/CG-FINAL-vocabulary-20241209/\">https://www.w3.org/community/reports/a11y-discov-vocab/CG-FINAL-vocabulary-20241209/</a></p>\n", | |
"<pre><code>).text)\n", | |
"</code></pre>\n", | |
"<p>there is an implicit structure in the document we can use to scoop up the noodles we want;\n", | |
"headings, the headings are noodles.</p>\n", | |
"<pre><code>df = Series(soup.select("h1,h2,h3,h4,h5,h6")).apply(lambda s: Series(dict(name=s.text, lev=int(s.name[1]))))\n", | |
"</code></pre>\n", | |
"<p>now we get out as many spoons we have, yes even the stabby one which is better known as a shiv.\n", | |
"anyway, we'll rearrange the noodles to spell out something useful.</p>\n", | |
"<details>\n", | |
" <summary>the magician stumbles off stage</summary>\n", | |
"<pre><code>mapping = df.groupby(df.lev.eq(2).cumsum().rename("group")).apply(\n", | |
" lambda df: df[filter] if (filter := df.lev.isin((2, 4, 5))).sum() > 1 else DataFrame()\n", | |
").assign(itemprop=None)\n", | |
"mapping.itemprop = mapping[mapping.lev.eq(2)].name.str.rpartition(" ")[0].str.rpartition(" ")[2]\n", | |
"mapping.itemprop = mapping.itemprop.ffill()\n", | |
"mapping = mapping[mapping.lev.isin((4,5))]\n", | |
"mapping = mapping.groupby("group").apply(\n", | |
" lambda df: (\n", | |
" df[df.lev.ne(4)]\n", | |
" ) if df.lev.eq(5).sum() > 0 else df\n", | |
").droplevel(level=0)\n", | |
"mapping = mapping.assign(short=mapping.name.str.partition(" ")[2])\n", | |
"</code></pre>\n", | |
"</details>\n", | |
"<p>tada! a <code>mapping</code>! clap please.</p>\n", | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"<pre><code>.dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
".dataframe thead th {\n", | |
" text-align: right;\n", | |
"}\n", | |
"</code></pre>\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th>name</th>\n", | |
" <th>lev</th>\n", | |
" <th>itemprop</th>\n", | |
" <th>short</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>group</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th rowspan=\"5\" valign=\"top\">5</th>\n", | |
" <th>11</th>\n", | |
" <td>2.2.1 AndroidAccessibility</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessibilityAPI</td>\n", | |
" <td>AndroidAccessibility</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>2.2.2 ARIA (deprecated)</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessibilityAPI</td>\n", | |
" <td>ARIA (deprecated)</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>2.2.3 ATK</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessibilityAPI</td>\n", | |
" <td>ATK</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>2.2.4 AT-SPI</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessibilityAPI</td>\n", | |
" <td>AT-SPI</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td>2.2.5 BlackberryAccessibility (obsolete)</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessibilityAPI</td>\n", | |
" <td>BlackberryAccessibility (obsolete)</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>...</th>\n", | |
" <th>...</th>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" <td>...</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <th>119</th>\n", | |
" <td>7.3.7 textOnVisual</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessMode</td>\n", | |
" <td>textOnVisual</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th rowspan=\"4\" valign=\"top\">11</th>\n", | |
" <th>123</th>\n", | |
" <td>8.2.1 auditory</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessModeSufficient</td>\n", | |
" <td>auditory</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>124</th>\n", | |
" <td>8.2.2 tactile</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessModeSufficient</td>\n", | |
" <td>tactile</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>125</th>\n", | |
" <td>8.2.3 textual</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessModeSufficient</td>\n", | |
" <td>textual</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>126</th>\n", | |
" <td>8.2.4 visual</td>\n", | |
" <td>4.0</td>\n", | |
" <td>accessModeSufficient</td>\n", | |
" <td>visual</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"<p>87 rows × 4 columns</p>\n", | |
"</div>\n", | |
"<p>and for my last trick, i give you an organized definition list of <code>metadata</code> terms that formally describe asistive technology affordances</p>\n", | |
"<pre><code>metadata = mapping.short.groupby(mapping.itemprop).agg(list).to_dict()\n", | |
"</code></pre>\n", | |
"<h2>accessibility discovery terms</h2>\n", | |
"<section id=itemprop>\n", | |
"<dl>\n", | |
"<dt>accessMode</dt>\n", | |
"<dd>auditory</dd>\n", | |
"<dd>tactile</dd>\n", | |
"<dd>textual</dd>\n", | |
"<dd>visual</dd>\n", | |
"<dd>chartOnVisual</dd>\n", | |
"<dd>chemOnVisual</dd>\n", | |
"<dd>colorDependent</dd>\n", | |
"<dd>diagramOnVisual</dd>\n", | |
"<dd>mathOnVisual</dd>\n", | |
"<dd>musicOnVisual</dd>\n", | |
"<dd>textOnVisual</dd>\n", | |
"<dt>accessModeSufficient</dt>\n", | |
"<dd>auditory</dd>\n", | |
"<dd>tactile</dd>\n", | |
"<dd>textual</dd>\n", | |
"<dd>visual</dd>\n", | |
"<dt>accessibilityAPI</dt>\n", | |
"<dd>AndroidAccessibility</dd>\n", | |
"<dd>ARIA (deprecated)</dd>\n", | |
"<dd>ATK</dd>\n", | |
"<dd>AT-SPI</dd>\n", | |
"<dd>BlackberryAccessibility (obsolete)</dd>\n", | |
"<dd>FuchsiaAccessibility</dd>\n", | |
"<dd>iAccessible2</dd>\n", | |
"<dd>iOSAccessibility (deprecated)</dd>\n", | |
"<dd>JavaAccessibility</dd>\n", | |
"<dd>MacOSXAccessibility (deprecated)</dd>\n", | |
"<dd>MSAA</dd>\n", | |
"<dd>NSAccessibility</dd>\n", | |
"<dd>UIAccessibility</dd>\n", | |
"<dd>UIAutomation</dd>\n", | |
"<dt>accessibilityControl</dt>\n", | |
"<dd>fullKeyboardControl</dd>\n", | |
"<dd>fullMouseControl</dd>\n", | |
"<dd>fullSwitchControl</dd>\n", | |
"<dd>fullTouchControl</dd>\n", | |
"<dd>fullVideoControl</dd>\n", | |
"<dd>fullVoiceControl</dd>\n", | |
"<dt>accessibilityFeature</dt>\n", | |
"<dd>annotations</dd>\n", | |
"<dd>ARIA</dd>\n", | |
"<dd>bookmarks (deprecated)</dd>\n", | |
"<dd>index</dd>\n", | |
"<dd>pageBreakMarkers</dd>\n", | |
"<dd>pageNavigation</dd>\n", | |
"<dd>readingOrder</dd>\n", | |
"<dd>structuralNavigation</dd>\n", | |
"<dd>tableOfContents</dd>\n", | |
"<dd>taggedPDF</dd>\n", | |
"<dd>alternativeText</dd>\n", | |
"<dd>audioDescription</dd>\n", | |
"<dd>captions (deprecated)</dd>\n", | |
"<dd>closedCaptions</dd>\n", | |
"<dd>describedMath</dd>\n", | |
"<dd>longDescription</dd>\n", | |
"<dd>openCaptions</dd>\n", | |
"<dd>signLanguage</dd>\n", | |
"<dd>transcript</dd>\n", | |
"<dd>displayTransformability</dd>\n", | |
"<dd>synchronizedAudioText</dd>\n", | |
"<dd>timingControl</dd>\n", | |
"<dd>unlocked</dd>\n", | |
"<dd>ChemML</dd>\n", | |
"<dd>latex</dd>\n", | |
"<dd>latex-chemistry</dd>\n", | |
"<dd>MathML</dd>\n", | |
"<dd>MathML-chemistry</dd>\n", | |
"<dd>ttsMarkup</dd>\n", | |
"<dd>highContrastAudio</dd>\n", | |
"<dd>highContrastDisplay</dd>\n", | |
"<dd>largePrint</dd>\n", | |
"<dd>braille</dd>\n", | |
"<dd>tactileGraphic</dd>\n", | |
"<dd>tactileObject</dd>\n", | |
"<dd>fullRubyAnnotations</dd>\n", | |
"<dd>horizontalWriting</dd>\n", | |
"<dd>rubyAnnotations</dd>\n", | |
"<dd>verticalWriting</dd>\n", | |
"<dd>withAdditionalWordSegmentation</dd>\n", | |
"<dd>withoutAdditionalWordSegmentation</dd>\n", | |
"<dt>accessibilityHazard</dt>\n", | |
"<dd>flashing</dd>\n", | |
"<dd>motionSimulation</dd>\n", | |
"<dd>sound</dd>\n", | |
"<dd>none</dd>\n", | |
"<dd>noFlashingHazard</dd>\n", | |
"<dd>noMotionSimulationHazard</dd>\n", | |
"<dd>noSoundHazard</dd>\n", | |
"<dd>unknown</dd>\n", | |
"<dd>unknownFlashingHazard</dd>\n", | |
"<dd>unknownMotionSimulationHazard</dd>\n", | |
"<dd>unknownSoundHazard</dd>\n", | |
"</dl>\n", | |
"</section>" | |
], | |
"text/x-python": [ | |
"\n", | |
"(\"\"\"## scraping in the document\n", | |
"\n", | |
"lets make a delicious warm bowl BeautifulSoup of with disability related noodles\n", | |
"roasted over a warm cache.\"\"\")\n", | |
"\n", | |
"import requests; __import__(\"requests_cache\").install_cache()\n", | |
"soup = bs4.BeautifulSoup(requests.get(url :=\n", | |
"(\"\"\"https://www.w3.org/community/reports/a11y-discov-vocab/CG-FINAL-vocabulary-20241209/\"\"\")\n", | |
"\n", | |
").text)\n", | |
"\n", | |
"(\"\"\"there is an implicit structure in the document we can use to scoop up the noodles we want;\n", | |
"headings, the headings are noodles.\"\"\")\n", | |
"\n", | |
"df = Series(soup.select(\"h1,h2,h3,h4,h5,h6\")).apply(lambda s: Series(dict(name=s.text, lev=int(s.name[1]))))\n", | |
"\n", | |
"(\"\"\"now we get out as many spoons we have, yes even the stabby one which is better known as a shiv.\n", | |
"anyway, we'll rearrange the noodles to spell out something useful.\n", | |
"\n", | |
"<details>\n", | |
" <summary>the magician stumbles off stage</summary>\"\"\")\n", | |
"\n", | |
"mapping = df.groupby(df.lev.eq(2).cumsum().rename(\"group\")).apply(\n", | |
" lambda df: df[filter] if (filter := df.lev.isin((2, 4, 5))).sum() > 1 else DataFrame()\n", | |
").assign(itemprop=None)\n", | |
"mapping.itemprop = mapping[mapping.lev.eq(2)].name.str.rpartition(\" \")[0].str.rpartition(\" \")[2]\n", | |
"mapping.itemprop = mapping.itemprop.ffill()\n", | |
"mapping = mapping[mapping.lev.isin((4,5))]\n", | |
"mapping = mapping.groupby(\"group\").apply(\n", | |
" lambda df: (\n", | |
" df[df.lev.ne(4)]\n", | |
" ) if df.lev.eq(5).sum() > 0 else df\n", | |
").droplevel(level=0)\n", | |
"mapping = mapping.assign(short=mapping.name.str.partition(\" \")[2])\n", | |
"\n", | |
"(\"\"\"</details>\n", | |
"\n", | |
"tada! a `mapping`! clap please.\n", | |
"\n", | |
"{{mapping._repr_html_()}}\n", | |
"\n", | |
"and for my last trick, i give you an organized definition list of `metadata` terms that formally describe asistive technology affordances\"\"\")\n", | |
"\n", | |
"metadata = mapping.short.groupby(mapping.itemprop).agg(list).to_dict()\n", | |
"\n", | |
"(\"\"\"## accessibility discovery terms\n", | |
"\n", | |
"<section id=itemprop>\n", | |
"{% for k, v in metadata.items() %}\n", | |
"{{k}}\n", | |
"{% for i in v %}: {{i}}\n", | |
"{% endfor %}\n", | |
"{% endfor %}\n", | |
"</section>\"\"\");\n", | |
"\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%% \n", | |
"## scraping in the document\n", | |
"\n", | |
"lets make a delicious warm bowl BeautifulSoup of with disability related noodles\n", | |
"roasted over a warm cache.\n", | |
" \n", | |
" import requests; __import__(\"requests_cache\").install_cache()\n", | |
" soup = bs4.BeautifulSoup(requests.get(url :=\n", | |
"https://www.w3.org/community/reports/a11y-discov-vocab/CG-FINAL-vocabulary-20241209/\n", | |
" \n", | |
" ).text)\n", | |
"\n", | |
"there is an implicit structure in the document we can use to scoop up the noodles we want;\n", | |
"headings, the headings are noodles.\n", | |
"\n", | |
" df = Series(soup.select(\"h1,h2,h3,h4,h5,h6\")).apply(lambda s: Series(dict(name=s.text, lev=int(s.name[1]))))\n", | |
"\n", | |
"now we get out as many spoons we have, yes even the stabby one which is better known as a shiv.\n", | |
"anyway, we'll rearrange the noodles to spell out something useful.\n", | |
"\n", | |
"<details>\n", | |
" <summary>the magician stumbles off stage</summary>\n", | |
"\n", | |
" mapping = df.groupby(df.lev.eq(2).cumsum().rename(\"group\")).apply(\n", | |
" lambda df: df[filter] if (filter := df.lev.isin((2, 4, 5))).sum() > 1 else DataFrame()\n", | |
" ).assign(itemprop=None)\n", | |
" mapping.itemprop = mapping[mapping.lev.eq(2)].name.str.rpartition(\" \")[0].str.rpartition(\" \")[2]\n", | |
" mapping.itemprop = mapping.itemprop.ffill()\n", | |
" mapping = mapping[mapping.lev.isin((4,5))]\n", | |
" mapping = mapping.groupby(\"group\").apply(\n", | |
" lambda df: (\n", | |
" df[df.lev.ne(4)]\n", | |
" ) if df.lev.eq(5).sum() > 0 else df\n", | |
" ).droplevel(level=0)\n", | |
" mapping = mapping.assign(short=mapping.name.str.partition(\" \")[2])\n", | |
"\n", | |
"</details>\n", | |
"\n", | |
"tada! a `mapping`! clap please.\n", | |
"\n", | |
"{{mapping._repr_html_()}}\n", | |
"\n", | |
"and for my last trick, i give you an organized definition list of `metadata` terms that formally describe asistive technology affordances \n", | |
"\n", | |
" metadata = mapping.short.groupby(mapping.itemprop).agg(list).to_dict()\n", | |
"\n", | |
"## accessibility discovery terms\n", | |
"\n", | |
"<section id=itemprop>\n", | |
"{% for k, v in metadata.items() %}\n", | |
"{{k}}\n", | |
"{% for i in v %}: {{i}}\n", | |
"{% endfor %}\n", | |
"{% endfor %}\n", | |
"</section>\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 147, | |
"id": "9bc05bb4-ebbe-4696-b9f1-43c7a84739bd", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<style>\n", | |
".jp-OutputArea-output :is(dd, dt) {\n", | |
" float: unset;\n", | |
"}\n", | |
"\n", | |
"section#itemprop {\n", | |
" dd {\n", | |
" display: inline;\n", | |
" & + dd {\n", | |
" &::before {\n", | |
" content: \", \";\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"</style>" | |
], | |
"text/x-python": [ | |
"\n", | |
"(\"\"\"<style>\n", | |
".jp-OutputArea-output :is(dd, dt) {\n", | |
" float: unset;\n", | |
"}\n", | |
"\n", | |
"section#itemprop {\n", | |
" dd {\n", | |
" display: inline;\n", | |
" & + dd {\n", | |
" &::before {\n", | |
" content: \\\", \\\";\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"</style>\"\"\");\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%\n", | |
"<style>\n", | |
".jp-OutputArea-output :is(dd, dt) {\n", | |
" float: unset;\n", | |
"}\n", | |
"\n", | |
"section#itemprop {\n", | |
" dd {\n", | |
" display: inline;\n", | |
" & + dd {\n", | |
" &::before {\n", | |
" content: \", \";\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
"}\n", | |
"\n", | |
"</style>" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:p311] *", | |
"language": "python", | |
"name": "conda-env-p311-py" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment