# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. # License: Apache License, Version 2.0 module RTM::Sugar module Topic module Typed # Returns the associations, names, occurrences and roles whose # type equals this topic. # # The result may be empty. # # :call-seq: # typed -> Array of Associations, Names, Occurrences and Roles # def typed _index = topic_map.type_instance_index _index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_roles(self).to_a end # Returns the associations, names, occurrences and roles whose # type equals this topic or subtypes # of this topic. # # The result may be empty. # # :call-seq: # transitive_typed -> Array of Associations, Names, Occurrences and Roles # def transitive_typed trans_typed = typed #may be empty transitive_subtypes.each do |subtype| trans_typed.concat(subtype.typed) end trans_typed = trans_typed.uniq #no duplicates outside of tmql mode end # Returns the associations whose type equals this topic. # # The result may be empty. # # :call-seq: # typed_associations -> Array of Associations # def typed_associations topic_map.type_instance_index.get_associations(self).to_a end # Returns the associations whose type equals this topic or subtypes # of this topic. # # The result may be empty. # # :call-seq: # transitive_typed_associations -> Array of Associations # def transitive_typed_associations trans_types_assocs = typed_associations #may be empty transitive_subtypes.each do |subtype| trans_types_assocs.concat(subtype.typed_associations) end trans_types_assocs = trans_types_assocs.uniq #no duplicates outside of tmql mode end # Returns the names whose type equals this topic. # # The result may be empty. # # :call-seq: # typed_names -> Array of Names # def typed_names topic_map.type_instance_index.get_names(self).to_a end # Returns the names whose type equals this topic or subtypes # of this topic. # # The result may be empty. # # :call-seq: # transitive_typed_names -> Array of Associations # def transitive_typed_names trans_types_names = typed_names #may be empty transitive_subtypes.each do |subtype| trans_types_names.concat(subtype.typed_names) end trans_types_names = trans_types_names.uniq #no duplicates outside of tmql mode end # Returns the occurrences whose type equals this topic. # # The result may be empty. # # :call-seq: # typed_occurrences -> Array of Occurrences # def typed_occurrences topic_map.type_instance_index.get_occurrences(self).to_a end # Returns the occurrences whose type equals this topic or subtypes # of this topic. # # The result may be empty. # # :call-seq: # transitive_typed_occurrences -> Array of Associations # def transitive_typed_occurrences trans_types_occs = typed_occurrences #may be empty transitive_subtypes.each do |subtype| trans_types_occs.concat(subtype.typed_occurrences) end trans_types_occs = trans_types_occs.uniq #no duplicates outside of tmql mode end # Returns the roles whose type equals this topic. # # The result may be empty. # # :call-seq: # typed_roles -> Array of Roles # def typed_roles topic_map.type_instance_index.get_roles(self).to_a end # Returns the roles whose type equals this topic or subtypes # of this topic. # # The result may be empty. # # :call-seq: # transitive_typed_roles -> Array of Associations # def transitive_typed_roles trans_types_roles = typed_roles #may be empty transitive_subtypes.each do |subtype| trans_types_roles.concat(subtype.typed_roles) end trans_types_roles = trans_types_roles.uniq #no duplicates outside of tmql mode end # Determines whether this topic is instance (directly or indirectly) # of the argument type. # # Type may be a topic reference. # # :call-seq: # topic_is_a?(type) # def topic_is_a?(type) topic_map.cached self, :is_a?, type do self.transitive_types.include?(topic_map.get(type)) end end # States if this topic is used as type of a typed Construct. # # :call-seq: # used_as_type? -> true or false # def used_as_type? used_as_name_type? || used_as_occurrence_type? || used_as_association_type? || used_as_role_type? end # States if this topic is used as type of an Association. # # :call-seq: # used_as_association_type? -> true or false # def used_as_association_type? not self.typed_associations.empty? end # States if this topic is used as type of a Name. # # :call-seq: # used_as_name_type? -> true or false # def used_as_name_type? not self.typed_names.empty? end # States if this topic is used as type of an Occurrence. # # :call-seq: # used_as_occurrence_type -> true or false # def used_as_occurrence_type? not self.typed_occurrences.empty? end # States if this topic is used as type of a Role. # # :call-seq: # used_as_role_type? -> true or false # def used_as_role_type? not self.typed_roles.empty? end end end end