Skip to content

Commit

Permalink
Fix issue with tags splitting naively at colons
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jan 22, 2024
1 parent 13e2089 commit 5dc9dbf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/test/parseEntry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,44 @@ const expectedEntries = [
},
],
},
{
id: 96792,
headwords: [
{
text: '牛河博士',
readings: ['ngau4 ho2 bok3 si6'],
},
],
tags: [
{
name: 'pos',
value: '名詞',
},
{
name: 'label',
value: '專名',
},
{
name: 'label',
value: '潮語',
},
{
name: 'ref',
value: 'https://evchk.fandom.com/zh/wiki/曹宏威',
},
],
senses: [
{
explanation: {
yue: [
'香港#學者 曹宏威喺#網民 之間嘅叫法,佢因為#乾炒牛河 而一舉成名',
],
eng: ['Wung-wai Tso, literally "Doctor Beef Chow-fun"'],
},
egs: [],
},
],
},
];

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/testdata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ eng:to follow the rules strictly; to ""go by the book""; to leave no room for di
<eg>
yue:唔好怪我揸正嚟做。 (m4 hou2 gwaai3 ngo5 zaa1 zeng3 lei4 zou6.)
eng:Don't blame me for following the rules too strictly.",,OK,已公開
96792,牛河博士:ngau4 ho2 bok3 si6,"(pos:名詞)(label:專名)(label:潮語)(ref:https://evchk.fandom.com/zh/wiki/曹宏威)
yue:香港#學者 曹宏威喺#網民 之間嘅叫法,佢因為#乾炒牛河 而一舉成名
eng:Wung-wai Tso, literally ""Doctor Beef Chow-fun""",,OK,未公開
6 changes: 3 additions & 3 deletions src/util/entryParse/parseEntryToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ function parseTags(entryLines) {
}
const tags = firstLine.split(')(').map((tag) => {
tag = tag.replace(/[()]/g, '');
let [name, value] = tag.split(':');
name = name.trim();
value = value.trim();
let colonIndex = tag.indexOf(':');
const name = tag.slice(0, colonIndex).trim();
const value = tag.slice(colonIndex + 1).trim();
return {
name,
value,
Expand Down

0 comments on commit 5dc9dbf

Please sign in to comment.