From df9a4d5138bb665b7ef52ff7ba94520500320dfc Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 25 May 2020 23:03:19 +0200 Subject: [PATCH] Add documentation --- jishoScrape/index.js | 13 +++++++------ jishoScrape/src/dataFetching.js | 17 ++++++++++++++++- kanjiLib.tex | 20 +++++++++++++++----- main.tex | 16 +++++++++------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/jishoScrape/index.js b/jishoScrape/index.js index cb139c1..463d160 100644 --- a/jishoScrape/index.js +++ b/jishoScrape/index.js @@ -1,6 +1,6 @@ const fs = require('fs'); -/* Local files */ +/* Import local files */ const {fetchKanjiFromTxt, fetchKanjiFromJisho} = require('./src/dataFetching.js'); const {getKanjiTexData} = require('./src/texConversion.js'); const {kanjiTable} = require('./src/kanjiTables.js'); @@ -13,11 +13,11 @@ async function main(jlptLevel) { const kanjiArray = await fetchKanjiFromTxt(`./data/txt/${jlptLevel}.txt`); console.log(`${jlptLevelCaps}: Fetched txt`); - const results = await fetchKanjiFromJisho(kanjiArray); + const jishoResults = await fetchKanjiFromJisho(kanjiArray); console.log(`${jlptLevelCaps}: Fetched Jisho data`); - const sortedKanjiArray = results.map(result => result.query); - const texData = getKanjiTexData(results); + const sortedKanjiArray = jishoResults.map(result => result.query); + const texData = getKanjiTexData(jishoResults); console.log(`${jlptLevelCaps}: Processed pages`); const resultTable = kanjiTable(sortedKanjiArray); @@ -37,7 +37,8 @@ async function main(jlptLevel) { fs.writeFile(`./data/pages/${jlptLevel}.tex`, resultPage, (err) => {if (err) console.error(err)}); } -async function mainWrapper() { +/* Handle args */ +async function argWrapper() { try { if (!/n\d/.test(process.argv[2])) throw 'Input not valid'; @@ -47,4 +48,4 @@ async function mainWrapper() { } } -mainWrapper(); \ No newline at end of file +argWrapper(); \ No newline at end of file diff --git a/jishoScrape/src/dataFetching.js b/jishoScrape/src/dataFetching.js index f132cb6..b876084 100644 --- a/jishoScrape/src/dataFetching.js +++ b/jishoScrape/src/dataFetching.js @@ -3,12 +3,23 @@ const util = require('util'); const jishoApi = require('unofficial-jisho-api'); const jisho = new jishoApi(); +/** + * Reads a txt file and splits the characters into an array + * @param {string} file Path to file + * @returns {string[]} Kanji + */ async function fetchKanjiFromTxt(file) { const read = util.promisify(fs.readFile); const data = await read(file, 'utf8'); return data.split(''); } +/** + * Makes a delayed kanji search request in order not to overload the server. + * @param {string} kanji The character to search for + * @param {number} delay Number of milliseconds delay to the request + * @return {promise} A promise that's going to run a request after the specified delay + */ async function delayedJishoCall(kanji, delay) { return new Promise((res, rej) => { setTimeout(() => { @@ -20,7 +31,11 @@ async function delayedJishoCall(kanji, delay) { /* Sort list of result array */ const sortKanji = (kanjiData) => kanjiData.sort((a, b) => (a.strokeCount > b.strokeCount) ? 1 : -1); -/* Function to fetch jisho data for all kanjis in an array */ +/** + * Searches for kanji with a 50ms interval between each request. + * @param {string[]} kanjiArray A list of kanji to search for. + * @returns {object} JSON data containing a sorted list of search responses. + */ async function fetchKanjiFromJisho(kanjiArray) { const promises = kanjiArray.map(async (kanji, i) => await delayedJishoCall(kanji, i*50)); const data = await Promise.all(promises); diff --git a/kanjiLib.tex b/kanjiLib.tex index 197ff9a..464d10d 100644 --- a/kanjiLib.tex +++ b/kanjiLib.tex @@ -5,7 +5,9 @@ \definecolor{myGreen}{RGB}{72, 194, 78} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ---------------------------------------------------------------------------- % +% JLPT Section % +% ---------------------------------------------------------------------------- % \newcommand{\jlptSection}[1]{ \section*{\uppercase{#1}} @@ -19,7 +21,9 @@ \break } -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ---------------------------------------------------------------------------- % +% Header line % +% ---------------------------------------------------------------------------- % \newcommand{\taughtIn}[1]{ Taught in: #1 \newline @@ -76,7 +80,9 @@ \vspace{1cm} } -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ---------------------------------------------------------------------------- % +% Meaning % +% ---------------------------------------------------------------------------- % \newtcolorbox{meaningBox}{ enhanced, @@ -98,7 +104,9 @@ \end{center} } -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ---------------------------------------------------------------------------- % +% Kunyomi and Onyomi % +% ---------------------------------------------------------------------------- % \newtcolorbox{kunyomiBox}{ enhanced, @@ -143,7 +151,9 @@ \vspace{0.5cm} } -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% ---------------------------------------------------------------------------- % +% Kanji Drawing Box % +% ---------------------------------------------------------------------------- % \newCJKfontfamily\drawingKanji{Choumei} \newCJKfontfamily\drawingFirstKanji{KanjiStrokeOrders} diff --git a/main.tex b/main.tex index 8abefcb..f7e924e 100644 --- a/main.tex +++ b/main.tex @@ -1,7 +1,6 @@ % !TEX program = xelatex \documentclass{article} -\usepackage{fontspec} \usepackage{hyperref} \hypersetup{ colorlinks=true, @@ -18,18 +17,21 @@ top=20mm, } +\setlength{\parskip}{0.5em} +\setlength{\parindent}{0pt} + \usepackage{longtable} %N1 table is too long. +%Japanese typesetting and fonts \usepackage[japanese]{babel} \usepackage{xeCJK} +\usepackage{fontspec} \setCJKmainfont{Noto Sans Mono CJK JP} \setmainfont{Open Sans} \input{./kanjiLib.tex} -\setlength{\parindent}{0pt} - -\usepackage{etoc} +\usepackage{etoc} %For local tocs containing level based kanji list. \begin{document} @@ -44,11 +46,11 @@ %TODO: Add more detailed information -Thanks to for making both the Choumei font and the variant containing stroke order numbers. You can find his work at \url{https://www.nihilist.org.uk/} +Thanks to Timothy Eyre for making the Choumei font and the edition containing stroke order numbers. You can find his work at \url{https://www.nihilist.org.uk/} -Metadata is taken from \url{https://jisho.org/} +Kanji data is taken from \url{https://jisho.org/} -This is a list of all kanji in N5 (according to \href{http://www.tanos.co.uk/jlpt/skills/kanji/}{tanos.co.uk}) +This document splits the kanjis into JLPT levels. Please note that there is no official list of kanji JLPT levels. This list is based on \href{http://www.tanos.co.uk/jlpt/skills/kanji/}{tanos.co.uk}. \break