diff --git a/cosite001.ipynb b/cosite001.ipynb index eb36d96..5ce4ed8 100644 --- a/cosite001.ipynb +++ b/cosite001.ipynb @@ -20,23 +20,22 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime\n", "import sys\n", "import time\n", - "from SPARQLWrapper import SPARQLWrapper, JSON\n", "import requests\n", "import html\n", "\n", "\n", "api_url = \"https://climatekg.semanticclimate.net/api.php\"\n", "\n", - "def fetch_mediawiki_data(api_url, params):\n", + "def fetch_mediawiki_data(api_url, params, session):\n", " try:\n", - " response = requests.get(api_url, params=params)\n", + " response = session.get(api_url, params=params)\n", " response.raise_for_status() # Raise an exception for HTTP errors\n", " data = response.json()\n", " return data\n", @@ -50,19 +49,36 @@ " \n", " for item_id, item_data in results.items():\n", " #print(item_data)\n", - " subcats = item_data[\"printouts\"].get(\"subcategoryOf\", [None])\n", - " subcat = \"\"\n", - " if len(subcats) > 0: \n", - " subcat = subcats[0] \n", - " definition = \"\"\n", - " if item_data[\"printouts\"].get(\"definition\", [{}]):\n", - " definition = item_data[\"printouts\"].get(\"definition\", [{}])[0].get(\"Text\", {}).get(\"item\", [None])[0]\n", + " \n", + " multilang_fields = [\"description\"]\n", + " entity_fields = [\"subCategoryOf\", \"synonyms\", \"similarTo\"]\n", + " txt_fields = [\"term\",\"description_plain\",\"vocabulary\",\"acronym\",\"tags\"]\n", " item = {\n", - " \"id\": item_id,\n", - " \"term\": item_data[\"printouts\"].get(\"term\", [None])[0],\n", - " \"definition\": definition,\n", - " \"subCategoryOf\": subcat\n", + " \"id\": item_id\n", " }\n", + "\n", + " for fieldname in txt_fields:\n", + " if item_data[\"printouts\"].get(fieldname, [{}]):\n", + " #print(fieldname)\n", + " item[fieldname] = item_data[\"printouts\"].get(fieldname, [None])[0]\n", + " else:\n", + " item[fieldname] = \"\"\n", + " \n", + " for fieldname in entity_fields:\n", + " if item_data[\"printouts\"].get(fieldname, [{}]):\n", + " #print(fieldname)\n", + " item[fieldname] = str(item_data[\"printouts\"].get(fieldname, [None]))\n", + " else:\n", + " item[fieldname] = \"\"\n", + "\n", + " for fieldname in multilang_fields:\n", + " if item_data[\"printouts\"].get(fieldname, [{}]):\n", + " #print(fieldname)\n", + " item[fieldname] = item_data[\"printouts\"].get(fieldname, [{}])[0].get(\"Text\", {}).get(\"item\", [None])[0]\n", + " else:\n", + " item[fieldname] = \"\"\n", + " \n", + "\n", " items.append(item)\n", " \n", " return items\n", @@ -79,95 +95,381 @@ " markdown += f'|{item[\"subCategoryOf\"]}'\n", " markdown += '|\\n'\n", " \n", - " return markdown\n", + " # Rows\n", + " for item in items:\n", + " html += ''\n", + " html += f'{item[\"id\"]}'\n", + " html += f'{item[\"term\"]}'\n", + " html += f'{item[\"definition\"]}'\n", + " html += f'{item[\"subCategoryOf\"]}'\n", + " html += ''\n", + " \n", + " html += ''\n", + " return html\n", + "\n", + "def generate_html_span(items, vocabulary):\n", + " \n", + " html = f'## {vocabulary}\\n' \n", + " for item in items: \n", + " html += f''' \n", + "
\n", + "\n", + "### {item[\"term\"]} \n", + "\n", + "{item[\"description\"]}\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "{item[\"description_plain\"]}\n", + " \n", + "**Akronym (label)** \n", + " \n", + "{item[\"acronym\"]}\n", + " \n", + "**Tag (label)**\n", + " \n", + "{item[\"tags\"]}\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "{item[\"similarTo\"]}\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "{item[\"subCategoryOf\"]}\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "{item[\"synonyms\"]}\n", + " \n", + " '''\n", + " return html\n", + "\n", + "def login(api_url, username, password):\n", + " session = requests.Session()\n", + " \n", + " # Step 1: GET request to fetch login token\n", + " login_token_params = {\n", + " 'action': 'query',\n", + " 'meta': 'tokens',\n", + " 'type': 'login',\n", + " 'format': 'json'\n", + " }\n", + " response = session.get(api_url, params=login_token_params)\n", + " response.raise_for_status()\n", + " login_token = response.json()['query']['tokens']['logintoken']\n", + " \n", + " # Step 2: POST request to log in\n", + " login_params = {\n", + " 'action': 'login',\n", + " 'lgname': username,\n", + " 'lgpassword': password,\n", + " 'lgtoken': login_token,\n", + " 'format': 'json'\n", + " }\n", + " response = session.post(api_url, data=login_params)\n", + " response.raise_for_status()\n", + " login_result = response.json()\n", + " \n", + " if login_result['login']['result'] == 'Success':\n", + " print('Logged in successfully')\n", + " return session\n", + " else:\n", + " print('Failed to log in')\n", + " sys.exit(1)\n", "\n", + "def get_glossary(vocabulary, session):\n", "\n", - "def get_glossary():\n", " params = {\n", " 'action': 'ask',\n", - " 'query': '[[Item:+]] [[has subobject::+]] [[P1::Term]] |?Wikibase description=definition |?P3=term |?P10.P3=subcategoryOf',\n", + " 'query': f'[[Item:+]] [[has subobject::+]] [[P1::Term]] [[P18::{vocabulary}]]|?Wikibase description=description |?P26=description_plain |?P3=term |?P10.P3=subCategoryOf |?P21=acronym |?P22=tags |?P23=similarTo |?P18=vocabulary |?P24=synonyms',\n", " 'format': 'json'\n", " }\n", "\n", - " response = fetch_mediawiki_data(api_url, params)\n", + " response = fetch_mediawiki_data(api_url, params, session)\n", " items = extract_items(response)\n", + " \n", " if items:\n", - " # Generate the markdown for the table\n", - " markdown_table = generate_markdown_table(items)\n", - " print(markdown_table)\n", - "\n", - "\n", - "\n" + " # Generate the HTML for the table\n", + " html = '\\n\\n'\n", + " #html += generate_html_table(items)\n", + " html += generate_html_span(items,vocabulary)\n", + " html += '\\n'\n", + " print(html)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "Logged in successfully\n", + "\n", + "\n", + "## CoSite\n", + " \n", + "
\n", + "\n", + "### Co-Site \n", "\n", - "| ID | Begriff | Definition | Unterkategorie von |\n", - "|---|---|---|---|\n", - "|Item:Q10|low confidence|Each finding is grounded in an evaluation of underlying evidence and agreement. The IPCC calibrated language uses five qualifiers to express a level of confidence (very low, low, medium, high and very high )|qualifiers|\n", - "|Item:Q100|baseline/reference|The reference point or period against which changes are measured, providing a baseline for analysis.|terms|\n", - "|Item:Q1000|AOGCM|Atmosphere-Ocean General Circulation Model|acronyms|\n", - "|Item:Q1001|AOSIS|Alliance of Small Island States|acronyms|\n", - "|Item:Q1002|APEC|Asia-Pacific Economic Cooperation|acronyms|\n", - "|Item:Q1003|APP|Agricultural Adaptation and Perception|acronyms|\n", - "|Item:Q1004|APRA|Australian Prudential Regulation Authority|acronyms|\n", - "|Item:Q1005|AQ|air quality|acronyms|\n", - "|Item:Q1006|AR4|Fourth Assessment Report of the Intergovernmental Panel on Climate Change|acronyms|\n", - "|Item:Q1007|AR5|Fifth Assessment Report of the Intergovernmental Panel on Climate Change|acronyms|\n", - "|Item:Q1008|AR6|Sixth Assessment Report of the Intergovernmental Panel on Climate Change|acronyms|\n", - "|Item:Q1009|AR7|Seventh Assessment Cycle of the Intergovernmental Panel on Climate Change|acronyms|\n", - "|Item:Q101|baseline scenario|A hypothetical scenario used as a benchmark to assess the impact of potential changes or interventions.||\n", - "|Item:Q1010|ARA|Arab Region of Asia|acronyms|\n", - "|Item:Q1011|ARC|African Risk Capacity|acronyms|\n", - "|Item:Q1012|ARO|Arctic Ocean|acronyms|\n", - "|Item:Q1013|ARP|Arabian Peninsula|acronyms|\n", - "|Item:Q1014|ARPA-E|Advanced Research Projects Agency-Energy|acronyms|\n", - "|Item:Q1015|ARS|Arabian Sea|acronyms|\n", - "|Item:Q1016|Art.|Article (e.g., of the UNFCCC),|acronyms|\n", - "|Item:Q1017|ASAP|Adaptation for Smallholder Agriculture Programme|acronyms|\n", - "|Item:Q1018|ASBEC|Australian Sustainable Built Environment Council|acronyms|\n", - "|Item:Q1019|ASCM|Agreement on Subsidies and Countervailing Measures|acronyms|\n", - "|Item:Q102|BE|Berkeley Earth|acronyms|\n", - "|Item:Q1020|ASE|Amundsen Sea Embayment|acronyms|\n", - "|Item:Q1021|ASEAN|Association of Southeast Asian Nations|acronyms|\n", - "|Item:Q1022|ASFI|Australian Sustainable Finance Initiative|acronyms|\n", - "|Item:Q1023|ASI|Avoid-Shift-Improve|acronyms|\n", - "|Item:Q1024|ASK|available seat kilometres|acronyms|\n", - "|Item:Q1025|ASP|Adaptive Social Protection|acronyms|\n", - "|Item:Q1026|ATLAS|Adaptation Thought Leadership and Assessments|acronyms|\n", - "|Item:Q1027|AUC|Area under the Curve|acronyms|\n", - "|Item:Q1028|AUM|assets under management|acronyms|\n", - "|Item:Q1029|AUP|Auckland Unitary Plan|acronyms|\n", - "|Item:Q103|benthic|Organisms living on or in the sea floor, often used to indicate the health of marine ecosystems.||\n", - "|Item:Q1030|AUS|Australasia|acronyms|\n", - "|Item:Q1031|AusMCM|Australian–Maritime Continent monsoon|acronyms|\n", - "|Item:Q1032|AVHRR|Advanced Very High Resolution Radiometer|acronyms|\n", - "|Item:Q1033|AZM|Atlantic Zonal Modes|acronyms|\n", - "|Item:Q1034|BAT|best available technology|acronyms|\n", - "|Item:Q1035|BAU|Business-as-Usual|acronyms|\n", - "|Item:Q1036|BC|black carbon|acronyms|\n", - "|Item:Q1037|BCA|border carbon adjustment|acronyms|\n", - "|Item:Q1038|BCE|Before the Common Era|acronyms|\n", - "|Item:Q1039|BCP|biological carbon pump|acronyms|\n", - "|Item:Q104|benthos|||\n", - "|Item:Q1040|BDP|The Bangladesh Delta Plan|acronyms|\n", - "|Item:Q1041|BECCS|Bioenergy with Carbon Dioxide Capture and Storage|acronyms|\n", - "|Item:Q1042|BEES|building energy efficiency standards|acronyms|\n", - "|Item:Q1043|BEMS|building energy management systems|acronyms|\n", - "\n" + "Co-Kreation in der Region - Systematisch und innovativ Transfer entwickeln\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "Forschungsprojekt\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Wissenschaftskommunikation \n", + "\n", + "Wissenschaftskommunikation umfasst alle Aspekte der Kommunikation wissenschaftlicher Arbeit und wissenschaftlicher Ergebnisse, sowohl innerhalb der Wissenschaft als auch bei der Kommunikation zwischen Wissenschaft und Öffentlichkeit.\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Wissenschaftskommunikation umfasst alle Aspekte der Kommunikation wissenschaftlicher Arbeit und wissenschaftlicher Ergebnisse, sowohl innerhalb der Wissenschaft als auch bei der Kommunikation zwischen Wissenschaft und Öffentlichkeit.\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Makroebene \n", + "\n", + "Ebene der Wissenschaftskommunikation mit dem Ziel der Kommunikation über das Gesamtsystem wissenschaftlicher Funktionen und Leistungen für die Gesellschaft.\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Ebene der Wissenschaftskommunikation mit dem Ziel der Kommunikation über das Gesamtsystem wissenschaftlicher Funktionen und Leistungen für die Gesellschaft.\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Mesoebene \n", + "\n", + "Ebene der Wissenschaftskommunikation mit dem Fokus auf die Kommunikation wissenschaftlicher Einrichtungen zu eigenen Aufgaben und Leistungen.\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Ebene der Wissenschaftskommunikation mit dem Fokus auf die Kommunikation wissenschaftlicher Einrichtungen zu eigenen Aufgaben und Leistungen.\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Mikroebene \n", + "\n", + "Ebene der Wissenschaftskommunikation mit dem Fokus auf die Kommunikation einzelner Wissenschaftler zu Forschungsthemen sowie Projekten (Vorhaben und Ergebnissen).\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Ebene der Wissenschaftskommunikation mit dem Fokus auf die Kommunikation einzelner Wissenschaftler zu Forschungsthemen sowie Projekten (Vorhaben und Ergebnissen).\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Kommunikation \n", + "\n", + "Austausch oder die Übertragung von Informationen, die auf verschiedene Arten (verbal, nonverbal und paraverbal) und auf verschiedenen Wegen (Sprechen, Schreiben) stattfinden kann.\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Austausch oder die Übertragung von Informationen, die auf verschiedene Arten (verbal, nonverbal und paraverbal) und auf verschiedenen Wegen (Sprechen, Schreiben) stattfinden kann.\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### Wissenschaft \n", + "\n", + "Gesamtheit des menschlichen Wissens, der Erkenntnisse und der Erfahrungen einer Zeitepoche, welche systematisch erweitert, gesammelt, aufbewahrt, gelehrt und tradiert wird.\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "Gesamtheit des menschlichen Wissens, der Erkenntnisse und der Erfahrungen einer Zeitepoche, welche systematisch erweitert, gesammelt, aufbewahrt, gelehrt und tradiert wird.\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "
\n", + "\n", + "### sdsdf \n", + "\n", + "sdsd\n", + "\n", + "**Klartextbeschreibung (label)**\n", + " \n", + "dsfsdf\n", + " \n", + "**Akronym (label)** \n", + " \n", + "\n", + " \n", + "**Tag (label)**\n", + " \n", + "\n", + " \n", + "**Ähnlich (label)**\n", + " \n", + "\n", + " \n", + "**Unterklasse von (label)**\n", + " \n", + "\n", + " \n", + "**Synonyme (label)**\n", + " \n", + "\n", + " \n", + " \n", + "\n" ] } ], "source": [ - "get_glossary()" + "username = 'reader' # Replace with your username\n", + "password = 'readonly' # Replace with your password\n", + "\n", + "session = login(api_url, username, password)\n", + "get_glossary(\"CoSite\", session)" ] } ], @@ -187,7 +489,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/docs/Co-Site-Glossar.docx b/docs/Co-Site-Glossar.docx index 8553af6..87a65c6 100644 Binary files a/docs/Co-Site-Glossar.docx and b/docs/Co-Site-Glossar.docx differ diff --git a/docs/Co-Site-Glossar.epub b/docs/Co-Site-Glossar.epub index 9495f84..4d83329 100644 Binary files a/docs/Co-Site-Glossar.epub and b/docs/Co-Site-Glossar.epub differ diff --git a/docs/Co-Site-Glossar.pdf b/docs/Co-Site-Glossar.pdf index d786a1b..162f13e 100644 Binary files a/docs/Co-Site-Glossar.pdf and b/docs/Co-Site-Glossar.pdf differ diff --git a/docs/contributors.html b/docs/contributors.html index 749813d..6d69da2 100644 --- a/docs/contributors.html +++ b/docs/contributors.html @@ -2,7 +2,7 @@ - + diff --git a/docs/cosite001.html b/docs/cosite001.html index 70d2ce5..8bbac2d 100644 --- a/docs/cosite001.html +++ b/docs/cosite001.html @@ -2,7 +2,7 @@ - + @@ -171,8 +171,24 @@
-