Querying Wikipedia from Pharo

Hernán Morales Durand announced a new fun library with which we can query wikipedia.

Some examples follow:

1) Retrieve in JSON movies from the beautiful Julianne Moore:

| jsonResults |
jsonResults := DBPediaSearch new
        setJsonFormat;
        timeout: 5000;
        query: 'SELECT DISTINCT ?filmName WHERE {
  ?film foaf:name ?filmName .
  ?film dbpedia-owl:starring ?actress .
  ?actress foaf:name ?name.
  FILTER(contains(?name, "Julianne"))
  FILTER(contains(?name, "Moore"))
}';
        execute

To actually get only the titles using NeoJSON:

((((NeoJSONReader fromString: jsonResults) at: #results) at: #bindings)
    collect: [ : entry | entry at: #filmName ]) collect: [ : movie | movie
at: #value ]

2) Retrieve in XML which genre plays those crazy Dream Theater guys  :

DBPediaSearch new
        setXmlFormat;
        setDebugOn;
        timeout: 5000;
        query: 'SELECT DISTINCT ?genreLabel
WHERE {
    ?resource dbpprop:genre ?genre.
    ?resource rdfs:label "Dream Theater"@en.
    ?genre rdfs:label ?genreLabel
    FILTER (lang(?genreLabel)="en")
}
 LIMIT 100';
        execute

More examples are available in DBPediaSearch class side. You can install it
from the Configuration Browser.
If you want to contribute, just ask me and you will be added as contributor.
Best regards,

Hernán
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: