Stardog js get json query results

4 views
Skip to first unread message

timea....@gmail.com

unread,
Apr 20, 2015, 9:58:21 AM4/20/15
to sta...@clarkparsia.com
Hi all,

I'm trying out stardog.js to get some query results, but so far I've got:

Uncaught TypeError: Cannot read property 'extend' of undefinedConnection.query 
@ stardog.js:428(anonymous function) 

My script is:
<html>
<head>
 <script src="../bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
  <script src="../bower_components/expect/index.js" type="text/javascript"></script>
  <script src="../bower_components/lodash/dist/lodash.js" type="text/javascript"></script>
  <script src="../bower_components/mocha/mocha.js" type="text/javascript"></script>
  <script src="../js/stardog.js" type="text/javascript"></script>
</head>
<body>Hello everybody!
<h2>Results</h2>
    <textarea id="results" rows=30 cols=100>
    </textarea>
</body>
<script type="text/javascript">
var conn = new Stardog.Connection();
conn.setEndpoint("http://localhost:5820/");
conn.setReasoning(true);
conn.setCredentials("smth", "smth");

conn.query({
        database: "mydb",
        query: "select distinct ?s where { ?s ?p ?o }",  
        limit: 10,
        offset: 0
    },
    function (data) {
        console.log(data.results.bindings);
        document.getElementById("results").innerHTML = data.results.bindings;
        $("#results").append(data.results.bindings);
});
});
});
</script>
</html>

Any thoughts?
I don't know much about cross-reference domain or MIME types, I would like to get JSON objects back, and so far I got nothing.
Please help,
Timi.

Edgar Rodriguez

unread,
Apr 20, 2015, 12:09:23 PM4/20/15
to sta...@clarkparsia.com
Hi,


On Mon, Apr 20, 2015 at 9:58 AM, <timea....@gmail.com> wrote:
Hi all,

I'm trying out stardog.js to get some query results, but so far I've got:

Uncaught TypeError: Cannot read property 'extend' of undefinedConnection.query 
@ stardog.js:428(anonymous function) 

This seems to be an issue with the dependencies included, it looks like your script can't find `lodash` which contains the definition of the `extend` function. Please make sure that you have the correct paths to the dependencies in your `script` tags. You can use Bower[1] to download/manage these dependencies and install stardog.js with the command:

bower install stardog


My script is:
<html>
<head>
 <script src="../bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
  <script src="../bower_components/expect/index.js" type="text/javascript"></script>
  <script src="../bower_components/lodash/dist/lodash.js" type="text/javascript"></script>
  <script src="../bower_components/mocha/mocha.js" type="text/javascript"></script>
  <script src="../js/stardog.js" type="text/javascript"></script>

You don't need to list `mocha` and `expect` as dependencies, those are only required to run the stardog.js test suite.
 
</head>
<body>Hello everybody!
<h2>Results</h2>
    <textarea id="results" rows=30 cols=100>
    </textarea>
</body>
<script type="text/javascript">
var conn = new Stardog.Connection();
conn.setEndpoint("http://localhost:5820/");
conn.setReasoning(true);
conn.setCredentials("smth", "smth");

conn.query({
        database: "mydb",
        query: "select distinct ?s where { ?s ?p ?o }",  
        limit: 10,
        offset: 0
    },
    function (data) {
        console.log(data.results.bindings);
        document.getElementById("results").innerHTML = data.results.bindings;
        $("#results").append(data.results.bindings);
});
});
});

There seems to be an issue with the syntax for this call, the closing brackets don't match.
 
</script>
</html>

Any thoughts?
I don't know much about cross-reference domain or MIME types, I would like to get JSON objects back, and so far I got nothing.

By default, stardog.js gets the query results with the application/sparql-results+json mimetype, but you can always set the accept mimetype from [2] in the query call, e.g. getting the result of a construct query in json-ld:

conn.query({
database: "nodeDB",
query: "construct where { ?s ?p ?o }",
mimetype: "application/ld+json",

limit: 10,
offset: 0
},
function (data) {
...
});

 
Best,
Edgar
Please help,
Timi.

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Timi Bagosi

unread,
Apr 21, 2015, 3:55:12 AM4/21/15
to sta...@clarkparsia.com
Thanks Edgar, 
I corrected everything you said, and I did use bower install and it does install correctly everything (I can see the file tree and the required js files).
Even though, the error is still the same, 
Uncaught TypeError: Cannot read property 'extend' of undefined.
My script now is corrected to:

<html>
<head>
  <script src="bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
  <script src="bower_components/lodash/dist/lodash.js" type="text/javascript"></script>
  <script src="bower_components/stardog/js/stardog.js" type="text/javascript"></script>
</head>
<body>Hello everybody!
<h2>Results</h2>
    <textarea id="results" rows=30 cols=100>
    </textarea>
</body>
<script type="text/javascript">

var conn = new Stardog.Connection();
conn.setEndpoint("http://localhost:5820/");
conn.setReasoning(true);
conn.setCredentials("admin", "admin");
alert("Conn: "+conn);
conn.query({
        database: "tradr",
        query: "construct where { ?s ?p ?o }",  
        mimetype: "application/ld+json",
        limit: 10,
        offset: 0
    },
    function (data) {
      alert("Data: "+data.results);
        console.log(data.results.bindings);
        document.getElementById("results").innerHTML = data.results.bindings;
});
</script>
</html>


Anything would help,
thanks,
Timi.

Edgar Rodriguez

unread,
Apr 21, 2015, 11:47:19 AM4/21/15
to sta...@clarkparsia.com
On Tue, Apr 21, 2015 at 3:55 AM, Timi Bagosi <timea....@gmail.com> wrote:
Thanks Edgar, 
I corrected everything you said, and I did use bower install and it does install correctly everything (I can see the file tree and the required js files).
Even though, the error is still the same, 
Uncaught TypeError: Cannot read property 'extend' of undefined.
My script now is corrected to:

I just ran your script with a database locally and it works. I can't reproduce your issue. You may want to use something like Chrome Developer Tools to help you identify the problem.
 
This won't show you something useful, you may want to serialize the response object to string with `JSON.stringify(data)`.
 
});
</script>
</html>


Anything would help,
thanks,
Timi.

Best,
Edgar
 
Reply all
Reply to author
Forward
0 new messages