<?xml version="1.0" encoding="UTF-8"?>
<!--
  「台風解析・予報情報（５日予報）」の構造（状況把握用）
  
  気象庁防災情報XMLフォーマット　技術資料
  http://xml.kishou.go.jp/tec_material.html
  の解説資料セット http://xml.kishou.go.jp/jmaxml_20120615_Manual(pdf).zip
  の「台風解析・予報情報電文（新形式）_解説資料.pdf」
  をもとにして３日予報を５日予報に改めたもの 
-->
<grammar xmlns:jx="http://xml.kishou.go.jp/jmaxml1/" xmlns:jb="http://xml.kishou.go.jp/jmaxml1/informationBasis1/" xmlns:je="http://xml.kishou.go.jp/jmaxml1/elementBasis1/" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:jm="http://xml.kishou.go.jp/jmaxml1/body/meteorology1/" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <start>
    <element name="jx:Report">
      <element name="jx:Control">
        <element name="jx:Title">
          <choice>
            <value>台風解析・予報情報（５日予報）</value>
            <value>台風解析・予報情報（３日予報）</value>
          </choice>
        </element>
        <element name="jx:DateTime">
          <ref name="utc_date_time"/>
        </element>
        <element name="jx:Status">
          <choice>
            <value>通常</value>
            <value>訓練</value>
            <value>試験</value>
          </choice>
        </element>
        <element name="jx:EditorialOffice">
          <value>気象庁本庁</value>
        </element>
        <element name="jx:PublishingOffice">
          <value>気象庁予報部</value>
        </element>
      </element>
      <element name="jb:Head">
        <element name="jb:Title">
          <value>台風解析・予報情報</value>
        </element>
        <!-- 発表時刻 -->
        <element name="jb:ReportDateTime">
          <ref name="jst_date_time"/>
        </element>
        <!-- 解析時刻 -->
        <element name="jb:TargetDateTime">
          <ref name="jst_date_time"/>
        </element>
        <element name="jb:TargetDuration">
          <choice>
            <value>PT120H</value>
            <a:documentation>(1) jx:Control/jx:Title と同じ情報を与える</a:documentation>
            <value>PT72H</value>
          </choice>
        </element>
        <!-- TC番号 -->
        <element name="jb:EventID">
          <data type="NMTOKEN">
            <param name="pattern">TC\d\d\d\d</param>
          </data>
        </element>
        <element name="jb:InfoType">
          <choice>
            <value>発表</value>
            <value>訂正</value>
            <value>取消</value>
          </choice>
        </element>
        <!-- 情報番号というが起算・加算条件は未詳 -->
        <element name="jb:Serial">
          <data type="nonNegativeInteger"/>
        </element>
        <element name="jb:InfoKind">
          <choice>
            <value>台風解析・予報情報（５日予報）</value>
            <a:documentation>(2) jx:Control/jx:Title と同じ</a:documentation>
            <value>台風解析・予報情報（３日予報）</value>
          </choice>
        </element>
        <element name="jb:InfoKindVersion">
          <value>1.0_0</value>
        </element>
        <element name="jb:Headline">
          <element name="jb:Text">
            <empty/>
          </element>
        </element>
      </element>
      <element name="jm:Body">
        <element name="jm:MeteorologicalInfos">
          <a:documentation>(3) 内部に jm:MeteorologicalInfo/jm:DateTime/@type=実況 は必ず存在する</a:documentation>
          <attribute name="type">
            <value>台風情報</value>
          </attribute>
          <oneOrMore>
            <element name="jm:MeteorologicalInfo">
              <element name="jm:DateTime">
                <a:documentation>(4) text() は一意
(5) @type は一意</a:documentation>
                <attribute name="type">
                  <choice>
                    <value>実況</value>
                    <value>推定　１時間後</value>
                    <value>予報　３時間後</value>
                    <value>予報　６時間後</value>
                    <value>予報　９時間後</value>
                    <value>予報　１２時間後</value>
                    <value>予報　１５時間後</value>
                    <value>予報　１８時間後</value>
                    <value>予報　２１時間後</value>
                    <value>予報　２４時間後</value>
                    <value>予報　４５時間後</value>
                    <value>予報　４８時間後</value>
                    <value>予報　６９時間後</value>
                    <value>予報　７２時間後</value>
                    <value>延長予報　９６時間後</value>
                    <value>延長予報　１２０時間後</value>
                  </choice>
                </attribute>
                <ref name="jst_date_time"/>
              </element>
              <element name="jm:Item">
                <optional>
                  <element name="jm:Kind">
                    <a:documentation>(6) 呼称は実況のみ存在、実況には必ず存在</a:documentation>
                    <element name="jm:Property">
                      <element name="jm:Type">
                        <value>呼称</value>
                      </element>
                      <element name="jm:TyphoonNamePart">
                        <element name="jm:Name">
                          <data type="string">
                            <param name="pattern">[\-A-Z]*</param>
                          </data>
                        </element>
                        <element name="jm:NameKana">
                          <ref name="all_katakana_or_empty"/>
                        </element>
                        <element name="jm:Number">
                          <optional>
                            <data type="nonNegativeInteger"/>
                          </optional>
                        </element>
                        <element name="jm:Remark">
                          <choice>
                            <empty/>
                            <value>台風発生</value>
                            <value>台風発生（域外から入る）</value>
                            <value>台風消滅（域外へ出る）</value>
                            <value>台風消滅（温帯低気圧化）</value>
                            <value>台風消滅（熱帯低気圧化）</value>
                            <value>台風発生の可能性が小さくなった</value>
                            <value>発表間隔変更（毎時から３時間毎）</value>
                            <value>発表間隔変更（３時間毎から毎時）</value>
                            <value>台風発生予想</value>
                            <value>温帯低気圧化しつつある</value>
                          </choice>
                        </element>
                      </element>
                    </element>
                  </element>
                </optional>
                <element name="jm:Kind">
                  <element name="jm:Property">
                    <element name="jm:Type">
                      <value>階級</value>
                    </element>
                    <element name="jm:ClassPart">
                      <a:documentation>(8) 後述</a:documentation>
                      <element name="je:TyphoonClass">
                        <a:documentation>(7) 空になるのは延長予報だけ</a:documentation>
                        <attribute name="type">
                          <value>熱帯擾乱種類</value>
                        </attribute>
                        <choice>
                          <empty/>
                          <ref name="typhoon_class"/>
                        </choice>
                      </element>
                      <optional>
                        <element name="je:AreaClass">
                          <a:documentation>(8-1) 実況・推定では常に AreaClass がある</a:documentation>
                          <attribute name="type">
                            <value>大きさ階級</value>
                          </attribute>
                          <!-- 実況・推定で大きさ階級を決定しないときは空になる -->
                          <choice>
                            <empty/>
                            <ref name="typhoon_size_class"/>
                          </choice>
                        </element>
                      </optional>
                      <optional>
                        <element name="je:IntensityClass">
                          <a:documentation>(8-2) 実況・推定・予報では常に IntensityClass がある</a:documentation>
                          <attribute name="type">
                            <value>強さ階級</value>
                          </attribute>
                          <choice>
                            <empty/>
                            <ref name="typhoon_intensity_class"/>
                          </choice>
                        </element>
                      </optional>
                    </element>
                  </element>
                </element>
                <element name="jm:Kind">
                  <element name="jm:Property">
                    <element name="jm:Type">
                      <value>中心</value>
                    </element>
                    <element name="jm:CenterPart">
                      <a:documentation>(9) 予報・延長予報には常に予報円 ProbabilityCircle がある
(10) 実況・推定には常に Coordinate 2つがある</a:documentation>
                      <choice>
                        <element name="jm:ProbabilityCircle">
                          <attribute name="type">
                            <value>予報円</value>
                          </attribute>
                          <ref name="basepoint_pair"/>
                          <ref name="radii_yohouen"/>
                        </element>
                        <ref name="coordinate_pair"/>
                      </choice>
                      <optional>
                        <element name="jm:Location">
                          <a:documentation>(11) 予報のうち、予報時間が２４未満で１２でないものでは欠く</a:documentation>
                          <text/>
                        </element>
                      </optional>
                      <element name="je:Direction">
                        <attribute name="type">
                          <value>移動方向</value>
                        </attribute>
                        <attribute name="unit">
                          <value>１６方位漢字</value>
                        </attribute>
                        <optional>
                          <attribute name="condition">
                            <value>不定</value>
                          </attribute>
                        </optional>
                        <optional>
                          <attribute name="description">
                            <value>不定</value>
                          </attribute>
                        </optional>
                        <!-- 空の実例はないが、予想される -->
                        <choice>
                          <empty/>
                          <ref name="direction_sixteen"/>
                        </choice>
                      </element>
                      <element name="je:Speed">
                        <attribute name="type">
                          <value>移動速度</value>
                        </attribute>
                        <attribute name="unit">
                          <value>ノット</value>
                        </attribute>
                        <attribute name="description"/>
                        <optional>
                          <attribute name="condition">
                            <choice>
                              <value>ゆっくり</value>
                              <value>ほとんど停滞</value>
                            </choice>
                          </attribute>
                        </optional>
                        <choice>
                          <empty/>
                          <data type="positiveInteger"/>
                        </choice>
                      </element>
                      <element name="je:Speed">
                        <a:documentation>(25) km/h単位の移動速度は ノット 単位の移動速度の関数</a:documentation>
                        <attribute name="type">
                          <value>移動速度</value>
                        </attribute>
                        <attribute name="unit">
                          <value>km/h</value>
                        </attribute>
                        <attribute name="description"/>
                        <optional>
                          <attribute name="condition">
                            <choice>
                              <value>ゆっくり</value>
                              <value>ほとんど停滞</value>
                            </choice>
                          </attribute>
                        </optional>
                        <choice>
                          <empty/>
                          <data type="positiveInteger"/>
                        </choice>
                      </element>
                      <optional>
                        <element name="je:Pressure">
                          <a:documentation>(12) 実況・推定・予報では常に Pressure がある</a:documentation>
                          <attribute name="type">
                            <value>中心気圧</value>
                          </attribute>
                          <attribute name="unit">
                            <value>hPa</value>
                          </attribute>
                          <attribute name="description"/>
                          <data type="positiveInteger"/>
                        </element>
                      </optional>
                    </element>
                  </element>
                </element>
                <optional>
                  <element name="jm:Kind">
                    <a:documentation>(13) 風は延長予報以外には常にある、ただし、Remark が
"台風消滅（温帯低気圧化）"
"台風消滅（熱帯低気圧化）"
"台風発生の可能性が小さくなった"
の場合はその限りでない</a:documentation>
                    <element name="jm:Property">
                      <element name="jm:Type">
                        <value>風</value>
                      </element>
                      <element name="jm:WindPart">
                        <!-- 最大風速と最大瞬間風速が、それぞれノット・米毎秒で書かれる -->
                        <element name="je:WindSpeed">
                          <a:documentation>(24) ノット単位の風速は m/s 単位の風速の関数</a:documentation>
                          <attribute name="type">
                            <value>最大風速</value>
                          </attribute>
                          <attribute name="unit">
                            <value>ノット</value>
                          </attribute>
                          <!--
                            中心の移動速度と異なり condition は
                            最大速度が得られた位置を特定するものであるらしい。
                            値「なし」は中心付近でない場所を示すらしく、
                            数値欠損の印ではない。
                          -->
                          <attribute name="condition">
                            <choice>
                              <value>中心付近</value>
                              <value>なし</value>
                            </choice>
                          </attribute>
                          <attribute name="description"/>
                          <data type="nonNegativeInteger"/>
                        </element>
                        <element name="je:WindSpeed">
                          <attribute name="type">
                            <value>最大風速</value>
                          </attribute>
                          <attribute name="unit">
                            <value>m/s</value>
                          </attribute>
                          <attribute name="condition">
                            <choice>
                              <value>中心付近</value>
                              <value>なし</value>
                            </choice>
                          </attribute>
                          <attribute name="description"/>
                          <data type="nonNegativeInteger"/>
                        </element>
                        <element name="je:WindSpeed">
                          <attribute name="type">
                            <value>最大瞬間風速</value>
                          </attribute>
                          <attribute name="unit">
                            <value>ノット</value>
                          </attribute>
                          <attribute name="description"/>
                          <data type="nonNegativeInteger"/>
                        </element>
                        <element name="je:WindSpeed">
                          <attribute name="type">
                            <value>最大瞬間風速</value>
                          </attribute>
                          <attribute name="unit">
                            <value>m/s</value>
                          </attribute>
                          <attribute name="description"/>
                          <data type="nonNegativeInteger"/>
                        </element>
                      </element>
                      <zeroOrMore>
                        <element name="jm:WarningAreaPart">
                          <a:documentation>(19) @type は Property 内で一意
(14) 実況・推定には常に強風域がある
(15) 暴風域はあるとすれば実況または推定
(20) 実況・推定において
     最大風速が 25 m/s に達していれば常に暴風域がある
(16) 暴風警戒域はあるとすれば予報
(21) 予報において
     最大風速が 25 m/s に達していれば常に暴風警戒域がある</a:documentation>
                          <attribute name="type">
                            <choice>
                              <value>暴風域</value>
                              <value>強風域</value>
                              <value>暴風警戒域</value>
                            </choice>
                          </attribute>
                          <element name="je:WindSpeed">
                            <attribute name="type">
                              <value>風速</value>
                            </attribute>
                            <attribute name="unit">
                              <value>ノット</value>
                            </attribute>
                            <attribute name="condition">
                              <value>以上</value>
                            </attribute>
                            <attribute name="description"/>
                            <data type="positiveInteger"/>
                          </element>
                          <element name="je:WindSpeed">
                            <attribute name="type">
                              <value>風速</value>
                            </attribute>
                            <attribute name="unit">
                              <value>m/s</value>
                            </attribute>
                            <attribute name="condition">
                              <value>以上</value>
                            </attribute>
                            <attribute name="description"/>
                            <data type="positiveInteger"/>
                          </element>
                          <element name="je:Circle">
                            <ref name="radii_of_wind"/>
                          </element>
                        </element>
                      </zeroOrMore>
                    </element>
                  </element>
                </optional>
                <element name="jm:Area">
                  <a:documentation>Item について、
(17) 実況・推定には常に強風域 Area が存在
(18) 予報・延長予報には常に予報円 Area が存在
都合、 Area は必ず一つ存在する</a:documentation>
                  <element name="jm:Name">
                    <value>熱帯低気圧</value>
                  </element>
                  <choice>
                    <element name="je:Circle">
                      <a:documentation>(22) 強風域 Area/Circle は WarningAreaPart/Circle と同一内容</a:documentation>
                      <attribute name="type">
                        <value>強風域</value>
                      </attribute>
                      <ref name="basepoint_pair"/>
                      <ref name="radii_of_wind"/>
                    </element>
                    <element name="je:Circle">
                      <a:documentation>(23) 予報円 Area/Circle は ProbabilityCircle と同一内容</a:documentation>
                      <attribute name="type">
                        <value>予報円</value>
                      </attribute>
                      <ref name="basepoint_pair"/>
                      <ref name="radii_yohouen"/>
                    </element>
                  </choice>
                </element>
              </element>
            </element>
          </oneOrMore>
        </element>
      </element>
    </element>
  </start>
  <!-- basepoint_pair と酷似構造であることを見やすくするため別ルール建て -->
  <define name="coordinate_pair">
    <element name="je:Coordinate">
      <attribute name="type">
        <value>中心位置（度）</value>
      </attribute>
      <optional>
        <!-- 消滅または発生可能性減のとき省略 -->
        <attribute name="condition">
          <choice>
            <value>正確</value>
            <value>ほぼ正確</value>
            <value>不確実</value>
          </choice>
        </attribute>
      </optional>
      <attribute name="description">
        <ref name="latlon_decimal_ja"/>
      </attribute>
      <ref name="latlon_decimal_ascii"/>
    </element>
    <element name="je:Coordinate">
      <attribute name="type">
        <value>中心位置（度分）</value>
      </attribute>
      <optional>
        <!-- 消滅または発生可能性減のとき省略 -->
        <attribute name="condition">
          <choice>
            <value>正確</value>
            <value>ほぼ正確</value>
            <value>不確実</value>
          </choice>
        </attribute>
      </optional>
      <attribute name="description">
        <ref name="latlon_sexagesimal_ja"/>
      </attribute>
      <ref name="latlon_sexagesimal_ascii"/>
    </element>
  </define>
  <!-- Area/Circle と CenterPart/ProbabilityCircle で使われる -->
  <define name="basepoint_pair">
    <element name="je:BasePoint">
      <attribute name="type">
        <value>中心位置（度）</value>
      </attribute>
      <attribute name="description">
        <ref name="latlon_decimal_ja"/>
      </attribute>
      <ref name="latlon_decimal_ascii"/>
    </element>
    <element name="je:BasePoint">
      <attribute name="type">
        <value>中心位置（度分）</value>
      </attribute>
      <attribute name="description">
        <ref name="latlon_sexagesimal_ja"/>
      </attribute>
      <ref name="latlon_sexagesimal_ascii"/>
    </element>
  </define>
  <!--
    Area/Circle[@type=強風域] と
    Kind/Property[Type='予報円']/WarningAreaPart/Circle で使う
  -->
  <define name="radii_of_wind">
    <element name="je:Axes">
      <choice>
        <!-- 強風域は、均等円か、偏心円で長径・短径を示す2つのAxisか -->
        <ref name="all_round_axis"/>
        <group>
          <ref name="ordinary_axis"/>
          <ref name="ordinary_axis"/>
        </group>
      </choice>
    </element>
  </define>
  <!-- 均等円の場合の Axes の中身 (読みやすさのため別ルール) -->
  <define name="all_round_axis">
    <element name="je:Axis">
      <element name="je:Direction">
        <attribute name="type">
          <value>方向</value>
        </attribute>
        <attribute name="unit">
          <value>８方位漢字</value>
        </attribute>
        <attribute name="description">
          <value>全域</value>
        </attribute>
        <optional>
          <attribute name="condition">
            <value>全域</value>
          </attribute>
        </optional>
        <optional>
          <ref name="direction_eight"/>
        </optional>
      </element>
      <!-- 偏心していない例が与えられていないが、意味的に用意すべき -->
      <element name="je:Radius">
        <attribute name="type">
          <value>半径</value>
        </attribute>
        <attribute name="unit">
          <value>海里</value>
        </attribute>
        <attribute name="description"/>
        <optional>
          <attribute name="condition">
            <value>なし</value>
          </attribute>
        </optional>
        <optional>
          <data type="integer"/>
        </optional>
      </element>
      <element name="je:Radius">
        <attribute name="type">
          <value>半径</value>
        </attribute>
        <attribute name="unit">
          <value>km</value>
        </attribute>
        <attribute name="description"/>
        <optional>
          <attribute name="condition">
            <value>なし</value>
          </attribute>
        </optional>
        <optional>
          <data type="integer"/>
        </optional>
      </element>
    </element>
  </define>
  <!-- 偏心円の場合の Axes の中身のひとつ -->
  <define name="ordinary_axis">
    <element name="je:Axis">
      <element name="je:Direction">
        <attribute name="type">
          <value>方向</value>
        </attribute>
        <attribute name="unit">
          <value>８方位漢字</value>
        </attribute>
        <ref name="direction_eight"/>
      </element>
      <element name="je:Radius">
        <attribute name="type">
          <value>半径</value>
        </attribute>
        <attribute name="unit">
          <value>海里</value>
        </attribute>
        <attribute name="description"/>
        <data type="positiveInteger"/>
      </element>
      <element name="je:Radius">
        <attribute name="type">
          <value>半径</value>
        </attribute>
        <attribute name="unit">
          <value>km</value>
        </attribute>
        <attribute name="description"/>
        <data type="positiveInteger"/>
      </element>
    </element>
  </define>
  <!-- Area/Circle[@type=予報円] と Kind[Property/Type='予報円'] で使う -->
  <define name="radii_yohouen">
    <element name="je:Axes">
      <!-- 予報円の場合は Axis は常に全方位で1つしかない -->
      <element name="je:Axis">
        <element name="je:Direction">
          <attribute name="type">
            <value>方向</value>
          </attribute>
          <attribute name="unit">
            <value>８方位漢字</value>
          </attribute>
          <attribute name="description">
            <value>全域</value>
          </attribute>
          <attribute name="condition">
            <value>全域</value>
          </attribute>
        </element>
        <element name="je:Radius">
          <attribute name="type">
            <value>７０パーセント確率半径</value>
          </attribute>
          <attribute name="unit">
            <value>海里</value>
          </attribute>
          <attribute name="description"/>
          <data type="positiveInteger"/>
        </element>
        <element name="je:Radius">
          <attribute name="type">
            <value>７０パーセント確率半径</value>
          </attribute>
          <attribute name="unit">
            <value>km</value>
          </attribute>
          <attribute name="description"/>
          <data type="positiveInteger"/>
        </element>
      </element>
    </element>
  </define>
  <!--
    
    以下はデータ型
    
  -->
  <define name="typhoon_class">
    <choice>
      <value>台風(TY)</value>
      <value>台風(STS)</value>
      <value>台風(TS)</value>
      <value>熱帯低気圧(TD)</value>
      <value>ハリケーン(Hurricane)</value>
      <value>発達した熱帯低気圧(Tropical Storm)</value>
      <value>温帯低気圧(LOW)</value>
    </choice>
  </define>
  <define name="typhoon_size_class">
    <choice>
      <value>大型</value>
      <value>超大型</value>
    </choice>
  </define>
  <define name="typhoon_intensity_class">
    <choice>
      <value>強い</value>
      <value>非常に強い</value>
      <value>猛烈な</value>
    </choice>
  </define>
  <define name="direction_eight">
    <choice>
      <value>北</value>
      <value>北東</value>
      <value>東</value>
      <value>南東</value>
      <value>南</value>
      <value>南西</value>
      <value>西</value>
      <value>北西</value>
    </choice>
  </define>
  <define name="direction_sixteen">
    <choice>
      <value>北</value>
      <value>北北東</value>
      <value>北東</value>
      <value>東北東</value>
      <value>東</value>
      <value>東南東</value>
      <value>南東</value>
      <value>南南東</value>
      <value>南</value>
      <value>南南西</value>
      <value>南西</value>
      <value>西南西</value>
      <value>西</value>
      <value>西北西</value>
      <value>北西</value>
      <value>北北西</value>
    </choice>
  </define>
  <define name="all_katakana_or_empty">
    <data type="string">
      <param name="pattern">[ァ-ー]*</param>
    </data>
  </define>
  <define name="utc_date_time">
    <data type="dateTime">
      <param name="pattern">\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ</param>
    </data>
  </define>
  <define name="jst_date_time">
    <data type="dateTime">
      <param name="pattern">\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\+09:00</param>
    </data>
  </define>
  <define name="latlon_decimal_ascii">
    <data type="string">
      <param name="pattern">\+\d\d\.\d[\-+]\d\d\d\.\d/</param>
    </data>
  </define>
  <define name="latlon_decimal_ja">
    <data type="string">
      <param name="pattern">北緯[０-９]+．[０-９]度[東西]経[０-９]+．[０-９]度</param>
    </data>
  </define>
  <define name="latlon_sexagesimal_ascii">
    <data type="string">
      <param name="pattern">\+\d\d\d\d[\-+]\d\d\d\d\d/</param>
    </data>
  </define>
  <define name="latlon_sexagesimal_ja">
    <data type="string">
      <param name="pattern">北緯[０-９]{2}度[０-９]{2}分[東西]経[０-９]{3}度[０-９]{2}分</param>
    </data>
  </define>
</grammar>
