How do I obtain properties from included types in a query? - freebase

I'm trying to get the name and official website of wine producers via querying for Freebase wine producer topics: https://www.freebase.com/wine/wine_producer?schema=
However, unlike the "name" property, official_website comes from the included type organization/organization. Freebase's query editor seems a bit clumsy in that it can't recognize included types, so it errs when I try to obtain the official_website of a wine producer - the editor seems to fail to recognize a wine producer as an organization/organization: http://tinyurl.com/kr7m86w
Here's my query:
[{
"id": null,
"name": null,
"type": "/wine/wine_producer",
"official_website": null,
"wines": []
}]
How do I get the official website URL of a wine producer?

You appear to be misunderstanding how included types work. They have no special significance in this context (and MQL doesn't even know about them).
You can abbreviate property names for any properties of /type/object (e.g. id, name, type) and any property belonging to the most recently specified type (e.g. wines), but anything else must be fully qualified.
The official_website property belongs to /common/topic, not /organization/organization, so the query with the fully qualified property name is:
[{
"id": null,
"name": null,
"type": "/wine/wine_producer",
"/common/topic/official_website": [],
"wines": []
}]
Note also that:
official_website is not unique, so it needs [], not null
this only returns the first 100 wine producers (the default limit)

Related

Optional Types?

My current query is this:
[{
"type": "/people/person",
"also:type": "/film/actor",
"name": "Chuck Norris",
"/imdb/topic/name_id": null,
"date_of_birth": null,
"/film/actor/film": [{
"film": [{
"name": null,
"imdb_id": []
}]
}]
}]
And this works fine for actors. But I want to return films, given a name or IMDB Name ID etc., for anyone who has worked in films. So directors, products, writers etc.
To do this though, requires lots of different types, like: executive_produced_by, produced_by, directed_by etc.
At the moment, if I pass in Mike Newell, I get no results, as he isn't an actor, but a director among other things.
Any ideas as to how to do this in a single query? I am essentially looking for optional types. e.g. find Mike Newell in /film/actors or /film/directed_by etc.
What documentation have you consulted so far? You can use the |= operator to specify multiple IDs, types, etc. You can use the optional: true clause to make a value optional for a property (otherwise, it'll exclude entities which don't have a value for that property).
What have you tried so far and found lacking?

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 :-)

Searching for a property in Freebase

What would be the MQL query if I want to search for a property that has a particular string either in its name or the actual link path. For name, I was able to put a ~= matching on the name property, but not in the link path. I tried to use the ~= in the id, but it says we cannot do matching in the id.
[{
"/type/object/id": "wikipedia",
"name~=": "wikipedia",
"/type/object/type": "/type/property",
"/type/object/name": null
"limit": 200
}]​
Is there a way to also search for strings in the id ?
A couple of things:
the ~= operator works on a whole word basis, so if you want to find the string "wikipedia" in all contexts, you'll want to use "*wikipedia*"
IDs aren't stored with fully formed paths, instead they're a sequence of keys in their respective namespaces (think filenames in directories)
You'll need two separate queries to match both the properties and their containing domains since you can't do unions like that in MQL.
For properties who's names contain wikipedia:
[{
"type": "/type/property",
"name~=" : "*wikipedia*",
"name": null,
"id":null,
"limit": 200
}]​
and for properties which belong to types who's IDs contain wikipedia:
[{
"type": "/type/property",
"name": null,
"id":null,
"schema" : {"key":{"namespace":{"name~=":"*wikipedia*"}},"id":null},
"limit": 200
}]​
That second query may need a little refinement, but it should give you the basic idea.

Freebase MQL - Don't show parent object if a value in array element is present?

Trying to get some movies and their genres but leave out any records that contain the genre "Thriller" in the array of genres.
How do I not only ignore the genre key itself for "Thriller", but squelch that entire movie result? With my current query, Thriller is removed from the array of genres, but the parent object (film) is still displayed.
Here's my current workup in the query editor:
http://tinyurl.com/d2g54lj
[{
'type':'/film/film',
'limit':5,
'name':null,
'/film/film/genre': [],
'/film/film/genre!=': "Thriller",
}]​
The answer provided is correct, but changes some other stuff in the query too. Here's the direct equivalent to the original query:
[{
"type": "/film/film",
"limit": 5,
"name": null,
"genre": [],
"x:genre": {"name":"Thriller",
"optional":"forbidden"},
}]​
The important part is the "optional":"forbidden". The default property used is "name", but we need to specify it explicitly when we use a subclause (to allow us to specify the "optional" keyword). Using ids instead of names, as #kook did, is actually more reliable, so that's an improvement, but I wanted people to be able to see the minimum necessary to fix the broken query.
We can abbreviate the property name to "genre" from "/film/film/genre" since "type":"/film/film" is included (we also never need to use /type/object for properties like /type/object/name).
Answering my own question.
So the trick is to not use the != (but not) operator, but to actually flip it on its head and use the "|=" (one of) operator with 'forbid', like so:
[{
'type':'/film/film',
'limit':5,
'name':null,
'/film/film/genre': [{
"id": null,
"optional": true
}],
"forbid:/film/film/genre": {
"id|=": [
"/en/thriller",
"/en/slapstick"
],
"optional": "forbidden"
}
}]​
Thanks to the following post:
Freebase query - exclusion of certain values

Resources