██████████ のブログ

なんか技術的なメモ & ブクマ (no affiliate ads)

辞書

Abstract

前提
私は Mac の 辞書.app 好き好き太郎です (ウィズダム英和辞典なんかをポップアップできたり Spotlight 検索できたりするので)
 
何が問題か
ある単語がわからないとき,
従来手法:
辞書.app で調べる → わからない → インターネットで調べる → わかった → 100年後 → 辞書.app で調べる → わからない → インターネットで調べる → わかった
だった.ダルい.
 
私の解決策は何か
提案手法:
辞書.app で調べる → わからない → インターネットで調べる → わかった → コピペを 辞書.app 用の自作辞書にぶっ込んでおく → 100年後 → 辞書.app で調べる → わかった

結果 何がわかったか
100万回ぐらい調べてみればダルみが軽減されていることが明確にわかる.翻訳者も翻訳するときに辞書を構築するらしいし (揺れを抑える意味合いもあるんだろうけど).


辞書.app 用の自作辞書の作り方は 付録: Dictionary Development Kit が参考になる

で,↓ みたいなのを ↑ のように自作していきたいなぁ,というお話がこの記事の主旨.(なお,英辞郎に関しては Mac 版はガワに 辞書.app が使われているので最新データを買うだけで ↑ を達成できる)

凡例

語義 (日本語)

語義 (英語)

▸ 例文

NOAD: New Oxford American Dictionary
WIS: ウィズダム英和辞典
英辞郎: 英辞郎
英文法: 安藤貞雄 現代英文法講義

語彙

footprint

the amount of memory or disk space required by a program
NOAD


gotcha

ドッキリ

(North American) an instance of publicly tricking someone or exposing them to ridicule, especially by means of an elaborate deception.
NOAD

good to go
  1. 《be ~》〈米俗〉用意[準備]ができている
  2. 《be ~》〈米俗〉予定[計画]どおりに進んでいる

▸ Now that I’ve explained all of this, you’re all good to go write your own compilers right?


look for

~を予期する,~を期待する
英辞郎

▸ Next we're going to look for CallExpressions.


module resolution

Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import { a } from "moduleA"; in order to check any use of a, the compiler needs to know exactly what it represents, and will need to check its definition moduleA.
https://www.typescriptlang.org/docs/handbook/module-resolution.html


nit

In the context of "nit: removed whitespace," I would assume that the term is short for nit-pick (* 虱潰し に近い). That is, a small change that may not be very important, but is technically correct.
https://stackoverflow.com/questions/27810522/what-does-nit-mean-in-hacker-speak


polyfill

In web development, a polyfill is code that implements a feature on web browsers that do not support the feature. Most often, it refers to a JavaScript library that implements an HTML5 web standard, either an established standard (supported by some browsers) on older browsers, or a proposed standard (not supported by any browsers) on existing browsers. Formally, "a polyfill is a shim for a browser API".
https://en.wikipedia.org/wiki/Polyfill_(programming)


take

〈関数などが〉(引数に)〈値など〉を受け取る

▸ For our parser we're going to take our array of tokens and turn it into an AST.

than A could ever hope to

could
直接法過去 能力:
 習慣的用法 (知覚・認識含む) または否定文においてのみ使用できる
仮定法過去 認識的可能性
英文法

ever
〖比較級・最上級の後で〗かつて, 今まで(に); まさに (!最上級のほかにfirst, last, onlyなどを強調)
WIS

1. A がこれまで (...することを) 望みえた以上に

▸ Yakaterinka Rukovsky, or Russia, as he called her, was perfect and a hundred times better in the net than Jake Holliday could ever hope to be.

▸ There are far more things to write about than I could ever hope to touch upon in a reasonably sized post so I cut it off short, but I hope that this was, if not informative, then at least amusing.

2. A が (...することを) 望むであろうぐらいに

▸ Watching Frankie grow into a talented and confident young girl has made Grace as happy as any mother could hope to be.

that is not to

(とはいえ,それは) 〜というわけではない

used to make sure the person you are talking to does not think something that is not true
https://www.ldoceonline.com/dictionary/that-is-not-to-say

▸ I’m quite happy in my job but that’s not to say I’m going to do it for the rest of my life.

付録: Dictionary Development Kit

以下は "/Developer/Extras/Dictionary Development Kit/documents/Dictionary Development Kit.rtf" からの引用 (macOS High Sierra)

TOC

  • [1] Abstract
  • [2] Prepare source data
  • [2-1] Dictionary contents XML
  • [2-2] StyleSheet
  • [2-3] Front/Back Matter
  • [2-4] Dictionary-specific Preference
  • [2-5] OtherResources
  • [2-6] Info.plist
  • [2-7] Makefile
  • [3] Build

[1] Abstract

This document describes how to build a new dictionary for Dictonary.app. Make a copy of 'project_template' folder to somewhere else. It is your project folder. And, do the following steps.

[2] Prepare source data

[2-1] Dictionary contents XML

Prepare dictionary contents as a file like MyDictionary.xml. It's encoding should be UTF-8. If you use different file name, you need to edit the variable 'DICT_SRC_PATH' in Makefile.

Please refer the documents below for the content schema. /Developer/Extras/Dictionary Development Kit/documents/Dictionary Format.rtf The schema is defined using RELAX NG (http://www.relaxng.org/). It is possible to validate the dictionary source using RELAX NG validator programs. (cf. http://www.relaxng.org/#validators )

It is highly recommended to validate your dictionary source before building new dictionary. For example, using Jing (http://www.thaiopensource.com/relaxng/jing.html), it is possible to validate a XML as below.
$ java -jar 'path of jing.jar' 'schema definition' 'XML to validate'
If you are in the project_template folder and Jing is at ../jing/, the command line would be as below.
$ java -jar ../jing/bin/jing.jar ../documents/DictionarySchema/AppleDictionarySchema.rng MyDictionary.xml

[2-2] StyleSheet

Need to prepare a style sheet to be used for the contents. You may edit the MyDictionary.css. If you use different file name, you need to edit the variable 'CSS_PATH' in Makefile.

[2-3] Front/Back Matter

The example dictionary in the project_template has Front/Back Matter page. It is implemented as an entry in the contents source file. The entry has the id "front_back_matter". The id for the purpose is defined in the Info.plist with the key DCSDictionaryFrontMatterReferenceID.

Please modify the content entry and the value of the DCSDictionaryFrontMatterReferenceID. If the dictionary doesn't have Front/Back Matter, the content entry and the Info.plist entry should be removed from the project_template.

[2-4] Dictionary-specific Preference

The project_template contains the example files for it.

OtherResources/
    MyDictionary_prefs.html
    MyDictionary.xsl

Please modify them and the corresponding entries in the Info.plist. i.e. DCSDictionaryDefaultPrefs, DCSDictionaryPrefsHTML, and DCSDictionaryXSL. If the dictionary doesn't have preference, these files and entries should be removed from the project_template.

[2-5] OtherResources

A dictionary might contain some pictures or some other resources. They should be placed in the 'OtherResources' folder in the 'project_template' folder. The contents of the folder are copied into the newly built dictionary while building the dictionary.

Suppose you place 'Images' folder, and placed 'test.png' in it.

OtherResources/
    Images/
        test.png

The 'Images' folder will be copied into the dictionary. The contents can be referred as relative path "Images/test.png" in the contents XML when using the dictionary.

[2-6] Info.plist

Edit each value of the followings in the Info.plist If you use different file name for this plist, you need to edit the variable 'PLIST_PATH' for it in Makefile.

<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>My Dictionary</string>
<key>CFBundleIdentifier</key>
<string>com.apple.dictionary.MySample</string>
<key>CFBundleName</key>
<string>MyDictionary</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>DCSDictionaryCopyright</key>
<string>Copyright © 2007 Apple Inc.</string>
<key>DCSDictionaryManufacturerName</key>
<string>Apple Inc.</string>

<key>DCSDictionaryFrontMatterReferenceID</key>
<string>front_back_matter</string>

<key>DCSDictionaryDefaultPrefs</key>
<dict>
  <key>pronunciation</key>
  <string>0</string>
  <key>version</key>
  <string>1</string>
</dict>
<key>DCSDictionaryPrefsHTML</key>
<string>MyDictionary_prefs.html</string>
<key>DCSDictionaryXSL</key>
<string>MyDictionary.xsl</string>

Below is the explanations for each items.

  • CFBundleDevelopmentRegion
    Please specify a region.

  • CFBundleDisplayName
    Full display name of the dictionary. If this is not supplied, the file-system name is used as alternated.

  • CFBundleIdentifier
    Identifier of the dictionary bundle. Please specify a unique ID.

  • CFBundleName
    Short display name of the dictionary.

  • CFBundleShortVersionString
    Version of the dictionary.

  • DCSDictionaryCopyright
    Copyright notice of the dictionary.

  • DCSDictionaryManufacturerName
    Manufacturer name of the dictionary.

  • DCSDictionaryFrontMatterReferenceID
    Entry ID of the Front/Back Matter page of the dictionary. If your dictionary doesn't have such entry, just remove the key/value pair. The document "Dictionary Format.rtf" explains how the value is used.

  • DCSDictionaryDefaultPrefs
    Default values for the dictionary-specific preferences. If your dictionary doesn't have preferences, just remove the key/value pair. The document "Dictionary Format.rtf" explains how the value is used.

  • DCSDictionaryPrefsHTML

  • DCSDictionaryXSL
    These entries indicate files used to implement the dictionary-specific preferences. If your dictionary doesn't have preferences, just remove the key/value pair. The document "Dictionary Format.rtf" explains how the value is used.

This file needs to be prepared as an XML text file. Binary format plist file can't be used to build dictionary. It is possible to convert binary plist to XML using plutil command.

[2-7] Makefile

You need to name the new dictionary. Edit 'DICT_NAME' for it. It is used as the folder name of the dictionary. When DICT_NAME ="My Dictionary", "My Dictionary.dictionary" will be created.

If this Dictionary Development Kit is installed at a different location from "/Developer/Extras/Dictionary Development Kit", you need to modify the 'DICT_BUILD_TOOL_DIR' value to reflect it.

As you can see from the Makefile, the building process is carried out by a script 'build_dict.sh' which is in "/Developer/Extra/Dictionary Development Kit/bin/". It takes 4 arguments --- dictionary_name, dictionary_source_path, StyleSheet_path, and InfoPlist_path. It builds new dictionary in ./objects folder. When you use the script directly, please set appropriate path of the build tool to the variable 'DICT_BUILD_TOOL_DIR' as Makefile is doing. The 'build_dict.sh' uses the variable to find sub-commands.

You can pass following options before other ordinary arguments to 'build_dict.sh' command:

"-e 1" When this option is specified, the body text data in the dictionary body file are encrypted. Both Dictionary.app and DictionaryServices.framework decrypt the data automatically when they use the content data.

"-v [10.5 | 10.6]" This option specify the minimum system version which the dictionary can work with. If specifying 10.6, the dictionary size will be smaller but not be usable with 10.5. Default value is 10.5.

[3] Build

Launch Terminal.app, and on the terminal window, 'cd' to your project folder. Type 'make'.

If it finished successfully, type 'make install' to install it. The new dictionary is copied into your ~/Library/Dictionaries/.

After installing, you can delete all intermediate files in 'objects' folder. Type 'make clean', and the 'objects' folder is removed.

Let's launch Dictionary.app and test it.