# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 module RTM::AR::IO # JTM Export. # Each Topic Maps Construct gets a to_jtm method. module TOJTM module TopicMap # returns the JTM representation of this topic map def to_jtm_hash(*a) j={} #j['base_locator'] = base_locator, # with absolute item_identifiers its not needed j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['topics'] = topics.map{|i| i.to_jtm_hash} unless topics.empty? j['associations'] = associations.map{|i| i.to_jtm_hash} unless associations.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end module Topic # returns the JTM representation of this topic def to_jtm_hash(*a) j={} j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['subject_identifiers'] = subject_identifiers.map{|i| i.reference} unless subject_identifiers.empty? unless j['item_identifiers'] || j['subject_identifiers'] j['item_identifiers'] = [to_jtm_ref] end j['subject_locators'] = subject_locators.map{|i| i.reference} unless subject_locators.empty? j['names'] = names.map{|i| i.to_jtm_hash} unless names.empty? j['occurrences'] = occurrences.map{|i| i.to_jtm_hash} unless occurrences.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm def to_jtm_ref if subject_identifiers.first return subject_identifiers.first.reference end if item_identifiers.first return item_identifiers.first.reference end "t#{id}" end end module Association # returns the JTM representation of this association def to_jtm_hash(*a) j={} j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['type'] = type.to_jtm_ref if type j['scope'] = scope.map{|i| i.to_jtm_hash} unless scope.empty? j['roles'] = roles.map{|i| i.to_jtm_hash} unless roles.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end module TopicName def to_jtm_hash(*a) j={} j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['value'] = value if value j['type'] = type.to_jtm_ref if type j['scope'] = scope.map{|i| i.to_jtm_hash} unless scope.empty? j['variants'] = variants.map{|i| i.to_jtm_hash} unless variants.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end module Occurrence def to_jtm_hash(*a) j={} j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['value'] = value if value j['datatype'] = datatype if datatype j['type'] = type.to_jtm_ref if type j['scope'] = scope.map{|i| i.to_jtm_hash} unless scope.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end module AssociationRole def to_jtm_hash(*a) j={} j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['player'] = player.to_jtm_ref if player j['type'] = type.to_jtm_ref if type j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end module Variant def to_jtm_hash(*a) j={} j['reifier'] = reifier.to_jtm_ref if reifier j['item_identifiers'] = item_identifiers.map{|i| i.reference} unless item_identifiers.empty? j['value'] = value if value j['scope'] = scope.map{|i| i.to_jtm_hash} unless scope.empty? j end def to_jtm(*a) to_jtm_hash.to_json(*a) end alias :to_json :to_jtm end RTM::AR.register_extension self end end