1
yomichan-import/meikyou.go
stephenmk 853d0b33dc
Use empty interface type for dictionary glossaries
Necesssary for structured content support
2023-01-22 14:14:33 -06:00

787 lines
14 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package yomichan
import (
"regexp"
"strings"
zig "foosoft.net/projects/zero-epwing-go"
)
type meikyouExtractor struct {
partsExp *regexp.Regexp
expForeignMetaExp *regexp.Regexp
expShapesExp *regexp.Regexp
expBracketedExp *regexp.Regexp
expTermsExp *regexp.Regexp
readGroupExp *regexp.Regexp
metaExp *regexp.Regexp
}
func makeMeikyouExtractor() epwingExtractor {
var foreignMeta = []string{
"和製",
"中国",
"朝鮮",
"イタリア",
"スペイン",
"ドイツ",
"フランス",
"オランダ",
"ポルトガル",
"ギリシア",
"アラビア",
"チベット",
"タガログ",
"ヘブライ",
"ヒンディー",
"マレーシア",
"ラテン",
"アフリカーンス",
"ロシア",
"ハワイ",
"マレー",
"スウェーデン",
"ノルウェー・デンマーク",
"フィンランド",
"サンスクリット",
"ポーランド",
}
return &meikyouExtractor{
partsExp: regexp.MustCompile(`([^(【〖[]+)(?:【(.*)】)?(?:\[(.*)\])?(?:(.*))?`),
expForeignMetaExp: regexp.MustCompile(strings.Join(foreignMeta, "|")),
expShapesExp: regexp.MustCompile(`[▼▽]+`),
expBracketedExp: regexp.MustCompile(`(?:[〈《])([^〉》]*)(?:[〉》])`),
expTermsExp: regexp.MustCompile(`([^]*)?(?:(.*))?`),
readGroupExp: regexp.MustCompile(`[‐・]+`),
metaExp: regexp.MustCompile(`〘([^〙]*)〙`),
}
}
func (e *meikyouExtractor) extractTerms(entry zig.BookEntry, sequence int) []dbTerm {
matches := e.partsExp.FindStringSubmatch(entry.Heading)
if matches == nil {
return nil
}
var expressions, readings []string
if expression := matches[2]; len(expression) > 0 {
expression = e.expShapesExp.ReplaceAllLiteralString(expression, "")
expression = e.expBracketedExp.ReplaceAllString(expression, "$1")
if termsMatches := e.expTermsExp.FindStringSubmatch(expression); termsMatches != nil {
termsMatches = termsMatches[1:]
for _, terms := range termsMatches {
if len(terms) > 0 {
for _, split := range strings.Split(terms, "・") {
expressions = append(expressions, split)
}
}
}
}
}
if expression := matches[3]; len(expression) > 0 {
expression = e.expForeignMetaExp.ReplaceAllLiteralString(expression, "")
expression = strings.Replace(expression, "", " ", -1)
for _, split := range strings.Split(expression, "・") {
expressions = append(expressions, split)
}
}
if reading := matches[1]; len(reading) > 0 {
reading = e.readGroupExp.ReplaceAllLiteralString(reading, "")
readings = append(readings, reading)
}
var tags []string
for _, split := range strings.Split(entry.Text, "\n") {
if matches := e.metaExp.FindStringSubmatch(split); matches != nil {
for _, tag := range strings.Split(matches[1], "・") {
tags = append(tags, tag)
}
}
}
var terms []dbTerm
if len(expressions) == 0 {
for _, reading := range readings {
term := dbTerm{
Expression: reading,
Glossary: []any{entry.Text},
Sequence: sequence,
}
e.exportRules(&term, tags)
terms = append(terms, term)
}
} else {
for _, expression := range expressions {
for _, reading := range readings {
term := dbTerm{
Expression: expression,
Reading: reading,
Glossary: []any{entry.Text},
Sequence: sequence,
}
e.exportRules(&term, tags)
terms = append(terms, term)
}
}
}
return terms
}
func (e *meikyouExtractor) extractKanji(entry zig.BookEntry) []dbKanji {
return nil
}
func (e *meikyouExtractor) exportRules(term *dbTerm, tags []string) {
for _, tag := range tags {
if tag == "名" {
term.addRules("n")
} else if tag == "代" {
term.addRules("pn")
} else if tag == "連体" {
term.addRules("adj-pn")
} else if tag == "副" {
term.addRules("adv")
} else if tag == "副ト" || tag == "副トニ" || tag == "トニ" {
term.addRules("adv-to")
} else if tag == "副助" {
term.addRules("adv")
term.addRules("prt")
} else if tag == "格助" || tag == "終助" {
term.addRules("prt")
} else if tag == "接" {
term.addRules("conj")
} else if tag == "接助" {
term.addRules("conj")
term.addRules("prt")
} else if tag == "接尾" {
term.addRules("suf")
} else if tag == "接頭" {
term.addRules("pref")
} else if tag == "補形" {
term.addRules("aux-adj")
} else if strings.HasPrefix(tag, "助動") || strings.HasPrefix(tag, "補動") {
term.addRules("aux-v")
} else if tag == "形動トタル" {
term.addRules("adj-t")
term.addRules("adv-to")
} else if tag == "形" {
term.addRules("adj-i")
} else if tag == "形動" {
term.addRules("adj-na")
}
if strings.Contains(tag, "他") {
term.addRules("vt")
}
if strings.Contains(tag, "自") {
term.addRules("vi")
}
if strings.Contains(tag, "一") {
term.addRules("v1")
} else if strings.ContainsAny(tag, "二四五") && tag != "二" && tag != " トニ" {
term.addRules("v5")
} else if strings.Contains(tag, "サ変") && (strings.HasSuffix(term.Expression, "する") || strings.HasSuffix(term.Expression, "為る")) {
term.addRules("vs")
} else if term.Expression == "来る" {
term.addRules("vk")
}
}
}
func (*meikyouExtractor) getRevision() string {
return "meikyou1"
}
func (*meikyouExtractor) getFontNarrow() map[int]string {
return map[int]string{
41249: " ",
41250: "¡",
41251: "¢",
41252: "£",
41253: "¤",
41254: "¥",
41255: "¦",
41256: "§",
41257: "¨",
41258: "©",
41259: "ª",
41260: "«",
41261: "¬",
41262: "­",
41263: "®",
41264: "¯",
41265: "°",
41266: "±",
41267: "²",
41268: "³",
41269: "´",
41270: "µ",
41271: "",
41272: "·",
41273: "¸",
41274: "¹",
41275: "º",
41276: "»",
41277: "¼",
41278: "½",
41279: "¾",
41280: "¿",
41281: "À",
41282: "Á",
41283: "Â",
41284: "Ã",
41285: "Ä",
41286: "Å",
41287: "Æ",
41288: "Ç",
41289: "È",
41290: "É",
41291: "Ê",
41292: "Ë",
41293: "Ì",
41294: "Í",
41295: "Î",
41296: "Ï",
41297: "Ð",
41298: "Ñ",
41299: "Ò",
41300: "Ó",
41301: "Ô",
41302: "Õ",
41303: "Ö",
41304: "×",
41305: "Ø",
41306: "Ù",
41307: "Ú",
41308: "Û",
41309: "Ü",
41310: "Ý",
41311: "Þ",
41312: "ß",
41313: "à",
41314: "á",
41315: "â",
41316: "ã",
41317: "ä",
41318: "å",
41319: "æ",
41320: "ç",
41321: "è",
41322: "é",
41323: "ê",
41324: "ë",
41325: "ì",
41326: "í",
41327: "î",
41328: "ï",
41329: "ð",
41330: "ñ",
41331: "ò",
41332: "ó",
41333: "ô",
41334: "õ",
41335: "ö",
41336: "÷",
41337: "ø",
41338: "ù",
41339: "ú",
41340: "û",
41341: "ü",
41342: "ý",
41505: "þ",
41506: "ÿ",
41507: "Ā",
41508: "ā",
41509: "Ă",
41510: "ă",
41511: "Ą",
41512: "ą",
41513: "Ć",
41514: "ć",
41515: "Ĉ",
41516: "ĉ",
41517: "Ċ",
41518: "ċ",
41519: "Č",
41520: "č",
41521: "Ď",
41522: "ď",
41523: "Đ",
41524: "đ",
41525: "Ē",
41526: "ē",
41527: "Ĕ",
41528: "ĕ",
41529: "Ė",
41530: "ė",
41531: "Ę",
41532: "ę",
41533: "Ě",
41534: "ě",
41535: "Ĝ",
41536: "ĝ",
41537: "Ğ",
41538: "ğ",
41539: "Ġ",
41540: "ġ",
41541: "Ģ",
41542: "ģ",
41543: "Ĥ",
41544: "ĥ",
41545: "Ħ",
41546: "ħ",
41547: "Ĩ",
41548: "ĩ",
41549: "Ī",
41550: "ī",
41551: "Ĭ",
41552: "ĭ",
41553: "Į",
41554: "į",
41555: "İ",
41556: "ı",
41557: "IJ",
41558: "ij",
41559: "Ĵ",
41560: "ĵ",
41561: "Ķ",
41562: "ķ",
41563: "ĸ",
41564: "Ĺ",
41565: "ĺ",
41566: "Ļ",
41567: "ļ",
41568: "Ľ",
41569: "ľ",
41570: "Ŀ",
41571: "ŀ",
41572: "Ł",
41573: "ł",
41574: "Ń",
41575: "ń",
41576: "Ņ",
41577: "ņ",
41578: "Ň",
41579: "ň",
41580: "ʼn",
41581: "Ŋ",
41582: "ŋ",
41583: "Ō",
41584: "ō",
41585: "Ŏ",
41586: "ŏ",
41587: "Ő",
41588: "ő",
41589: "Œ",
41590: "œ",
41591: "Ŕ",
41592: "ŕ",
41593: "Ŗ",
41594: "ŗ",
41595: "Ř",
41596: "ř",
41597: "Ś",
41598: "ś",
41761: "Ŝ",
41762: "ŝ",
41763: "Ş",
41764: "ş",
41765: "Š",
41766: "š",
41767: "Ţ",
41768: "ţ",
41769: "Ť",
41770: "ť",
41771: "Ŧ",
41772: "ŧ",
41773: "Ũ",
41774: "ũ",
41775: "Ū",
41776: "ū",
41777: "Ŭ",
41778: "ŭ",
41779: "Ů",
41780: "ů",
41781: "Ű",
41782: "ű",
41783: "Ų",
41784: "ų",
41785: "Ŵ",
41786: "ŵ",
41787: "Ŷ",
41788: "ŷ",
41789: "Ÿ",
41790: "Ź",
41791: "ź",
41792: "Ż",
41793: "ż",
41794: "Ž",
41795: "ž",
41796: "ſ",
41797: "Ǎ",
41798: "ǎ",
41799: "Ǐ",
41800: "ǐ",
41801: "Ǒ",
41802: "ǒ",
41803: "Ǔ",
41804: "ǔ",
41805: "ƒ",
41806: "ˆ",
41807: "˜",
41808: "ɔ",
41809: "ɔ̀",
41810: "ɔ́",
41811: "ǝ",
41812: "ǝ̀",
41813: "ǝ́",
41814: "ʌ",
41815: "ʌ̀",
41816: "ʌ́",
41817: "",
41818: "ɑ",
41819: "ɑ̀",
41820: "ɑ́",
41821: "ʃ",
41822: "ʊ",
41823: "θ",
41824: "ʒ",
41825: "ɒ",
41826: "ǽ",
41827: "ɚ",
41828: "ɡ",
41829: "ʤ",
41830: "ʧ",
41831: "-",
41832: ".",
41833: "¯",
41834: "",
41835: "",
41836: "",
41837: "",
41838: "",
41839: "",
41840: "",
41841: "",
41842: "",
41843: "°",
41844: "",
41845: "",
41846: "",
41847: "",
41848: "",
41849: "",
41850: "",
41851: "",
41852: "",
41853: "",
41854: "",
42017: "",
42018: "",
42019: "",
42020: "",
42021: "",
}
}
func (*meikyouExtractor) getFontWide() map[int]string {
return map[int]string{
45089: "",
45090: "",
45091: "©",
45092: "æ",
45093: "æ̀",
45094: "ǽ",
45095: "",
45096: "",
45097: "",
45098: "",
45099: "",
45100: "",
45101: "",
45102: "",
45103: "",
45104: "",
45105: "",
45106: "",
45107: "",
45108: "",
45109: "",
45110: "",
45111: "",
45112: "",
45113: "",
45114: "",
45115: "",
45116: "",
45117: "",
45118: "",
45119: "",
45120: "",
45121: "",
45122: "",
45123: "",
45124: "",
45125: "",
45126: "",
45127: "",
45128: "",
45129: "",
45130: "",
45131: "",
45132: "",
45133: "",
45134: "",
45135: "",
45136: "",
45137: "",
45138: "",
45139: "",
45140: "",
45141: "",
45142: "",
45143: "",
45144: "",
45145: "",
45146: "",
45147: "",
45148: "",
45149: "",
45150: "",
45151: "",
45152: "",
45153: "",
45154: "",
45155: "",
45156: "",
45157: "",
45158: "",
45159: "",
45160: "",
45161: "",
45162: "",
45163: "",
45164: "",
45165: "",
45166: "",
45167: "",
45168: "",
45169: "",
45170: "",
45171: "",
45172: "",
45173: "",
45174: "",
45175: "",
45176: "",
45177: "",
45178: "",
45179: "",
45180: "",
45181: "",
45182: "",
45345: "",
45346: "",
45347: "",
45348: "",
45349: "",
45350: "",
45351: "",
45352: "",
45353: "",
45354: "",
45355: "",
45356: "",
45357: "",
45358: "",
45359: "",
45360: "",
45361: "",
45362: "",
45363: "",
45364: "",
45365: "",
45366: "",
45367: "",
45368: "",
45369: "",
45370: "",
45371: "",
45372: "",
45373: "",
45374: "",
45375: "",
45376: "",
45377: "",
45378: "",
45379: "",
45380: "",
45381: "",
45382: "",
45383: "",
45384: "",
45385: "",
45386: "",
45387: "",
45388: "",
45389: "",
45390: "",
45391: "",
45392: "",
45393: "",
45394: "",
45395: "",
45396: "",
45397: "",
45398: "",
45399: "",
45400: "",
45401: "",
45402: "",
45403: "",
45404: "",
45405: "",
45406: "",
45407: "",
45408: "",
45409: "",
45410: "",
45411: "",
45412: "",
45413: "",
45414: "",
45415: "",
45416: "",
45417: "",
45418: "",
45419: "",
45420: "",
45421: "",
45422: "",
45423: "",
45424: "",
45425: "",
45426: "",
45427: "",
45428: "",
45429: "",
45430: "",
45431: "",
45432: "",
45433: "",
45434: "",
45435: "",
45436: "",
45437: "",
45438: "",
45601: "",
45602: "",
45603: "",
45604: "",
45605: "",
45606: "",
45607: "",
45608: "",
45609: "",
45610: "",
45611: "",
45612: "",
45613: "",
45614: "",
45615: "",
45616: "",
45617: "",
45618: "",
45619: "",
45620: "",
45621: "",
45622: "",
45623: "",
45624: "",
45625: "",
45626: "",
45627: "",
45628: "",
45629: "",
45630: "",
45631: "",
45632: "",
45633: "",
45634: "",
45635: "",
45636: "",
45637: "",
45638: "",
45639: "",
45640: "",
45641: "",
45642: "",
45643: "",
45644: "",
45645: "",
45646: "",
45647: "",
45648: "",
45649: "",
45650: "",
45651: "",
45652: "",
45653: "",
45654: "",
45655: "",
45656: "",
45657: "",
45658: "",
45659: "",
45660: "",
45661: "",
45662: "",
45663: "",
45664: "",
45665: "",
45666: "",
45667: "",
45668: "",
45669: "",
45670: "",
45671: "",
45672: "",
45673: "",
45674: "",
45675: "",
45676: "",
45677: "",
45678: "",
45679: "",
45680: "",
45681: "",
45682: "",
45683: "",
45684: "",
45685: "-",
45686: "~",
45687: "¢",
45688: "£",
45689: "",
45690: "",
45691: "",
45692: "",
45693: "",
45694: "",
45857: "",
45858: "",
45859: "",
45860: "",
45861: "",
45862: "",
45863: "",
45864: "",
}
}