Querying Freebase to get all relations between two concepts - freebase

I'd like to query Freebase in order to obtain all the relations that occur between two concepts.
My problem is that I'd like to do this using two concepts' names.
For example: I have "Ball" as a concept (and I don't want to say to Freebase if it is Ball as in Dance or as in Sports Equipment) and I want to find out if there are relations between it and "Football" (in this case, there is just one concept on Freebase for Football, so it is easier); the ouput should be "/sports/sports_equipment/sport_used_for".
For now I just managed to do the same query using the id of the concepts, but I would like to search for relations as I explained before, without knowing the exact meaning of the concept title (Ball in the example).
The query that I have so far is this:
{
"type": "/type/link",
"source": {
"id": "/m/0dpm1v"
},
"master_property": null,
"target": {
"id": "/m/02vx4"
}
}
Thank you in advance for the help

"name" was what I was looking for. I don't know because I did not try/find this before.
Thak you anyway.
{
"type": "/type/link",
"source": {
"name": "ball"
},
"master_property": null,
"target": {
"name": "football"
}
}

Related

Azure Cosmos SQL - working with nested arrays and using LIKE keyword

For some time when I had to find particular element of array by particular value I've been using ARRAY_CONTAINS function. Now I have documents with nested arrays where I have to search not but particular value, but using regex.
As an example of document let me use one from official documentation:
{
"id": "AndersenFamily",
"lastName": "Andersen",
"parents": [
{ "firstName": "Thomas" },
{ "firstName": "Mary Kay"}
],
"children": [
{
"firstName": "Henriette Thaulow",
"gender": "female",
"grade": 5,
"pets": [{ "givenName": "Fluffy" }]
}
],
"address": { "state": "WA", "county": "King", "city": "Seattle" },
"creationDate": 1431620472,
"isRegistered": true
}
What I need is to select and fully get all documents where at least one of children has at least one pets element where givenName contains "fluf".
What SQL query do I build to achieve it?
Here's a query that uses JOINs to flatten out the inner pets arrays and apply a filter, then return the entire matching family items:
SELECT VALUE f
FROM Families f
JOIN c IN f.children
JOIN p IN c.pets
WHERE p.givenName LIKE "%Fluf%"
The complexity of figuring out such queries is one reason why I think it's worth considering modeling data to be as flat as possible, including normalizing out to have separate pets items for example, which can be queried with direct property filters without dealing with nesting. Combining everything into a large Family object as the examples do isn't necessarily a good idea in practice depending on your goals.

Conditional query in Freebase API

I am looking to extract list of tourist attractions and their city,state and country information from Freebase. The property that has location is
"/location/location/containedby". There are different types for this object, "location/location" or "/base/biblioness/bibs_location". If the object has "/base/biblioness/bibs_location" i can get the value of "city", "state" etc. however if the object only has the type "/location/location" i need to go and get its "containedby" field and redo the above logic.
My question is can i perform a conditional query in Freebase like if type == "/location/location/" get xyz. if type== "/base/biblioness/bibs_location" get abc
MQL:
[{
"type": "/travel/tourist_attraction",
"id": null,
"name": null,
"name~=": "^San Diego",
"/location/location/containedby": {
"type": "/base/biblioness/bibs_location",
"name": null,
"id": null
},
"/location/location/geolocation": [{
"id": null,
"latitude": null,
"longitude": null
}]
}]
MQL doesn't support conditional logic, but you can query all the information that you're potentially interested in, making the subqueries optional so they don't filter the results, and then look at what you get back. It'll require conditional code in your result processor, but you won't have to make multiple queries. For example, you could query multiple levels of /location/location/contained by as well as /base/biblioness/bibs_location/state and whatever else you want.
Before you go spending too much time on this though, you might want to check how well populated /base/biblioness/bibs_location is. It looks to me like it's got less than 2K entities.

Freebase MQL query to get all info about a specific date

I'm wondering if it is possible to get all info about a specific date from Freebase.
I can easily retrieve info about a date giving a specific topic, for example, to grab all persons of interest who were born on a specific date:
[{
"type":"/people/person",
"limit":1000,
"sort":"name",
"name":null,
"guid":null,
"timestamp":null,
"/people/person/date_of_birth":"1955-02-24"
}]
Is it possible to grab all types? I'm after things like people born on that date (which I have), major events (start of a war, assassination of a person of interest, etc), and so on.
Essentially I want to match all fields that are dates and return the full information about that entry, regardless of type.
Reflection is what you need here:
[{
"/type/reflect/any_value": [{
"type": "/type/datetime",
"value": "1955-02-24",
"link": {
"source": {
"id": null
},
"master_property": null
}
}]
}]
A couple of notes on that: the MQL manual I've linked to is somewhat bitrotted in its details but is still the best documentation that exists on MQL. Secondly, there's what I'm pretty sure is in MQL bug if you use "*": null or more specifically "target_value": null in the link clause above which makes it ignore the outer value you specified... so don't do that :-)

Freebase currency query

I have a little problem, maybe can you help me. I'm trying to get the "currency features" from freebase. So I tried to do : "/base/schemastaging/person_extra/net_worth": null but, I can't get the value written on freebase (for example, with Madonna, it's 650,000,000). Do you know, why it's not working ?
First of all, as the property path suggests, /base/schemastaging/person_extra/net_worth is just being staged right now so the final property ID will be something else (follow the mailing list to discuss new schema). You should NOT be using this property for anything other than experimentation.
The reason why you don't see the data that you want withe the following query is because this property is a CVT.
{
"id": "/en/madonna",
"type": "/base/schemastaging/person_extra",
"net_worth": null
}
CVT values are complex objects that need to be expanded to access the values that you want. In this case, net_worth is a CVT so that we can record a person's net worth at different points in time.
If you expand your query to include the relevant properties from /measurement_unit/dated_money_value you'll see the data that you're after.
{
"id": "/en/madonna",
"type": "/base/schemastaging/person_extra",
"net_worth": {
"amount": null,
"currency": null,
"valid_date": null
}
}
One other issue, that isn't obvious from this example, is that since there can be multiple dated money values, you'll need to make your query more precise so as to get only the latest value. You can do that like this;
{
"id": "/en/madonna",
"type": "/base/schemastaging/person_extra",
"net_worth": {
"amount": null,
"currency": null,
"valid_date": null,
"sort": "-valid_date",
"limit": 1,
"optional": true
}
}​
Update: Made net worth an optional property value.

Freebase query - exclusion of certain values

I want to retrieve name of all movies and their genre. It's ok if information about genre is empty, but if genre is known I want to retrieve it.
"/film/film/genre": [{"id":null,"optional":"optional"}]
But I'm not interested in gay pornography, so I want to exclude all movies with genre "/en/gay_pornography".
"/film/film/genre": [{"id|=":["/en/gay_pornography"],"optional":"forbidden"}]
The problem is, how to combine it in one query? I.e. how to get all movies, even those with no genre and exclude pr0n?
Edit: it's required to exclude multiple genres, e.g. also /en/pornographic_movie
You're basically there: you just need two "genre" clauses. MQL lets you do this by allowing arbitrary prefixes on any clause:
[{
"id": null,
"type": "/film/film",
"genre": [{
"id": null,
"optional": true
}],
"forbid:genre": {
"id|=": [
"/en/gay_pornography",
"/en/pornographic_movie"
],
"optional": "forbidden"
}
}]​
http://tinyurl.com/4449ufg
Use the "but not" operator:
"genre": [{
"id": null,
"id!=": "/en/gay_pornography",
"optional": true
}]
Full example: http://tinyurl.com/3tjdb4j
Edit: This doesn't answer the question. It just prevents that particular id from being listed as a genre of the film but doesn't forbid the film. #phillip-kendal's answer is correct.

Resources