watson discovery query -- result set not as expected - watson

I would like to query the discovery service 'news collection' and I am using this query command.
discovery.query({ environment_id: ‘my env id’,
collection_id: ‘my coll id’,
“count”: 10,
“return”: “title,enrichedTitle.text”,
“query”: “dieter zetsche”,
“aggregations”: [ “term(docSentiment.type:2)“]
}, function(err, response) { …
I am expecting the following response structure
{
“matching_results”: 7607,
“aggregations”: [
{...}
],
“passages”: [],
“results”: [
{...}
]
}
but I get only the response without the ‘aggregation’ -- any recommendation???
like this
{"matching_results":7603,
"results":[
{"id":"....

Please note that the JSON object name for Sentiment Analysis has been changed from docSentiment to sentiment
More details here: https://www.ibm.com/watson/developercloud/doc/discovery/migrate-nlu.html#overview-of-major-changes

Related

Why does Neo4j 3.1.x return empty for relationships?

Using 3.1.5 and the example from the Neo4j documentation:
To return a relationship, just include it in the RETURN list.
Query.
MATCH (n { name: 'A' })-[r:KNOWS]->(c)
RETURN r
The relationship is returned by the example.
Table 3.63. Result
r
1 row
:KNOWS[0]\{\}
returns empty for the relationship. As far as I can tell, all return 'relationship' results in
{
"results": [
{
"columns": [
"r"
],
"data": [
{
"row": [
{}
],
"meta": [
{
"id": 927,
"type": "relationship",
"deleted": false
}
]
}
]
}
],
"errors": []
}
Is this a change? A known-issue? The way it always was?
It's the way it always was for JSON result (ie. via the HTTP connector).
In JSON, neo4j return all relationship's property.
If you use a a driver for Bolt connector, you will recieve a Relationship object with the startId & endId node, relationship's type, and the properties.
Cheers
UPDATE
You have access to the relationship's properties.
With this dataset : MERGE (:Test {id:1})-[:REL {value:'Test'}]->(:Test {id:2})
Via this curl command :
curl -v http://localhost:7474/db/data/transaction/commit -u neo4j:admin --data '{"statements":[{"statement":"MATCH (:Test)-[r:REL]->(:Test) RETURN r"}]}' -H "Content-Type: application/json"
Result is :
{"results":[{"columns":["r"],"data":[{"row":[{"value":"Test"}],"meta":[{"id":273,"type":"relationship","deleted":false}]}]}],"errors":[]}
You see the extract {"value":"Test"} is your relationship !

Neocons Cypher tquery and accessing values from keys

After calling neo4j with neocons (cy/tquery conn node-query {:_nodeid _nodeid}), how do you perform accessing functions to get property values from the keys that are returned from the neo4j datastore response?
For example if this object was the response from the neo4j datastore, what neocons syntax do I use to access the value stored in key "attributes"?
[ {
"id": "letter-a",
"name": "Letter A",
"attributes": [ ... ]
}]
Currently I can only get so far as (first _response) but (get-in (first _response) [:attributes]) is giving me back nil
******************* EDIT *******************************
Here is the cypher query string I use as an argument to invoke the tquery function:
(def node-query "MATCH (n)-[attributelist:RELATIONSHIPTYPE]->(target)
RETURN n.id AS id,
n.name AS name,
COLLECT({
target : target.id
}) AS attributes;")
I don't understand what type of variable tquery returns? It looks like this object when the client displays it all the way in the browser:
[
{
"id": "node-999990a0a0a0sa0",
"name": "Node Name",
"attributes": [
{
"target": "node-id-one"
},
{
"target": "node-id-two"
},
{
"target": "node-id-two"
},
{
"target": "node-id-two"
},
{
"target": "node-id-three"
}
]
}
]
But I want to intercept what is returned from the tquery before the clojure server delivers it to the client and I want to manipulate the array value of the key "attributes" so I can run a reduce (tally) report before I deliver a rebuilt object response to the client.
{
...
"attributes" : {
"node-id-one" : 1,
"node-id-two" : 3,
"node-id-three" : 1
}
}
But I am having trouble because I do not know the syntax to access the "attributes" key from the object that is returned from the tquery
Sorry I don't understand your question. Which query did you run with tquery?
Usually you return the data you're interested in directly from the query.
e.g
MATCH (p:Person)-[:ACTED_IN]->(m)
WHERE p.name = "Tom Hanks"
RETURN m.title, m.released`
Otherwise you'd have to requery using a label+unique-property
MATCH (m:Movie)
WHERE m.title = "The Matrix"
RETURN m.title, m.released`
or node-id match.
MATCH (m:Movie)
WHERE id(m) = 123
RETURN m.title, m.released`
You usually would use parameters instead of literal values, i.e. {name}, {title}, {id}.
Update
I think for intercepting you would have to look into the neocons implementation.
Note: there is no clojure server, it's a Neo4j server with an http endpoint.
You should be able to do what you want (almost) in cypher.
MATCH (n)-[:RELATIONSHIPTYPE]->(target)
WITH n, target.id as target, count(*) as c
RETURN n.id as id, n.name as name, collect([target,c]) as targets;
Unfortunately right now there are no dynamic map-keys in Cypher, so a tuple-collection will have to do.
PS
You should use a label at least for your n (and optionally target) nodes.

How to structure falcor router to get all available IDs?

I'm experimenting with using Falcor to front the Guild Wars 2 API and want to use it to show game item details. I'm especially interested in building a router that can use multiple datasources to combine the results of different APIs.
The catch is, Item IDs in Guild Wars 2 aren't contiguous. Here's an example:
[
1,
2,
6,
11,
24,
56,
...
]
So I can't just write paths on the client like items[100..120].name because there's almost certainly going to be a bunch of holes in that list.
I've tried adding a route to my router so I can just request items, but that sends it into an infinite loop on the client. You can see that attempt on GitHub.
Any pointers on the correct way to structure this? As I think about it more maybe I want item.id instead?
You shouldn't find your self asking for ids from a Falcor JSON Graph object.
It seems like you want to build an array of game ids:
{
games: [
{ $type: "ref", value: ["gamesById", 352] },
{ $type: "ref", value: ["gamesById", 428] }
// ...
],
gamesById: {
352: {
gameProp1: ...,
},
428: {
gameProp2: ...
}
}
}
[games, {from: 5, to: 17 }, "gameProp1"]
Does that work?
You can use 'get' API of Falcor, It retrieves multiple values.. You can pass any number of required properties as shown below
var model=new falcor.Model({
cache:{
genereList:[
{name:"Recently Watched",
titles:[
{id:123,
name: "Ignatius",
rating: 4}
]
},
{name:"New Release",
titles:[
{id:124,
name: "Jessy",
rating: 3}
]
}
]
}
});
Getting single value
model.getValue('genereList[0].titles[0].name').
then(function(value){
console.log(value);
});
Getting multiple values
model.get('genereList[0..1].titles[0].name', 'genereList[0..1].titles[0].rating').
then(function(json){
console.log(JSON.stringify(json, null, 4));
})

How do you use parameters with neo4j?

I am looking at the documentation for neo4j and I see that I can use parameters when I create objects. Specifically when I look at this page I see the code:
{
"props" : {
"position" : "Developer",
"name" : "Andres"
}
}
Query.
CREATE ({ props })
Yet when I use the web interface to access my neo4j database on my local machine I do not know how to specify the parameter. Simply copy/pasting that JSON object yields an error. I see on the page that
Exactly how to submit them depends on the driver in use.
but how does one use them on that command line/web interface?
Cypher supports queries with parameters which are submitted as JSON. For example, the following is the REST API usage. For the Java embedded API please refer to the following documentation: http://docs.neo4j.org/chunked/milestone/tutorials-cypher-parameters-java.html
MATCH (x { name: { startName }})-[r]-(friend)
WHERE friend.name = { name }
RETURN TYPE(r)
Example request
POST http://localhost:7474/db/data/cypher
Accept: application/json; charset=UTF-8
Content-Type: application/json
{
"query" : "MATCH (x {name: {startName}})-[r]-(friend) WHERE friend.name = {name} RETURN TYPE(r)",
"params" : {
"startName" : "I",
"name" : "you"
}
}
Example response
200: OK
Content-Type: application/json; charset=UTF-8
{
"columns" : [ "TYPE(r)" ],
"data" : [ [ "know" ] ]
}
Parameters are not currently supported in regular Cypher statements in the Neo4j 2.0 browser. However, you can use the :POST syntax to achieve this.
Refer to the documentation for more information on Cypher queries via REST API.
http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html
Update:
The following query allows you to accomplish this in the browser, although it is not an ideal experience:
:POST /db/data/transaction/commit {
"statements": [
{
"statement": "MATCH (u:User {name:{username}}) RETURN u.name as username",
"parameters": {
"username": "my name"
}
}
]
}
The syntax to define params in the browser's command line is :params followed by the variable you would like to define, just type in :params and you will get a sense of how this command works from the resulting prompts.
For the case of HTTP API, in the latest version (v3.5 as of this writing), use the following syntax, copied from https://neo4j.com/docs/http-api/current/http-api-actions/execute-multiple-statements/:
{
"statements" : [ {
"statement" : "CREATE (n) RETURN id(n)"
}, {
"statement" : "CREATE (n {props}) RETURN n",
"parameters" : {
"props" : {
"name" : "My Node"
}
}
} ]
}

Emit Tuples From Erlang Views In CouchDB

CouchDB, version 0.10.0, using native erlang views.
I have a simple document of the form:
{
"_id": "user-1",
"_rev": "1-9ccf63b66b62d15d75daa211c5a7fb0d",
"type": "user",
"identifiers": [
"ABC",
"DEF",
"123"
],
"username": "monkey",
"name": "Monkey Man"
}
And a basic javascript design document:
{
"_id": "_design/user",
"_rev": "1-94bd8a0dbce5e2efd699d17acea1db0b",
"language": "javascript",
"views": {
"find_by_identifier": {
"map": "function(doc) {
if (doc.type == 'user') {
doc.identifiers.forEach(function(identifier) {
emit(identifier, {\"username\":doc.username,\"name\":doc.name});
});
}
}"
}
}
}
which emits:
{"total_rows":3,"offset":0,"rows":[
{"id":"user-1","key":"ABC","value":{"username":"monkey","name":"Monkey Man"}},
{"id":"user-1","key":"DEF","value":{"username":"monkey","name":"Monkey Man"}},
{"id":"user-1","key":"123","value":{"username":"monkey","name":"Monkey Man"}}
]}
I'm looking into building an Erlang view that does the same thing. Best attempt so far is:
%% Map Function
fun({Doc}) ->
case proplists:get_value(<<"type">>, Doc) of
undefined ->
ok;
Type ->
Identifiers = proplists:get_value(<<"identifiers">>, Doc),
ID = proplists:get_value(<<"_id">>, Doc),
Username = proplists:get_value(<<"username">>, Doc),
Name = proplists:get_value(<<"name">>, Doc),
lists:foreach(fun(Identifier) -> Emit(Identifier, [ID, Username, Name]) end, Identifiers);
_ ->
ok
end
end.
which emits:
{"total_rows":3,"offset":0,"rows":[
{"id":"user-1","key":"ABC","value":["monkey","Monkey Man"]},
{"id":"user-1","key":"DEF","value":["monkey","Monkey Man"]},
{"id":"user-1","key":"123","value":["monkey","Monkey Man"]}
]}
The question is - how can I get those values out as tuples, instead of as arrays? I don't imagine I can (or would want to) use records, but using atoms in a tuple doesn't seem to work.
lists:foreach(fun(Identifier) -> Emit(Identifier, {id, ID, username, Username, name, Name}) end, Identifiers);
Fails with the following error:
{"error":"json_encode","reason":"{bad_term,{<<\"user-1\">>,<<\"monkey\">>,<<\"Monkey Man\">>}}"}
Thoughts? I know that Erlang sucks for this specific kind of thing (named access) and that I can do it by convention (id at first position, username next, real name last), but that makes the client side code pretty ugly.
The JSON object {"foo":"bar","baz":1} is {[{<<"foo">>,<<"bar">>},{<<"baz">>,1}]}
In Erlang lingua it is a proplist wrapped in a tuple.
It's not pretty, but very efficient :)
To get a feel for it you can play with the JSON lib that ships with CouchDB:
Start CouchDB with the -i
(interactive) flag
On the resulting erlang shell, type: couch_util:json_decode(<<"{\"foo\":\"bar\"}">>).
Profit
// in later versions of CouchDB, this is ejson:decode()
For test_suite_reports bd, that has tests field:
[
{
"name": "basics",
"status": "success",
"duration": 21795
},
{
"name": "all_docs",
"status": "success",
"duration": 385
} ...
I have wrote this to get name and status:
fun({Doc}) ->
Name = fun(L) -> proplists:get_value(<<"name">>, L, null) end,
Status = fun(L) -> proplists:get_value(<<"status">>, L, null) end,
Tests = proplists:get_value(<<"tests">>, Doc, null),
lists:foreach(fun({L}) -> Emit(Name(L), Status(L)) end, Tests)
end.
If you like experimental features (that still work...), you might want to have a look to Erlang exprecs.
I found it extremely helpful in creating a sort of dynamic records for Erlang.

Resources