THL Toolbox > Developers' Zone > Ruby On Rails Development > Using RoR Knowledge Maps Web Services
Contributor(s): Tom Benner, ANDRES MONTANO
The data from Knowledge Maps is accessible through web services that involve URLs similar to the web interface's URLs. For a category like Geographical Features, the web interface page is at:
The category's information can be accessed in JSON or XML at:
The children of the category are listed at:
A treed listing of the category's descendants is available at the following URL. This listing isn't currently available in JSON, but a modified JSON version of it is in development.
RoR also provides an easy XML builder that can be used to create custom XML responses.
The Topical Map Builder is intended to be used by other applications to provide controlled vocabulary. The other applications take XML output of controlled vocabulary lists or hierarchies built within the Topical Map Builder application, and then use them as options that editors choose from in filling in a given field.
To fetch main categories:
To fetch all categories hierarchically:
"with_features" only includes categories that have place dictionary features associated to it. "with_shapes" only includes categories that have place dictionary features that have a shape file.
To fetch all categories in a flat list:
To fetch basic information on a specific category:
To fetch detailed information (translated titles, descriptions, authors, etc.) on a specific category:
To fetch immediate children of a specific category:
To fetch all descendantes of a specific category hierarchically:
To fetch all descendantes of a specific category in a flat list:
The following notes are written in relationship to integrating the Topical Map Builder with the Ruby on Rails Place Dictionary to provide the feature thesaurus used in the latter application to specify "feature types".
The feature types are fetched from here: http://staging.tmb.thdl.org/categories/20/children
If you want to see the tree fully expanded in xml you get it from here: http://staging.tmb.thdl.org/categories/20/children/all.xml
To see the place dictionaries' integration in action, go to the admin features (http://staging.places.thdl.org/admin/features) and view feature (I guess the only feature available!). Then, if you click on view link at object types, and then new, you will see the browsable tree to select a feature. Once you save it, you will see it in the feature's view.
For future reference, here is how you use to topical map builder integration plugin:
app> script/plugin install -x
app> script/generate topical_map_categories
The active resource model will is called Category. The fields you can see at the above xml url, but the only one I used here is 'title'.
I patched the active resource classes for it to act more like a active records, so you can do belongs_to:
class FeatureObjectType < ActiveRecord::Base
belongs_to :object_type, :class_name => 'Category' …
To integrate it into an edit action the ability to select a category from the tree, you get the parent category from the controller. In a "typical" rails app it would just look like this:
@parent_object_type = Category.find(20) # feature thesaurus id in topical map builder
With this weird resource controller I placed it like this:
@parent_object_type = Category.find(20) # feature thesaurus id in topical map builder end
Finally, in the new/edit view, you do this:
<%= f.label :object_type %>
(@parent_object_type, :feature_object_type, :object_type) %>
@parent_object_type is the main category, in this case feature type and the next two arguments are new name of the form variable and the name of the attribute.
For the display, you treat it as a normal active record. For instance:
<%= @feature_object_type.object_type.title %>
Provided for unrestricted use by the Tibetan and Himalayan Library
How to Pull up Select Menu from One Branch of a Kmap & Also show the selected types in the resultant display ON A HTML PAGE
On a given HTML page, you have a search box and want to put a link to "select from tree" to use a kmap or kmap branch to filter the search by those types.
Thus you have to know how to have just one branch show up in the select from tree, rather than the entire Kmap tree.
In addition, once you choose some types, and hit ok, the search box should then show the types that the search is being constrained by.
How to Display a branch of a Kmap with hyperlinks to corresponding Place Dictionary entries ON A HTML PAGE
On a given HTML page, we want to show a Kmap or branch of a kmap tree, and make each one of the categories programmaticaly linked to the corresponding entries in the Place Dictionary that have used those Kmap categories.