Module: RTM::Sugar::Topic::Characteristics

Defined in:
rtm/lib/rtm/sugar/topic/characteristics.rb,
rtm/spec/rtm/sugar/topic/characteristics_spec.rb

Overview

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

Instance Method Summary

Instance Method Details

- (Object) external_occurrences

Returns all Occurrences of this Topic whose datatype is IRI

:call-seq:

  external_occurrences -> Set of Occurrences


20
21
22
# File 'rtm/lib/rtm/sugar/topic/characteristics.rb', line 20

def external_occurrences
  occurrences.select{|y| y.getDatatype.toExternalForm == RTM::PSI[:IRI]}
end

- (Object) internal_occurrences

Returns all Occurrences of this Topic whose datatype is not IRI

:call-seq:

  internal_occurrences -> Set of Occurrences


11
12
13
# File 'rtm/lib/rtm/sugar/topic/characteristics.rb', line 11

def internal_occurrences
  occurrences.select{|x| x.getDatatype.toExternalForm != RTM::PSI[:IRI]}
end

- (Object) names_by(args = {})

Returns the names of this topic which may be filtered for their type, value and/or scope.

If scope is set to :ucs, names which exist in the unconstrained scope are selected. If scope is set to :any (default), scope does not constrain the names-Array. Else, only the names which whose scope contains one of the given themes are returned.

Returns an empty Array if no names match or if the name type or scope does not exist.

:call-seq:

  names_by -> Array of Names
  names_by(:type => identifier) -> Array of Names
  names_by(:value => string) -> Array of Names
  names_by(:scope => identifier) -> Array of Names
  names_by(:type => identifier, :value => string) -> Array of Names
  names_by(:type => identifier, :value => string, :scope => identifier) -> Array of Names
  and so on


44
45
46
47
48
49
50
51
52
53
# File 'rtm/lib/rtm/sugar/topic/characteristics.rb', line 44

def names_by(args = {})
  raise("names_by: arguments must be a Hash") unless args.is_a?(Hash)
  default_hash = {:type => :any, :value => :any, :scope => :any}   
  args = default_hash.merge(args)
  #filter for type
  _names = args[:type] == :any ? names : names(args[:type])
  _names = self.filter_by(_names,args)
  # return Array
  return _names.to_a
end

- (Object) occurrences_by(args = {})

Returns Occurrences of this Topic which may be filtered for their type, value, datatype and/or scope.

If scope is set to :ucs, Occurrences which exist in the unconstrained scope are selected. If scope is set to :any (default), scope does not constrain the Occurrence-Array. Else, only the occurrences which whose scope contains one of the given themes are returned.

Returns an empty Array if no Occurrences match or if the Occurrence type or scope does not exist.

:call-seq:

  occurrence_by -> Array of Occurrences
  occurrences_by(:type => argument) -> Array of Occurrences
  occurrences_by(:value => argument) -> Array of Occurrences
  occurrences_by(:scope => argument) -> Array of Occurrences
  occurrences_by(:datatype => argument) -> Array of Occurrences
  occurrences_by(:type => argument1, :value => argument2) -> Array of Occurrences
  occurrences_by(:type => argument1, :value => argument2, :scope => argument3, :datatype => argument4) -> Array of Occurrences
  and so on


76
77
78
79
80
81
82
83
84
85
86
# File 'rtm/lib/rtm/sugar/topic/characteristics.rb', line 76

def occurrences_by(args = {})
  raise("occurrences_by: arguments must be a Hash") unless args.is_a?(Hash)
  default_hash = {:type => :any, :value => :any, :scope => :any, :datatype => :any}
  args = default_hash.merge(args)
  #filter for type
  _occurrences = args[:type] == :any ? occurrences : occurrences(args[:type])
  _occurrences = self.filter_by(_occurrences,args)
  #filter for datatype
  _occurrences = _occurrences.select{|o| o.datatype == args[:datatype]} unless args[:datatype] == :any
  return _occurrences.to_a
end