On this page:
local-name-string?
local-name
local-name->string

2 Module name🔗ℹ

 (require rdf/core/name) package: rdf-core

Figure 1 in the introduction included a both a PrefixName and LocalName datatype, but these are actually more commonly used in combination, and with the datatype Namespace. Figure 2 introduces the type PrefixedName which is a tuple of prefix and local-name, and the type NamespacedName which is a tuple of namespace IRI and local-name. Prefixed names can be translated into namespaced names by substituting the prefix name with the corresponding namespace in a NamespaceMap.

Name Module Overview

The value space for a local name is sometimes different in RDF implementations, depending on their age and representation support. The definitions used in this package are those defined by SPARQL and adopted by Turtle, for more information see Appendix: Names Defined.

predicate

(local-name-string? v)  boolean?

  v : string?
This predicate returns #t if the value of v is valid according to the SPARQL production PN_LOCAL.

Examples:
> (require rdf/core/name)
> (local-name-string? "a-valid-name")

#t

> (local-name-string? 'another-valid-name)

#f

> (local-name-string? "?")

#t

> (local-name-string? "")

#f

struct

(struct local-name ()
    #:constructor-name string->local-name)
This structure provides a safe and efficient way to wrap a string that conforms to the predicate local-name-string?. This ensures that the name cannot be mutated, and the predicate local-name? is more efficient than parsing the string.

Examples:
> (require racket/list racket/string)
> (let ((long-name (string-join (map (lambda (_) "this-is-a-long-name")
                                     (range 1 200))
                                "-also-")))
    (time (local-name-string? long-name))
    (let ((name (string->local-name long-name)))
      (time (local-name? name))))

cpu time: 79 real time: 79 gc time: 46

cpu time: 0 real time: 0 gc time: 0

#t

Returns the local name as a string.

Examples:
> (require rdf/core/name)
> (local-name->string (string->local-name "a-valid-name"))

"a-valid-name"

The following table shows how different combinations of namespace, prefix, local name, and IRI can be constructed.

function

  

from

  

add

  

into

  

map?

resource-append-name

  

resource?

  

local-name?

  

url?

  

No

namespace+name->prefixed-name

  

resource?

  

local-name?

  

prefixed-name?

  

Yes

nsname->resource

  

nsname?

  

  

resource?

  

No

nsname-make-nsname

  

nsname?

  

local-name?

  

nsname?

  

No

nsname->prefixed-name

  

nsname?

  

  

prefixed-name?

  

Yes

prefix+name->nsname

  

prefix?

  

local-name?

  

nsname?

  

Yes

prefix+name->resource

  

prefix?

  

local-name?

  

resource?

  

Yes

prefixed-name->nsname

  

prefixed-name?

  

  

nsname?

  

Yes

prefixed-name->resource

  

prefixed-name?

  

  

resource?

  

Yes