Get KA exercise hierarchy - khan-academy

Is there a way to get a json with the whole exercise tree using the API, like this (array or object)?
Math
"Early Math"...
...
"Algebra II"
"Advanced Functions"
"Determine the domain of funs"
...
"Compare features of funs"
...
Tnx.

The topictree endpoint has all of this information, and you can use the kind filter to show exercises (and topics). http://www.khanacademy.org/api/v1/topictree?kind=Exercise
You can also load individual topics to navigate the entire tree (not just videos and exercises). For example, this URL gets direct information about the "combining-functions" topic:
http://www.khanacademy.org/api/v1/topic/combining-functions?format=pretty
From there, you can see that there's a child article with ID "xd2620963". You can load JSON information about that article using the /api/v1/articles endpoint (which unfortunately isn't documented):
http://www.khanacademy.org/api/v1/articles/xd2620963?format=pretty
Or, with many topics, they will have child topics that you can navigate to.
(That format=pretty at the end just makes the JSON response a little more human-readable; you should leave it off when accessing the JSON programmatically.)

Related

getting correct names for Dbpedia sparqlwrapper queries

I am querying DBpedia for information about organizations and I am using "dbpedia.org/page/[organization]" to find what name is used for those organizations. It will usually fix the inputted name to the name it uses. eg dbpedia.org/page/Tmobile will be redirected to T-Mobile.
When making a query using SPARQLwrapper to 'http://dbpedia.org/sparql' these names usually work but not always (such as the previous T-Mobile example. How can I find the specific name to use when querying DBpedia using SPARQLwrapper?
My first thought is that you're using the wrong URIs for your SPARQL queries -- .../page/... are HTML representations of the descriptions of the entities. .../resource/... are the identifiers of the entities (which get redirected to the .../page/... when you use a web browser, which requests HTML, to dereference the .../resource/... URIs).
In other words, instead of, for instance (results here) --
DESCRIBE <http://dbpedia.org/page/Tmobile>
-- try (results here) --
DESCRIBE <http://dbpedia.org/resource/Tmobile>

finding organization and industry/sector from string in dbpedia

I am generating a short list of 10 to 20 strings which I want to lookup on dbpedia to see if they have an organization tag and if so return the industry/sector tag. I have been looking at the SPARQLwrapper queries on their website but am having trouble constructing one that returns organization and sector/industry for my string. Is there a way to do this?
If I use the code below I get a list of industry types I think rather than the industry of the company.
from SPARQLWrapper import SPARQLWrapper, JSON
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
SELECT ?industry WHERE
{ <http://dbpedia.org/resource/IBM> a ?industry}
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
Instead of looking at queries which are meant to help you understand the querying tool, you should start by looking at the data which is being queried. For instance, just click http://dbpedia.org/resource/IBM, and look at the properties (the left hand column) to see its rdf:type values (of which there are MANY)!
Note that IBM is not described as a ?industry. IBM is described as a <http://dbpedia.org/resource/Public_company> (among other things). On the other hand, IBM is also described as having three values for <http://dbpedia.org/ontology/industry> --
<http://dbpedia.org/resource/Cloud_computing>
<http://dbpedia.org/resource/Information_technology>
<http://dbpedia.org/resource/Cognitive_computing>
I don't know whether these are what you're actually looking for or not, but hopefully what I've done above will start you down the right path to whatever you do want to get out of DBpedia.

Are aggregate-wide events acceptable?

In an application that uses event sourcing is it acceptable to have aggregate-wide events?
Consider a contrived example of a blog application that provides the ability to create posts and add and remove simple tags (post would be the aggregate root).
This might result in the following events:
PostCreated: postId, "title", "content"
TagAdded: postId, "Foo"
TagAdded: postId, "Bar"
TagAdded: postId, "Baz"
TagRemoved: postId, "Bar"
Replaying the above event stream would result in a post with a title, content and two tags ("Foo" & "Baz").
Now imagine the user interface only allows you to select existing tags whilst creating a post and doesn't accept free text; only privileged users have the ability to update the master list of tags.
Now when a privileged user creates a new tag, a corresponding event needs to be created so that a) the information is actually stored in the event storage and b) at some point the read model is updated so that users creating blog posts can select the new tag in the UI.
Having an event that looks like TagCreated: postId, "NewTag" doesn't seem right to me as the information does not directly apply to a single post.
Considering that in this case the information does not warrant it's own aggregate root and will only be used in this bounded context I would expect an event along the lines of:
TagCreated("NewTag")
These events would be stored in the event storage using the same aggregate id as the previous set of events for a specific post but without an id for the specific aggregate instance.
So far this sounds like a logical way to handle the problem but was wondering if I am missing anything obvious by approaching it this way.
IMHO you're complicating your life unnecessary. Domain events are usually available cross bounded context and they should be associated with an aggregate root (AR) by referencing its id.
In your example, I'd consider Tag to be a value object, so it would require a post id. But if you want the Tag to be available as itself, then it would be an AR and so, the event would have a TagId property.
Btw, a domain event is a DTO, meant to be available everywhere, they're not a domain detail that needs to be encapsulated in an aggregate.
I think you missed the concept "tag catalog" or something like that. It could have a single aggregate (or perhaps you will sometimes have several catalogs for different user groups or something like that) with the catalog as the root, containing all the tags as value objects.

How do I get the most popular tags?

How do I get the most popular tags from Instagram API? I searched the API, but didn't find a way to retrieve this data. This website gets it, but how?
The question is old, but for others also struggling the same problem, as Sebastien mentioned there is no such query. However I have been recently needing same functionality and came down idea that small traversal pretty much solves the problem.
Instagram doesn't respond you a list of tags starting with just one letter.
Example:
https://api.instagram.com/v1/tags/search?q=a
This URL returns just one element, which is "a". However if you send a request containing two characters like
https://api.instagram.com/v1/tags/search?q=aa
then you'll end up with the most popular tags starting on "aa"
Afterwards you can simply traverse your desired alphabet in O(N^2) time and by joining responses you'll end up with a list of most popular tags.
Length in case of English(Latin) alphabet would be 26^2 = 676
Though you shouldn't probably try getting any more tags as the limit is still 5,000 requests and 26^3 would go for 17576.
foreach(character in 'a'...'
{
foreach(character in 'a'...'z')
{
Send hashtag request 'aa'...'az'...'zz'
Get json and merge with previous array
}
}
Sort final array by [media_count]
Alternate approach would be to parse some huge dictionary (wikipedia dump for example) and sort out top 5000 most common prefixes and try querying them.
I don't think the API supports that query. What you can do is check this popular media endpoint and deduce popular tags from there:
http://instagram.com/developer/endpoints/media/#get_media_popular
The website you mention could be using multiple Real-time subscriptions and generate that list of popular tags by consolidatingthe harvested information. That wouldbe my guess.
I think the best thing is to ask them directly.

Looking up types from Freebase

I am trying to find a list of relevant types to a certain string from Freebase, lets say for example i enter Jordan, then i will have a list with types country, person, athlete .. etc.
I have found several ways for the query, for example:
First Query
trying to get the JSON fails, using:
$.getJSON('http://api.freebase.com/api/service/search?query=jordan',function (data) {
console.log(data);
});
There is another query that gives me better result, as i only get the types here but i also cannot get the JSON file from it.
Will appreciate any help.
Your problem has probably less to do with freebase and more to do the fact that you can't do cross domain http requests. You are requesting data from api.freebase.com but you are probably hosting this page in another domain.
You can use the JSONP mechanism to circumvent that restriction, here is some documentation:
http://api.jquery.com/jQuery.getJSON/
Read the section JSONP.
Another couple of points:
Are you trying to search for all entities that somehow match the word "jordan" or are you looking for exactly all the entities that are named "jordan" ? Your best bet is to use the /search API instead of /mqlread which is for structured database queries.
You are also using the legacy API that is deprecated. Here is some docs on the new API:
http://wiki.freebase.com/wiki/API
Here's how your request will look (note that you 'll need an API key for production):
https://www.googleapis.com/freebase/v1/search?query=jordan&mql_output=[{%22name%22%20:%20null,%22type%22:[]}]

Resources