Search code examples
nosqlmarklogictriplesrdf-xml

Transform and ingest graph RDF XML failure


Following previous post:

Graph data model to transform XML to RDF

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sbase="http://my.semantics/projects/" xmlns:spi="http://my.semantics/projects/incentive/" version="2.0">
 
   <xsl:template match="projects">
      <xsl:element name="rdf:RDF">
         <xsl:for-each select="project">
            <xsl:element name="rdf:Description">
               <xsl:attribute name="rdf:about" select="concat('http://my.semantics/projects/incentive/', projectID)" />
               <xsl:attribute name="sbase:program" select="program" />
               <xsl:attribute name="sbase:projectID" select="projectID" />
               <xsl:attribute name="sbase:projectName" select="projectName" />
               <xsl:attribute name="sbase:recipient" select="recipient" />
               <xsl:element name="sbase:about">
                  <xsl:attribute name="rdf:resource" select="'http://my.semantics/ontology/economy'" />
               </xsl:element>
               <xsl:element name="spi:postalCode">
                  <xsl:value-of select="postalCode" />
               </xsl:element>
               <xsl:element name="spi:region">
                  <xsl:value-of select="region" />
               </xsl:element>
               <xsl:element name="spi:industry">
                  <xsl:value-of select="industry" />
               </xsl:element>
               <xsl:element name="spi:incentiveType">
                  <xsl:value-of select="incentiveType" />
               </xsl:element>
               <xsl:element name="spi:startDate">
                  <xsl:value-of select="startDate" />
               </xsl:element>
               <xsl:element name="spi:totalAwarded">
                  <xsl:value-of select="totalAwarded" />
               </xsl:element>
               <xsl:element name="spi:totalInvestment">
                  <xsl:value-of select="totalInvestment" />
               </xsl:element>
               <xsl:element name="spi:disbursementsToDate">
                  <xsl:value-of select="disbursementsToDate" />
               </xsl:element>
               <xsl:element name="rdf:comment">
                  <xsl:value-of select="projectDescription" />
               </xsl:element>
            </xsl:element>
         </xsl:for-each>
      </xsl:element>
   </xsl:template>
</xsl:transform>

If I use sem:rdf-insert(xdmp:xslt-eval($rdf-xml, $doc),"rdfxml", (), "rdf-incentive"), I got error:

XDMP-AS: (err:XPTY0004) $triples as sem:triple* -- Invalid coercion: xs:untypedAtomic() as sem:triple

If sem:rdf-load((xdmp:xslt-eval($rdf-xml,$doc)),"rdfxml",(),(),"rdf-incentive")

I got error:

SVC-FILOPN: xdmp:document-get()…: No such file or directory


Solution

  • Given the complexity of RDF syntax, you can consider

    separate XSL to declare shared RDF attributes

       <xsl:attribute-set name="incentiveRDFAttr">
          <xsl:attribute name="rdf:about" select="concat('http://my.semantics/projects/incentive/', projectID)"/>
          <xsl:attribute name="sbase:program" select="program"/>
          <xsl:attribute name="sbase:projectID" select="projectID"/>
          <xsl:attribute name="sbase:projectName" select="projectName"/>
          <xsl:attribute name="sbase:recipient" select=" recipient"/>        
       </xsl:attribute-set>
    
       <xsl:attribute-set name="rdfDataTime">
          <xsl:attribute name="rdf:datatype" select="'http://www.w3.org/2001/XMLSchema#dateTime'"/>   
       </xsl:attribute-set>
        
       <xsl:attribute-set name="rdfDecimal">
          <xsl:attribute name="rdf:datatype" select="'http://www.w3.org/2001/XMLSchema#decimal'"/>   
       </xsl:attribute-set>
    ««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»«»»««»»««»»««»»
    

    call the attribute XSL in the main RDF transform XSL

    <!-- Ingested attribute XSL in module database -->
        <xsl:include href="/xsl/rdf-attributes.xsl"/>  
        
        <xsl:template match="projects">
          <xsl:element name="rdf:RDF">
            <xsl:for-each select="project">
              <xsl:element name="rdf:Description" use-attribute-sets="incentiveRDFAttr">
    ««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»«»»««»»««»»««»»
                <xsl:element name="spi:startDate" use-attribute-sets="rdfDataTime"><xsl:value-of select="normalize-space(startDate)"/></xsl:element>
                <xsl:element name="spi:totalAwarded" use-attribute-sets="rdfDecimal"><xsl:value-of select="normalize-space(totalAwarded)"/></xsl:element>
    ««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»««»»«»»««»»««»»««»»
              </xsl:element>          
            </xsl:for-each>        
          </xsl:element>
        </xsl:template>
    

    Please use sem:rdf-parse to serialise RDF triples after XSL transform and during ingestion:

      sem:rdf-insert(
        sem:rdf-parse(xdmp:xslt-eval($rdf-xml, $doc), "rdfxml"),
        ("rdfxml", "directory=/my/semantics/"),
        (),
        "rdf-incentive"
      )