Help:Property constraints portal/Format

From Wikidata
Jump to navigation Jump to search
Translate this page;
Other languages:
Deutsch • ‎English • ‎français • ‎polski • ‎русский • ‎српски / srpski • ‎українська • ‎العربية • ‎中文

This page contains changes. Please contact a translation admin to mark them for translation.


Other languages:
Deutsch • ‎English • ‎français • ‎polski • ‎русский • ‎српски / srpski • ‎українська • ‎العربية • ‎中文
Pictogram voting regex.svg

format constraint (Q21502404) specifies that values for a property should conform to a certain pattern.

For example, the value for GNIS ID (P590) should always be a number with up to eight digits, without leading zeroes: [1-9][0-9]{0,7}.

The pattern is a regular expression, but the flavor varies: KrBot, which creates the database reports, uses PCRE; the WikibaseQualityConstraints extension, which powers Special:ConstraintReport and the gadget, uses the Wikidata Query Service, which currently uses java.util.regex, but might change to XQuery 1.0 / XPath 2.0 regular expressions ([1]?) as specified by SPARQL if BlazeGraph implements support for them. The flavors are mostly, but not entirely compatible; for compatibility with both constraint engines, stick to the common subset of the flavors.

If no constraint scope (P4680) is specified, this constraint is checked everywhere.

Possible actions[edit]

There are several possible ways to address a violation of this constraint:

  • The most likely case is that the value is malformed in some way. Often the fix is straightforward: add a missing prefix or remove one that should be implicit, add punctuation (e. g. add hyphens to an ISBN), fix capitalization, etc.
  • It’s possible that the value is correct, but does not belong to this property, and that it should be moved to a statement for a different property (e. g. ISBN-13 (P212) to ISBN-10 (P957)).
  • It’s possible that the identifier has expanded its range and the regex needs to be adapted (e.g. an identifier now uses up to 15 digits and not 10 as when it was first defined).
  • It’s possible that the item is a rare, but legitimate exception to the constraint, and nothing should be done.

Parameters[edit]

This constraint has one mandatory and one optional parameter:

format as a regular expression (P1793)
Contains the format / pattern. Must contain exactly one value (no value Help or unknown value Help is not permitted), which must be a valid regular expression.
syntax clarification (P2916)
Contains a human-readable description of the pattern. Can be specified several times in different languages.
Warning: format as a regular expression (P1793) is also often used as a top-level statement of a property, but this usage does not constitute a constraint: to specify a format constraint, a property constraint (P2302)  format constraint (Q21502404) statement with format as a regular expression (P1793) qualifier must be used.

Examples[edit]

Example 1[edit]

Values for image (P18) should end with certain file extension like .jpg or .png.

property constraint
Normal rank format constraint Arbcom ru editing.svg edit
format as a regular expression (?i).+\.(jpg|jpeg|png|svg|tif|tiff|gif|xcf)
▼ 0 reference
+ add reference
+ add value

Example 2[edit]

Using syntax clarification (P2916) parameter for explaining the regular expression in human-readable text. For example, value of IPA transcription (P898) doesn't contain : (colon) or ' (apostrophe). Correct character is ː (length) or ˈ (stress). This regular expression is difficult to understand without explanation.

property constraint
Normal rank format constraint Arbcom ru editing.svg edit
format as a regular expression [^:]+
syntax clarification colon is not a valid IPA character, the correct character for a length mark is ː (English)
▼ 0 reference
+ add reference
Normal rank format constraint Arbcom ru editing.svg edit
format as a regular expression [^']+
syntax clarification apostrophe is not a valid IPA character, the correct character for primary stress is ˈ (English)
▼ 0 reference
+ add reference
+ add value

Template[edit]

When the constraint is set to the property, the following template is automatically displayed in the property talk page. The template is created by Module:Constraints using Template:Constraint, invoked from Template:Property documentation. Translations are defined at Module:i18n/constraints.

Format “(?i).+\.(jpg|jpeg|png|svg|tif|tiff|gif|xcf|webp)|”: value must be formatted using this pattern (PCRE syntax). (Help)
Exceptions are possible as rare values may exist.
List of this constraint violations: Database reports/Constraint violations/P18#Format, SPARQL, SPARQL (new)

Lists[edit]

Lists of properties which are set format constraint.