SWP JSON service to generate datatype, type, xml:lang for values of variables

15 views
Skip to first unread message

Paula Markes

unread,
Jul 31, 2016, 7:52:41 AM7/31/16
to Topbraid Google Group
Hello,

I’m trying to use the SWP JSON services to generate the following types of information about a value in a variable - e.g. such as below, datatype, type, xml:lang.

      {
        "lab": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "Some Label Here" }
      } ,
      {
        "lab": { "type": "literal" , "xml:lang": “en-GB" , "value": "Some Other Label Here" }
      } ,

I have no trouble doing this using _format=JSON when executing a spin template, or when exporting JSON from the Composer tool.  But I’m finding I am doing things very manually in SWP; but perhaps that’s the nature of SWP, I’m not sure.  

But is there a way for me to generate this kind of information (datatype, type, xml:lang) about every value for a variable when I use the swon namespace in SWP when creating a JSON service?

Here’s an example below that I copied from one of the help web pages.  I can do this very easily with a spin template and from Composer.  I’m now trying to do that with a JSON service created using SWP.  Can you provide any info on how to do that?

{

  "head": {

    "vars": [ "name" , "count" ]

  } ,

  "results": {

    "bindings": [

      {

        "name": { "type": "literal" , "value": "Alice" } ,

        "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "3" }

      } ,

      {

        "name": { "type": "literal" , "value": "Bob" } ,

        "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "1" }

      } ,

      {

        "name": { "type": "literal" , "value": "Charlie" } ,

        "count": { "datatype": "http://www.w3.org/2001/XMLSchema#integer" , "type": "typed-literal" , "value": "1" }

      }

    ]

 }

}


-Paula




Holger Knublauch

unread,
Jul 31, 2016, 6:44:27 PM7/31/16
to topbrai...@googlegroups.com
Hi Paula,

yes you can use the SWON namespace to produce the output you describe. Here is an (untested) example for the case in which the variable names are known in advance:

<swon:Array>
    <ui:forEach ui:resultSet="{# SELECT ?lab WHERE { ... } }">
        <swon:Object>
            <swon:Value arg:name="lab">
                <swon:Object>
                    <swon:Value arg:name="datatype" arg:value="{= datatype(?lab) }" />
                    <swon:Value arg:name="type" arg:value="{= IF(isLiteral(?lab), 'typed-literal', 'iri') }" />
                    <swon:Value arg:name="value" arg:value="{= ?lab }" />
                    <ui:if ui:condition="{= lang(?lab) != '' }">
                        <swon:Value arg:name="xml:lang" arg:value="{= lang(?lab) }" />
                    </ui:if>
                </swon:Object>
            </swon:Value>
        </swon:Object>
    </ui:forEach>
</swon:Array>

Make the above the ui:prototype of a subclass of ui:JSONServices.

If you need a more generic solution, you can still use SWON, but instead of hard-coding the variable names you'd need to operate on the result set using the SPR functions

http://spinrdf.org/spr.html

HTH
Holger
--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbrai...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paula Markes

unread,
Jul 31, 2016, 10:21:16 PM7/31/16
to Topbraid Google Group
Thanks Holger!

I used your example below and modified it a bit and got the results needed.  So I think I’m good to go.
I was hoping for a method as simple as the way JSON is generated with a spin template. :-)  But this works too.
Thanks again for the help!

-Paula
Reply all
Reply to author
Forward
0 new messages