% $Id: RDFinXML.lsl,v 1.4 1999/08/02 07:17:27 connolly Exp $
%
% http://www.w3.org/RDF/Group/1998/02/WD-rdf-syntax-19980216/#grammar

RDFinXML: trait

   includes
     URISyntax,
     XMLElement,
     XMLNames,
     RDFCore, RDFUtil

   introduces
      eval: List[Content], URI ® Set[Arc]
      eval: List[UContent], URI ® Set[Arc]

      expressions: List[UElement], URI  ® Set[Arc]
      expression: UElement, URI ® Set[Arc]
      description: Map[URI,String[Char]], List[UElement], URI ® Set[Arc]
      sequence: Map[URI,String[Char]], List[UElement], URI ® Set[Arc]
      alternatives: Map[URI,String[Char]], List[UElement], URI ® Set[Arc]
      bag: Map[URI,String[Char]], List[UElement], URI ® Set[Arc]
      collection: List[UElement], Ord, Node, URI ® Set[Arc]

      properties: List[UElement], Node, URI ® Set[Arc]
      properties: Map[URI,String[Char]], Node, URI ® Set[Arc]

      property: UElement, Node, URI ® Arc

      propObj: Map[URI,String[Char]], URI ® Node

      value: List[UContent], URI ® Value

      RDFSyntax: ® URI % address of schema of RDF, Seq, Alt, ...
      RDF: ® URI
      Description: ® URI
      HREF: ® URI
      ID: ® URI
      BAGID: ® URI
      LI: ® URI

      local: ® URI % some URI that won't ever apear in a NS declaration

   asserts
     " e: UElement, le: List[UElement],
             content: List[Content],
             r: Node, ps: Set[Arc], lc: List[UContent],
             str: String[Char], v: String[Char],
             attrs: Map[URI,String[Char]],
             i, base: URI,
             n: Ord

     eval(content, base) = eval(expand(content, local, base), base);

     eval(empty:List[UContent], base) º {};

% <rdf:RDF> ... lc ... </rdf:RDF>
     eval({elt([RDF, attrs, lc])}, base) = expressions(elements(lc), base);

     expressions(empty, base) º {};

% <e> .. le ..
     expressions(e \precat le, base) º
       expression(e, base) \U expressions(le, base);


% <rdf:Description attrs>... lc ... </rdf:Description>
     expression([Description, attrs, lc], base) º
       description(e.attributes, elements(e.content), base);
     expression([Seq, attrs, lc], base) º
       sequence(e.attributes, elements(e.content), base);
     expression([Alt, attrs, lc], base) º
       alternatives(e.attributes, elements(e.content), base);
     expression([Bag, attrs, lc], base) º
       bag(e.attributes, elements(e.content), base);

% attrs>... lc ... </rdf:Description>
     description(attrs, le, base) º
         properties(le, propObj(e.attributes, base), base) \U
         properties(attrs, propObj(e.attributes, base), base);
%@@ \U reification(attrs, le, base);

% anonymous propObj
% <rdf:Description>
     $ r ( propObj({}, base) = r );

     propObj(update(attrs, i, v), base) º
% <rdf:Description rdf:HREF="foo">
       if i = HREF
         then [combine(base, asURIRef(v))]
% <rdf:Description rdf:ID="foo">
       else if i = ID
         then [base||toName(v)]
       else propObj(attrs, base);

     properties(empty, r, base) º {};

     properties(e \precat le, r, base) º
       insert(property(e, r, base), properties(le, r, base));
%@@ abbreviations

% <e.name>e.content</e.name>
     property(e, r, base) =
       [[e.name], r, value(e.content, base)];

     value({data(str)}, base) º str(str);
     value({elt(e)}, base) º ref([expression(e, base)]);
% @@ handle abbreviations, e.g. typed


% abbreviated syntax: properties from attributes
% "Specifically; each XML attribute A specified with a Description ..."
     properties({}, r, base) = {};

     (i Ø= ID Ú i Ø= HREF Ú i Ø= BAGID) Þ
       properties(update(attrs, i, v), r, base) =
         insert([[i], r, str(v)],
           properties(attrs, r, base));

     bag(attrs, le, base) º
       insert([InstanceOf, propObj(attrs, base), ref([Bag])],
              collection(le, 1, propObj(attrs, base), base));
%@@ \U collection(attrs, ...)

     collection(empty, n, r, base) º {};

% <rdf:LI rdf2:HREF="v"/>...
     collection([LI, update({}, HREF, v), empty] \precat le, n, r, base) º
       insert([[n], r, ref([combine(base, asURIRef(v))])],
              collection(le, n+1, r, base));

% <rdf:LI>v</rdf:LI>
     collection([LI, {}, {data(str)}] \precat le, n, r, base) º
       insert([[n], r, str(v)],
              collection(le, n+1, r, base));


% review notes 1998-03-10

% "The ID attribute, if specified, provides the URI
% fragment identifier for C. "
% @@ wrong sorts.

% review notes 1998-03-07


% "Description contains ..."
% Description refers to the non-terminal in the grammar? not clear.

% "... the remaining elements that cause the creation
% of properties in the model instance."
% too operational. suggest: "that represent properties in a model."

% "these two attributes have XML AttType ID."
% not without XML attribute declarations, they don't.

[Index]


HTML generated using lsl2html.