Skip to content

from_n3 fails on numeric shortcuts #1769

@jpmccu

Description

@jpmccu

From the turtle spec [1]:

Data Type Abbreviated Lexical Description
xsd:integer -5 "-5"^^xsd:integer Integer values may be written as an optional sign and a series of digits. Integers match the regular expression "[+-]?[0-9]+".
xsd:decimal -5.0 "-5.0"^^xsd:decimal Arbitrary-precision decimals may be written as an optional sign, zero or more digits, a decimal point and one or more digits. Decimals match the regular expression "[+-]?[0-9]*.[0-9]+".
xsd:double 4.2E9 "4.2E9"^^xsd:double Double-precision floating point values may be written as an optionally signed mantissa with an optional decimal point, the letter "e" or "E", and an optionally signed integer exponent. The exponent matches the regular expression "[+-]?[0-9]+" and the mantissa one of these regular expressions: "[+-]?[0-9]+.[0-9]+", "[+-]?.[0-9]+" or "[+-]?[0-9]".

Testing this, I get:

>>> rdflib.util.from_n3("-5")
rdflib.term.BNode('-5')
>>> rdflib.util.from_n3("-5.0")
rdflib.term.BNode('-5.0')
>>> rdflib.util.from_n3("4.2E9")
rdflib.term.BNode('4.2E9')

It does seem to work on positive integers:

>>> rdflib.util.from_n3("5")
rdflib.term.Literal('5', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer'))

[1] https://www.w3.org/TR/turtle/#literals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions