|
【注意】 このドキュメントは、ダブリン・コアの要素をHTMLで記述する方法を定めている、RFC 2731「Encoding Dublin Core Metadata in HTML」の和訳です。このドキュメントの正式版は英語版であり、このドキュメントには翻訳に起因する誤りがありえます。誤訳、誤植などのご指摘は、訳者までお願い致します。 First Update: 2005年11月20日Network Working Group J. Kunze HTMLによるダブリン・コア・メタデータのエンコードこのメモのステータスこのメモは、インターネット・コミュニティのための情報を提供するものです。いかなる種類のインターネットの規格も指定しません。このメモの配布には制限はありません。 著作権表示Copyright (C) The Internet Society (1999). All Rights Reserved. 1. 要約ダブリン・コア[DC1]は、情報資源を記述するためのメタデータ要素の小集合です。このドキュメントは、HTML[HTML4.0]のMETAとLINKタグを使用して、これらの要素をどのように表現できるかを説明しています。HTMLファイルに組み込まれたメタデータ要素の列は、そのファイルの記述であるととらみなされます。例では、[SWISH-E]、[freeWAIS-sf2.0]、[GLIMPSE]、[HARVEST]、[ISEARCH]などや、付録にあるPerl[PERL] スクリプトなどの、メタデータをインデキシング、表示、操作する現行のソフトウェアとの相互運用を可能にする仕様を示しています。 2. HTML、ダブリン・コア、ダブリン・コア以外ののメタデータダブリン・コア(DC)メタデータ・イニシアティブ[DCHOME]は、資源記述カテゴリー[DC1]の小集合であるメタデータ(文字通り、データに関するデータ)の要素を作成しました。通常、メタデータ要素は、記述する資源に比べて小さく、資源の形式が許す場合には、その資源に組み込むことができます。このような形式としては、HTML(Hypertext Markup Language)とXML(Extensible Markup Language)の2つがあげられます。HTMLは現在広く利用されていますが、Resource Description Framework[RDF]を併用したXML[XML]がいったん標準化されると、さらに豊かなメタデータのエンコードの表現手段が約束されます。[RDF]仕様では、省略構文を順守して、HTMLドキュメント内でRDFを実際に使用する方法を記述しています。 このドキュメントでは、HTML4.0[HTML4.0]を使用してメタデータをエンコードする方法を説明しています。このドキュメントは、要素のセマンティクスとは関係しておらず、これに関しては他の場所で定義されています。説明に役立つように、要素のセマンティクスの一部について触れますが、ここで掲載しているセマンティクスは決定的なものであると考えるべきではありません。 HTMLのエンコードでは、DCメタデータの要素をDC以外の要素と混在させることができます(このような混在がこれらの非以外のDC要素の使用を規定している規則と整合性がある場合は)。DC要素は接頭辞「DC」で示されます、そして、DC以外の要素は、例えばA-Core[AC]の要素には接頭辞「AC」を使用するなど、別の接頭辞で示します。 3. METAタグHTMLのMETAタグは、名前付きメタデータ要素をエンコードするように設計されています。各要素には、ドキュメントやその他の情報資源のある側面が記述されます。例えば、以下のタグ付きメタデータ要素
<meta name = "DC.Creator"
content = "Simpson, Homer">
は、Homer Simpsonが作者(Creator)であると述べており、作者(Creator)という要素をDC要素セットで定義しています。以下のより一般的な形式では、
<meta name = "PREFIX.ELEMENT_NAME"
content = "ELEMENT_VALUE">
大文字で書かれた単語を、実際の記述に置き換えます。従って、この例では以下のようになります。
ELEMENT_NAME は、 Creator
ELEMENT_VALUE は、 Simpson, Homer
そして、PREFIX は、 DC
METAタグ内では、ダブリン・コアの要素名の最初の文字は大文字です。DCでは、要素値におけるアルファベットの大文字小文字の違いや、同時に記述できるMETAタグ要素の数や、その順序に制限がありません。同じ名前の1つ以上のDC要素を記述でき、各DC要素はオプションです。次の例は、2人の著者、2つのタイトルを持ち、その他のメタデータを持たない本の記述です。
<meta name = "DC.Title"
content = "The Communist Manifesto">
<meta name = "DC.Creator"
content = "Marx, K.">
<meta name = "DC.Creator"
content = "Engels, F.">
<meta name = "DC.Title"
content = "Capital">
接頭辞「DC」がMETAを使用してエンコードされた各ダブリン・コア要素に先行し、ピリオド(.)によって後続の要素名と区切られています。各DC以外の要素は、その起源と定義を追跡するために使用できる接頭辞でエンコードすべきです。接頭辞と要素定義の間は、次項で説明するように、LINKタグでリンク付けされます。A-Core[AC]の電子メールといったDC以外の要素をDC要素と一緒に記述することもできます。
<meta name = "DC.Creator"
content = "Da Costa, José">
<meta name = "AC.Email"
content = "dacostaj@peoplesmail.org">
<meta name = "DC.Title"
content = "Jesse "The Body" Ventura--A Biography">
この例では、一部の特殊文字をどのようにエンコードできるかも示しています。最初の要素内の著者名には、HTML文字実体参照でエンコードされた付加記号が含まれています--この事例ではアクセント付きのE。同様に、最後の行には、要素コンテンツの区切り記号であると解釈されないようにエンコードされた2つのダブル引用符が含まれています。 4. LINKタグHTMLのLINKタグは、要素名接頭辞をそれが識別する要素集合の参照定義に関連付けるために使用できます。資源を記述しているMETAタグの列には、その列に出現する異なる接頭辞ごとに、この1つのLINKタグがなければ完全ではありません。前例に以下の2つのLINKタグを追加すれば、完全であると見なせます。
<link rel = "schema.DC"
href = "http://purl.org/DC/elements/1.0/">
<link rel = "schema.AC"
href = "http://metadata.net/ac/2.0/">
一般に、この関連付けは以下の形式をとります。 <link rel = "schema.PREFIX" href = "LOCATION_OF_DEFINITION">この場合、実際の記述では、PREFIXは接頭辞に置き換え、LOCATION_OF_DEFINITIONは定義しているドキュメントのURLやURNに置き換えます。LINKとMETAタグの列をHTMLファイルのHEAD部分に組み込むと、囲みこんでいるHTMLファイル自体の情報を記述していることになります。自身に記述を組み込んだ完全なHTMLファイルをここに掲載してあります。
<html>
<head>
<title> A Dirge </title>
<link rel = "schema.DC"
href = "http://purl.org/DC/elements/1.0/">
<meta name = "DC.Title"
content = "A Dirge">
<meta name = "DC.Creator"
content = "Shelley, Percy Bysshe">
<meta name = "DC.Type"
content = "poem">
<meta name = "DC.Date"
content = "1820">
<meta name = "DC.Format"
content = "text/html">
<meta name = "DC.Language"
content = "en">
</head>
<body><pre>
Rough wind, that moanest loud
Grief too sad for song;
Wild wind, when sullen cloud
Knells all the night long;
Sad storm, whose tears are vain,
Bare woods, whose branches strain,
Deep caves and dreary main, -
Wail, for the world's wrong!
</pre></body>
</html>
5. エンコードの推奨HTMLでは、原則的にも実際的にも、ここで推奨する以上にメタデータのエンコードに対して柔軟性が認められています。柔軟性を制限すると、メタデータを抽出し処理するソフトウェアの開発が用意になります。現在のようなインターネット・メタデータの初期発展段階では、簡単なプロトタイプの作成や実験によって、有用な規格の開発を促進することができます。 したがって、接頭辞と要素名の大文字表記、属性値のダブル引用符(")の付与、1行に1つ以上のMETAタグを開始しないことに関する、本ドキュメントで例示したタグ付け形式を順守することが推奨されます。柔軟性に対する余地は大いにありますが、形式を選択してそれを維持することにより、おそらくメタデータの取り扱いや編集がより簡単になると思われます。以下のMETAタグは、推奨を順守した3つの異る形式の同じメタデータを意味します。
<META NAME="DC.Format"
CONTENT="text/html; 12 Kbytes">
<meta
Content = "text/html; 12 Kbytes"
Name = "DC.Format"
>
<meta name = "DC.Format" content = "text/html; 12 Kbytes">
これらの推奨を使用すると、[SWISH-E]、[freeWAIS-sf2.0]、[GLIMPSE]、[HARVEST]、[ISEARCH]などの、有名で、自由に入手可能なソフトウェア・パッケージが収集、インデキシング、操作できるメタデータを作成できることが分かっています。これらの仕様は、付録に掲載されているメタデータ処理スクリプトでも機能しますし、[DCHOME]のサイトから参照されている大部分の[DCPROJECTS]アプリケーションでも機能します。LINKタグと修飾子の仕様(次項を参照)に対するソフトウェアのサポートは、現時点では広範囲ではありません。 メタデータ要素の順序は、通常は保持されません。メタデータのインデキシングや表示を行うソフトウェアの作者は、同じ名前を持つMETAタグが付与されている要素内の相対的な順序(例えば、複数の著者内の)を保持しようとするべきですが、メタデータを提供したり検索する人々には、未知のシステムを経由したメタデータの順序が保持されている保証はありません。 6. ダブリン・コアの実際の記述実際に資源を記述する際には、しばしば、ダブリン・コア要素を修飾して意味のニュアンスを加える必要があります。通則もDC修飾子の特定のセマンティクスもこのドキュメントの範囲ではありませんが、以後の例に現実感を与えるために、修飾子の構文の常用に関して例示しています。詳細な説明はしませんが、METAタグを補うために現在(変更される可能性あり)使用されている任意の修飾子の構文の3つの方法をまとめると以下のようになります。
<meta lang = "LANGUAGE_OF_METADATA_CONTENT" ... >
<meta scheme = "CONTROLLED_FORMAT_OR_VOCABULARY_OF_METADATA" ... >
<meta name = "PREFIX.ELEMENT_NAME.SUBELEMENT_NAME" ... >
従って、スペイン語の遺作は以下のように記述できます。
<meta name = "DC.Language"
scheme = "rfc1766"
content = "es">
<meta name = "DC.Title"
lang = "es"
content = "La Mesa Verde y la Silla Roja">
<meta name = "DC.Title"
lang = "en"
content = "The Green Table and the Red Chair">
<meta name = "DC.Date.Created"
content = "1935">
<meta name = "DC.Date.Available"
content = "1939">
このドキュメントの例で使用されている修飾子の構文とラベル接尾辞(要素名とピリオドに続く)は、修飾子のHTMLエンコードにおける現在の傾向を反映しているだけであるということに注意してください。この構文とこれらの接尾辞の使用は、標準でも推奨でもありません。 7. ダブリン・コア要素のエンコードこの項は、非常に簡単なダブリン・コアのエンコードの例で構成されており、要素順に並べられています。 タイトル(資源に与えられた名前)
<meta name = "DC.Title"
content = "Polycyclic aromatic hydrocarbon contamination">
<meta name = "DC.Title"
content = "Crime and Punishment">
<meta name = "DC.Title"
content = "Methods of Information in Medicine, Vol 32, No 4">
<meta name = "DC.Title"
content = "Still life #4 with flowers">
<meta name = "DC.Title"
lang = "de"
content = "Das Wohltemperierte Klavier, Teil I">
作者(コンテンツを作成したエンティティー)
<meta name = "DC.Creator"
content = "Gogh, Vincent van">
<meta name = "DC.Creator"
content = "van Gogh, Vincent">
<meta name = "DC.Creator"
content = "Mao Tse Tung">
<meta name = "DC.Creator"
content = "Mao, Tse Tung">
<meta name = "DC.Creator"
content = "Plato">
<meta name = "DC.Creator"
lang = "fr"
content = "Platon">
<meta name = "DC.Creator.Director"
content = "Sturges, Preston">
<meta name = "DC.Creator.Writer"
content = "Hecht, Ben">
<meta name = "DC.Creator.Producer"
content = "Chaplin, Charles">
主題(トピックあるいはキーワード)
<meta name = "DC.Subject"
content = "heart attack">
<meta name = "DC.Subject"
scheme = "MESH"
content = "Myocardial Infarction; Pericardial Effusion">
<meta name = "DC.Subject"
content = "vietnam war">
<meta name = "DC.Subject"
scheme = "LCSH"
content = "Vietnamese Conflict, 1961-1975">
<meta name = "DC.Subject"
content = "Friendship">
<meta name = "DC.Subject"
scheme = "ddc"
content = "158.25">
記述(アカウント、要約、コンテンツの抄録)
<meta name = "DC.Description"
lang = "en"
content = "The Author gives some Account of Himself and Family
-- His First Inducements to Travel -- He is
Shipwrecked, and Swims for his Life -- Gets safe on
Shore in the Country of Lilliput -- Is made a
Prisoner, and carried up the Country">
<meta name = "DC.Description"
content = "A tutorial and reference manual for Java.">
<meta name = "DC.Description"
content = "Seated family of five, coconut trees to the left,
sailboats moored off sandy beach to the right,
with volcano in the background.">
公開者(資源を利用可能にしたエンティティー)
<meta name = "DC.Publisher"
content = "O'Reilly">
<meta name = "DC.Publisher"
content = "Digital Equipment Corporation">
<meta name = "DC.Publisher"
content = "University of California Press">
<meta name = "DC.Publisher"
content = "State of Florida (USA)">
寄与者(寄与した別のエンティティー)
<meta name = "DC.Contributor"
content = "Curie, Marie">
<meta name = "DC.Contributor.Photographer"
content = "Adams, Ansel">
<meta name = "DC.Contributor.Artist"
content = "Sendak, Maurice">
<meta name = "DC.Contributor.Editor"
content = "Starr, Kenneth">
日付(資源の期間内のイベントの。[WTN8601]推奨)
<meta name = "DC.Date"
content = "1972">
<meta name = "DC.Date"
content = "1998-05-14">
<meta name = "DC.Date"
scheme = "WTN8601"
content = "1998-05-14">
<meta name = "DC.Date.Created"
content = "1998-05-14">
<meta name = "DC.Date.Available"
content = "1998-05-21">
<meta name = "DC.Date.Valid"
content = "1998-05-28">
<meta name = "DC.Date.Created"
content = "triassic">
<meta name = "DC.Date.Acquired"
content = "1957">
<meta name = "DC.Date.Accepted"
scheme = "WTN8601"
content = "1998-12-02T16:59">
<meta name = "DC.Date.DataGathered"
scheme = "ISO8601"
content = "98-W49-3T1659">
<meta name = "DC.Date.Issued"
scheme = "ANSI.X3.X30-1985"
content = "19980514">
型(性質やジャンル、カテゴリー。[DCT1]推奨)
<meta name = "DC.Type"
content = "poem">
<meta name = "DC.Type"
scheme = "DCT1"
content = "software">
<meta name = "DC.Type"
content = "software program source code">
<meta name = "DC.Type"
content = "interactive video game">
<meta name = "DC.Type"
scheme = "DCT1"
content = "dataset">
<meta name = "DC.Type"
content = "web home page">
<meta name = "DC.Type"
content = "web bibliography">
<meta name = "DC.Type"
content = "painting">
<meta name = "DC.Type"
content = "image; woodblock">
<meta name = "DC.Type"
scheme = "AAT"
content = "clipeus (portrait)">
<meta name = "DC.Type"
lang = "en-US"
content = "image; advertizement">
<meta name = "DC.Type"
scheme = "DCT1"
content = "event">
<meta name = "DC.Type"
content = "event; periodic">
フォーマット(物理的あるいはデジタルのデータ形式。オプションでサイズも)
<meta name = "DC.Format"
content = "text/xml">
<meta name = "DC.Format"
scheme = "IMT"
content = "text/xml">
<meta name = "DC.Format"
scheme = "IMT"
content = "image/jpeg">
<meta name = "DC.Format"
content = "A text file with mono-spaced tables and diagrams.">
<meta name = "DC.Format"
content = "video/mpeg; 14 minutes">
<meta name = "DC.Format"
content = "unix tar archive, gzip compressed; 1.5 Mbytes">
<meta name = "DC.Format"
content = "watercolor; 23 cm x 31 cm">
識別子(資源の)
<meta name = "DC.Identifier"
content = "http://foo.bar.org/zaf/">
<meta name = "DC.Identifier"
content = "urn:ietf:rfc:1766">
<meta name = "DC.Identifier"
scheme = "ISBN"
content = "1-56592-149-6">
<meta name = "DC.Identifier"
scheme = "LCCN"
content = "67-26020">
<meta name = "DC.Identifier"
scheme = "DOI"
content = "10.12345/33-824688ab">
情報源(資源の起源への参照)
<meta name = "DC.Source"
content = "Shakespeare's Romeo and Juliet">
<meta name = "DC.Source"
content = "http://a.b.org/manon/">
言語(資源のコンテンツの。[RFC1766]推奨)
<meta name = "DC.Language"
content = "en">
<meta name = "DC.Language"
scheme = "rfc1766"
content = "en">
<meta name = "DC.Language"
scheme = "ISO639-2"
content = "eng">
<meta name = "DC.Language"
scheme = "rfc1766"
content = "en-US">
<meta name = "DC.Language"
content = "zh">
<meta name = "DC.Language"
content = "ja">
<meta name = "DC.Language"
content = "es">
<meta name = "DC.Language"
content = "de">
<meta name = "DC.Language"
content = "german">
<meta name = "DC.Language"
lang = "fr"
content = "allemand">
関係(関連する資源への参照)
<meta name = "DC.Relation.IsPartOf"
content = "http://foo.bar.org/abc/proceedings/1998/">
<meta name = "DC.Relation.IsFormatOf"
content = "http://foo.bar.org/cd145.sgml">
<meta name = "DC.Relation.IsVersionOf"
content = "http://foo.bar.org/draft9.4.4.2">
<meta name = "DC.Relation.References"
content = "urn:isbn:1-56592-149-6">
<meta name = "DC.Relation.IsBasedOn"
content = "Shakespeare's Romeo and Juliet">
<meta name = "DC.Relation.Requires"
content = "LWP::UserAgent; HTML::Parse; URI::URL;
Net::DNS; Tk::Pixmap; Tk::Bitmap; Tk::Photo">
範囲(コンテンツの限度や範囲)
<meta name = "DC.Coverage"
content = "US civil war era; 1861-1865">
<meta name = "DC.Coverage"
content = "Columbus, Ohio, USA; Lat: 39 57 N Long: 082 59 W">
<meta name = "DC.Coverage"
scheme = "TGN"
content = "Columbus (C,V)">
<meta name = "DC.Coverage.Jurisdiction"
content = "Commonwealth of Australia">
権利(権利管理ステートメントのテキストや識別子)
<meta name = "DC.Rights"
lang = "en"
content = "Copyright Acme 1999 - All rights reserved.">
<meta name = "DC.Rights"
content = "http://foo.bar.org/cgi-bin/terms">
8. セキュリティ問題ここで文書化されているHTMLでダブリン・コア・メタデータをエンコードするための構文規則によって、コンピュータやネットワークへが直接危険に晒されることはありません。この規則を用いて、不正確であったり、故意に誤りを発生させることさえある(「インデックス・スパム」の形で迷惑を与える)メタデータをエンコードできますが、これはダブリン・コア・セットのメタデータのエンコードに制限らず、HTML METAタグの乱用の一般的なパターンを映し出しています。従来のメタデータ・エンコード・スキーム(例えば、[MARC])の生産の品質は、平均的なウェブサイトの品質を大いに上回る状況にありますが、そのようなスキーマでも不正確さを免れないわけではありません。 METAタグでエンコードしたメタデータを処理するシステムは、正確性と妥当性に関する問題をその設計と実装の一部として考慮する必要があり、そのようなシステムのユーザは、設計と実装の条件を考慮する必要があります。メタデータ来歴ステートメントの追加や、メタデータのデジタル署名による署名、メタデータ作成の部分的な自動化などの様々なアプローチがアプリケーションと関連しているかもしれませんが、これらは、このドキュメントや、このドキュメントで記述する基本的なMETAタグ構文のはるか範囲外にあります。 9. 付録 -- HTMLでエンコードしたメタデータを操作するPerlスクリプトこの項には、バージョン4と5のPerl[PERL]スクリプト言語インタプリタで動作する2つの簡単なプログラムが含まれています。これらは、自分の組織の必要性に応じてや、調査企画書、ベンチャー投資の入札などに自由に適用することができます。これらのスクリプトで構築すれば、実装者は様々なアプリケーションを容易に実現できます。 スクリプト1: メタデータ・フォーマット変換 以下に、このドキュメント内のすべてのメタデータ・エンコードの例を正しく認識する簡単なPerlスクリプトを示しています。これは、スクリプト作成のわずかな努力によって、ある形式から別の形式にメタデータを変換するユーティリティを作成できるということを示しています。マイナー・チェンジで十分に多くの出力形式をサポートできます。
#!/depot/bin/perl
#
# This simple perl script extracts metadata embedded in an HTML file
# and outputs it in an alternate format. Issues warning about missing
# element name or value.
#
# Handles mixed case tags and attribute values, one per line or spanning
# several lines. Also handles a quoted string spanning multiple lines.
# No error checking. Does not tolerate more than one "<meta" per line.
print "@(urc;\n";
while (<>) {
next if (! /<meta/i);
($meta) = /(<meta.*$)/i;
if (! /<meta.*>/i) {
while (<>) {
$meta .= $_;
last if (/>/);
}
}
$name = $meta =~ /name\s*=\s*"([^"]*)"/i
? $1 : "MISSING ELEMENT NAME";
$content = $meta =~ /content\s*=\s*"([^"]*)"/i
? $1 : "MISSING ELEMENT VALUE";
($scheme) = $meta =~ /scheme\s*=\s*"([^"]*)"/i;
($lang) = $meta =~ /lang\s*=\s*"([^"]*)"/i;
if ($lang || $scheme) {
$mod = " ($lang";
if (! $scheme)
{ $mod .= ")"; }
elsif (! $lang)
{ $mod .= "$scheme)" }
else
{ $mod .= ", $scheme)"; }
}
else
{ $mod = ""; }
print " @|$name$mod; $content\n";
}
print "@)urc;\n";
# ---- end of Perl script ----
LINKタグの項(4項)のメタデータ・ファイルの例に変換スクリプトを実行すると、以下が出力されます。
@(urc;
@|DC.Title; A Dirge
@|DC.Creator; Shelley, Percy Bysshe
@|DC.Type; poem
@|DC.Date; 1820
@|DC.Format; text/html
@|DC.Language; en
@)urc;
スクリプト2: メタデータの自動作成 プリセットや計算済みのデフォルトの提供、構文の検証、値の範囲の検証、スペル・チェックなどの処理を自動化によってアシストしなければ、高品質なメタデータの作成と維持には非常にコストがかかりえます。スクリプトによって、個々のメタデータ提供者の負担を各ドキュメントのタイトルのみにまで軽減できれば、かなり楽になります。以下はそのようなスクリプトの1つです。これによって、HTMLドキュメントの提供者は、類似した1つのHTMLコメント・ステートメントを用いて、組み込み資源の記述全体を簡略化できます。
<!--metablock Little Red Riding Hood -->
我々のスクリプトは、特に、タイトル付きの一種の「メタデータ・ブロック」宣言としてこのステートメントを処理します。一般的な形式は以下のとおりです。
<!--metablock TITLE_OF_DOCUMENT -->
このステートメントは、スクリプトがこれを完全なメタデータの記述に置き換え、その他の置き換えを生じさせるという点において、「ウェブのSSI(server-side include)」と非常に似た動作をします。このスクリプトをインストールすると、ウェブ・サーバ・プロシージャー作成への統合に適したHTMLファイルを出力できます。 個々の提供者は、メタデータ要素の変化の少ないプリセット値の「テンプレート」ファイルを別個に維持します。提供者のニーズが簡単なものであれば、ドキュメントごとに異なるタイトル以外の要素の値のみを、自動的に作成できます。このスクリプトを使用すれば、テンプレート内やドキュメント内からの変数として値を参照できます。我々の変数参照は、「(--mbVARNAME)」の形式を持っており、以下は、テンプレート内でどのように記述されているかを示しています。
<title> (--mbtitle) </title>
<meta name = "DC.Creator"
content = "Simpson, Homer">
<meta name = "DC.Title"
content = "(--mbtitle)">
<meta name = "DC.Date.Created"
content = "(--mbfilemodtime)">
<meta name = "DC.Identifier"
content = "(--mbbaseURL)/(--mbfilename)">
<meta name = "DC.Format"
content = "text/html; (--mbfilesize)">
<meta name = "DC.Language"
content = "(--mblanguage)-BUREAUCRATESE">
<meta name = "RC.MetadataAuthority"
content = "Springfield Nuclear">
<link rel = "schema.DC"
href = "http://purl.org/DC/elements/1.0/">
<link rel = "schema.RC"
href = "http://nukes.org/ReactorCore/rc">
上記のテンプレートは、変数参照が実際の値に置き換えられた時にドキュメントに記述されるメタデータを表しています。我々のスクリプトの仕様によって、以下の変数がテンプレートとドキュメントの両方において置き換えられるでしょう。
(--mbfilesize) 最終出力ファイルのサイズ
(--mbtitle) ドキュメントのタイトル
(--mblanguage) ドキュメントの言語
(--mbbaseURL) ドキュメント識別子の開始部分
(--mbfilename) 識別子の最終部分(.htmlを差し引いた)
(--mbfilemodtime) ドキュメントの最終変更日
このスクリプトを実行するHTMLファイルの例は以下のとおりです。
<html>
<head>
<!--metablock Nutritional Allocation Increase -->
<meta name = "DC.Type"
content = "Memorandum">
</head>
<body>
<p>
From: Acting Shift Supervisor
To: Plant Control Personnel
RE: (--mbtitle)
Date: (--mbfilemodtime)
<p>
Pursuant to directive DOH:10.2001/405aec of article B-2022,
subsection 48.2.4.4.1c regarding staff morale and employee
productivity standards, the current allocation of doughnut
acquisition funds shall be increased effective immediately.
</body>
</html>
ドキュメント全体に置き換えが行われるため、提供者は、2度ではなく1度だけタイトルを入力すればよいということに注意してください(タイトルは通常、HTMLのヘッダーに1度入力し、HTML本体に再度入力しなければなりません)。このスクリプトの実行後、上記のファイルは以下のように変ります。
<html>
<head>
<title> Nutritional Allocation Increase </title>
<meta name = "DC.Creator"
content = "Simpson, Homer">
<meta name = "DC.Title"
content = "Nutritional Allocation Increase">
<meta name = "DC.Date.Created"
content = "1999-03-08">
<meta name = "DC.Identifier"
content = "http://moes.bar.com/doh/homer.html">
<meta name = "DC.Format"
content = "text/html; 1320 bytes">
<meta name = "DC.Language"
content = "en-BUREAUCRATESE">
<meta name = "RC.MetadataAuthority"
content = "Springfield Nuclear">
<link rel = "schema.DC"
href = "http://purl.org/DC/elements/1.0/">
<link rel = "schema.RC"
href = "http://nukes.org/ReactorCore/rc">
<meta name = "DC.Type"
content = "Memorandum">
</head>
<body>
<p>
From: Acting Shift Supervisor
To: Plant Control Personnel
RE: Nutritional Allocation Increase
Date: 1999-03-08
<p>
Pursuant to directive DOH:10.2001/405aec of article B-2022,
subsection 48.2.4.4.1c regarding staff morale and employee
productivity standards, the current allocation of doughnut
acquisition funds shall be increased effective immediately.
</body>
</html>
この変換を完遂するスクリプトは以下のとおりです。
#!/depot/bin/perl
#
# This Perl script processes metadata block declarations of the form
# <!--metablock TITLE_OF_DOCUMENT --> and variable references of the
# form (--mbVARNAME), replacing them with full metadata blocks and
# variable values, respectively. Requires a "template" file.
# Outputs an HTML file.
#
# Invoke this script with a single filename argument, "foo". It creates
# an output file "foo.html" using a temporary working file "foo.work".
# The size of foo.work is measured after variable replacement, and is
# later inserted into the file in such a way that the file's size does
# not change in the process. Has little or no error checking.
$infile = shift;
open(IN, "< $infile")
or die("Could not open input file \"$infile\"");
$workfile = "$infile.work";
unlink($workfile);
open(WORK, "+> $workfile")
or die("Could not open work file \"$workfile\"");
@offsets = (); # records locations for late size replacement
$title = ""; # gets the title during metablock processing
$language = "en"; # pre-set language here (not in the template)
$baseURL = "http://moes.bar.com/doh"; # pre-set base URL here also
$filename = "$infile.html"; # final output filename
$filesize = "(--mbfilesize)"; # replaced late (separate pass)
($year, $month, $day) = (localtime( (stat IN) [9] ))[5, 4, 3];
$filemodtime = sprintf "%s-%02s-%02s", 1900 + $year, 1 + $month, $day;
sub putout { # outputs current line with variable replacement
if (! /\(--mb/) {
print WORK;
return;
}
if (/\(--mbfilesize\)/) # remember where it was
{ push @offsets, tell WORK; } # but don't replace yet
s/\(--mbtitle\)/$title/g;
s/\(--mblanguage\)/$language/g;
s/\(--mbbaseURL\)/$baseURL/g; s/\(--mbfilename\)/$filename/g;
s/\(--mbfilemodtime\)/$filemodtime/g;
print WORK;
}
while (<IN>) { # main loop for input file
if (! /(.*)<!--metablock\s*(.*)/) {
&putout;
next;
}
$title = $2;
$_ = $1;
&putout;
if ($title =~ s/\s*-->(.*)//) {
$remainder = $1;
}
else {
while (<IN>) {
$title .= $_;
last if (/(.*)\s*-->(.*)/);
}
$title .= $1;
$remainder = $2;
}
open(TPLATE, "< template")
or die("Could not open template file");
while (<TPLATE>) # subloop for template file
{ &putout; }
close(TPLATE);
$_ = $remainder;
&putout;
}
close(IN);
# Now replace filesize variables without altering total byte count.
select( (select(WORK), $| = 1) [0] ); # first flush output so we
if (($size = -s WORK) < 100000) # can get final file size
{ $scale = 0; } # and set scale factor or
else { # compute it, keeping width of size field low
for ($scale = 0; $size >= 1000; $scale++)
{ $size /= 1024; }
}
$filesize = sprintf "%7.7s %sbytes",
$size, (" ", "K", "M", "G", "T", "P") [$scale];
foreach $pos (@offsets) { # loop through saved size locations
seek WORK, $pos, 0; # read the line found there
$_ = <WORK>;
# $filesize must be exactly as wide as "(--mbfilesize)"
s/\(--mbfilesize\)/$filesize/g;
seek WORK, $pos, 0; # rewrite it with replacement
print WORK;
}
close(WORK);
rename($workfile, "$filename")
or die("Could not rename \"$workfile\" to \"$filename\"");
# ---- end of Perl script ----
10. 著者の住所John A. Kunze Fax: +1 415-476-4653 11. 参考文献
12. 著作権表示全文Copyright (C) The Internet Society (1999). All Rights Reserved. 上記の著作権表示およびこの段落が、すべての複製物や派生著作物に含まれていれば、このドキュメントとその翻訳を複製し他者に提供でき、コメントや説明を加えた、または、実装を支援する派生著作物を、全体・部分を問わずいかなる類の制限なしに作成、複製、出版、配布しても構いません。しかし、このドキュメント自体には、インターネット標準化プロセスで定義されている著作権の手順に従う必要があるインターネット標準の開発のために必要である場合や、英語以外の言語に翻訳する必要がある場合を除き、インターネット協会やその他のインターネット組織の著作権情報やこれの機関への参照を削除するなどの、いかなる方法によっても変更を加えてはなりません。 上記で与えられた条件付きの承認は永続的なものであり、インターネット協会や、その後継者または譲受人によって取り消されることはありません。 このドキュメントおよびここに含まれている情報は「現状のまま」で提供されており、インターネット協会およびインターネット・エンジニアリング・タスク・フォースは、ここにある情報の使用がいかなる権利をも侵害しないという保証や、特定目的に対する市場性や適合性のいかなる黙示保証を含む(しかし、これに限定されない)、明示または黙示を問わないすべての保証から免責されます。 謝辞RFC編集機能の基金は現在、インターネット協会によって提供されています。 CyberLibrarian : tips on computer for librarians, 1998-
|