What if every subject that we think about can have explicit representation in our computers?

Authoring topic maps using Ruby-based DSL: CTM, the way I like it

 

Designing and using Domain Specific Languages (DSL) is a popular programming style in Ruby community. I am experimenting with Ruby-based DSL for authoring topic maps. Surprisingly, the result is very close to my view on the “ideal” CTM (Compact Topic Maps syntax).

I just would like to share a sample that should demonstrate main ideas of this approach. It is a piece of Ruby code that generates topic maps (behind the scenes).

First topic map defines some simple ontology.


# some definitions to support DSL
# should be included

topic_map :ontology_tm do

  tm_base "http://www.example.com/topic_maps/people/" 

  topic(:person) {
    sid   "http://psi.example.com/Person" 
    name  "Person" 
    isa :topic_type
  }

  topic(:first_name) {
    sid   "http://psi.example.com/first_name" 
    name  "first name" 
    isa :name
  }

  topic(:last_name) {
    sid   "http://psi.example.com/last_name" 
    name  "last name" 
    isa :name
  }

  topic(:web_page) {
    sid   "http://psi.example.com/web_page" 
    name  "web page" 
    isa :occurrence
    datatype :uri
  }

  topic(:age) {
    sid   "http://psi.example.com/age" 
    name  "age" 
    isa :occurrence
    datatype :integer
  }

  topic(:description) {
    sid   "http://psi.example.com/description" 
    name  "description" 
    isa :occurrence
    datatype :string
  }

  topic(:works_for) {
    sid   "http://psi.example.com/works_for" 
    name  "works for" 
    isa :property
    association :employment
    first_role :employee
    second_role :employer
    third_role :position_type  
    third_role_prefix :as
  }

  topic(:likes) {
    sid   "http://psi.example.com/likes" 
    name  "likes" 
    isa [:property, :association]
    association :likes
    first_role :person
    second_role :object
  }

end

Second topic map includes ontology and asserts some facts.

    
topic_map :facts_tm do  

  tm_base "http://www.example.com/topic_maps/people/john_smith" 

  tm_include :ontology_tm

  topic :john_smith do
      sid "http://psi.example.com/JohnSmith" 
      name  "John Smith" 
      name  "Johnny", :scope => :alt_name
      first_name "John" ; last_name  "Smith" 
      web_page "http://a.example.com/JohnSmith.htm" 
      works_for topic(:example_dot_com){
                              sid "http://www.example.com" 
                              name "example.com"; isa :company
                         }, 
                        :as => :program_manager, 
                        :scope => :date_2008_02_28
      likes [:italian_opera, :new_york]
      age 35
      description <<EOF
John Smith is a very nice person.
He works for example.com and likes Italian opera.
EOF

  end

end

 
· CTM · Domain Specific Language · Ruby (programming language) · Topic Maps ·

Home