sparql with swa:Button

48 views
Skip to first unread message

Shreelakshmi G.M

unread,
Jul 24, 2015, 7:25:13 AM7/24/15
to TopBraid Suite Users
I want to display sparql query result, onclick of a button.
how can I do this ?

Shreelakshmi G.M

unread,
Jul 25, 2015, 6:14:53 AM7/25/15
to TopBraid Suite Users, shre...@gmail.com
I am trying the following 


        <swa:Window arg:layoutPanel="west" arg:title="Event Publisher">
            <button onclick="{= swa:publishEvent(&quot;testQuery&quot;, &quot;&lt;swa:ResultSetObjectsView arg:resultSet=quot;{#SELECT ?class
                          WHERE {
                              ?class a owl:Class .
                          } }quot;&gt;&quot;) }">Click to Send Event</button>
        </swa:Window>
        <swa:Window arg:layoutPanel="center" arg:title="Event Subscriber">
            <swa:Subscribe arg:code="$('#label').html(data)" arg:event="testQuery"/>
            <span>Hello&nbsp;</span>
            <span id="label"/>
        </swa:Window>
    </swa:FullScreenBorderLayout>
</ui:setContext>

I know that in the above code snippet, 2nd argument of publishEvent should be string, which is not here.
How to get sparql resultset as a string and pass it over here. Is there any other way to about this ?

Thanks,
Shreelakshmi

Holger Knublauch

unread,
Jul 26, 2015, 7:06:49 PM7/26/15
to topbrai...@googlegroups.com
Hi Shreelakshmi,

I am not entirely clear what requirement you are implementing. It sounds like you want users to enter a SPARQL query and then have a swa:ResultSetObjectsView (or swa:ResultSetGrid?) to display the results? If yes then the following can be used (also attached as complete file):

<ui:group>
    <p>SPARQL Query:</p>
    <textarea cols="80" id="sparql" rows="10"/>
    <p>
        <button onclick="gadgets.Hub.publish('sparql', $('#sparql').val())">Execute</button>
    </p>
    <p>
        <swa:Subscribe arg:code="swa.load('results', { 'queryString': JSON.stringify(data) })" arg:event="sparql"/>
        <ui:loadable ui:loadId="results" ui:loadOnDemand="true">
            <b>Results of {= ?queryString }:</b>
            <ui:call ui:queryString="{= ?queryString }" ui:varName="results">
                <swa:ResultSetGrid arg:resultSet="{= ?results }"/>
            </ui:call>
        </ui:loadable>
    </p>
</ui:group>

Put the file into your workspace and go to http://localhost:8083/tbl/swp?_viewClass=ex:SPARQLEditor


If this is not the scenario you need, please clarify.

HTH
Holger
--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), Reference Data Manager (RDM), TopBraid Composer, TopBraid Live, TopBraid Insight, 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.

dynamicSPARQLExample.ui.ttlx

Shreelakshmi G.M

unread,
Jul 27, 2015, 3:26:45 AM7/27/15
to TopBraid Suite Users, shre...@gmail.com
Thanks for the reply Holger.
I need the same scenario, but I am getting error, when I tried the solution above, at line,  <ui:call ui:queryString="{= ?queryString }" ui:varName="results">
as "Undefined SWP property ui:queryString". I even changed this to ui:query, then I am getting the error as "Malformed qname".

Thanks in advance,
Shreelakshmi

On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:

Holger Knublauch

unread,
Jul 27, 2015, 3:29:01 AM7/27/15
to topbrai...@googlegroups.com
You may need to update your TopBraid version. ui:queryString was added with version 4.5.

Holger
--

Shreelakshmi G.M

unread,
Jul 27, 2015, 3:43:26 AM7/27/15
to topbrai...@googlegroups.com
Is there any solution apart from updating. can I use ui:query ?

You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/6IP1cH7hpnk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.

Shreelakshmi G.M

unread,
Jul 27, 2015, 3:56:03 AM7/27/15
to topbrai...@googlegroups.com

I m using version 4.3

Holger Knublauch

unread,
Jul 27, 2015, 4:36:08 AM7/27/15
to topbrai...@googlegroups.com
I am afraid there is no built-in alternative in SWP before 4.5. However you could in principle send the query to TopBraid's SPARQL endpoint and then parse the result set in JavaScript.

Holger

Shreelakshmi G.M

unread,
Jul 27, 2015, 4:59:46 AM7/27/15
to topbrai...@googlegroups.com
Thanks Holger, I will try this.

Shreelakshmi G.M

unread,
Jul 27, 2015, 6:55:31 AM7/27/15
to topbrai...@googlegroups.com

Shreelakshmi G.M

unread,
Jul 29, 2015, 6:20:42 AM7/29/15
to TopBraid Suite Users, shre...@gmail.com
Hello Holger,

How can I send query to TopBraid's SPARQL endpoint. Is it through ui:CreateLink? I am getting error if I use ui:CreateLink.

Thanks,
Shreelakshmi

Shreelakshmi G.M

unread,
Jul 29, 2015, 7:14:19 AM7/29/15
to TopBraid Suite Users
I cant enter sparql query directly in the SPARQL endpoint. User will enter the question in natural language, which will be converted to SPARQL query and shows the results.

Can this be done by invoking the SPARQL endpoint from SWA application.

Thanks,
Shreelakshmi 

Holger Knublauch

unread,
Jul 29, 2015, 4:19:23 PM7/29/15
to topbrai...@googlegroups.com
The workflow could be

a) User enters natural language
b) The JavaScript calls a servlet that turns that language into SPARQL via a GET request
c) The JavaScript takes this SPARQL and sends it to tbl/sparql?query=... via GET
d) The JavaScript parses the resulting JSON or XML to display result rows

I don't see SWP involved here at all.

Holger

Shreelakshmi G.M

unread,
Aug 4, 2015, 1:52:17 AM8/4/15
to TopBraid Suite Users
Thanks Holger,

I could follow the workflow as suggested by you and it is working, but some SPARQL queries show error message when they are sent to "tbl/sparql?query=".

Thanks, 
Shreelakshmi

On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:

Holger Knublauch

unread,
Aug 4, 2015, 1:58:25 AM8/4/15
to topbrai...@googlegroups.com
You have not provided sufficient details to get helpful responses. What is the error message, what is the query string sent to the server? Maybe you should use POST instead of GET requests to pass the query string to the service.

Holger
--

Shreelakshmi G.M

unread,
Aug 4, 2015, 2:43:14 AM8/4/15
to TopBraid Suite Users
The query I am sending is 
SELECT  ?class
WHERE {
    ?class a owl:Class .
    ?class rdfs:subClassOf* <http://www.xyz.org/ontology/mechanisms1#Elements> .
}

I am sending it through POST request and I am getting HTTP 500 ERROR

Problem accessing /tbl/sparql. Reason:

    Invalid SPARQL query string SELECT  ?class WHERE {?class a owl:Class . ?class rdfs:subClassOf* <http://www.xyz.org/ontology/mechanisms1: Encountered " "<" "< "" at line 1, column 68. 

Was expecting one of:
    <IRIref> ...
    <PNAME_NS> ...
    <PNAME_LN> ...
    <BLANK_NODE_LABEL> ...
    <VAR1> ...
    <VAR2> ...
    "true" ...
    "false" ...
    <INTEGER> ...
    <DECIMAL> ...
    <DOUBLE> ...
    <INTEGER_POSITIVE> ...
    <DECIMAL_POSITIVE> ...
    <DOUBLE_POSITIVE> ...
    <INTEGER_NEGATIVE> ...
    <DECIMAL_NEGATIVE> ...
    <DOUBLE_NEGATIVE> ...
    <STRING_LITERAL1> ...
    <STRING_LITERAL2> ...
    <STRING_LITERAL_LONG1> ...
    <STRING_LITERAL_LONG2> ...
    "(" ...
    <NIL> ...
    "[" ...
    <ANON> ...
    "/" ...
    "|" ...
    "^" ...
 
If I go to the link http://localhost:8083/tbl/sparql and paste the same query and run it from there, I am getting the proper result.

Thanks,
Shreelakshmi
On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:

Holger Knublauch

unread,
Aug 4, 2015, 2:44:47 AM8/4/15
to topbrai...@googlegroups.com
Please try again, and prepend the default prefix declarations, e.g. for the owl: namespace.

Holger
--

Shreelakshmi G.M

unread,
Aug 4, 2015, 2:52:58 AM8/4/15
to TopBraid Suite Users
I am getting the same error, Is it something to do with escape character for "/" character ?


You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/6IP1cH7hpnk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.

Shreelakshmi G.M

unread,
Aug 4, 2015, 3:06:53 AM8/4/15
to TopBraid Suite Users
If I try executing this :

PREFIX countries: <http://topbraid.org/countries#>
SELECT ?name ?abbrev
WHERE
{ ?country a countries:Country .
?country rdfs:label ?name .
?country countries:abbreviation ?abbrev .
}
}

I am getting the following error:

Problem accessing /tbl/sparql. Reason:

    Invalid SPARQL query string PREFIX countries: <http://topbraid.org/countries: Encountered " "<" "< "" at line 1, column 19.
Was expecting:
    <IRIref> ...


On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:

Jerven Tjalling Bolleman

unread,
Aug 4, 2015, 3:10:17 AM8/4/15
to topbrai...@googlegroups.com
On 2015-08-04 08:52, Shreelakshmi G.M wrote:
> I am getting the same error, Is it something to do with escape
> character for "/" character ?
More likely the escaping of # is not done in your code that is
submitting a sparql request. Are you sure it is a POST?

Regards,
Jerven

PS. Not affiliated in any way with Topquadrant
>
> On Tue, Aug 4, 2015 at 12:14 PM, Holger Knublauch
> <hol...@topquadrant.com> wrote:
>
> Please try again, and prepend the default prefix declarations, e.g. for
> the owl: namespace.
>
> Holger
>
> On 8/4/2015 16:43, Shreelakshmi G.M wrote:
>
> The query I am sending is 
> SELECT  ?CLASS
> WHERE {
>     ?CLASS A OWL:CLASS .
>     ?CLASS RDFS:SUBCLASSOF*
> <HTTP://WWW.XYZ.ORG/ONTOLOGY/MECHANISMS1#ELEMENTS> [2] .
> }
>
> I am sending it through POST request and I am getting HTTP 500 ERROR
>
> Problem accessing /tbl/sparql. Reason:
>
> Invalid SPARQL query string SELECT ?class WHERE {?class a owl:Class .
> ?class rdfs:subClassOf* <http://www.xyz.org/ontology/mechanisms1 [1]:
> If I go to the link http://localhost:8083/tbl/sparql [3] and paste the
> same query and run it from there, I am getting the proper result.
>
> Thanks,
> Shreelakshmi
> On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:
> I want to display sparql query result, onclick of a button.
> how can I do this ? --
> You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include Enterprise
> Vocabulary Network (EVN), Reference Data Manager (RDM), TopBraid
> Composer, TopBraid Live, TopBraid Insight, 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 [4].
>
> --
> You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include Enterprise
> Vocabulary Network (EVN), Reference Data Manager (RDM), TopBraid
> Composer, TopBraid Live, TopBraid Insight, 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 a topic in the
> Google Groups "TopBraid Suite Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/topbraid-users/6IP1cH7hpnk/unsubscribe
> [5].
> To unsubscribe from this group and all its topics, send an email to
> topbraid-user...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout [4].
>
> --
> You received this message because you are subscribed to the Google
> Group "TopBraid Suite Users", the topics of which include Enterprise
> Vocabulary Network (EVN), Reference Data Manager (RDM), TopBraid
> Composer, TopBraid Live, TopBraid Insight, 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 [4].
>
>
> Links:
> ------
> [1] http://www.xyz.org/ontology/mechanisms1
> [2] http://www.xyz.org/ontology/mechanisms1#Elements
> [3] http://localhost:8083/tbl/sparql
> [4] https://groups.google.com/d/optout
> [5]
> https://groups.google.com/d/topic/topbraid-users/6IP1cH7hpnk/unsubscribe

--
Jerven Tjalling Bolleman
SIB | Swiss Institute of Bioinformatics
CMU - 1, rue Michel Servet - 1211 Geneva 4
t: +41 22 379 58 85 - f: +41 22 379 58 58
Jerven....@isb-sib.ch - http://www.isb-sib.ch


Shreelakshmi G.M

unread,
Aug 4, 2015, 3:17:56 AM8/4/15
to TopBraid Suite Users
Thanks Holger and Jerven,

The problem is solved,

I escaped the characters in the query,
I changed the query to POST request to,

http://localhost:8083/tbl/sparql?query=SELECT  ?class WHERE {?class a owl:Class . ?class rdfs:subClassOf* <http:/%2Fwww.xyz.org%2Fontology%2Fmechanisms1%23Elements%3E .}

Thanks, 
Shreelakshmi

On Friday, 24 July 2015 16:55:13 UTC+5:30, Shreelakshmi G.M wrote:
Reply all
Reply to author
Forward
0 new messages