Class: QDA::FragmentTable
Overview
a FragmentTable holds a collection of fragments. It contains a number of CodeSets of Fragments. Each CodeSet can be retrieved either by document title or by document dbid.
tbl = FragmentTable.new()
f = Fragment.new('Weft QDA', 'the title', 6, 1)
tbl.add(f)
tbl['the title'] tbl[1]
Instance Method Summary
collapse
Methods inherited from CodingTable
#codes?, #join, #join!, #merge, #merge!, #num_of_chars, #num_of_codes, #num_of_docs, #remove, #remove!, #sort, #subtract
Constructor Details
Returns a new instance of FragmentTable.
355
356
357
358
|
# File 'lib/weft/coding.rb', line 355
def initialize
@titles = Hash.new() { | h, k | h[k] = CodeSet }
super()
end
|
Instance Method Details
#[](k) ⇒ Object
Assumes this is a document title if a string, or an dbid if an integer
361
362
363
|
# File 'lib/weft/coding.rb', line 361
def [](k)
k.kind_of?(String) ? super(@titles[k]) : super(k)
end
|
#add(fragment) ⇒ Object
Always use this method to add fragments to the collection
373
374
375
376
377
378
379
|
# File 'lib/weft/coding.rb', line 373
def add(fragment)
unless fragment.is_a?(Fragment)
raise ArgumentError, "Fragment expected, got #{fragment.inspect}"
end
self[fragment.docid].add(fragment)
@titles[fragment.doctitle] = fragment.docid
end
|
#each_set ⇒ Object
394
395
396
|
# File 'lib/weft/coding.rb', line 394
def each_set
titles.each { | title | yield self[ @titles[title] ] }
end
|
#each_title ⇒ Object
385
386
387
|
# File 'lib/weft/coding.rb', line 385
def each_title()
titles.each { | title | yield title, self[ @titles[title] ] }
end
|
#set(docid, fragset) ⇒ Object
365
366
367
368
369
370
|
# File 'lib/weft/coding.rb', line 365
def set(docid, fragset)
super(docid, fragset)
if fragset[0] and fragset[0].respond_to?(:doctitle)
@titles[fragset[0].doctitle] = fragset[0].docid
end
end
|
#sets ⇒ Object
389
390
391
392
|
# File 'lib/weft/coding.rb', line 389
def sets
docids = titles.map { | t | @titles[t] }
values_at( *docids )
end
|
#titles ⇒ Object
381
382
383
|
# File 'lib/weft/coding.rb', line 381
def titles()
@titles.keys.sort
end
|
#to_codingtable ⇒ Object
398
399
400
401
402
403
404
|
# File 'lib/weft/coding.rb', line 398
def to_codingtable()
ct = CodingTable.new
each do | docid, codeset |
ct[docid] = QDA::CodeSet[ *codeset.map { | frag | frag.to_code } ]
end
return ct
end
|