I am working with Freebase, I want to locate some organization from Freebase.
For example, I want to extract location (city, country, ...) from Cardiff University. For that I have made this query to view all properties of the entity:
https://www.googleapis.com/freebase/v1/mqlread?
query=
[
{"name":"cardiff%20university",
"*":[{}],
"type":"/education/university"}
]
Link of query here
But O do not see any field of location neither UK, Cardiff or something similar.
I think that Freebase has not got this information, but when I go to webpage, I can see "Cardiff", "Wales"
and "United Kingdom".
How can I retrieve this information?
When you use the * wildcard property you're asking for all the property values for the specified type which in this case is /education/university. The containedby property that you're looking for is part of /location/location so it doesn't get shown.
There are two ways to show containedby in your query. One is to explicitly ask for that property using the full property path like this:
[{
"name": "Cardiff University",
"type": "/education/university",
"/location/location/containedby": [{}]
}]
The other way is to specify the default type as /location/location and then add the /education/university constraint using a prefix like this:
[{
"name": "cardiff university",
"*": [{}],
"type": "/location/location",
"f:type": "/education/university"
}]
Related
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)
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.
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 :-)
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.
I'm trying to get all events in a geo bounding box (that approximately covers France), but I want to exclude all recurring events, so I don't get heaps of French Tennis opens and the like. For this I used the following in my query.
"/time/event/instance_of_recurring_event": {
"id": null,
"optional": "forbidden"
}
However, I've noted Cannes film festivals appear (the individual events for each year), because they do not have the instance_of_recurring_event property set. I can however see that the Recurring Event "Cannes Film Festival" has links to the 2006, 2007, 2008 (etc) film festival events, so I thought I might be able to eliminate them using some reflection. What I have so far is:
[{
"name": null,
"id": null,
"/time/event/instance_of_recurring_event": {
"id": null,
"optional": "forbidden"
},
"/time/event/locations": [{
"geolocation": {
"latitude>": 43.2,
"latitude<": 49.68,
"longitude>": -5.1,
"longitude<": 7.27
}
}],
"/type/reflect/any_reverse": [{
"id": null,
"estimate-count": null,
"name": null,
"/time/recurring_event/current_frequency": null
}]
}]
This allows me to see that the 2008 Cannes film festival is linked to by the Cannes Film Festival subject (that has a yearly recurrence), but I don't know if there's any way to use that to eliminate the 2008 Cannes film festival from my list. Does that make sense?
Try here for the query editor.
Thanks for any help!
Try this: http://tinyurl.com/3okuuzw
A couple of changes:
I added the type: /time/event so that you 'll only get objects of that type. In your query, you were not restricting by type, and in Freebase, you can assert a property on an object without the type. This is a minor change and probably won't have a big effect.
The /film/film_festival_event type of which the Cannes festival is one has a property /film/film_festival_event/festival pointing to the festival series.
I added a clause at the end of the query to exclude objects that have that property set with the assumption that they are recurring events.
This will only work for film festivals, but you can re-use the same pattern for other properties.
[{
"name": null,
"mid": null,
"type" :"/time/event",
"/time/event/instance_of_recurring_event": {
"id": null,
"optional": "forbidden"
},
"/time/event/locations": [{
"geolocation": {
"latitude>": 43.2,
"latitude<": 49.68,
"longitude>": -5.1,
"longitude<": 7.27
}
}],
"/film/film_festival_event/festival": [{
"mid": null,
"optional": "forbidden",
"limit" : 0
}]
}]
Some additional points:
a. You should use "mid" instead of "id" if you want to store the identifiers in your db or re-use them in any way later. mid is a stronger identifier than id since it survives merges and other data transformations. It's also faster to ask for mid instead of id - actually makes a big difference when the result set is large.
b. "limit" : 0 says "don't return this clause at all in the results". I think you still need the mid because you have to have at least one property in a clause that has other directives (limit and optional in this case).