Class: Words::Relation
- Inherits:
-
Object
- Object
- Words::Relation
- Defined in:
- lib/relation.rb
Constant Summary collapse
- RELATION_TO_SYMBOL =
{ "-c" => :member_of_this_domain_topic, "+" => :derivationally_related_form, "%p" => :part_meronym, "~i" => :instance_hyponym, "@" => :hypernym, ";r" => :domain_of_synset_region, "!" => :antonym, "#p" => :part_holonym, "%s" => :substance_meronym, ";u" => :domain_of_synset_usage, "-r" => :member_of_this_domain_region, "#s" => :substance_holonym, "=" => :attribute, "-u" => :member_of_this_domain_usage, ";c" => :domain_of_synset_topic, "%m"=> :member_meronym, "~" => :hyponym, "@i" => :instance_hypernym, "#m" => :member_holonym, "$" => :verb_group, ">" => :cause, "*" => :entailment, "\\" => :pertainym, "<" => :participle_of_verb, "&" => :similar_to, "^" => :see_also }
- SYMBOL_TO_RELATION =
RELATION_TO_SYMBOL.invert
Instance Method Summary collapse
- #destination ⇒ Object
- #destination_word ⇒ Object
-
#initialize(relation_construct, source_synset, wordnet_connection) ⇒ Relation
constructor
A new instance of Relation.
- #inspect ⇒ Object
- #is_semantic? ⇒ Boolean
- #relation_type ⇒ Object
- #relation_type?(type) ⇒ Boolean
- #source_word ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(relation_construct, source_synset, wordnet_connection) ⇒ Relation
Returns a new instance of Relation.
17 18 19 20 21 22 23 24 25 |
# File 'lib/relation.rb', line 17 def initialize(relation_construct, source_synset, wordnet_connection) @wordnet_connection = wordnet_connection @symbol, @dest_synset_id, @pos, @source_dest = relation_construct.split('.') @dest_synset_id = @pos + @dest_synset_id @symbol = RELATION_TO_SYMBOL[@symbol] @source_synset = source_synset end |
Instance Method Details
#destination ⇒ Object
66 67 68 69 70 |
# File 'lib/relation.rb', line 66 def destination @destination ||= Synset.new(@dest_synset_id, @wordnet_connection, nil) end |
#destination_word ⇒ Object
40 41 42 43 44 45 |
# File 'lib/relation.rb', line 40 def destination_word return nil if is_semantic? @destination_word ||= destination.words[@source_dest[2..3].to_i(16)-1] end |
#inspect ⇒ Object
82 83 84 85 86 |
# File 'lib/relation.rb', line 82 def inspect { :symbol => @symbol, :dest_synset_id => @dest_synset_id, :pos => @pos, :source_dest => @source_dest }.inspect end |
#is_semantic? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/relation.rb', line 27 def is_semantic? @source_dest == "0000" end |
#relation_type ⇒ Object
60 61 62 63 64 |
# File 'lib/relation.rb', line 60 def relation_type @symbol end |
#relation_type?(type) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/relation.rb', line 47 def relation_type?(type) case when SYMBOL_TO_RELATION.include?(type.to_sym) type.to_sym == @symbol when RELATION_TO_SYMBOL.include?(pos.to_s) POINTER_TO_SYMBOL[type.to_sym] == @symbol else false end end |
#source_word ⇒ Object
33 34 35 36 37 38 |
# File 'lib/relation.rb', line 33 def source_word return nil if is_semantic? @source_word ||= @source_synset.words[@source_dest[0..1].to_i(16)-1] end |
#to_s ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/relation.rb', line 72 def to_s if is_semantic? @to_s ||= "Semantic #{relation_type.to_s.gsub('_', ' ')} relation between #{@source_synset.synset_id} and #{@dest_synset_id}" else @to_s ||= "#{relation_type.to_s.gsub('_', ' ').capitalize} relation between #{@source_synset.synset_id}'s word \"#{source_word}\" and #{@dest_synset_id}'s word \"#{destination_word}\"" end end |