Show
Ignore:
Timestamp:
07/08/08 07:25:54 (5 months ago)
Author:
deveiant
Message:

Checkpoint commit

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/wordnet/lexicon.rb

    r79 r86  
    3131 
    3232require 'rbconfig' 
     33require 'pathname' 
    3334require 'bdb' 
    3435require 'sync' 
     
    6566    # The path to the WordNet BerkeleyDB Env. It lives in the directory that 
    6667    # this module is in. 
    67     DefaultDbEnv = File::join( Config::CONFIG['datadir'], "ruby-wordnet" ) 
     68    DEFAULT_DB_ENV = File::join( Config::CONFIG['datadir'], "ruby-wordnet" ) 
    6869 
    6970    # Options for the creation of the Env object 
    70     EnvOptions = { 
     71    ENV_OPTIONS = { 
    7172        :set_timeout    => 50, 
    7273        :set_lk_detect  => 1, 
    7374        :set_verbose    => false, 
     75        :set_lk_max     => 3000, 
    7476    } 
    7577 
    7678    # Flags for the creation of the Env object (read-write and read-only) 
    77     EnvFlagsRW = BDB::CREATE|BDB::INIT_TRANSACTION|BDB::RECOVER|BDB::INIT_MPOOL 
    78     EnvFlagsRO = BDB::INIT_MPOOL 
    79  
    80     # Table names (actually database names in BerkeleyDB) 
    81     TableNames = { 
    82         :index => "index", 
    83         :data => "data", 
    84         :morph => "morph", 
    85     } 
    86  
     79    ENV_FLAGS_RW = BDB::CREATE|BDB::INIT_TRANSACTION|BDB::RECOVER|BDB::INIT_MPOOL 
     80    ENV_FLAGS_RO = BDB::INIT_MPOOL 
    8781 
    8882 
     
    9589    ### opened with the specified +mode+, which can either be a numeric  
    9690    ### octal mode (e.g., 0444) or one of (:readonly, :readwrite). 
    97     def initialize( dbenv=DefaultDbEnv, mode=:readonly ) 
    98         raise ArgumentError, "Cannot find data directory '#{dbenv}'" unless 
    99             File::directory?( dbenv ) 
    100  
     91    def initialize( dbenv=DEFAULT_DB_ENV, mode=:readonly ) 
    10192        @mode = normalize_mode( mode ) 
    102         debug_msg "Mode is: %04o" % [ mode ] if $DEBUG 
     93        debug_msg "Mode is: %04o" % [ mode ] 
     94 
     95        envflags = 0 
     96        dbflags  = 0 
    10397 
    10498        unless self.readonly? 
    10599            debug_msg "Using read/write flags" 
    106             envflags = EnvFlagsRW 
     100            envflags = ENV_FLAGS_RW 
    107101            dbflags = BDB::CREATE 
    108102        else 
    109103            debug_msg "Using readonly flags" 
    110             envflags = EnvFlagsRO 
     104            envflags = ENV_FLAGS_RO 
    111105            dbflags = 0 
    112106        end 
     
    116110 
    117111        begin 
    118             @env = BDB::Env::new( dbenv, envflags, EnvOptions ) 
     112            @env = BDB::Env.new( dbenv, envflags, ENV_OPTIONS ) 
    119113            @index_db = @env.open_db( BDB::BTREE, "index", nil, dbflags, @mode ) 
    120114            @data_db = @env.open_db( BDB::BTREE, "data", nil, dbflags, @mode ) 
     
    194188        wordkey = self.make_word_key( word, part_of_speech ) 
    195189        return nil unless @index_db.key?( wordkey ) 
    196         @index_db[ wordkey ].split( WordNet::SubDelimRe ).length 
     190        @index_db[ wordkey ].split( WordNet::SUB_DELIM_RE ).length 
    197191    end 
    198192 
     
    221215        # Make synset keys from the entry, narrowing it to just the sense 
    222216        # requested if one was specified. 
    223         synkeys = entry.split( SubDelimRe ).collect {|off| "#{off}%#{pos}" } 
     217        synkeys = entry.split( SUB_DELIM_RE ).collect {|off| "#{off}%#{pos}" } 
    224218        if sense 
    225219            return lookup_synsets_by_key( synkeys[sense - 1] ) 
     
    321315                    # synset, add it 
    322316                    if indexdb.key?( word ) 
    323                         indexdb[ word ] << SubDelim << synset.offset unless 
     317                        indexdb[ word ] << SUB_DELIM << synset.offset unless 
    324318                            indexdb[ word ].include?( synset.offset ) 
    325319                    else 
     
    355349                    if indexdb.key?( word ) 
    356350                        offsets = indexdb[ word ]. 
    357                             split( SubDelimRe ). 
     351                            split( SUB_DELIM_RE ). 
    358352                            reject {|offset| offset == synset.offset} 
    359353 
    360354                        unless offsets.empty? 
    361                             index_db[ word ] = newoffsets.join( SubDelim ) 
     355                            index_db[ word ] = newoffsets.join( SUB_DELIM ) 
    362356                        else 
    363357                            index_db.delete( word ) 
     
    389383        return WordNet::Noun if original.nil? 
    390384        osym = original.to_s.intern 
    391         return WordNet::SyntacticCategories[ osym ] if 
    392             WordNet::SyntacticCategories.key?( osym ) 
    393         return original if SyntacticSymbols.key?( original ) 
     385        return WordNet::SYNTACTIC_CATEGORIES[ osym ] if 
     386            WordNet::SYNTACTIC_CATEGORIES.key?( osym ) 
     387        return original if SYNTACTIC_SYMBOLS.key?( original ) 
    394388        return nil 
    395389    end