Class: Broadlistening::Argument
- Inherits:
-
Object
- Object
- Broadlistening::Argument
- Defined in:
- lib/broadlistening/argument.rb
Overview
Represents an extracted argument (opinion) from a comment.
Arguments are created during the extraction step and enriched through subsequent pipeline steps (embedding, clustering).
Instance Attribute Summary collapse
-
#arg_id ⇒ Object
Returns the value of attribute arg_id.
-
#argument ⇒ Object
Returns the value of attribute argument.
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#cluster_ids ⇒ Object
Returns the value of attribute cluster_ids.
-
#comment_id ⇒ Object
Returns the value of attribute comment_id.
-
#embedding ⇒ Object
Returns the value of attribute embedding.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#url ⇒ Object
Returns the value of attribute url.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
-
.from_comment(comment, opinion_text, index) ⇒ Argument
Create an Argument from a Comment during extraction.
-
.from_hash(hash) ⇒ Argument
Create an Argument from a hash.
Instance Method Summary collapse
-
#comment_id_int ⇒ Integer
Extract numeric comment_id from arg_id if comment_id is not set.
-
#in_cluster?(cluster_id) ⇒ Boolean
Check if argument belongs to a specific cluster.
-
#initialize(arg_id:, argument:, comment_id:, embedding: nil, x: nil, y: nil, cluster_ids: nil, attributes: nil, url: nil, properties: nil) ⇒ Argument
constructor
A new instance of Argument.
-
#to_clustering_h ⇒ Hash
Convert to hash with only clustering data (for clustering.json).
-
#to_embedding_h ⇒ Hash
Convert to hash with only embedding data (for embeddings.json).
-
#to_h ⇒ Hash
Convert to hash for serialization.
Constructor Details
#initialize(arg_id:, argument:, comment_id:, embedding: nil, x: nil, y: nil, cluster_ids: nil, attributes: nil, url: nil, properties: nil) ⇒ Argument
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/broadlistening/argument.rb', line 18 def initialize( arg_id:, argument:, comment_id:, embedding: nil, x: nil, y: nil, cluster_ids: nil, attributes: nil, url: nil, properties: nil ) @arg_id = arg_id @argument = argument @comment_id = comment_id = @x = x @y = y @cluster_ids = cluster_ids @attributes = attributes @url = url @properties = properties end |
Instance Attribute Details
#arg_id ⇒ Object
Returns the value of attribute arg_id.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def arg_id @arg_id end |
#argument ⇒ Object
Returns the value of attribute argument.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def argument @argument end |
#attributes ⇒ Object
Returns the value of attribute attributes.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def attributes @attributes end |
#cluster_ids ⇒ Object
Returns the value of attribute cluster_ids.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def cluster_ids @cluster_ids end |
#comment_id ⇒ Object
Returns the value of attribute comment_id.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def comment_id @comment_id end |
#embedding ⇒ Object
Returns the value of attribute embedding.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def end |
#properties ⇒ Object
Returns the value of attribute properties.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def properties @properties end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def url @url end |
#x ⇒ Object
Returns the value of attribute x.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
14 15 16 |
# File 'lib/broadlistening/argument.rb', line 14 def y @y end |
Class Method Details
.from_comment(comment, opinion_text, index) ⇒ Argument
Create an Argument from a Comment during extraction
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/broadlistening/argument.rb', line 67 def self.from_comment(comment, opinion_text, index) new( arg_id: "A#{comment.id}_#{index}", argument: opinion_text, comment_id: comment.id, attributes: comment.attributes, url: comment.source_url, properties: comment.properties ) end |
.from_hash(hash) ⇒ Argument
Create an Argument from a hash
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/broadlistening/argument.rb', line 46 def self.from_hash(hash) new( arg_id: hash[:arg_id] || hash["arg_id"], argument: hash[:argument] || hash["argument"], comment_id: hash[:comment_id] || hash["comment_id"], embedding: hash[:embedding] || hash["embedding"], x: hash[:x] || hash["x"], y: hash[:y] || hash["y"], cluster_ids: hash[:cluster_ids] || hash["cluster_ids"], attributes: hash[:attributes] || hash["attributes"], url: hash[:url] || hash["url"], properties: hash[:properties] || hash["properties"] ) end |
Instance Method Details
#comment_id_int ⇒ Integer
Extract numeric comment_id from arg_id if comment_id is not set
129 130 131 132 133 134 |
# File 'lib/broadlistening/argument.rb', line 129 def comment_id_int return @comment_id.to_i if @comment_id match = @arg_id&.match(/\AA(\d+)_/) match ? match[1].to_i : 0 end |
#in_cluster?(cluster_id) ⇒ Boolean
Check if argument belongs to a specific cluster
122 123 124 |
# File 'lib/broadlistening/argument.rb', line 122 def in_cluster?(cluster_id) @cluster_ids&.include?(cluster_id) || false end |
#to_clustering_h ⇒ Hash
Convert to hash with only clustering data (for clustering.json)
109 110 111 112 113 114 115 116 |
# File 'lib/broadlistening/argument.rb', line 109 def to_clustering_h { arg_id: @arg_id, x: @x, y: @y, cluster_ids: @cluster_ids } end |
#to_embedding_h ⇒ Hash
Convert to hash with only embedding data (for embeddings.json)
99 100 101 102 103 104 |
# File 'lib/broadlistening/argument.rb', line 99 def { arg_id: @arg_id, embedding: } end |
#to_h ⇒ Hash
Convert to hash for serialization
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/broadlistening/argument.rb', line 81 def to_h { arg_id: @arg_id, argument: @argument, comment_id: @comment_id, embedding: , x: @x, y: @y, cluster_ids: @cluster_ids, attributes: @attributes, url: @url, properties: @properties }.compact end |