Skip to content

Commit 46cd050

Browse files
committed
Class-based navigation
1 parent b48dfa1 commit 46cd050

1 file changed

Lines changed: 79 additions & 11 deletions

File tree

  • src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/navigation.xsl

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<!ENTITY ac "https://w3id.org/atomgraph/client#">
66
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
77
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
8+
<!ENTITY srx "http://www.w3.org/2005/sparql-results#">
89
<!ENTITY ldt "https://www.w3.org/ns/ldt#">
910
<!ENTITY sd "http://www.w3.org/ns/sparql-service-description#">
1011
<!ENTITY sp "http://spinrdf.org/sp#">
@@ -23,6 +24,7 @@ xmlns:array="http://www.w3.org/2005/xpath-functions/array"
2324
xmlns:ac="&ac;"
2425
xmlns:ldh="&ldh;"
2526
xmlns:rdf="&rdf;"
27+
xmlns:srx="&srx;"
2628
xmlns:ldt="&ldt;"
2729
xmlns:sd="&sd;"
2830
xmlns:sp="&sp;"
@@ -32,11 +34,15 @@ extension-element-prefixes="ixsl"
3234
exclude-result-prefixes="#all"
3335
>
3436

37+
<!-- KEYS -->
38+
39+
<xsl:key name="type-count" match="srx:result" use="srx:binding[@name = 'type']/srx:uri"/>
40+
3541
<!-- PARAMS -->
3642

3743
<xsl:param name="class-types-string" as="xs:string">
3844
<![CDATA[
39-
SELECT DISTINCT ?type (COUNT(?s) AS ?count) (SAMPLE(?g) AS ?namedGraph)
45+
SELECT DISTINCT ?type (COUNT(?s) AS ?count)
4046
WHERE
4147
{ { ?s a ?type }
4248
UNION
@@ -478,17 +484,12 @@ LIMIT 10
478484
</xsl:variable>
479485
<xsl:variable name="select-json-string" select="ixsl:call(ixsl:get(ixsl:window(), 'JSON'), 'stringify', [ $select-json ])" as="xs:string"/>
480486
<xsl:variable name="select-xml" select="json-to-xml($select-json-string)" as="document-node()"/>
481-
482-
<!-- wrap SELECT into a DESCRIBE -->
483-
<xsl:variable name="query-xml" as="element()">
484-
<xsl:apply-templates select="$select-xml" mode="ldh:wrap-describe"/>
485-
</xsl:variable>
486-
<xsl:variable name="query-json-string" select="xml-to-json($query-xml)" as="xs:string"/>
487+
<xsl:variable name="query-json-string" select="xml-to-json($select-xml)" as="xs:string"/>
487488
<xsl:variable name="query-json" select="ixsl:call(ixsl:get(ixsl:window(), 'JSON'), 'parse', [ $query-json-string ])"/>
488489
<xsl:variable name="query-string" select="ixsl:call(ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'SelectBuilder'), 'fromQuery', [ $query-json ]), 'toString', [])" as="xs:string"/>
489490
<xsl:variable name="results-uri" select="ac:build-uri($endpoint, map{ 'query': $query-string })" as="xs:anyURI"/>
490491
<xsl:variable name="request-uri" select="ldh:href($results-uri, map{})" as="xs:anyURI"/>
491-
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>
492+
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/sparql-results+xml' } }" as="map(*)"/>
492493
<xsl:variable name="context" as="map(*)" select="
493494
map{
494495
'request': $request,
@@ -501,14 +502,70 @@ LIMIT 10
501502
on-failure="ldh:promise-failure#1"/>
502503
</xsl:template>
503504

504-
<!-- Handle the response from loading classes -->
505+
<!-- Handle the response from loading classes - extract type URIs and query ns endpoint -->
505506
<xsl:function name="ldh:class-tree-response" as="map(*)" ixsl:updating="yes">
506507
<xsl:param name="context" as="map(*)"/>
507508
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
508509
<xsl:variable name="container" select="$context('container')" as="element()"/>
509510

510511
<xsl:message>ldh:class-tree-response</xsl:message>
511512

513+
<xsl:for-each select="$response">
514+
<xsl:choose>
515+
<xsl:when test="?status = 200 and ?media-type = 'application/sparql-results+xml'">
516+
<xsl:for-each select="?body">
517+
<xsl:variable name="results" select="." as="document-node()"/>
518+
<!-- extract type URIs from SPARQL results -->
519+
<xsl:variable name="type-uris" select="$results/srx:sparql/srx:results/srx:result/srx:binding[@name = 'type']/srx:uri" as="xs:string*"/>
520+
521+
<xsl:choose>
522+
<xsl:when test="exists($type-uris)">
523+
<!-- build DESCRIBE query with VALUES clause -->
524+
<xsl:variable name="query-string" select="'DESCRIBE ?type WHERE { VALUES ?type { ' || string-join(for $uri in $type-uris return '&lt;' || $uri || '&gt;', ' ') || ' } }'" as="xs:string"/>
525+
<xsl:variable name="ns-uri" select="resolve-uri('ns', ldt:base())" as="xs:anyURI"/>
526+
<xsl:variable name="results-uri" select="ac:build-uri($ns-uri, map{ 'query': $query-string })" as="xs:anyURI"/>
527+
<xsl:variable name="request-uri" select="ldh:href($results-uri, map{})" as="xs:anyURI"/>
528+
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>
529+
<xsl:variable name="new-context" as="map(*)" select="
530+
map{
531+
'request': $request,
532+
'container': $container,
533+
'type-results': $results
534+
}"/>
535+
<ixsl:promise select="ixsl:http-request($new-context('request')) =>
536+
ixsl:then(ldh:rethread-response($new-context, ?)) =>
537+
ixsl:then(ldh:handle-response#1) =>
538+
ixsl:then(ldh:class-tree-describe-response#1)"
539+
on-failure="ldh:promise-failure#1"/>
540+
</xsl:when>
541+
<xsl:otherwise>
542+
<xsl:message>No class types found</xsl:message>
543+
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
544+
</xsl:otherwise>
545+
</xsl:choose>
546+
</xsl:for-each>
547+
</xsl:when>
548+
<xsl:otherwise>
549+
<xsl:message>
550+
Error loading class types from sparql endpoint
551+
</xsl:message>
552+
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
553+
</xsl:otherwise>
554+
</xsl:choose>
555+
</xsl:for-each>
556+
557+
<xsl:sequence select="$context"/>
558+
</xsl:function>
559+
560+
<!-- Handle the response from describing class types -->
561+
<xsl:function name="ldh:class-tree-describe-response" as="map(*)" ixsl:updating="yes">
562+
<xsl:param name="context" as="map(*)"/>
563+
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
564+
<xsl:variable name="container" select="$context('container')" as="element()"/>
565+
<xsl:variable name="type-results" select="$context('type-results')" as="document-node()"/>
566+
567+
<xsl:message>ldh:class-tree-describe-response</xsl:message>
568+
512569
<xsl:for-each select="$response">
513570
<xsl:choose>
514571
<xsl:when test="?status = 200 and ?media-type = 'application/rdf+xml'">
@@ -518,7 +575,8 @@ LIMIT 10
518575
<xsl:for-each select="$container">
519576
<xsl:result-document href="?." method="ixsl:append-content">
520577
<xsl:apply-templates select="$resources" mode="bs2:ClassTreeListItem">
521-
<xsl:sort select="ac:label(.)"/>
578+
<xsl:with-param name="type-results" select="$type-results" tunnel="yes"/>
579+
<xsl:sort select="xs:integer(key('type-count', @rdf:about, $type-results)/srx:binding[@name = 'count']/srx:literal)" order="descending"/>
522580
</xsl:apply-templates>
523581
</xsl:result-document>
524582
</xsl:for-each>
@@ -528,8 +586,9 @@ LIMIT 10
528586
</xsl:when>
529587
<xsl:otherwise>
530588
<xsl:message>
531-
Error loading class tree
589+
Error loading class descriptions from ns endpoint
532590
</xsl:message>
591+
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
533592
</xsl:otherwise>
534593
</xsl:choose>
535594
</xsl:for-each>
@@ -539,10 +598,19 @@ LIMIT 10
539598

540599
<!-- Render a class as a list item with expand button -->
541600
<xsl:template match="*[@rdf:about]" mode="bs2:ClassTreeListItem">
601+
<xsl:param name="type-results" as="document-node()?" tunnel="yes"/>
602+
<xsl:variable name="type-uri" select="@rdf:about" as="xs:anyURI"/>
603+
<xsl:variable name="count" select="$type-results/srx:sparql/srx:results/srx:result[srx:binding[@name = 'type']/srx:uri = $type-uri]/srx:binding[@name = 'count']/srx:literal" as="xs:string?"/>
604+
542605
<li>
543606
<button class="btn btn-small btn-expand-class"></button>
544607
<a href="{@rdf:about}" class="btn-logo btn-class">
545608
<xsl:apply-templates select="." mode="ac:label"/>
609+
<xsl:if test="exists($count)">
610+
<xsl:text> (</xsl:text>
611+
<xsl:value-of select="$count"/>
612+
<xsl:text>)</xsl:text>
613+
</xsl:if>
546614
</a>
547615
</li>
548616
</xsl:template>

0 commit comments

Comments
 (0)