Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Reading Parsing of Numbers #8

Merged
merged 4 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": "1.3.0",
"version": "1.4.0",
"scripts": {
"test": "ava"
"test": "ava",
"buildja": "node .\\src\\convertWikipedia.js ja 2022-12-01"
},
"dependencies": {
"pinyin-pro": "^3.18.5",
Expand Down
11 changes: 3 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ more Yomitan dictionaries and tools, see

## Download

**2024-01-04 Version 1.3**: More reading filtering for JA Wikipedia.

**2023-12-23 Version 1.2**: Improved parsing of more readings for the JA
Wikipedia release.

**2023-12-21 Version 1.1**: Updated script for better parsing of readings.

- **[Download JA Wikipedia for Yomitan](https://drive.google.com/open?id=14ZxYKI2JQ8QTpWTtNSH-TXu7wtMODcYB&usp=drive_fs)**
- **[Download JA Wikipedia for Yomitan](https://drive.google.com/open?id=14aNH8TeVDIk_EeW1zh4Os8VN7smK4vPd&usp=drive_fs)**
(~1.2M entries)
- **Last updated 2024-01-06: v1.4.0** (Better readings parsing)
- **[Download ZH Wikipedia for Yomitan](https://drive.google.com/open?id=14ZECT8FVl0KjxV3JPhzgdmIV8GEgx5ht&usp=drive_fs)**
(~1.2M entries)
- **Last updated 2023-12-21: v1.1.0**

# Usage

Expand Down
9 changes: 8 additions & 1 deletion src/readingParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@ function parseReadingFromBrackets(bracketContent, term) {
const latinRegex = /[a-zA-Z]/g;
const termHasLatin = term.match(latinRegex);

const readingCandidates = termHasLatin
let readingCandidates = termHasLatin
? noKanji
: noKanji.filter((reading) => !reading.match(latinRegex));

const numberRegex = /\d/g;
const termHasNumber = term.match(numberRegex);

readingCandidates = termHasNumber
? readingCandidates
: readingCandidates.filter((reading) => !reading.match(numberRegex));

if (readingCandidates.length > 0) {
let reading = readingCandidates[0];
reading = reading.replace(/ /g, '');
Expand Down
5 changes: 5 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const testCases = [
term: 'アクロカントサウルス',
expectedReading: '',
},
{
line: `<http://ja.dbpedia.org/resource/ロイヤル・オーク_(戦艦)> <http://www.w3.org/2000/01/rdf-schema#comment> "ロイヤル・オーク (HMS Royal Oak, 08) は、イギリス海軍のリヴェンジ級戦艦。デヴォンポート工廠で1914年1月15日起工。1914年11月17日進水。1916年5月1日就役。ロイヤル・オークとは清教徒革命当時、国王がその枝に隠れて難を逃れた木「ロイヤル・オーク」に由来する名前で、イギリス軍艦では8隻に命名されており、本艦がその8隻目にあたる。戦艦としては1894年に竣工したロイヤル・サブリン級戦艦に次いで2隻目となる。 本艦は就役直後の1916年5月31日から6月1日にかけてドイツ艦隊との間で戦われたユトランド沖海戦に参加し、ドイツ巡洋戦艦デアフリンガーと砲火を交えた。1939年10月14日にドイツ海軍の潜水艦U47によるスカパ・フロー奇襲作戦で撃沈された。"@ja .`,
term: 'ロイヤル・オーク',
expectedReading: '',
},
],
},
{
Expand Down