Skip to content

Commit

Permalink
Separate stuff out more
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 20, 2024
1 parent 3fda848 commit 0bd38b2
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 43 deletions.
31 changes: 31 additions & 0 deletions src/util/yomitan/convertEntryToDetailedDefinition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { convertHeadwordsToSC } from './convertHeadwordsToSC.js';
import { convertGlossToSC } from './convertGlossToSC.js';

/**
* Converts a dictionary entry to a detailed definition.
* @param {DictionaryEntry} entry
* @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').DetailedDefinition}
*/
function convertEntryToDetailedDefinition(entry) {
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').DetailedDefinition}
*/
const detailedDefinition = {
type: 'structured-content',
content: [
// Headword
convertHeadwordsToSC(entry.headwords),
{
tag: 'div',
data: {
wordshk: 'definition',
},
lang: 'yue',
content: entry.glosses.map((gloss) => {
return convertGlossToSC(gloss);
}),
},
],
};
return detailedDefinition;
}
49 changes: 6 additions & 43 deletions src/util/yomitan/convertEntryToYomitanTerm.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,18 @@
import { TermEntry } from 'yomichan-dict-builder';
import { convertReadingToRubySC } from './parseTextToSC';

/**
*
* @param {DictionaryEntry} entry
* @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').TermInformation[]}
*/
function convertEntryToYomitanTerm(entry) {
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').TermInformation[]}
*/
const terms = [];
return terms;
}
function convertEntryToYomitanTerms(entry) {

/**
* Converts headword(s) to structured content.
* @param {TextReadingPair[]} headwords
*/
function convertHeadwordsToSC(headwords) {
const headwordsSCList = headwords.map(headwordToSC);
const separator = '・';
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
const headwordsSCListWithSeparator = [];
for (let i = 0; i < headwordsSCList.length; i++) {
headwordsSCListWithSeparator.push(headwordsSCList[i]);
if (i !== headwordsSCList.length - 1) {
headwordsSCListWithSeparator.push(separator);
}
}

// Create terms for each headword
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent}
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').TermInformation[]}
*/
const sc = {
tag: 'div',
data: {
wordshk: 'headword',
},
lang: 'yue',
content: ['【', ...headwordsSCListWithSeparator, '】'],
};
return sc;
const yomitanTerms = [];
return yomitanTerms;
}

/**
* Converts a headword to structured content.
* @param {TextReadingPair} headword
* @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent}
*/
function headwordToSC(headword) {
return convertReadingToRubySC(headword);
}
43 changes: 43 additions & 0 deletions src/util/yomitan/convertHeadwordsToSC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { convertReadingToRubySC } from './parseTextToSC.js';

/**
* Converts headword(s) to structured content.
* @param {TextReadingPair[]} headwords
*/
function convertHeadwordsToSC(headwords) {
const headwordsSCList = headwords.map(headwordToSC);
const separator = '・';
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent[]}
*/
const headwordsSCListWithSeparator = [];
for (let i = 0; i < headwordsSCList.length; i++) {
headwordsSCListWithSeparator.push(headwordsSCList[i]);
if (i !== headwordsSCList.length - 1) {
headwordsSCListWithSeparator.push(separator);
}
}
/**
* @type {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent}
*/
const sc = {
tag: 'div',
data: {
wordshk: 'headword',
},
lang: 'yue',
content: ['【', ...headwordsSCListWithSeparator, '】'],
};
return sc;
}

/**
* Converts a headword to structured content.
* @param {TextReadingPair} headword
* @returns {import('yomichan-dict-builder/dist/types/yomitan/termbank').StructuredContent}
*/
function headwordToSC(headword) {
return convertReadingToRubySC(headword);
}

export { convertHeadwordsToSC };

0 comments on commit 0bd38b2

Please sign in to comment.