Skip to content

Commit

Permalink
Adding tests for the N-Triples parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipfennell committed Apr 4, 2012
1 parent 5324c4a commit 72d346c
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/xquery/app/lib/rdf-interfaces/Graph.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ xquery version "1.0-ml" encoding "utf-8";

module namespace graph = "http://www.w3.org/TR/rdf-interfaces/Graph";

import module namespace impl = "http://www.w3.org/TR/rdf-interfaces/Implemetation"
at "/lib/rdf-interfaces/Implemetation.xqy";
import module namespace impl = "http://www.w3.org/TR/rdf-interfaces/Implementation"
at "/lib/rdf-interfaces/Implementation.xqy";

import module namespace common = "http://www.w3.org/TR/rdf-interfaces/Common"
at "/lib/rdf-interfaces/Common.xqy";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ xquery version "1.0-ml" encoding "utf-8";

module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser";

import module namespace rdvenv = "http://www.w3.org/TR/rdf-interfaces/RDFEnvironment"
at "/lib/rdf-interfaces/RDFEnvironment.xqy";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";
Expand All @@ -50,6 +53,10 @@ declare function ntdp:parse($toParse as xs:string, $callBack as item(),
$base as xs:string?, $filter as item()?, $graph as element(graph)?)
as element(graph)
{
xdmp:xslt-invoke('xslt/ntriples-to-graph.xsl', document {<nt:RDF>{$toParse}</nt:RDF>})/*
let $tempGraph as element(graph) :=
xdmp:xslt-invoke('xslt/ntriples-to-graph.xsl',
document {<nt:RDF>{$toParse}</nt:RDF>})/graph
return
rdvenv:create-graph(<rdf-environment/>, $tempGraph/triple)
};

41 changes: 39 additions & 2 deletions src/main/xquery/app/lib/rdf-interfaces/RDFEnvironment.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,44 @@ declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
declare namespace rdfi = "http://www.w3.org/TR/rdf-interfaces";


declare variable $DEFAULT_ENVIRONMENT as element(rdf-environment) :=
<rdf-environment xmlns="http://www.w3.org/TR/rdf-interfaces">
<prefix-map>
<entry xml:id="owl">http://www.w3.org/2002/07/owl#</entry>
<entry xml:id="rdf">http://www.w3.org/1999/02/22-rdf-syntax-ns#</entry>
<entry xml:id="rdfs">http://www.w3.org/2000/01/rdf-schema#</entry>
<entry xml:id="rdfa">http://www.w3.org/ns/rdfa#</entry>
<entry xml:id="xhv">http://www.w3.org/1999/xhtml/vocab#</entry>
<entry xml:id="xml">http://www.w3.org/XML/1998/namespace</entry>
<entry xml:id="xsd">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="xs">http://www.w3.org/2001/XMLSchema#</entry>
</prefix-map>
<term-map>
<entry xml:id="string">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="boolean">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="dateTime">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="date">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="time">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="int">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="double">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="float">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="decimal">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="positiveInteger">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="integer">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="nonPositiveInteger">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="negativeInteger">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="long">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="int">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="short">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="byte">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="nonNegativeInteger">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="unsignedLong">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="unsignedInt">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="unsignedShort">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="unsignedByte">http://www.w3.org/2001/XMLSchema#</entry>
<entry xml:id="positiveInteger">http://www.w3.org/2001/XMLSchema#</entry>
</term-map>
</rdf-environment>;


(:~
Expand All @@ -63,7 +100,7 @@ declare namespace rdfi = "http://www.w3.org/TR/rdf-interfaces";
:)
declare function rdfenv:create-graph(
$contextRDFEnvironment as element(rdf-environment),
$triples as element(rdfi:triple)*)
$triples as element(triple)*)
as element(graph)
{
<graph>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<xsl:param name="language" as="xs:string?"/>

<xsl:choose>
<xsl:when test="if (string-length($language) gt 0) then matches($language, '[a-z]+(-[A-Z0-9]+)*') else true()">
<xsl:when test="if (string-length($language) gt 0) then matches($language, '[a-z]+(-[A-Za-z0-9]+)*') else true()">
<xsl:value-of select="concat('&quot;', nt:escape-string($string), '&quot;', if (string-length($language) gt 0) then concat('@', $language) else '')"/>
</xsl:when>
<xsl:otherwise>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
<!-- XML Literals. -->
<xsl:when test="ends-with(nt:get-datatype(regex-group(5)), '#XMLLiteral')">
<xsl:copy-of use-when="system-property('xsl:product-name') eq 'SAXON'"
select="saxon:parse(concat('&lt;rdfi:XMLLiteral xmlns:trix=''http://www.w3.org/2004/03/trix/trix-1/''&gt;', nt:unescape-string(nt:get-data-value(regex-group(5))), '&lt;/rdfi:XMLLiteral&gt;'))/rdfi:XMLLiteral/(* | text())"
select="saxon:parse(concat('&lt;rdfi:XMLLiteral xmlns:rdfi=''http://www.w3.org/TR/rdf-interfaces''&gt;', nt:unescape-string(nt:get-data-value(regex-group(5))), '&lt;/rdfi:XMLLiteral&gt;'))/rdfi:XMLLiteral/(* | text())"
copy-namespaces="no"/>
<xsl:copy-of use-when="system-property('xsl:product-name') eq 'MarkLogic Server'"
select="xdmp:unquote(concat('&lt;rdfi:XMLLiteral xmlns:trix=''http://www.w3.org/2004/03/trix/trix-1/''&gt;', nt:unescape-string(nt:get-data-value(regex-group(5))), '&lt;/rdfi:XMLLiteral&gt;'))/rdfi:XMLLiteral/(* | text())"
select="xdmp:unquote(concat('&lt;rdfi:XMLLiteral xmlns:rdfi=''http://www.w3.org/TR/rdf-interfaces''&gt;', nt:unescape-string(nt:get-data-value(regex-group(5))), '&lt;/rdfi:XMLLiteral&gt;'))/rdfi:XMLLiteral/(* | text())"
copy-namespaces="no"/>
</xsl:when>
<!-- Other Typed Literals. -->
Expand Down Expand Up @@ -154,7 +154,7 @@

<!-- Match language code. -->
<xsl:function name="nt:match-lang-code" as="xs:string">
<xsl:value-of select="'@[a-z]+(-[A-Z0-9]+)*'"/>
<xsl:value-of select="'@[a-z]+(-[a-zA-Z0-9]+)*'"/>
</xsl:function>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource5> <http://example.org/property> <http://example.org/resource2> .
<http://example.org/resource6> <http://example.org/property> <http://example.org/resource2> .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource7> <http://example.org/property> "simple literal" .
<http://example.org/resource8> <http://example.org/property> "backslash:\\" .
<http://example.org/resource9> <http://example.org/property> "dquote:\"" .
<http://example.org/resource10> <http://example.org/property> "newline:\n" .
<http://example.org/resource11> <http://example.org/property> "return\r" .
<http://example.org/resource12> <http://example.org/property> "tab:\t" .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[ # comment line after whitespace]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[
<http://example.org/resource1> <http://example.org/property> <http://example.org/resource2> .
_:anon <http://example.org/property> <http://example.org/resource2> .
<http://example.org/resource2> <http://example.org/property> _:anon .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource17> <http://example.org/property> "\u20AC" .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource16> <http://example.org/property> "\u00E9" .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource4> <http://example.org/property> <http://example.org/resource2> .
]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource30> <http://example.org/property> "chat"@fr .
<http://example.org/resource31> <http://example.org/property> "chat"@en .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource13> <http://example.org/property> <http://example.org/resource2>.
<http://example.org/resource14> <http://example.org/property> "x".
<http://example.org/resource15> <http://example.org/property> _:anon.]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[ <http://example.org/resource3> <http://example.org/property> <http://example.org/resource2> . ]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[<http://example.org/resource32> <http://example.org/property> "abc"^^<http://example.org/datatype1> .]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
xquery version "1.0-ml" encoding "utf-8";

declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare default element namespace "http://www.w3.org/TR/rdf-interfaces";
declare namespace nt = "http://www.w3.org/ns/formats/N-Triples";

import module namespace ntdp = "http://www.w3.org/TR/rdf-interfaces/NTriplesDataParser"
at "/lib/rdf-interfaces/NTriplesDataParser.xqy";


let $doc as element(nt:RDF) :=
<nt:RDF xmlns:nt="http://www.w3.org/ns/formats/N-Triples"><![CDATA[
<http://example.org/resource21> <http://example.org/property> ""^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource22> <http://example.org/property> " "^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource23> <http://example.org/property> "x"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource23> <http://example.org/property> "\""^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource24> <http://example.org/property> "<a></a>"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource25> <http://example.org/property> "a <b></b>"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource26> <http://example.org/property> "a <b></b> c"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource26> <http://example.org/property> "a\n<b></b>\nc"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
<http://example.org/resource27> <http://example.org/property> "chat"^^<http://www.w3.org/2000/01/rdf-schema#XMLLiteral> .
]]></nt:RDF>
return
ntdp:parse(string($doc), '', (), (), ())
11 changes: 3 additions & 8 deletions src/test/xquery/rdf-interfaces/rdf-environment/create-graph.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ declare namespace rdfi = "http://www.w3.org/TR/rdf-interfaces";
import module namespace rdfenv = "http://www.w3.org/TR/rdf-interfaces/RDFEnvironment"
at "/lib/rdf-interfaces/RDFEnvironment.xqy";

let $rdfEnvironment as element(rdf-environment) :=
<rdf-environment>
<prefix-map/>
<term-map/>
</rdf-environment>

let $graph as element() :=
<graph xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xs="http://www.w3.org/2001/XMLSchema#">
<graph>
<uri>#default</uri>
<triple>
<uri>http://example.org/book/book1</uri>
Expand All @@ -41,5 +36,5 @@ let $graph as element() :=
</graph>
return
rdfenv:create-graph($rdfEnvironment, $graph/rdfi:triple) instance of element(graph)
rdfenv:create-graph($rdfenv:DEFAULT_ENVIRONMENT, $graph/rdfi:triple) instance of element(graph)

0 comments on commit 72d346c

Please sign in to comment.