Class: Cyc::Collection
- Inherits:
-
Object
- Object
- Cyc::Collection
- Defined in:
- lib/cyc/collection.rb
Overview
- Author
-
Aleksander Pohl ([email protected])
- License
-
MIT/X11 License
This class is used to represent Cyc collections.
Instance Attribute Summary collapse
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(other) ⇒ Object
- #ancestor?(node) ⇒ Boolean
- #children ⇒ Object
- #comment ⇒ Object
-
#initialize(symbol, cyc) ⇒ Collection
constructor
A new instance of Collection.
- #lexemes ⇒ Object
- #parents ⇒ Object
- #printed? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(symbol, cyc) ⇒ Collection
Returns a new instance of Collection.
9 10 11 12 13 |
# File 'lib/cyc/collection.rb', line 9 def initialize(symbol, cyc) @symbol = symbol @cyc = cyc @printed = false end |
Instance Attribute Details
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
7 8 9 |
# File 'lib/cyc/collection.rb', line 7 def symbol @symbol end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 60 |
# File 'lib/cyc/collection.rb', line 57 def ==(other) return false unless other.is_a? Collection self.symbol == other.symbol end |
#=~(other) ⇒ Object
62 63 64 65 66 |
# File 'lib/cyc/collection.rb', line 62 def =~(other) return false unless other.is_a? Collection self.parents - other.parents == [] && other.parents - self.parents == [] end |
#ancestor?(node) ⇒ Boolean
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cyc/collection.rb', line 68 def ancestor?(node) return true if node == :Thing ancestors = @parents.dup while !ancestors.empty? ancestor = ancestors.shift return true if ancestor == node ancestors += ancestor.parents ancestors.uniq! end false end |
#children ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cyc/collection.rb', line 31 def children unless @children children = @cyc.max_specs(symbol) if children @children = children.map{|p| Collection.new(p,@cyc)} else @children = [] end end @children end |
#comment ⇒ Object
43 44 45 |
# File 'lib/cyc/collection.rb', line 43 def comment @cyc.comment(@symbol) end |
#lexemes ⇒ Object
47 48 49 50 51 |
# File 'lib/cyc/collection.rb', line 47 def lexemes() default_str = [@cyc.symbol_str(symbol)] aux_strs = @cyc.symbol_strs(symbol) || [] (default_str + aux_strs).uniq.compact.join(", ") end |
#parents ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cyc/collection.rb', line 19 def parents unless @parents parents = @cyc.min_genls(symbol) @parents = if parents parents.map{|p| Collection.new(p,@cyc)} else [] end end @parents end |
#printed? ⇒ Boolean
15 16 17 |
# File 'lib/cyc/collection.rb', line 15 def printed? @printed end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/cyc/collection.rb', line 53 def to_s @symbol.to_s end |