Freebase query result buried under nonsense - freebase

A beginner's question about freebase:
I am looking for the imdb id of a movie called "O". If I use the searchbox on the freebase.com website and constrain the search by type to all:/film/film, then I get a high quality result with the best match on top:
http://www.freebase.com/search?query=o&lang=en&all=%2Ffilm%2Ffilm&scoring=entity&prefixed=true
But this does not include the imdb id. When I try to recreate and refine this search using the query editor, I can't figure out how to do a "general query". The best I could come up with was doing a fuzzy name search like this:
[{
"type": "/film/film",
"name": null,
"name~=": "o",
"imdb_id": [],
"rottentomatoes_id": []
}]
The result contains exactly the information I want, but the movie "O" is only the 12th result in the list, buried under lots of nonsense:
http://www.freebase.com/query?lang=%2Flang%2Fen&q=[{%22type%22%3A%22%2Ffilm%2Ffilm%22%2C%22name%22%3Anull%2C%22name~%3D%22%3A%22o%22%2C%22imdb_id%22%3A[]%2C%22rottentomatoes_id%22%3A[]}]
How can I improve the quality of my result? What special magic does the "?query=o" use that "name~=":"o" does not have?

When you use query=o, freebase does some smart sorting of the results, display exact matches first, followed by less exact matches.
With your query name ~= o you are not searching for movies with name "O", but for movies that contain "O" in their names (the ~= operator). If you want to search for a specific movie title, then specify the exact name:
[{
"type": "/film/film",
"name": "o",
"imdb_id": [],
"rottentomatoes_id": []
}]
This will result in output:
{
"result": [{
"imdb_id": [
"tt0184791"
],
"name": "O",
"type": "/film/film",
"rottentomatoes_id": [
"o"
]
}]
}

If Search gives you the topic that you want, why not just use the output parameter to add the IMDB ID (or whatever else you want) to the output that you request it return?

Related

Convert the JSON attribute from smallcase to uppercase in XQuery and Marklogic 10

I have loaded the below JSON in MarkLogic and I need to convert the Name property value to upper case:
{ "Name": "User", "Id": "1", "date": "2022-01-01" }
Any way to convert the value to upper case in Marklogic and XQuery, looking like below format?
{ "Name": "USER", "Id": "1", "date": "2022-01-01" }
One way would be to select the Name, use upper-case() and create a text() node, and then use xdmp:node-replace().
Assuming that you have the document assigned to a variable $doc:
let $name := $doc/Name
return xdmp:node-replace($name, text {upper-case($name) } )
For reference, there are a few examples in the documentation of updating different types of properties:
https://docs.marklogic.com/guide/app-dev/json#id_60123

Parsing nested JSON and creating new keys with jq

I have a JSON file that has hundreds of objects. Each object has 2 keys with nested object\arrays one for assignee and another for epics.
[
{
"id": 1111111111,
"assignee": {
"id": 1234,
"firstName": "John",
"lastName": "Doe",
"email": "Doe#doe.com",
},
"epics": [
{
"id": 111,
"title": "Big Code Issues",
"version": 16
}
],
"location": "Nerdville"
}
]
from the current assignee key. I want to create a two new keys assigneeId and assigneeName. Where the assigneeName is the firstName and lastName combined. The original nested assignee key can be discarded.
from the epics key I would like to create and epicsID key with a value of id from epics. The rest of the keys in the nested key can be discarded.
I am very new to jq but i would like to create following output.
[
{
"id": 1111111111,
"assigneeId": 1234,
"assingeeName": "John Doe",
"epicsid": 111,
"location": "Nerdville"
}
]
I can create and remove keys with JQ but I am have not been able to iterate the JSON file to grab values from with the nested keys and put into new keys. I have been getting errors based on different command I been running but the main one is "Cannot index array with string "epics"".
Any help would be greatly appreciated
After fixing a very small technical problem with your JSON, the following produces the required result:
map( {id,
assigneeId: .assignee.id,
assigneeName: (.assignee | .firstName + " " + .lastName),
epicsid: .epics[0].id,
location } )
You might wish to modify this if the "epics" array has more than one item in it.

Cosmos DB Gremlin "project" not producing expected results

I have the following traversal that shows that the selected Vertex has 14 Edges labeled "follows".
g.V().has('user','email','me#email.com').project('name','email','follow-edges').by('name').by('email').by(outE().hasLabel('follows').project('id','inV').by('id').by('inV'))
Which produces the following results:
[{
"name": "David",
"email": "me#email.com",
"follow-edges": 14}]
But when I want to project the "follows" Edge's id and inV ids, I'm only getting one result item back.
g.V().has('user','email','david#me.com').project('name','email','follow-edges').by('name').by('email').by(outE().hasLabel('follows').project('edge-id', 'inV-id').by('id').by('inV'))
Results:
[{
"name": "David",
"email": "me#email.com",
"follow-edges": {
"edge-id": "ccc06183-f4ca-410d-9c3c-9d2dfd93f5f0",
"inV-id": "f4703a07-f42d-46f9-86be-7f5440f07f12"
}}]
I was expecting to get a list of all the "follows" edge's for the selected vertex. Similiar to the answer given by Stephen Mallette at this link.
Does anyone know why this is not working?
You need to reduce the stream of objects in your anonymous traversal in by() - note my addition of fold():
g.V().has('user','email','david#me.com').
project('name','email','followedges').
by('name').
by('email').
by(outE().hasLabel('follows').
project('edge-id', 'inV-id').
by('id').
by('inV').fold())
I assume that "inV" is an actual property and you're not trying to get the "in vertex" of the edge. If you are trying to get the "in vertex" then you need by(inV().id()).

How do I create a Slot that accepts a currency amount

I want to receive a dollar amount in my utterance. So, for example, if I ask Alexa:
Send $100.51 to Kroger.
(pronounced, One hundred dollars and fifty one cents) I want to receive the value 100.51 in a proper slot.
I have tried searching and I defined my utterance slots like this:
"slots": [
{
"name": "Amount",
"type": "AMAZON.NUMBER"
}
]
But on JSON input I only get this result:
"slots": {
"Amount": {
"name": "Amount",
"value": "?"
}
}
How can I make Alexa accepts currency values?
I'm a bit confused by what you wrote in your last sentence and the code, but I'll confirm that there is no built-in intent or slot for handling currency.
So, you'll have to do it manually using AMAZON.NUMBER slot type as you seem to be trying.
I would imagine that you will want to create utterences with two AMAZON.NUMBER slots - one for dollars and one for cents.
Easy, make a custom slot and just use $10.11, $.03, and $1003.84 as the sample's. It will work as currency now, accepting users dollars and cents utterances and converting them to a dollar $XX.XX format.

converting Freebase MQL to TinkerPop3 gremlin?

Even though Freebase was deprecated in Jun. 2015, I was impressed by Freebase's MQL. It is intuitive, concise, declarative, and easy to understand/write.
These days I'm learning about TinkerPop3 and gremlin. I think gremlin has many good features. I wonder whether I could convert Freebase MQL to TinkerPop3 gremlin.
Let's say, I have TinkerPop3 sample data "The Crew" and following MQL:
[{
"type": "person",
"name": null,
"develops": {
"type": "software",
"release_date": null, // release_date is not in the crew data.
// Just added for test
"name": null,
"sort": "-name", // descending sort
"limit": 2 // print only two software
},
"uses": {
"type": "software",
"release_date": null,
"name": null,
"sort": "name", // ascending sort
"limit": 2
}
}]
Above MQL means "find person", and for each person "print his two developed software and used software". Please keep in mind that above MQL is just an example for testing.
I've tried to convert MQL to a single gremlin. But I couldn't convert it. So I'm asking you. Is it possible? then how to convert, if impossible why? (If it is possible it would be better if a generated gremlin is efficient in terms of optimization and execution.)
If single gremlin is impossible, then is it possible assembling two or more gremlin can generate as same as MQL's output without performance loss?
Thanks in advanced.
The fastest query to solve this problem should be the following:
gremlin> g.V().hasLabel("person").as("person").
gremlin> map(out("develops").order().by("name", decr).limit(2).fold()).as("develops").select("person").
gremlin> map(out("uses").order().by("name", incr).limit(2).fold()).as("uses").
gremlin> select("person","develops","uses")
==>[person:v[1], develops:[v[11], v[10]], uses:[v[10], v[11]]]
==>[person:v[7], develops:[v[11], v[10]], uses:[v[10], v[11]]]
==>[person:v[8], develops:[v[10]], uses:[v[10], v[11]]]
==>[person:v[9], develops:[], uses:[v[10], v[11]]]
However, using the match() step, you can probably enhance the readability (although it contains the same steps):
g.V().hasLabel("person").match(
__.as("person").out("develops").order().by("name", decr).limit(2).fold().as("develops"),
__.as("person").out("uses").order().by("name", incr).limit(2).fold().as("uses")).
select("person","develops","uses")
UPDATE
Since you don't want to see me (v[9]) in the result set, you can add a simple filter condition:
g.V().hasLabel("person").as("person").
filter(outE("develops").and().outE("uses")).
map(out("develops").order().by("name", decr).limit(2).fold()).as("develops").select("person").
map(out("uses").order().by("name", incr).limit(2).fold()).as("uses").
select("person","develops","uses")

Resources