Class: TM::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/nysol/dictionary.rb

Overview

辞書クラス複数の単純エントリ、複合エントリから構成される

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Returns a new instance of Dictionary.



510
511
512
513
# File 'lib/nysol/dictionary.rb', line 510

def initialize
  @sEntries = Hash.new # 単純エントリ
  @cEntries = Hash.new # 複合エントリ
end

Instance Attribute Details

#cEntriesObject (readonly)

Returns the value of attribute cEntries.



508
509
510
# File 'lib/nysol/dictionary.rb', line 508

def cEntries
  @cEntries
end

#sEntriesObject (readonly)

Returns the value of attribute sEntries.



507
508
509
# File 'lib/nysol/dictionary.rb', line 507

def sEntries
  @sEntries
end

Instance Method Details

#find(entry) ⇒ Object

entryを辞書から検索し、辞書上のentryを返す。なければnilを返す。



517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/nysol/dictionary.rb', line 517

def find(entry)
  result=nil
  if entry != nil then
#if @sEntries[entry.to_s]!=nil then
#puts "sss=#{entry.to_s}, no=#{@sEntries[entry.to_s].iterNo}"
#end
    if entry.scFlag==0 then
      result=@sEntries[entry.to_s]
    else
      result=@cEntries[entry.to_s]
    end
  end
  return result
end

#findAll(chunk) ⇒ Object

chunk上の全entryを辞書から検索し、該当する辞書上の全entryを返す。



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/nysol/dictionary.rb', line 533

def findAll(chunk)
  result=[]
  # 単純エントリ辞書検索
  if dsEntry=find(chunk.sEntry) then 
    result << dsEntry

    # 複合エントリ辞書検索
    chunk.cEntries.each{|cEntry|
      if dcEntry=find(cEntry) then
        result << dsEntry
      end
    }
  end
  return result
end

#load(iFile) ⇒ Object

指定した辞書ファイルから評価表現を読み込む0:用言句,1:格助詞句,2:格助詞,3:極性,4:iterNo



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/nysol/dictionary.rb', line 551

def load(iFile)
  count=0
  Mcsv.new("i=" + iFile).each(true) {|nam,val|
    if not /\A#/=~ val[0] then # '#'から始まればコメントと考える(デバッグ目的で利用)
      #                     dPhrase,pPhrase,polarity
      dPhrase  = DeclinedPhrase.new(val[0])
      polarity = val[3].to_i
      iterNo   = val[4].to_i
      if val[1]==nil then
        entry = SimpleEntry.new(dPhrase, polarity, iterNo)
        @sEntries[entry.to_s] = entry
        count+=1
      else
        pPhrase = ParticlePhrase.new(val[1],val[2])
        entry = ComplexEntry.new(dPhrase, pPhrase, polarity, iterNo)
        @cEntries[entry.to_s] = entry
        count+=1
      end
    end
  }
  return count
end

#show(fp = STDERR) ⇒ Object



574
575
576
577
578
579
580
581
582
583
# File 'lib/nysol/dictionary.rb', line 574

def show(fp=STDERR)
  @sEntries.each{|key,entry|
    entry.show(fp)
    fp.puts ""
  }
  @cEntries.each{|key,entry|
    entry.show(fp)
    fp.puts ""
  }
end