Skip to content

Commit

Permalink
Figure out the capital of Mongolia
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Nov 30, 2011
1 parent 26c3b34 commit c0166e4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions index.html
Expand Up @@ -105,6 +105,55 @@ <h3><a href="#">Tell you how tall is the Eiffel tower</a></h3>
</div>
<div class="resultsholder"></div>
</div>
<h3><a href="#">Find you what is the capital of Mongolia</a></h3>
<div id="mongolia">
<p>This code digs out the answer:</p>
<div class="exampleholder">
<textarea>
var vie = new VIE();
vie.use(new vie.DBPediaService());

var mongoliaURI = "<http://dbpedia.org/resource/Mongolia>";
var capitalPropURI = "<http://dbpedia.org/property/capital>";
var namePropURI = "rdfschema:label";

vie
.load({entity : mongoliaURI})
.using('dbpedia')
.execute()
.done(function (entities) {
_.each(entities, function (e) {
if (e.id === mongoliaURI) {
var capitalURI = e.get(capitalPropURI).id;
vie
.load({entity : capitalURI})
.using('dbpedia')
.execute()
.done(function(capitalEntities) {
_.each(capitalEntities, function(entity) {
if (entity.id != capitalURI) {
return true;
}
var url = entity.id.substr(1, entity.id.length - 2);
var label;
_.each(entity.get('rdfschema:label'), function(labelLang) {
if (labelLang.substr(-2) === 'en') {
label = labelLang.substr(2, labelLang.length - 7);
}
});

jQuery('#mongolia .resultsholder').append(
jQuery('<p>The capital of Mongolia is <a href="' + url + '">' + label + '</a>.</p>')
);
});
});
}
});
});
</textarea>
<button>Run</button>
</div>
<div class="resultsholder"></div>
</div>
</article>

Expand Down

0 comments on commit c0166e4

Please sign in to comment.