Discussions on The Complete Metaweb Query Language (MQL) Reference Guide
Start a New Discussion
-
-
is there any way to retrieve a random item in list of items? I often run into scenarios where i want to test a random series of (valid) us addresses against my business rules. it would be great if i could so something like this:
{
"
query" : [
{
"citytown" : null,
"limit" : 10,
"sort" : random,
"state_province_region" : null,
"street_address" : null,
"type" : "/location/mailing_address"
}
]-
Currently there is no way to have MQL return a random set of items. You might want to post this as an enhancement request here.
-
Good morning all.
Has a random feature become manifest in the meantime or is is on the agenda?
Cheers
martin
-
Hi.
Are there any news about random selection?
I could imagine some pseudo-randomization that would work by sorting the items by guid and introducing a "guid > random guid" condition. With really huge ammount of data there should practically always be 10 elements returning at "limit":10
But before I try that out I'd like to hear if there has been any progress on random set queries in MQL.
Best Regards
Thomas
-
+1 to random sorting!
-
-
-
I figured enough that you can use "limit" reserved to get the first few results of a query,
say for some query
"limit" : 5
this fetches the first five ,
how do I fetch the next 5
-
You use cursors. Ask for cursor:null in your first query. It will come back with a token filled in; pass that back to get the next set of results and a new cursor.
-
Can you explain this a little further, please? I tried the query :
{
"cursor" : null,
"limit" : 5,
"name" : null,
"type" : "/music/artist"
}and I got an error saying that cursor was a reserved word.
Thanks
-
Wouldn't using the 'offset' reserved word be a more elegant (and intuitive for those with experience in databases) method of implementing this?
-
Sorry; the cursor needs to go in the query envelope, not the query itself. See §4.7 of the API doc:
{
"cursor":null,
"query" : {
"limit" : 5,
"name" : null,
"type" : "/music/artist"
}
}
The cursor is not the same as offset; we don’t currently have arbitrary offset support. The cursor must be sent back to the server to get the next page of results; a query can’t yet skip forward an arbitrary number of results.
-
Hi,
I'd like to use the cursors to paginate my result but I haven't found any good documentation/example about how to use them... The parameter I need are the convential 'page' and 'per_page',
for 'per_page' parameter I'm using use 'limit',
How can I use the cursor to fetch the right offset of result?
-
Marco: paginated results is a future feature which a lot of people have been asking for. I believe it requires changes to our underlying graph database (we do not use an RDBMS, it's something completely different). When it's done and released, you can bet we'll be publicising the fact broadly, so stay tuned. For now, cursors are the only way to handle this.
-
Thanks Skud for your fast replay!
Could you please show me an example or give me a link to a tutorial about how to handle this using cursors?
thanks!
-
Hi Macro79, recently our graph database got support for pages.
You just need to use the 'page' and 'limit' keywords in your mql query, here's the first page:
http://api.freebase.com/api/service/mqlread?query={"page":0,"query":[{"name":null,"type":"/music/artist","limit":5}]}
The new Query Editor supports pages in the 'envelope' options: http://www.freebase.com/app/queryeditor
-
-
-
Hi,
I'm new in MQL. I try to get list of countries sorted by population. I came from the Vietnamese restaurant query which is working:
[
{
"/business/business_location/address" : {
"citytown" : null,
"state_province_region" : null
},
"cuisine" : "Vietnamese",
"name" : null,
"type" : "/dining/restaurant"
}
]
Modified query gives me surprisingly an error (not mentioned the sorting issue):[
{
"/location/statistical_region" : {
"population" : null
},
"name" : null,
"sort" : "name",
"type" : "/location/country"
}
]
Any help is appreciated
Robert
-
The problem with your query is that you are looking for a country that has a statistical region that has a population. That is not what you want. You want a country which, when considered as a statistical region, has a population. Or more succinctly, you want a country with a population.
When treating a topic with more than one type, you often need to use the fully-qualified property names. You were on the right track, but rather than using a subordinate object, you just wanted a longer string. Consider:
[{"name":null,"type":"/location/country", /location/statistical_region/population":[{"number":null,"year":null}]}]
That will get you the populations. Note also that we have to delve into the population, since it actually has a number and a year, not just a number.
You can sort by any property present in the response, and use periods to nest. To sort by the population number, you’ll want to sort the populations for a specific country first, then sort the countries by their highest populations:
[{"name":null,"type":"/location/country", /location/statistical_region/population":[{"number":null,"year":null,"sort":"-number"}],"sort":"-/location/statistical_region/population.number"}]
That will sort the way you want. You will find that former countries show up in that list; you may want to constrain the years for the population counts.
-
-
-
Dense, hard-to-understand material is made doubly difficult to read and process by lousy typography. The way that headers and lists are smooshed into each other on this page makes it very difficult to understand.
-
Thanks for letting us know - I have heard that it was a bug in this release and will be fixed in the next one.
-
This is a problem caused by an update in the CSS used to layout the page, and some faulty mark-up in the original file. We hope to have this all fixed in the next couple weeks when the new version of the manual is posted.
-
-
-
As there is not one above, i created a C# version here :
If anyone knows a good place to put it please do so. New to this so don't wanna edit the description of the article!
-
Thanks, weblivz! Probably the best place to put this is under Application Developer Tips, but I'm copying our docs guy, Phil, on this so he can help you out.
-
Hey there, sorry it took so long, I was on vacation when you posted this. I've added the code to our Application Developer Tips and will add it to the full manual when the next version goes live in a couple weeks.
-
-
-
In the documentation it says that * matches a single word, but when I ran the queries for band names with two / three names, the lists were the same. The number of *'s and spaces didn't seem to make a difference to the search.
-
Good catch, thanks. I filed a bug with our doc team on that.
-
HI Maccaday, can you tell me what the query was, and what results were returned? * matches any single word, so "I * you" matches both "I love you" and "I hate you." So, depending on the query, it's possible to get the kind of results you describe, but I'd need to see the query and the results before I can figure out what's going on.
-
Hey Maccaday, can you provide both the query you were using and the results? * can be used to match any single word, so "I * you" will return both "I love you" and "I hate you," so it's possible to get the kind of results you describe, depending on what the query was. Send that info on and I'll try to figure out what's up and, if necessary, correct the docs.
-
Further investigation has revealed some genuine wonkiness in the use of the single * as a wildcard; as soon as we track down what's really happening we'll try to fix the functionality and the documentation as well. Stay tuned, but please do send me that query so we can have a test case to work with.
-
Hey Maccaday, I found something in the new, updated version of the MQL manual that we'll be publishing soon that may explain your problem. If you're trying to use the wildcard for phrase matching, where you want word order respected and the wildcard to stand-in for one word, you need to use escaped quotes around the phrase. So, instead of:
{
"name" : null,
"name~=" : "I * you",
"type" : "/music/track"
}you would need to use the following query to get all track names that contain the phrase "I * you" :
{
"name" : null,
"name~=" : "\"I * you\"",
"type" : "/music/track"
}
-
-
-
"One of the fundamental aspects of Metaweb is that all links between nodes are bi-directional."
Is this really true? There are properties that have no reverse property defined, and are in effect unidirectional.
These can be found with the following query:
[
{
"id" : null,
"limit" : 10,
"reverse_property" : {
"id" : null,
"optional" : "forbidden"
},
"type" : "/type/property"
}
]-
All links are truly bidirectional. The client may not show them, but that is not the same thing. The Explore view (change view to tools/explore in the URL, or hit F8 to expose the tool bar at the bottom of the page) shows all incoming and outgoing links. Non-reciprocated properties can also be accessed in MQL using the ! operator:
{
"!/music/release/artist" : [
{
"name" : null
}
],
"id" : "/en/the_beatles"
}
-
-
-
-
I need to obtain data across multiple guid's within a single query. E.g. this simple query gets the name for a single guid. Is there a way to pass in multiple IDs to get back information on each? I.e. I don't want to perform 100's of individual queries.
{
"id" : "/guid/9202a8c04000641f800000000023907a",
"name" : null,
}
Thanks,
biosopher-
Your excellent question here (and also on the Query Builder page) might already be answered in the archives of the App developers mail list (linked to on the App page). In fact I know the question about getting the description was answered recently on one of our two mail lists.
-
Thanks for the pointer gmackenz. I was searching for the wrong terms and getting zero results. You pointed me in the right direction:
http://www.freebase.com/api/trans/raw/guid/9202a8c04000641f80000000001170a3
http://www.freebase.com/api/trans/blurb/guid/9202a8c04000641f80000000001170a3
http://www.freebase.com/api/trans/blurb/guid/9202a8c04000641f800000000038e04d?maxlength=300As discussed in detail here
http://markmail.org/message/fot76nyzeprvsgly#query:+page:1+mid:hkzgwbs6pbznui4w+state:results
http://markmail.org/message/fot76nyzeprvsgly#query:freebase.com%20API%2Ftrans+page:1+mid:balofou7axzv53vr+state:resultsThanks,
biosopher
-
-
-
section 4.8 states "The trans service does not support a callback parameter as the mqlread service does", this is outdated since the api states it can and it can:
http://www.freebase.com/view/guid/9202a8c04000641f8000000007628edf
The trans example could use some improvement too since it is digging out "unrelated" documents from the store. It would be more informative and more consistent to get documents on the band "the police"
Query to get guid's for articles and images
{
"article" : [
{
"guid" : [
{}
],
"id" : null
}
],
"id" : "/en/the_police",
"image" : [
{
"guid" : [
{}
],
"id" : null
}
],
"type" : "/common/topic"
}
Query to get the article (function foo can format result without using a proxy):
http://www.freebase.com/api/trans/raw/guid/9202a8c04000641f800000000006df25?callback=foo
Query to get the image (you can use this as the source property of the image element)
http://www.freebase.com/api/trans/image_thumb/guid/9202a8c04000641f8000000003c18713?maxwidth=300&maxheight=300
Note: you cannot make an image bigger than the origional with maxwith and maxheight
-
-
-
It looks like it isn't possible to use the write service to create weblinks, as it's outside the schema. But maybe I'm wrong.
If we want to establish a link for an object, am I correct in guessing that the schema would need to incorporate a link property?
-
The type /common/topic has a property "webpage" that you can use. All topics should include /common/topic as one of the types (although it won't be listed explicitly on the page) -- it's what gives them the images, weblinks, description, and "also known as" properties.
-
-
-
Helo,
I am trying to write an MQL to count the number of instances of a given type but not being able to figure out. Can anyone help please?
-
{
"type" : "/type/type_name",
"return" : "count"
}
I tried to find the documentation for this, but I wasn't able to. We're in the process of cleaning up the documenation, and I am sure will be included.
-
Thanks a lot cheunger. That was of great help.
-
No problem! One thing though... the query may time out on types with a large number of instances.
-
-
-
Section 2.4. Domains states that "domain objects are also instances of /type/namespace," which enforce id uniqueness.
But that doesn't seem to be true as there are only 8 domains co-typed as namespace: (and 19,000+ domains that aren't).
Is it true that domains behave like namespaces (without needing to be co-typed)? I did a quick test and it seems like they enforce unqiue ids just like namespaces.
I think it would be helpful to clarify exactly what are the differences between domains and namespaces.
-
-
-
Helo all,
I am trying to analyze user define types in freebase - types defined the users in their default domains or user defined domains, not yet promoted to the standard freebase domains. I have been trying to make up an MQL for that but it doesn't seem to be easy (as I cannot do pattern matching on the "id"). Any ideas?
-
-
-
-
I'm writing a small app on FreeBase.
I'm trying to build a category tree which shows the main categories (sports, arts & crafts, etc.) and lets the user drill down to additional sub categories.
Is there something like this already built which I can use?
I notice that I can get a list of the categories for "Sports" like this:
{ "query" : [ { "domains" : [ { "id" : null, "name" : null, "type" : "/type/domain" } ], "name" : "Sports", "type" : "/freebase/domain_category" } ]}
but I can't figure out how to get a list of categories under "Sports/Basketball"-
Sports is a "domain category", which has a list of domains (via a property). Sports/Basketball (id: /Basketball) is a domain, and when you say a "list of categories" in that domain, you're referring to the types in that domain. So, the query to look up types in a specific domain by id /Basketball is:
{
"query" : [
{
"id" : "/basketball",
"type" : "/type/domain",
"types" : [
{
"id" : null,
"name" : null,
"type" : "/type/type"
}
]
}
]
}
-
-
-
If you spot a mistake in the mqlwrite docs then please reply here.
-
5.1.11. Namespaces
What if we query the id of a note?
We get the guids of the notes rather than the fully-qualified names we've just defined.This behaviour seems to have changed. I get the fully-quailified names and not the guids as stated above:
"note":[{"id":"/user/willmoffat/note/C"}
... snip ... ] -
5.1.12.1. Creating Self-Referential Reciprocal Properties
At the time of this writing, the freebase.com client does not allow us to create reciprocal properties where both ends of the link refer the same type
This is no longer true. -
The "creating a domain" section is misleading: the new domain will not have the special permission structure that is usually associated with an instance of /type/domain. The only way to create that permission is to use a special domain creation entrypoint, which should be documented elsewhere rather than as part of the mqlwrite tutorial.
-
-
-
-
-
If you try a GET query that has the URL length go above about 4000 characters, you will get a "Transient Error" from the Freebase API. The API should really return an error of "URL too long, use POST".
Even though it isn't mentioned, the MQL Read does support POST. I recommend using it instead of GET.
-
-
-
I can't seem to find anything documenting the lifetime of a cursor value returned from the MQL read service.
Do cursors persist between query sessions? If so, for how long? Could I run a query to obtain some data, save the cursor, and then continue where I left off a few days later?
Thanks.
-
Hi rath,
The short answer is that cursors are stateless. The kinds of things that invalidate cursors are cursor format changes that happen with database software upgrades; but they're safe against time, session ends, or reuse.
If you're trying to use a cursor, and get a BADCURSOR reply from the server back, and there wasn't a database software upgrade, there are two possible explanations:
(a) a bug - cursors are complicated and underused, and it's quite possible that you're running into a bug.
(b) you've changed the query in some small way, so the cursor checksum that encodes the constraint around the cursor as well as the cursor text no longer matches the constraint you're actually submitting along with the cursor.
If it's an intermittent problem, it's likely (a); if it fails reliably, it's likely (b).
-
-
-
No mention of the WWW::Metaweb Perl Module?
-
No, and I don’t think any other community-created modules are mentioned here either. Someone has added a Python client to the list of Freebase Application instances; you could add WWW::Metaweb there, too.
-
-
-
-
Hi,
this graph data model is so general and versatile that it should replace the outdated relational model! Do you know about an existing implementation of this on top of a RDBMS in PHP? Or is the Metaweb backend data access layer available under some licence?-
Hi thsoft! You probably want to look into RDF and related semantic web technologies. One implementation I recently came across is Mulgara. I don't know much about it except that people were raving about it at a recent conference I attended, and it's meant to be pretty good. It's not in PHP nor does it sit atop an RDBMS, but it is open source software and should be installable on most systems if you want to play with it. If you specifically want a PHP/RDBMS one, hopefully I've given you enough background to help you google for it ;)
While Freebase's backend is something different again, it can be mapped into RDF for use with applications like Mulgara. I know there are people working on creating a full RDF dump of Freebase for just that sort of purpose. So in theory you could take those RDF dumps and load them into whatever it is that you end up using.
Best of luck, and let us know how it goes. If you're not already on the freebase developers' mailing list, you might want to join it. That's where most of these conversations usually take place.
-
-
-
In Chapter 5, it is mentioned that there is an argument for the mqlwrite (possibly mqlread too?) service which specifies the default language for the text values, but it is not documented anywhere. Is there such an argument and if yes, what is its usage?
-
Though the infrastructure is there for supporting multiple languages when you specifically ask for values, we haven't yet implemented the full support for being able to specify the language in the query envelope.
When that is implemented, you'll be able to say something along the lines of:
{"lang": "/lang/es",
"query": {"id": "/foo/bar", "name": null}}
to get the spanish name of /foo/bar
We'll be sure to make a large announcment when there is significant progress on this front.
-
-
-
Links to chapters detailing Freebase APIs (Chapter 1, etc...) appears to be broken in my browser (Mac/Firefox). Is there any other place on the website where I can get the detailed information about developer APIs for Freebase?
-
Oops! We change the format recently for the URLs of the Help topics and those links weren't updated.
Until I can get someone to correct the links, this is the index of the complete guide to API building:
Developing Metaweb-enabled Web Applications -
Fixed, was easier than expected to edit. All links should work correctly. Be sure to refresh the page/browser cache if the links still result in error pages for you.
-
-
-
-
-
In section 3.2.3, and example is given on how to get the ID of an object, more specifically, its guid. However, following along with the example, the online query editor actually returns the full-qualified name (right?), for example: "topic/en/the_police."
-
You are correct that this section is incorrect. We need to correct that. Two issues:
1) the syntax for guids in the ID field just changed to /guid/9202a8c04000641f800000000006df1b
2) if there's a human-readable ID for a topic, that we will be returned rather than the guid, so as you pointed out: /topic/en/the_police.
-
-
-
-