Class: QDA::CodingTable
- Inherits:
-
Hash
- Object
- Hash
- QDA::CodingTable
- Defined in:
- lib/weft/coding.rb
Overview
a hash representing a complex series of codes applied to one or more documents
Direct Known Subclasses
Instance Method Summary collapse
-
#add(item) ⇒ Object
add the coding of
item
to the coding table. -
#codes?(doc) ⇒ Boolean
returns true if this coding table contains coding for the document
doc
. - #each_set ⇒ Object
-
#initialize ⇒ CodingTable
constructor
A new instance of CodingTable.
-
#join(other) ⇒ Object
deletes all coding except that which is also covered by
other
. - #join! ⇒ Object
-
#merge(other) ⇒ Object
Adds the coding of the other coding table
other
to this one, modifying +self in place. - #merge!(other) ⇒ Object
- #num_of_chars ⇒ Object
- #num_of_codes ⇒ Object (also: #num_of_passages)
- #num_of_docs ⇒ Object
-
#remove(other) ⇒ Object
Removes all coding from this table that occurs in the other table
other
, modifying this CodingTable in place. - #remove!(other) ⇒ Object
-
#set(docid, codeset) ⇒ Object
Sets the coding of the document identified by
docid
to becodeset
. - #sets ⇒ Object
- #sort(&block) ⇒ Object
-
#subtract(item) ⇒ Object
remove the coding of
item
to the coding table.
Constructor Details
#initialize ⇒ CodingTable
Returns a new instance of CodingTable.
230 231 232 |
# File 'lib/weft/coding.rb', line 230 def initialize super { | h, k | h[k] = CodeSet.new() } end |
Instance Method Details
#add(item) ⇒ Object
add the coding of item
to the coding table. item
should be a QDA::Code or QDA::Fragment.
240 241 242 |
# File 'lib/weft/coding.rb', line 240 def add(item) self[item.docid].add(item) end |
#codes?(doc) ⇒ Boolean
returns true if this coding table contains coding for the document doc
277 278 279 |
# File 'lib/weft/coding.rb', line 277 def codes?(doc) key?(doc.dbid) and self[doc.dbid].length > 0 end |
#each_set ⇒ Object
341 342 343 |
# File 'lib/weft/coding.rb', line 341 def each_set() keys.sort.each { | docid | yield self[docid] } end |
#join(other) ⇒ Object
deletes all coding except that which is also covered by other
316 317 318 319 320 321 322 323 |
# File 'lib/weft/coding.rb', line 316 def join(other) both = keys.find_all { | doc | other.key?(doc) } results = self.class.new() both.each do | docid | results.set(docid, self[docid].intersect( other[docid] ) ) end return results end |
#join! ⇒ Object
325 326 327 |
# File 'lib/weft/coding.rb', line 325 def join! replace( join(other) ) end |
#merge(other) ⇒ Object
Adds the coding of the other coding table other
to this one, modifying +self in place
283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/weft/coding.rb', line 283 def merge(other) results = self.class.new() either = self.keys + other.keys either.uniq.each do | docid | if ! other[docid] results.set(docid, self[docid]) elsif ! self[docid] results.set(docid, other[docid]) else results.set( docid, self[docid].union(other[docid]) ) end end return results end |
#merge!(other) ⇒ Object
298 299 300 |
# File 'lib/weft/coding.rb', line 298 def merge!(other) replace( merge(other) ) end |
#num_of_chars ⇒ Object
271 272 273 |
# File 'lib/weft/coding.rb', line 271 def num_of_chars() values.inject(0) { | count, codeset | count += codeset.num_of_chars } end |
#num_of_codes ⇒ Object Also known as: num_of_passages
266 267 268 |
# File 'lib/weft/coding.rb', line 266 def num_of_codes() values.inject(0) { | count, codeset | count + codeset.length } end |
#num_of_docs ⇒ Object
262 263 264 |
# File 'lib/weft/coding.rb', line 262 def num_of_docs() keys.reject { | set | self[set].length == 0 }.length end |
#remove(other) ⇒ Object
Removes all coding from this table that occurs in the other table other
, modifying this CodingTable in place
304 305 306 307 308 309 310 |
# File 'lib/weft/coding.rb', line 304 def remove(other) results = self.class.new() each do | docid, codes | results.set(docid, codes.exclude( other[docid] ) ) end return results end |
#remove!(other) ⇒ Object
312 313 314 |
# File 'lib/weft/coding.rb', line 312 def remove!(other) replace( remove(other) ) end |
#set(docid, codeset) ⇒ Object
Sets the coding of the document identified by docid
to be codeset
245 246 247 248 249 250 251 |
# File 'lib/weft/coding.rb', line 245 def set(docid, codeset) unless codeset.kind_of?(CodeSet) raise ArgumentError, "Cannot set codeset #{codeset.inspect} as a CodingTable entry" end self[docid] = codeset end |
#sets ⇒ Object
337 338 339 |
# File 'lib/weft/coding.rb', line 337 def sets() values_at( *keys.sort ) end |
#sort(&block) ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/weft/coding.rb', line 329 def sort(&block) if block_given super(&block) else super { | a, b | a <=> b } end end |
#subtract(item) ⇒ Object
remove the coding of item
to the coding table. item
should be a QDA::Code or QDA::Fragment.
258 259 260 |
# File 'lib/weft/coding.rb', line 258 def subtract(item) self[item.docid].subtract(item) end |