I'm trying to find the best way to get the information displayed on a Freebase page via a MQL query.
I've tried the topic API but that includes a lot of metadata.
I've also tried using links/reflection as in:
{
"id": "/en/samsung_electronics",
"/type/reflect/any_master": [{
"link": {
"master_property": null
},
"name": null,
"id": null
}],
"/type/reflect/any_reverse": [{
"link": {
"master_property": null
},
"name": null,
"id": null
}],
"/type/reflect/any_value": [{
"link": {
"master_property": null
},
"value": null
}]
}
But that means I'll be missing some information, such as the number of employees because that's given as a "Dated Integer" which, of course, doesn't get automatically expanded and I won't know what I would have to expand in general. My best attempts at expanding all objects by nesting that query once in itself were met with a
"code": 503,
"message": "Backend Error"
In RDF/SPARQL (e.g. DBpedia) I'd just do select ?p ?o where {URI ?p ?o} and select ?s ?p where {?s ?p URI}, am I missing such a simple way to do this in Freebase?
So to summarize, I'm looking for a way to get the information on a Freebase HTML page with as little overhead as possible and without missing anything.
The Topic API was designed specifically for this use case (and is what's used to construct the Freebase HTML page). It takes a filter parameter which can be used to tailor its output to include only parts of the schema which are of interest. What metadata is getting in your way? Why can't you just skip it?
If you'd prefer to use SPARQL, there's an RDF dump available that you could load in your own triple store and query with SPARQL.
Related
I'm trying to extract the link to the NYTimes Topic page (among the topic_equivalent_webpage values) for Barack Obama from Freebase, but my query doesn't return any results, although it's on the webpage (http://www.freebase.com/m/02mjmr). This is my query:
[{
"id": "/en/barack_obama",
"type": "/common/topic",
"topic_equivalent_webpage": {
"value": null,
"value~=": "*nytimes*"
}
}]
I've also tried extracting all of the topic_equivalent_webpage values instead, using this query:
[{
"id": "/en/barack_obama",
"type": "/common/topic",
"topic_equivalent_webpage": []
}]
For some reason it only returns one of the values (http://www.worldcat.org/wcidentities/lccn-n94-112934).
Does anyone have any tips?
NOTE: All Freebase APIs are going away in a few months.
You have three choices:
Download the RDF dump and filter it. This is most appropriate for a large-scale download instead of using the API. For the property name and decoding process, see #3.
Use the Topic API i.e. https://www.googleapis.com/freebase/v1/topic/en/barack_obama?filter=/common/topic/topic_equivalent_webpage
Query MQL for the keys in the namespace that you want (ie the NY Times namespace)
[{
"id": "/en/barack_obama",
"key": [{
"namespace": "/source/nytimes",
"value": null
}]
}]
Normally the result is an identifier that gets substituted into a URI template, but in the NYT case it's basically a full URI path that just gets appended to http://nytimes.com/
The key value (e.g. top$002Freference$002Ftimestopics$002Fpeople$002Fo$002Fbarack_obama) will be MQL key encoded, so they'll need to be decoded, but in this case you can probably cheat and replace all "$002F" substrings with "/". If any other characters are encoded, just replace $dddd with the character that has that Unicode code point.
I am sending the following mql query to get a list of topics, their mids and "notable types", but in the results notable types are always empty.
[{
"name": "The beatles",
"/common/topic/notable_types": [], //also tried "null"
"mid": null,
"limit": 10
}]
But this is inconsistent with the online freebase. For example, the query returns
{
"mid": "/m/07c0j",
"/common/topic/notable_types": [],
"name": "The Beatles"
},
And by checking the webpage "http://www.freebase.com/m/07c0j" you can see it has a notable type of "music artist".
Any suggestions if I have used wrong query or anything to do with the freebase database?
Many thanks!
They should really return on error on this query. Notably types isn't available through the MQL API -- only the Topic API.
Context: I am geek but brand new to the Freebase APIs.
I found this page describing Given Name type on Freebase and have tried to query it and am meeting with frustration. I have tried:
[{
"domain": "/base/givennames",
"given_name": null
}]
which gives a "Type /type/object does not have property domain" error and
[{
"type": "/givennames",
"given_name": null
}]
which gives an "Unable to load schema for /givennames" error.
I am guessing that I am missing something important on the page describing the type. Any assistance is appreciated.
Matthew
The "Build Query" menu option on the far right hand side of the schema page is a good way to get started with queries. In this case you want something like this:
[{
"id": null,
"name": null,
"type": "/base/givennames/given_name"
}]
I'm having a hard time trying to get data about a person from Freebase using his social link - by a MQL query.
How could this be done?
Something like:
https://www.googleapis.com/freebase/v1/mqlread?query={
"*":[{}],
"/common/topic/social_media_presence":[{
"value":"http://twitter.com/JustinBieber"
}]
}
Those links are really stored as keys and the links are generated from templates with they key plugged in. You can see all the keys here: https://www.freebase.com/m/06w2sn5?keys=
A modified version of your query would be:
[{
"key": [{
"namespace": {
"id": "/authority/twitter"
},
"value": "JustinBieber"
}],
"*": [{}]
}]
You can do the same thing with other namespaces like /authority/facebook or /authority/musicbrainz as well as the various language wikipedias e.g. /wikipedia/en
I'm not sure how complete the coverage or currency of the social media info is though...
I want to find out how Wenjin SU and Jimei University are related in Freebase. I have found out the Wenjin SU has a type /business/board_member/which has property/business/board_member/leader_of. How can I use this information in an Freebase MQL to extract the term or mid of Jimei University?
If you go to the Freebase page for Wenjin SU you see that he has the type /business/board_member/ and under that section it lists him as the /business/board_member/leader_of Jimei University
The first thing you should do is go to the Query Editor and create a skeleton MQL query for that relationship:
{
"id": "/m/0sxhm9v",
"name": null,
"/business/board_member/leader_of": [{}]
}
When you run this query you get the following result:
{
"result": {
"name": "Wenjin SU",
"/business/board_member/leader_of": [{
"name": null,
"type": [
"/organization/leadership"
],
"id": "/m/0sxhm9s"
}],
"id": "/m/0sxhm9v"
}
}
This is not quite what you were asking for. It's saying that he is the leader_of an un-named topic /m/0sxhm9s. Now, if you visit the Freebase page for that topic you'll see that its a mediator node that connects a person and their role to an organization for a specific date range. You'll also notice that Jimei University is listed as the /organization/leadership/organization on this page.
We can now add this mediated property to our MQL query to get the full relationship that you're looking for:
{
"id": "/m/0sxhm9v",
"name": null,
"/business/board_member/leader_of": [{
"/organization/leadership/organization": {
}
}]
}
If you're building an application that has a pre-determined set of relationships like this then you can use this process of exploring the Freebase data to build MQL queries for those relationships. If you're looking to find any arbitrary connection between any two entities in Freebase then you'll need to download the Freebase Data Dumps and run a shortest path algorithm over the entire graph.