DS Specifications
Domain SpecificationsListsVocabularies
main
main
  • DS Specifications Overview
  • Domain Specifications
    • DS-V7
      • DS-V7 - Changelog
      • DS-V7 - Developer Notes
      • DS-V7 - Grammar
        • Domain Specification
          • @Context
          • Domain Specification Node
          • Property Node
          • Class Node
          • DataType Node
          • Enumeration Node
        • Verification Report
          • Verification Report Node
          • Error Entry Node
          • Error List for the domain-specific verification
        • DS-Path
      • DS-V7 - Examples
    • DS-V6
    • DS-V5
      • DS-V5 - Grammar
        • VerificationReport
          • Error List for the basic verification
          • Verification of schema.org annotations
          • Error List for the Meta verification of DS (unfinished)
          • Error List for the DS-based verification
        • Grammar and semantics of Domain Specifications
          • Enumeration Node
          • Property Node
          • Domain Specification Node
          • Class Node
          • Terms used in Domain Specifications
          • @Context
          • DataType Node
      • DS-V5 - Examples
    • DS-V4
    • DS-V3
      • DS-V3 - Examples
      • DS-V3 - Grammar
        • VerificationReport
          • Error List for the basic verification
          • Verification of schema.org annotations
          • Error List for the DS-based verification
          • Error List for the Meta verification of DS
        • Grammar and semantics of Domain Specifications
          • SDO Enumeration
          • SDO Property
          • Domain Specification
          • SDO Class
          • SDO Datatype
          • @Context
    • DS-V2
      • DS-V2 - Grammar
        • Grammar and semantics of Domain Specifications
          • Grammar Documentation for node type "RestrictedEnumeration"
          • Grammar Documentation for node type "CustomEnumerationValue"
          • Grammar Documentation for node type "Enumeration"
          • Grammar Documentation for node type "Property"
          • Grammar Documentation for node type "RestrictedProperty"
          • Grammar Documentation for node type "DomainSpecification"
          • Grammar Documentation for node type "RestrictedClass"
          • Grammar Documentation for node type "EnumerationValue"
          • Grammar Documentation for node type "Class"
          • Grammar Documentation for node type "DataType"
        • Numeric Pattern
        • Grammar Documentation for node type "VerificationReport"
          • Grammar Documentation for node type "Error"
          • Error codes for Verification Reports
        • Rules Grammar
          • Grammar Documentation for node type "ComplexRule"
          • Grammar Documentation for node type "DateRule"
          • Grammar Documentation for node type "TextRule"
          • Grammar Documentation for node type "TimeRule"
          • Grammar Documentation for node type "NumberRule"
          • Grammar Documentation for node type "BooleanRule"
          • Grammar Documentation for node type "DateTimeRule"
      • DS-V2 - Examples
    • DS-V1
      • DS-V1 - Examples
      • DS-V1 - Grammar
  • SDO-Verification
  • Lists
    • List-V1
  • Vocabularies
  • DS-Vocabulary
    • Input
      • Vocabulary for Domain Specifications
      • DS-Vocabulary
    • DS-Vocab-V1
Powered by GitBook
On this page
  • matchesPattern
  • isInSet
  • isInteger
  • isFloat
  • hasDigitsLength
  • hasDecimalDigitsLength
  1. Domain Specifications
  2. DS-V2
  3. DS-V2 - Grammar
  4. Rules Grammar

Grammar Documentation for node type "NumberRule"

PreviousGrammar Documentation for node type "TimeRule"NextGrammar Documentation for node type "BooleanRule"

Last updated 4 years ago

NumberRules are rules that apply on values which have the data type "Number", "Integer" or "Float" from Schema.org.

The specific rule type is given by the value in the "$rule" property. The properties which rules can have are explained in the Meta_Rules.md document. Note that the "subject" property can be omitted, if the "$path" object has an empty JSON Pointer as value (see Meta_Rules.md for details).

However, the data type for the "parameter" depends on the "$rule" value (e.g. arguments for the rule function), and is explained in the following.

matchesPattern

The "matchesPattern" rule checks if a given number (the validated subject) matches a given numeric pattern.

{
  "$type": "NumberRule",
  "$rule": "matchesPattern",
  "subject": {
      "$path": "/starRating/ratingValue"
  },
  "parameter": "0-5"
}

The parameter is a numeric pattern (see Meta_NumericPattern.md) that serves as the second argument for the rule function. The given number (the validated subject) must match this pattern.

isInSet

The "isInSet" rule checks if a given number (the validated subject) is in the given set of allowed values.

{
  "$type": "NumberRule",
  "$rule": "isInSet",
  "parameter": [1,2.5,3.77,5,10]
}

The parameter" is an array which contains numbers, which are valid instances for the given number (the validated subject).

isInteger

{
  "$type": "NumberRule",
  "$rule": "isInteger",
  "parameter": true
}

The parameter is a boolean, that must match the outcome of the Integer check to fulfill the constraint.

isFloat

{
  "$type": "NumberRule",
  "$rule": "isFloat",
  "parameter": false
}

The parameter is a boolean, that must match the outcome of the Float check to fulfill the constraint.

hasDigitsLength

The "hasDigitsLength" rule checks the digit amount of a given number (the validated subject), that matches a given numeric pattern.

{
  "$type": "NumberRule",
  "$rule": "hasDigitsLength",
  "parameter": "<=5"
}

The parameter is a numeric pattern (see Meta_NumericPattern.md) that serves as the second argument for the rule function. The amount of digits must match the pattern.

The number of digits for Floats omit the floating point. -> String(VALUE).replace('.', '').length

hasDecimalDigitsLength

The "hasDecimalDigitsLength" rule checks the decimal digit amount of a given number (the validated subject), that matches a given numeric pattern.

{
  "$type": "NumberRule",
  "$rule": "hasDecimalDigitsLength",
  "parameter": "2"
}

The parameter is a numeric pattern (see Meta_NumericPattern.md) that serves as the second argument for the rule function. The amount of digits after the floating point must match the pattern.

Integers are supposed to have 0 decimal digits.

The "isInteger" rule checks if a given number (the validated subject) is an Integer or not. The outcome must match a given boolean. There is no definition about what an "Integer" is at . For the domain specification context, we handle a number as an Integer, if and only if the number has no floating point. e.g. 1 is an Integer, 1. and 1.0 are not Integers

The "isFloat" rule checks if a given number (the validated subject) is a Float or not. The outcome must match a given boolean. There is no definition about what an "Float" is at . For the domain specification context, we handle a number as a Float, if and only if the number has a floating point. e.g. 1. and 1.0 are Floats, 1 is not

https://schema.org/Integer
https://schema.org/Float
Syntax diagram