Vagueness in "otherwise" statements in sec 7.4 of expansion algorithm

In the expansion algorithm, I got rather tripped up by this wording:

    3 If expanded property is @id and value is not a string, an invalid @id value error has been
      detected and processing is aborted. Otherwise, set expanded value to the result of using
      the IRI Expansion algorithm, passing active context, value, and true for document
      relative. 
    4 If expanded property is @type and value is neither a string nor an array of strings, an
      invalid type value error has been detected and processing is aborted. Otherwise, set
      expanded value to the result of using the IRI Expansion algorithm, passing active context,
      true for vocab, and true for document relative to expand the value or each of its items. 

Luckily dlongley was able to help sort things out, for I had been
confused for some time.  The way I read this was (in pseudocode):


  if expanded_property == "@id" and type(value) != string:
      throw_error("invalid @id value")
  else:
      exanded_value = iri_expansion(
          active_context, value, document_relative=True)

  if expanded_property == "@type" and not (
          type(value) == string or list_of_strings(value)):
      throw_error("invalid type value")
  else:
      if type(value) == list:
          expanded_value = []
          for v in value:
              expanded_value.append(iri_expansion(
                  active_context, v,
                  vocab=True, document_relative=True))
      else:
          expanded_value = iri_expansion(
              active_context, v,
              vocab=True, document_relative=True)
                  

Which is very different from:

  if expanded_property == "@id":
      if type(value) != string:
          throw_error("invalid @id value")

      exanded_value = iri_expansion(
          active_context, value, document_relative=True)

  if expanded_property == "@type"
      if not (type(value) == string or list_of_strings(value)):
          throw_error("invalid type value")

      if type(value) == list:
          expanded_value = []
          for v in value:
              expanded_value.append(iri_expansion(
                  active_context, v,
                  vocab=True, document_relative=True))
      else:
          expanded_value = iri_expansion(
              active_context, v,
              vocab=True, document_relative=True)


I was confused, why would expanded_value be overridden in either case!

This wording seems confusing... maybe a worthy addition to the erratta,
or at least to adjust in future revisions.

Thanks for all your hard work, json-ld folks!

 - Chris

Received on Tuesday, 8 September 2015 20:35:09 UTC