全站通知:

帮助:SMW/查询条件运算符

来自bilibili游戏中心 - WIKI
跳到导航 跳到搜索

[1]

语义MediaWiki提供了不同的查询运算符,以使用户通过复杂查询条件来实现查询需求。

注意:比较器仅适用于属性值,不适用于类别条件!!

通配符

通配符写为 "+" ,并且在给定条件下允许使用任何值。例如,[[攻击::+]],将返回具有属性“攻击”的所有页面。请注意,"+" 只能单独使用。有关通配符 "*" 和 "?" ,请参阅 类似于,不类似于 部分。

比较符

比较操作符是<>之类的特殊符号。 在属性条件里面,它们放在::后面。

  • >>:"大于"
  • <<:"小于"
  • >:默认为"大于等于",而当$smwStrictComparators = true;的时候,则为"大于"
  • <:默认为"小于等于",而当$smwStrictComparators = true;的时候,则为"小于"
  • :"大于等于"
  • :"小于等于"
  • !:"非"("不等于")
  • ~:«like»(类似于)字符串的模糊比较
  • !~:«not like»(不类似于)字符串的模糊比较

例如,

 [[攻击::>>400]]

比较符仅适用于属性值,不适用于类别。

若需限制哪些比较符可用,可由管理员修改配置参数 $smwgQComparators 来完成。

Depending on the value set to 模板:Config, interpretation of > and < can differ; the different behaviours are documented on the page about strict comparators.

When applying comparators to pages, then the title of the page (without namespace prefix) is used. However, this can be changed by setting another MediaWiki sortkey for that page, e.g. {{DEFAULTSORTKEY:custom key}}. Please mark that this applies to all comparators, including ! and ~. It is not possible to have multiple sortkeys for one page. In particular, redirect pages are not taken into account when applying comparators.

不等于

可以查询不等于某属性值的页面。例如,

 [[攻击::!400]]

将返回属性"攻击"不等于400的页面。请注意!此查询条件只可处理包含指定属性的页面,若页面未设置该属性则不在查询范围内。

类似于,不类似于

比较符 ~!~ 只可生效于属性的数据类型为 String and Page (SMW ≤ 1.7.x) or Text and Page (SMW ≥ 1.8.x) and since 模板:Release also for 模板:DataTypegh:smw:1129, 模板:DataTypegh:smw:1129 and 模板:DataTypegh:smw:1178. In a like condition, one uses "*" wildcards to match any sequence of characters and "?" to match any single character. For example, one could ask [[Address::~*Park Place*]] to select addresses containing the string "Park Place", or [[Honorific::~M?.]] to select both "Mr." and "Ms.".

Note that in case of 模板:DataType (SMW ≤ 1.7.x) all 255 storable characters are searchable, in case of 模板:DataType (SMW ≥ 1.8.x) only the first 40 characters (if more than 72 characters were stored as property value) or all 72 characters (if a maximum of 72 characters were stored as property value) are searchable as explained.[2]. For 模板:DataType all 255 characters are searchable (all SMW versions).

Also note that some special characters need masking when used in combination with comparator "~".

Example

Property "Path" of 模板:DataType holds something like "n:\path\morepath" as data value. To query for all pages that contain "n:\path\..." in property "Path" you need to mask the backslashes "\" to your query like this:

{{#ask:
 [[Path::~n:\\path\\+]]
  ...
}}

模板:Release and later supports another notation: like: and nlike:, which relies on the standard LIKE / NOT LIKE SQL syntax for a pattern match.gh:smw:2558

模板:Callout

关系符

大于等于,小于等于

With numeric values, you often want to select pages with property values within a certain range. For example

 [[Category:Actor]] [[height::>6 ft]] [[height::<7 ft]]

asks for all actors that are between 6 feet and and 7 feet tall. Note that this takes advantage of the automatic unit conversion: even if the height of the actor was set with [[Height::195cm]] it would be recognized as a correct answer (provided that the datatype for height understands both units, see Help:Custom units). Note that the comparator means greater/less than or equal – the equality symbol "=" is not needed.

It is also possible to describe this with OR conditions:gh:smw:1043:106536707

 [[Category:Actor]] [[height::>6 ft||<7 ft]]

Such range conditions on property values are mostly relevant if values can be ordered in a natural way. For example, it makes sense to ask [[Start date::>May 6 2006]] but it is not really helpful to say [[Homepage URL::>https://www.example.org]].

If a datatype has no natural linear ordering, Semantic MediaWiki will just apply the alphabetical order to the normalised datavalues as they are used in the RDF export. You can thus use greater than and less than to select alphabetic ranges of a property of 模板:DataType. For example, you could ask [[Surname::>Do]] [[Surname::<G]] to select surnames between "Do" and up to "G". For wiki pages, the comparator refers to the name of the given page (without the namespace prefix).

Here and in all other uses of comparators, it might happen that a searched for value really starts with a symbol like <. In this case, SMW can be prevented from interpreting the symbol as a comparator if a space is inserted after ::. For example, [[Property:: <br>]] really searches for pages with the value "<br>" for the given property.

大于,小于

At times you might want to exclude the precise value from the result itself, e.g. to find an actor taller than Hugh Laurie (1.89m), you can query using a combination of the ">" comparator and the "!" comparator:

 [[Category:Actor]] [[height::>1.89m]] [[height::!1.89m]]

Strict comparators

The default behaviour of SMW, where comparators < and > mean "less than or equal" and "greater than or equal", can be somewhat confusing for people that are familiar with the mathematical meaning of < and >. Thus you can choose to have SMW interpret < and > "strict", as explained here.

Values containing operator symbols

Cases may occur where the value of a given property starts with one of the following symbols: <, ≤, >, ≥, =, ! and ~. To assure that Semantic MediaWiki can handle those cases, value notations are white-space sensitive. To avoid confusion a space is inserted after ::. For example, [[Property:: <br>]] really searches for pages with the value "<br>" for the given property.

Case insensitivity

Starting with 模板:Releasegh:smw:1912gh:smw:2499 it is possible to enable case insensitive matching for properties of e.g. 模板:DataType, 模板:DataType, 模板:DataType and 模板:DataType (blob types, i.e. strings or text) using the SMW_FIELDT_CHAR_NOCASE option to 模板:Config.

模板:Callout

The following four examples will provide an overview of the general differences between having this feature enabled or not:

Example 1

Property "Has text" of datatype "Text" holds "CAseInSensitiveSearch" as data value on page "Example". If enabled queries No. 1 to 3 and if not (default) queries No. 1 to 3 will also select page "Example":

  1. {{#ask: [[Has text::~CASEIN*]] |?Has text }}
  2. {{#ask: [[Has text::~casein*]] |?Has text }}
  3. {{#ask: [[Has text::~CAseIn*]] |?Has text }}
Example 2

Property "Has page" of datatype "Page" holds "CAseInSensitiveSearch" as data value on page "Example". If enabled queries No. 1 and 2 and if not (default) query No. 3 will select page "Example":

  1. {{#ask: [[Has page::~CASEIN*]] |?Has page }}
  2. {{#ask: [[Has page::~casein*]] |?Has page }}
  3. {{#ask: [[Has page::~CAseIn*]] |?Has page }}
Example 3

Property "Has text" of datatype "Text" holds "CAseIn" as data value on page "Example". If enabled queries No. 1 to 3 and if not (default) query No. 3 will select page "Example":

  1. {{#ask: [[Has text::CASEIN]] |?Has text }}
  2. {{#ask: [[Has text::casein]] |?Has text }}
  3. {{#ask: [[Has text::CAseIn]] |?Has text }}
Example 4

Property "Has page" of datatype "Page" holds "CAseIn" as data value on page "Example". If enabled query No. 3 and if not (default) query No. 3 will select page "Example":

  1. {{#ask: [[Has page::CASEIN]] |?Has page }}
  2. {{#ask: [[Has page::casein]] |?Has page }}
  3. {{#ask: [[Has page::CAseIn]] |?Has page }}