# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 module RTM module Navigation module Topic # Returns all Topic players that exist in binary supertype-subtype Associations # where this Topic playes the subtype-Role. # # The result may be an empty Array. # # :call-seq: # direct-supertypes -> Array of Topics # def direct_supertypes roles_played(topic_map.get(RTM::PSI[:subtype]),topic_map.get(RTM::PSI[:supertype_subtype])). reject{|r| r.getParent.getRoles.size!=2}. map{|r| r.parent[RTM::PSI[:supertype]].first.player}.flatten.uniq end # Creates a binary supertype-subtype-Association where identifier defines # the player of the supertype-Role. The current Topic will play the # subtype-Role. Returns the created Association. # # Identifier may be a topic reference. # # :call-seq: # add_supertype(identifier) -> Association # def add_supertype(new_supertype) asso = topic_map.create_association(RTM::PSI[:supertype_subtype]) asso.create_role(RTM::PSI[:subtype],self) asso.create_role(RTM::PSI[:supertype],new_supertype) asso end # Creates one or several binary supertype-subtype-Associations where # each identifier defines # the player of a supertype-Role. The current topic will play the # subtype-Role in each association. Returns the associations. # # The identifiers may be topic references. # # :call-seq: # add_supertypes(identifier1, identifier2, ...) -> Array of Associtions # def add_supertypes(*args) args.flatten! args.map{|identifier| add_supertype(identifier)} end # Returns all supertypes of this Topic. The result includes # all direct supertypes # and the supertypes of these direct supertypes. # # The result may be an empty Array. # # :call-seq: # transitive_supertypes -> Array of Topics # def transitive_supertypes # topic_map.cached self, :transitive_supertypes do result_types = new_s_t = direct_supertypes until new_s_t.empty? new_s_t = new_s_t.map{|s| s.direct_supertypes}.flatten.uniq new_s_t = new_s_t.reject{|s| result_types.include?(s)} result_types = result_types + new_s_t end result_types # end end # Returns all supertypes of this Topic. The result includes the direct_supertypes # and the supertypes of these direct_supertypes of this Topic as well as the Topic itself. # # :call-seq: # transitive_supertypes_with_self -> Array of Topics # def transitive_supertypes_with_self transitive_supertypes + [self] end # Returns all Topics that exist in binary supertype-subtype Associations # where this Topic playes the supertype-Role. # # The result may be an empty Array. # # :call-seq: # direct-subtypes -> Array of Topics # def direct_subtypes roles(topic_map.get(RTM::PSI[:supertype]),topic_map.get(RTM::PSI[:supertype_subtype])). reject{|r| r.getParent.getRoles.size!=2}. map {|r| r.getParent[RTM::PSI[:subtype]].first.player}.flatten.uniq end # Creates a binary supertype-subtype-Association where identifier defines # the player of the subtype-Role. The current Topic will play the # supertype-Role. Returns the created Association. # # Identifier may be topic reference. # # :call-seq: # add_subtype(identifier) -> Association # def add_subtype(new_subtype) asso = topic_map.create_association(RTM::PSI[:supertype_subtype]) asso.create_role(RTM::PSI[:supertype],self) asso.create_role(RTM::PSI[:subtype],new_subtype) asso end # Creates one or several binary supertype-subtype-Associations where # each identifier defines # the player of a subtype-Role. The current topic will play the # supertype-Role in each association. Returns the associations. # # The identifiers may be topic references. # # :call-seq: # add_subtypes(identifier1, identifier2, ...) -> Array of Associtions # def add_subtypes(*args) args.flatten! args.map{|identifier| add_subtype(identifier)} end # Returns all subtypes of this Topic. The result includes the direct subtypes # and the subtypes of these direct subtypes. # # The result may be an empty Array. # # :call-seq: # transitive_subtypes -> Array of Topics # def transitive_subtypes topic_map.cached self, :transitive_subtypes do result_types = new_s_t = direct_subtypes until new_s_t.empty? new_s_t = new_s_t.map{|s| s.direct_subtypes}.flatten.uniq new_s_t = new_s_t.reject{|s| result_types.include?(s)} result_types = result_types + new_s_t end result_types end end # Returns all subtypes of this Topic. The result includes the direct_subtypes # and the subtypes of these direct_subtypes of this Topic as well as the Topic itself. # # :call-seq: # transitive_subtypes_with_self -> Array of Topics # def transitive_subtypes_with_self transitive_subtypes + [self] end alias :supertypes :transitive_supertypes alias :subtypes :transitive_subtypes alias :reverse_subtypes :supertypes alias :reverse_supertypes :subtypes end end end