[16] [DFN[[RUBYB[[[特徴述語]]]@en[feature predicate]]]]は、[[特徴集合]]に対する評価式です。

* 仕様書

[REFS[
- [1] [CITE@en[RFC 2295 - Transparent Content Negotiation in HTTP]] ([TIME[2014-08-31 19:36:42 +09:00]] 版) <http://tools.ietf.org/html/rfc2295#section-6.3>
]REFS]

* 意味

[4] [[特徴述語]]は、[[特徴集合]]の内容に関する[[述語]]です [SRC[>>1]]。

* 構文

[5] [[特徴述語]]は、[[特徴タグ]]か、[[特徴タグ]]の前に [CODE(HTTP)[[[!]]]]
を置いたものか、[[特徴タグ]]と値を [CODE(HTTP)[[[=]]]] または [CODE(HTTP)[[[!=]]]]
で結んだものか、[[特徴タグ]]と範囲を [CODE(HTTP)[[[=]]]] で結んだものです。 [SRC[>>1]]

[FIG(railroad)[
= |
== =
=== ?
==== [CODE(HTTP)[[[!]]]]
=== [[特徴タグ]]
== =
=== [[特徴タグ]]
=== |
==== [CODE(HTTP)[[[=]]]]
==== [CODE(HTTP)[[[!=]]]]
=== 値
== =
=== [[特徴タグ]]
=== [CODE(HTTP)[[[=]]]]
=== 範囲
]FIG]

[6] 範囲は、数値2つを [CODE(HTTP)[[[-]]]] で連結し、四角括弧で括ったものです。
ただし数値は省略できます。 [SRC[>>1]]

[FIG(railroad)[
= [CODE(HTTP)[[[''['']]]]
= [[OWS]]
= ?
== 数値
= [[OWS]]
= [CODE(HTTP)[[[-]]]]
= [[OWS]]
= ?
== 数値
= [[OWS]]
= [CODE(HTTP)[[['']'']]]]
]FIG]

[7] 数値の構文は明記されていません。例示は[[非負整数]]の[[ASCII数字]]列となっています。

[8] 仕様書の時代的背景から構文上[[空白]]が明示されていませんが、[[特徴タグ]]や値や数値の前後に
[[OWS]] を挿入できるものと推測されます。数値の前後に[[空白]]を挿入した例は示されています [SRC[>>1]]。

* 文脈

[3] [[変種説明]]の [CODE(HTTP)@en[[[features]]]] [[属性]]で使われます。

* 処理モデル

[9] [[利用者エージェント]]は[[特徴集合]]に対して[[特徴述語]]を次のように評価する[['''べきです''']] [SRC[>>1]]。

[FIG(steps)[
= [10] [[特徴タグ]]のみなら、その特徴が存在するかどうかを返します。
= [11] [[特徴タグ]]に [DFN[[CODE(HTTP)[[[!]]]]]] が付されているなら、
その特徴が存在しないかどうかを返します。
= [12] [[特徴タグ]]と [DFN[[CODE(HTTP)[[[=]]]]]] と値が示されているなら、
特徴がその値で存在するかどうかを返します。
= [13] [[特徴タグ]]と [DFN[[CODE(HTTP)[[[!=]]]]]] と値が示されているなら、
特徴がその値で存在しないかどうかを返します。
= [14] [[特徴タグ]]と範囲が示されているなら、
特徴が最低1つは数値として存在し、その最大値が範囲に含まれているかどうかを返します。
最初の数値が指定されていないなら 0、最後の数値が指定されていないなら[[∞]]とします。
]FIG]

;; [15] 範囲の最初の数値が最後の数値よりも大きな場合にどう解釈するのかは不明です。
また境界値を含むのかは不明です。

* 歴史

[FIG(quote)[
[FIGCAPTION[
[2] RFC 2295 (HTTP 透過内容折衝) 6.3 Feature predicates
]FIGCAPTION]

> Feature predicates are predicates on the contents of feature sets.
They appear in the features attribute of a variant description.

[DFN[特徴述語]]は、[[特徴集合]]の内容の[[述語]]です。
特徴述語は[[変種記述]]の [CODE(conneg)[[[feature]]]]
属性に出現します。

>
[PRE[
      fpred = [ "!" ] ftag
            | ftag ( "=" | "!=" ) tag-value
            | ftag "=" "[" numeric-range "]"

      numeric-range = [ number ] "-" [ number ]
]PRE]

> Feature predicates are used in features attributes (section 6.4),
which are used in variant descriptions (section 5).  Variant
descriptions can be transmitted in Alternates headers (section 8.3).

> Examples of feature predicates are
[PRE[
      blebber, !blebber, paper=a4, colordepth=5, blex!=54,
      dpi=[300-599], colordepth=[24-]
]PRE]

> Using the feature set of the current request, a user agent SHOULD
compute the truth value of the different feature predicates as follows.

>
: ftag      : true if the feature is present, false otherwise
: !ftag     : true if the feature is absent, false otherwise
: ftag=V    : true if the feature is present with the value V,
false otherwise,
: ftag!=V   : true if the feature is not present with the value V,
false otherwise,
: ftag=[N-M]: true if the feature is present with at least one
numeric value, while the highest value with which it
is present in the range N-M, false otherwise.  If N
is missing, the lower bound is 0.  If M is missing,
the upper bound is infinity.

> As an example, with the feature set
[PRE[
       { ( "blex"       , { } ),
         ( "colordepth" , { "5" } ),
         ( "UA-media"   , { "stationary" } ),
         ( "paper"      , { "A4", "A3" } ) ,
         ( "x-version"  , { "104", "200" } )
       }
]PRE]
the following predicates are true:
[PRE[
   blex, colordepth=[4-], colordepth!=6, colordepth, !screenwidth, UA-
   media=stationary, UA-media!=screen, paper=A4, paper =!A0,
   colordepth=[ 4 - 6 ], x-version=[100-300], x-version=[200-300]
]PRE]
and the following predicates are false:
[PRE[
      !blex, blebber, colordepth=6, colordepth=foo, !colordepth,
      screenwidth, screenwidth=640, screenwidth!=640, x-version=99, UA-
      media=screen, paper=A0, paper=a4, x-version=[100-199], wuxta
]PRE]
]FIG]
