Class: Java::DeTopicmapslabMajortomCore::TopicImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/rtm/majortom/core/topic.rb

Overview

Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig. License: Apache License, Version 2.0

Instance Method Summary collapse

Instance Method Details

#add_subtype(identifier) ⇒ Object



23
24
25
# File 'lib/rtm/majortom/core/topic.rb', line 23

def add_subtype(identifier)
  topic_map.get!(identifier).addSupertype(self)
end

#add_supertype(identifier) ⇒ Object



19
20
21
# File 'lib/rtm/majortom/core/topic.rb', line 19

def add_supertype(identifier)
  self.addSupertype(topic_map.get!(identifier))
end

#associations_played(filter = {}) ⇒ Object

Returns all Associations in which this Topic is a player.

A filter-hash may be used to filter for the type of the Role this Topic plays (:rtype), for the Association type (:atype), for the type of another role (:otype) as well as for the player of this other role (:oplayer). Each value of this filter-hash may be a topic reference.

The result may be empty.

:call-seq:

associations_played                         -> Array of Associations
associations_played({:rtype => identifier}) -> Array of Associations
associations_played({:atype => identifier}) -> Array of Associations
associations_played({:otype => identifier}) -> Array of Associations
associations_played({:otype => identifier, :oplayer => identifier}) -> Array of Associations
associations_played({:rtype => identifier, :atype => identifier}) -> Array of Associations
associations_played({:rtype => identifier, :atype => identifier, :otype => identifier}) -> Array of Associations
associations_played({:rtype => identifier, :atype => identifier, :otype => identifier, :oplayer => identifier}) -> Array of Associations


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rtm/majortom/core/topic.rb', line 70

def associations_played(filter = {})
  topic_map.cached self, :associations_played, filter do
    raise("associations_played(filter): filter must be a Hash") unless filter.is_a?(Hash)
    default_hash = {:rtype => :any, :atype => :any, :otype => :any, :oplayer => :any}
    filter = default_hash.merge(filter)

    # get all roles played
    roles = self.roles_played(filter[:rtype], filter[:atype])
    filter.delete(:rtype)
    filter.delete(:atype)

    #filter for the other roles types and players if there are other roles
    roles = roles.reject do |role|
      if role.parent.roles.size == 1 #association size
        if (filter[:otype] != :any) || filter[:player] != :any
        end
      else
        role.counterparts(filter).empty?
      end
    end

    # return parent associations
    roles.map{|role| role.parent}.uniq
  end
end

#best_label(theme = nil) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rtm/majortom/core/topic.rb', line 10

def best_label(theme = nil)
  theme = self.parent.get(theme) unless theme.is_a?(RTM::Topic)
  label = theme ? getBestLabel(theme) : getBestLabel
  if label.empty?
    label = self.reference(:outputstyle => :blank)
  end
  return label
end

#characteristics(type = :any) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/rtm/majortom/core/topic.rb', line 39

def characteristics(type=:any)
  _characteristics = names.to_a + occurrences.to_a
  return _characteristics if type == :any
  _type = topic_map.get(type)
  return [] unless _type
  #_characteristics.select{|c| c.type == _topic}
  _characteristics.select{|c| c.type.supertypes.include?(_type)}
end

#read_only?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/rtm/majortom/core/topic.rb', line 6

def read_only?
  return false unless (self.is_a?(Java::DeTopicmapslabMajortomDatabaseReadonly::JdbcReadOnlyTopic) || self.is_a?(Java::DeTopicmapslabMajortomInmemoryStoreRevisionReadonly::InMemoryReadOnlyTopic))
end

#supertypesObject Also known as: transitive_supertypes



27
28
29
30
31
32
33
34
35
36
# File 'lib/rtm/majortom/core/topic.rb', line 27

def supertypes
  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
  #return getSupertypes.to_a
end