From 3acf7178ee96d28bf7ebd6b452325dd51f176493 Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 22:29:00 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #1 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/deep-assistant/human-language/issues/1 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..26c0799 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/deep-assistant/human-language/issues/1 +Your prepared branch: issue-1-f9f2209a +Your prepared working directory: /tmp/gh-issue-solver-1757532538740 + +Proceed. \ No newline at end of file From 9ea70b520abd70d6d5f2395358a5c543515b2bab Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 22:29:16 +0300 Subject: [PATCH 2/3] Remove CLAUDE.md - PR created successfully --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 26c0799..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/deep-assistant/human-language/issues/1 -Your prepared branch: issue-1-f9f2209a -Your prepared working directory: /tmp/gh-issue-solver-1757532538740 - -Proceed. \ No newline at end of file From 1399b0436cccc010efe90faefe21bda1ccbd1ae8 Mon Sep 17 00:00:00 2001 From: konard Date: Wed, 10 Sep 2025 22:36:19 +0300 Subject: [PATCH 3/3] feat: Implement IPA (International Phonetic Alphabet) translation support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add IPA transcription retrieval from Wikidata P898 property - Support multiple language pronunciations with P407 qualifiers - Support pronunciation variety qualifiers (P5237) for dialects - Beautiful IPA display in entity viewer with /phonemic/ notation - Comprehensive error handling and caching integration - Add test suite for IPA functionality with real entity examples - Update documentation to reflect IPA feature completion Resolves #1: Make sure we have translation to IPA ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- README.md | 18 ++++++-- entities.html | 60 ++++++++++++++++++++++++++ examples/ipa-test.mjs | 96 +++++++++++++++++++++++++++++++++++++++++ wikidata-api-browser.js | 45 +++++++++++++++++++ wikidata-api.js | 45 +++++++++++++++++++ 5 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 examples/ipa-test.mjs diff --git a/README.md b/README.md index b1c3dc9..24840a2 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,13 @@ This project will fundamentally transform how we store, access, and verify human - **Flag emojis**: Visual language indicators for better UX - **Language persistence**: Settings saved in localStorage +### 6. International Phonetic Alphabet (IPA) Support โœจ +- **Universal pronunciation**: Display IPA transcriptions from Wikidata P898 property +- **Multi-language phonetics**: Support for pronunciation variants across different languages +- **Dialect support**: Includes pronunciation variety qualifiers for regional dialects +- **Visual phonetic notation**: Beautiful IPA display with /phonemic/ notation +- **Seamless integration**: Automatically appears when pronunciation data is available + ## ๐Ÿ“‹ Roadmap Based on our [GitHub issues](https://github.com/deep-assistant/human-language/issues), here's our development roadmap: @@ -68,9 +75,13 @@ Based on our [GitHub issues](https://github.com/deep-assistant/human-language/is - Update UI and API to reflect new terminology ### Phase 2: Enhanced Language Support -- [ ] **IPA Translation Support** ([#1](https://github.com/deep-assistant/human-language/issues/1)) - - Integrate International Phonetic Alphabet for universal pronunciation - - Enable true cross-linguistic unification +- [x] **IPA Translation Support** ([#1](https://github.com/deep-assistant/human-language/issues/1)) โœจ + - โœ… Integrated International Phonetic Alphabet retrieval from Wikidata P898 property + - โœ… Support for multiple language pronunciations with language qualifiers (P407) + - โœ… Support for pronunciation variety qualifiers (P5237) for dialects + - โœ… Beautiful IPA display in entity viewer with phonetic notation + - โœ… Comprehensive error handling and caching support + - โœ… Enables true cross-linguistic pronunciation unification - [ ] **Words Page Development** ([#14](https://github.com/deep-assistant/human-language/issues/14)) - Display words in native language and IPA @@ -143,6 +154,7 @@ Based on our [GitHub issues](https://github.com/deep-assistant/human-language/is - Handles all Wikidata API interactions - Configurable caching strategies - Batch request optimization + - IPA transcription retrieval (P898 property support) 2. **Text Transformer** (`transformation/text-to-qp-transformer.js`) - N-gram generation and matching diff --git a/entities.html b/entities.html index e4df7f8..afc7a8d 100644 --- a/entities.html +++ b/entities.html @@ -266,6 +266,7 @@ }); const [propertyLabels, setPropertyLabels] = React.useState({}); const [entityLabels, setEntityLabels] = React.useState({}); + const [ipaTranscriptions, setIpaTranscriptions] = React.useState([]); React.useEffect(() => { document.documentElement.setAttribute('data-theme', theme); @@ -294,6 +295,7 @@ setLabels({}); setDescriptions({}); setAvailableLanguages([]); + setIpaTranscriptions([]); }; window.addEventListener('hashchange', handleHashChange); return () => window.removeEventListener('hashchange', handleHashChange); @@ -354,12 +356,22 @@ const { propertyLabels: newPropertyLabels, entityLabels: newEntityLabels } = await labelManager.loadAllLabels(entityData.claims, languages); setPropertyLabels(newPropertyLabels); setEntityLabels(newEntityLabels); + + // Load IPA transcriptions + try { + const ipa = await apiClient.getIpaTranscription(entityId, languages); + setIpaTranscriptions(ipa); + } catch (ipaError) { + console.error('Error fetching IPA transcriptions:', ipaError); + setIpaTranscriptions([]); + } } else { console.log('No entity data found for:', entityId); setLabels({}); setDescriptions({}); setStatements({}); setAvailableLanguages([]); + setIpaTranscriptions([]); const savedLanguage = loadFromLocalStorage(STORAGE_KEYS.LANGUAGE, null); setSelectedLanguage(savedLanguage || uniquePreferredLangs[0] || 'en'); } @@ -371,6 +383,7 @@ setDescriptions({}); setStatements({}); setAvailableLanguages([]); + setIpaTranscriptions([]); const savedLanguage = loadFromLocalStorage(STORAGE_KEYS.LANGUAGE, null); setSelectedLanguage(savedLanguage || uniquePreferredLangs[0] || 'en'); setIsLoading(false); @@ -416,6 +429,53 @@

{labels[lang]?.value || 'No label available'}

) : (

No description available

)} + + {/* IPA Transcriptions Section */} + {ipaTranscriptions.length > 0 && ( +
+

+ ๐Ÿ—ฃ๏ธ IPA Pronunciation +

+ {ipaTranscriptions.map((ipa, index) => ( +
+ + /{ipa.value}/ + + {(ipa.language || ipa.variety) && ( + + {ipa.language && `(${getLabel(ipa.language)})`} + {ipa.variety && ipa.language && ' '} + {ipa.variety && `[${getLabel(ipa.variety)}]`} + + )} +
+ ))} +
+ )} 0) { + console.log(` โœ… Found ${ipaTranscriptions.length} IPA transcription(s):`); + ipaTranscriptions.forEach((ipa, index) => { + console.log(` ${index + 1}. /${ipa.value}/`); + if (ipa.language) { + console.log(` Language: ${ipa.language}`); + } + if (ipa.variety) { + console.log(` Variety: ${ipa.variety}`); + } + }); + } else { + console.log(' โŒ No IPA transcriptions found'); + } + + console.log(''); // Empty line for readability + + } catch (error) { + console.error(` โš ๏ธ Error testing ${entityId}:`, error.message); + console.log(''); + } + } +} + +async function testEdgeCases() { + console.log('\n๐Ÿ” Testing edge cases...\n'); + + // Test non-existent entity + try { + console.log('๐Ÿ“ Testing non-existent entity: Q999999999'); + const ipa = await client.getIpaTranscription('Q999999999', 'en'); + console.log(` Result: ${ipa.length} transcriptions found`); + } catch (error) { + console.log(` Expected error: ${error.message}`); + } + + // Test empty language parameter + try { + console.log('\n๐Ÿ“ Testing with empty language parameter:'); + const ipa = await client.getIpaTranscription('Q35120', ''); + console.log(` Result: ${ipa.length} transcriptions found`); + } catch (error) { + console.log(` Error: ${error.message}`); + } +} + +async function runAllTests() { + try { + await testIpaRetrieval(); + await testEdgeCases(); + + console.log('โœจ IPA functionality tests completed!'); + console.log('\n๐Ÿ“Š Summary:'); + console.log('- IPA transcription retrieval from P898 property: implemented'); + console.log('- Support for language qualifiers (P407): implemented'); + console.log('- Support for pronunciation variety qualifiers (P5237): implemented'); + console.log('- Error handling: implemented'); + + } catch (error) { + console.error('๐Ÿ’ฅ Test suite failed:', error); + } +} + +// Run the tests +runAllTests(); \ No newline at end of file diff --git a/wikidata-api-browser.js b/wikidata-api-browser.js index c5718f9..8370a80 100644 --- a/wikidata-api-browser.js +++ b/wikidata-api-browser.js @@ -106,6 +106,51 @@ class WikidataAPIClient { return data.entities[propertyId]; } + /** + * Get IPA transcription for an entity from P898 property + * @param {string} entityId - Entity ID (e.g., 'Q35120') + * @param {string} languages - Languages to fetch + * @returns {Promise} - Array of IPA transcriptions + */ + async getIpaTranscription(entityId, languages = 'en') { + try { + const entity = await this.fetchEntity(entityId, languages); + const ipa = []; + + if (entity && entity.claims && entity.claims.P898) { + entity.claims.P898.forEach(claim => { + if (claim.mainsnak && claim.mainsnak.datavalue) { + const transcription = { + value: claim.mainsnak.datavalue.value, + language: null, + variety: null + }; + + // Check qualifiers for language and pronunciation variety + if (claim.qualifiers) { + // Language qualifier (P407) + if (claim.qualifiers.P407 && claim.qualifiers.P407[0] && claim.qualifiers.P407[0].datavalue) { + transcription.language = claim.qualifiers.P407[0].datavalue.value.id; + } + + // Pronunciation variety qualifier (P5237) + if (claim.qualifiers.P5237 && claim.qualifiers.P5237[0] && claim.qualifiers.P5237[0].datavalue) { + transcription.variety = claim.qualifiers.P5237[0].datavalue.value.id; + } + } + + ipa.push(transcription); + } + }); + } + + return ipa; + } catch (error) { + console.error('Error fetching IPA transcription:', error); + return []; + } + } + /** * Search for entities and properties that match an exact word sequence * @param {string} query - Exact word sequence to search for diff --git a/wikidata-api.js b/wikidata-api.js index 8d0fb24..227d141 100644 --- a/wikidata-api.js +++ b/wikidata-api.js @@ -107,6 +107,51 @@ class WikidataAPIClient { return data.entities[propertyId]; } + /** + * Get IPA transcription for an entity from P898 property + * @param {string} entityId - Entity ID (e.g., 'Q35120') + * @param {string} languages - Languages to fetch + * @returns {Promise} - Array of IPA transcriptions + */ + async getIpaTranscription(entityId, languages = 'en') { + try { + const entity = await this.fetchEntity(entityId, languages); + const ipa = []; + + if (entity && entity.claims && entity.claims.P898) { + entity.claims.P898.forEach(claim => { + if (claim.mainsnak && claim.mainsnak.datavalue) { + const transcription = { + value: claim.mainsnak.datavalue.value, + language: null, + variety: null + }; + + // Check qualifiers for language and pronunciation variety + if (claim.qualifiers) { + // Language qualifier (P407) + if (claim.qualifiers.P407 && claim.qualifiers.P407[0] && claim.qualifiers.P407[0].datavalue) { + transcription.language = claim.qualifiers.P407[0].datavalue.value.id; + } + + // Pronunciation variety qualifier (P5237) + if (claim.qualifiers.P5237 && claim.qualifiers.P5237[0] && claim.qualifiers.P5237[0].datavalue) { + transcription.variety = claim.qualifiers.P5237[0].datavalue.value.id; + } + } + + ipa.push(transcription); + } + }); + } + + return ipa; + } catch (error) { + console.error('Error fetching IPA transcription:', error); + return []; + } + } + /** * Search for entities and properties that match an exact word sequence * @param {string} query - Exact word sequence to search for