Using Ror Topical Maps Web Services

THL Toolbox > Developers' Zone > Ruby On Rails Development > Using RoR Topical Map Web Services (DEPRECATED)

Using RoR Topical Map Web Services (DEPRECATED)

Contributor(s): Tom Benner, ANDRES MONTANO

Summary Information

The data from Topical 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.

Topical Map Builder Integration with Applications

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.

URLs are provided by Topical Maps API

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:

Topical Maps and Places Dictionary

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: external link: http://staging.tmb.thdl.org/categories/20/children

If you want to see the tree fully expanded in xml you get it from here: external link: http://staging.tmb.thdl.org/categories/20/children/all.xml

To see the place dictionaries' integration in action, go to the admin features ( external link: 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:

Install:
app> script/plugin install -x
app> external link: http://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/plugins/top
app> ical_map_builder_integration/trunk/

Integrate javascript, stylesheet, views and controller:

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:

def new
@parent_object_type = Category.find(20) # feature thesaurus id in topical map builder

end

With this weird resource controller I placed it like this:

new_action.before do
@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 %>
<%=
category_selector
(@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 external link: Tibetan and Himalayan Library

How to Pull up Select Menu from One Branch of a Topical Map & 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 topical map or topical map 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 topical map 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 Topical Map with hyperlinks to corresponding Place Dictionary entries ON A HTML PAGE

On a given HTML page, we want to show a Topical Map or branch of a topical map tree, and make each one of the categories programmaticaly linked to the corresponding entries in the Place Dictionary that have used those Topical Map categories.

Provided for unrestricted use by the external link: Tibetan and Himalayan Library