Changeset 103 for trunk/convertdb.rb

Show
Ignore:
Timestamp:
09/24/08 18:24:27 (3 months ago)
Author:
deveiant
Message:

Made the db converter look in more paths for the WordNet? dict files.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/convertdb.rb

    r102 r103  
    4444require 'optparse' 
    4545require 'fileutils' 
     46require 'uri' 
     47require 'net/http' 
    4648 
    4749 
     
    7981               Pathname.new( WordNet::Lexicon::DEFAULT_DB_ENV ).basename 
    8082 
     83    # Paths to search for WordNet dictionary files 
     84    WNDB_LOCAL_PATHS = [ 
     85        '/usr/local/WordNet-3.0/dict',      # Default install 
     86        '/usr/WordNet-3.0/dict',            # Default with --prefix=/usr 
     87        '/usr/local/share/WordNet',         # FreeBSD 
     88        './dict',                           # Extracted locally 
     89    ] 
     90 
     91    # URL to the latest database file archive 
     92    WNDB_TARBALL_URL = URI.parse( 'http://wordnet.princeton.edu/3.0/WordNet-3.0.tar.gz' ) 
     93 
    8194 
    8295    ### Create a new converter that will dump WordNet dictionary files into a BerkeleyDB  
     
    98111        exit unless /^y/i =~ prompt_with_default("Continue?", "y") 
    99112 
    100         # Open the database and check to be sure it's empty. Confirm overwrite if 
    101         # not. Checkpoint and set up logging proc if debugging. 
     113        # Confirm if we're going to clobber an existing database directory 
    102114        if @builddir.exist? && ( @builddir + 'data' ).exist? 
    103115            message ">>> Warning: Existing data in the Ruby-WordNet databases\n"\ 
     
    109121 
    110122        # Find the source data files 
    111         default = nil 
    112         wndirs = Pathname.glob( Pathname.getwd + 'WordNet-*' ) 
    113         localdict = Pathname.getwd + 'dict' 
    114         if !wndirs.empty? 
    115             default = wndirs.first + 'dict' 
    116         elsif localdict.exist? 
    117             default = localdict 
    118         else 
    119             default = '/usr/local/WordNet-3.0/dict' 
    120         end 
    121  
    122         message "Where can I find the WordNet data files?\n" 
    123         datadir = prompt_with_default( "Data directory", default ) 
    124         datadir = Pathname.new( datadir ) 
    125  
    126         abort( "Directory '#{datadir}' does not exist" ) unless datadir.exist? 
    127         abort( "'#{datadir}' is not a directory" ) unless datadir.directory? 
     123        datadir = find_data_files() 
    128124        testfile = datadir + "data.noun" 
    129         abort( "'#{datadir}' doesn't seem to contain the necessary files.") unless testfile.exist? 
     125        abort( "'#{datadir}' doesn't seem to contain the necessary files." ) unless testfile.exist? 
    130126 
    131127        # Open the lexicon readwrite into the temporary datadir 
     
    201197    end 
    202198 
    203  
    204     ####### 
    205     private 
    206     ####### 
    207199 
    208200    # Index entry patterns 
     
    375367    end 
    376368 
     369 
     370    ### Find the path to the WordNet dict directory with the files we're  
     371    ### going to parse in it. 
     372    def find_data_files 
     373        datadir = WNDB_LOCAL_PATHS.collect {|pn| Pathname.new(pn) }.find {|pn| pn.exist? } 
     374         
     375        unless datadir 
     376            message "Where can I find the WordNet data files?\n" 
     377            answer = prompt_with_default( "Data directory", WNDB_LOCAL_PATHS.first ) 
     378            datadir = Pathname.new( answer ) 
     379        end 
     380 
     381        abort( "Directory '#{datadir}' does not exist" ) unless datadir.exist? 
     382        abort( "'#{datadir}' is not a directory" ) unless datadir.directory? 
     383 
     384        return datadir 
     385    end 
     386     
    377387end # class WordNetConverter 
    378388