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/constants.rb

    r85 r86  
    88# E.g., 
    99# 
    10 #   WordNet::Adjective == WordNet::Constants::Adjective 
     10#   WordNet::Adjective == WordNet::Constants::Adjective 
    1111# 
    1212# If you do: 
    13 #   include WordNet::Constants 
     13#   include WordNet::Constants 
    1414# 
    1515# then: 
    16 #   Adjective == WordNet::Adjective 
     16#   Adjective == WordNet::Adjective 
    1717#  
    1818# == Synopsis 
    1919#  
    2020#   require 'wordnet' 
    21 #   include WordNet::Constants 
    22 # 
    23 #   lex = WordNet::Lexicon::new 
    24 #   origins = lex.lookup_synsets( "shoe", Noun ) 
     21#   include WordNet::Constants 
     22# 
     23#   lex = WordNet::Lexicon::new 
     24#   origins = lex.lookup_synsets( "shoe", Noun ) 
    2525#  
    2626# == Authors 
     
    3030# == Copyright 
    3131# 
    32 # Copyright (c) 2003, 2005 The FaerieMUD Consortium. All rights reserved. 
     32# Copyright (c) 2003-2008 The FaerieMUD Consortium. All rights reserved. 
    3333#  
    3434# This module is free software. You may use, modify, and/or redistribute this 
     
    4444module WordNet 
    4545 
    46     ### Constant-container module 
    47     module Constants 
    48  
    49         # Synset syntactic-category names -> indicators 
    50         # From: senseidx(5WN) 
    51         SyntacticCategories = { 
    52             :noun                => "n", 
    53             :verb                => "v", 
    54             :adjective           => "a", 
    55             :adverb              => "r", 
    56             :adjective_satellite => "s", 
    57         } 
    58         # Syntactic-category indicators -> names 
    59         SyntacticSymbols = SyntacticCategories.invert 
    60  
    61         # Map the categories into their own constants (eg., Noun) 
    62         SyntacticCategories.each {|sym,val| 
    63             cname = sym.to_s.capitalize 
    64             const_set( cname, val ) 
    65         } 
     46    ### Constant-container module 
     47    module Constants 
     48 
     49        # Synset syntactic-category names -> indicators 
     50        SYNTACTIC_CATEGORIES = { 
     51            :noun       => "n", 
     52            :verb       => "v", 
     53            :adjective  => "a", 
     54            :adverb     => "r", 
     55            :other      => "s", 
     56        } 
     57        # Syntactic-category indicators -> names 
     58        SYNTACTIC_SYMBOLS = SYNTACTIC_CATEGORIES.invert 
     59 
     60        # Map the categories into their own constants (eg., Noun) 
     61        SYNTACTIC_CATEGORIES.each do |sym,val| 
     62            cname = sym.to_s.capitalize 
     63            const_set( cname, val ) 
     64        end 
    6665 
    6766        # Information about pointer types is contained in the wninput(5WN) 
    6867        # manpage. 
    6968 
    70         # Synset pointer typenames -> indicators 
    71         PointerTypes = { 
    72             :antonym        => '!', 
    73             :hypernym       => '@', 
    74             :entailment     => '*', 
    75             :hyponym        => '~', 
    76             :meronym        => '%', 
    77             :holonym        => '#', 
    78             :cause          => '>', 
    79             :verb_group     => %{$}, 
    80             :similar_to     => '&', 
    81             :participle     => '<', 
    82             :pertainym      => '\\', 
    83             :attribute      => '=', 
    84             :derived_from   => '\\', 
    85             :see_also       => '^', 
    86             :derivation     => '+', 
    87             :domain         => ';', 
    88             :member         => '-', 
    89         } 
    90  
    91         # Synset pointer indicator -> typename 
    92         PointerSymbols = PointerTypes.invert 
    93  
    94         # Map the pointer types into their own symbols (eg., VerbGroup) 
    95         PointerTypes.each {|sym,val| 
    96             cname = sym.to_s[0,1].upcase + sym.to_s[1..-1] 
    97             const_set( cname, val ) 
    98         } 
     69        # Synset pointer typenames -> indicators 
     70        POINTER_TYPES = { 
     71            :antonym        => '!', 
     72            :hypernym       => '@', 
     73            :entailment     => '*', 
     74            :hyponym        => '~', 
     75            :meronym        => '%', 
     76            :holonym        => '#', 
     77            :cause          => '>', 
     78            :verb_group     => %{$}, 
     79            :similar_to     => '&', 
     80            :participle     => '<', 
     81            :pertainym      => '\\', 
     82            :attribute      => '=', 
     83            :derived_from   => '\\', 
     84            :see_also       => '^', 
     85            :derivation     => '+', 
     86            :domain         => ';', 
     87            :member         => '-', 
     88        } 
     89 
     90        # Synset pointer indicator -> typename 
     91        POINTER_SYMBOLS = POINTER_TYPES.invert 
     92 
     93        # Map the pointer types into their own symbols (eg., :verb_group => VerbGroup) 
     94        POINTER_TYPES.each do |sym,val| 
     95            cname = sym.to_s.gsub( /(?:^|_)(.)/ ) { $1.upcase } 
     96            const_set( cname, val ) 
     97        end 
    9998 
    10099        # Hypernym synset pointer types 
    101         HypernymTypes = { 
     100        HYPERNYM_TYPES = { 
    102101            nil             => '@', # Install non-subtype methods, too 
    103102            :instance       => '@i', 
     
    105104         
    106105        # Hypernym indicator -> type map 
    107         HypernymSymbols = HypernymTypes.invert 
     106        HYPERNYM_SYMBOLS = HYPERNYM_TYPES.invert 
    108107 
    109108        # Hyponym synset pointer types 
    110         HyponymTypes = { 
     109        HYPONYM_TYPES = { 
    111110            nil             => '~', # Install non-subtype methods, too 
    112111            :instance       => '~i', 
     
    114113         
    115114        # Hyponym indicator -> type map 
    116         HyponymSymbols = HyponymTypes.invert 
    117  
    118         # Meronym synset pointer types 
    119         MeronymTypes = { 
    120             :member         => '%m', 
    121             :stuff          => '%s', 
    122             :portion        => '%o', 
    123             :component      => '%p', 
    124             :feature        => '%f', 
    125             :phase          => '%a', 
    126             :place          => '%l', 
    127         } 
    128  
    129         # Meronym indicator -> type map 
    130         MeronymSymbols = MeronymTypes.invert 
    131  
    132         # Map the meronym types into their own constants (eg., MemberMeronym) 
    133         MeronymTypes.each {|sym,val| 
    134             cname = sym.to_s.capitalize + "Meronym" 
    135             const_set( cname, val ) 
    136         } 
    137  
    138         # Holonym synset pointer types 
    139         HolonymTypes = { 
    140             :member         => '#m', 
    141             :stuff          => '#s', 
    142             :portion        => '#o', 
    143             :component      => '#p', 
    144             :feature        => '#f', 
    145             :phase          => '#a', 
    146             :place          => '#l', 
    147         } 
    148  
    149         # Holonym indicator -> type map 
    150         HolonymSymbols = HolonymTypes.invert 
    151  
    152         # Map the holonym types into their own constants (eg., MemberHolonym) 
    153         HolonymTypes.each {|sym,val| 
    154             cname = sym.to_s.capitalize + "Holonym" 
    155             const_set( cname, val ) 
    156         } 
    157  
    158         # Domain synset pointer types 
    159         DomainTypes = { 
    160             :category       => ';c', 
    161             :region         => ';r', 
    162             :usage          => ';u', 
    163         } 
    164  
    165         # Domain indicator -> type map 
    166         DomainSymbols = DomainTypes.invert 
    167  
    168         # Map the domain types into their own constants (eg., CategoryDomain) 
    169         DomainTypes.each {|sym,val| 
    170             cname = sym.to_s.capitalize + "Domain" 
    171             const_set( cname, val ) 
    172         } 
    173  
    174         # Member synset pointer types 
    175         MemberTypes = { 
    176             :category       => '-c', 
    177             :region         => '-r', 
    178             :usage          => '-u', 
    179         } 
    180  
    181         # Member indicator -> type map 
    182         MemberSymbols = MemberTypes.invert 
    183  
    184         # Map the member types into their own constants (eg., CategoryMember) 
    185         MemberTypes.each {|sym,val| 
    186             cname = sym.to_s.capitalize + "Member" 
    187             const_set( cname, val ) 
    188         } 
    189  
    190         # Map of primary types to maps of their subtypes  
    191         PointerSubTypes = { 
    192             :hyponym    => HyponymTypes, 
    193             :hypernym   => HypernymTypes, 
    194             :meronym    => MeronymTypes, 
    195             :holonym    => HolonymTypes, 
    196             :member     => MemberTypes, 
    197             :domain     => DomainTypes, 
    198         } 
    199  
    200  
    201         # Record-part delimiter 
    202         Delim = '||' 
    203         DelimRe = Regexp::new( Regexp::quote(Delim) ) 
    204  
    205         # Record-subpart delimiter 
    206         SubDelim = '|' 
    207         SubDelimRe = Regexp::new( Regexp::quote(SubDelim) ) 
    208  
    209         # Lexicographer file index 
    210         Lexfiles = [ 
    211             "adj.all", 
    212             "adj.pert",          
    213             "adv.all",           
    214             "noun.Tops",         
    215             "noun.act",          
    216             "noun.animal",       
    217             "noun.artifact",         
    218             "noun.attribute",        
    219             "noun.body",         
    220             "noun.cognition",        
    221             "noun.communication",    
    222             "noun.event",        
    223             "noun.feeling",      
    224             "noun.food",         
    225             "noun.group",        
    226             "noun.location",         
    227             "noun.motive",       
    228             "noun.object",       
    229             "noun.person",       
    230             "noun.phenomenon",       
    231             "noun.plant",        
    232             "noun.possession",       
    233             "noun.process",      
    234             "noun.quantity",         
    235             "noun.relation",         
    236             "noun.shape",        
    237             "noun.state",        
    238             "noun.substance",        
    239             "noun.time",         
    240             "verb.body",         
    241             "verb.change",       
    242             "verb.cognition",        
    243             "verb.communication",    
    244             "verb.competition",      
    245             "verb.consumption",      
    246             "verb.contact",      
    247             "verb.creation",         
    248             "verb.emotion",      
    249             "verb.motion",       
    250             "verb.perception", 
    251             "verb.possession",       
    252             "verb.social",       
    253             "verb.stative",      
    254             "verb.weather",      
    255             "adj.ppl" 
    256         ] 
    257  
    258         # Verb sentences (?) -- used in building verb frames. 
    259         VerbSents = [ 
    260             "", 
    261             "Something ----s", 
    262             "Somebody ----s", 
    263             "It is ----ing", 
    264             "Something is ----ing PP", 
    265             "Something ----s something Adjective/Noun", 
    266             "Something ----s Adjective/Noun", 
    267             "Somebody ----s Adjective", 
    268             "Somebody ----s something", 
    269             "Somebody ----s somebody", 
    270             "Something ----s somebody", 
    271             "Something ----s something", 
    272             "Something ----s to somebody", 
    273             "Somebody ----s on something", 
    274             "Somebody ----s somebody something", 
    275             "Somebody ----s something to somebody", 
    276             "Somebody ----s something from somebody", 
    277             "Somebody ----s somebody with something", 
    278             "Somebody ----s somebody of something", 
    279             "Somebody ----s something on somebody", 
    280             "Somebody ----s somebody PP", 
    281             "Somebody ----s something PP", 
    282             "Somebody ----s PP", 
    283             "Somebody's (body part) ----s", 
    284             "Somebody ----s somebody to INFINITIVE", 
    285             "Somebody ----s somebody INFINITIVE", 
    286             "Somebody ----s that CLAUSE", 
    287             "Somebody ----s to somebody", 
    288             "Somebody ----s to INFINITIVE", 
    289             "Somebody ----s whether INFINITIVE", 
    290             "Somebody ----s somebody into V-ing something", 
    291             "Somebody ----s something with something", 
    292             "Somebody ----s INFINITIVE", 
    293             "Somebody ----s VERB-ing", 
    294             "It ----s that CLAUSE", 
    295             "Something ----s INFINITIVE" 
    296         ] 
    297  
    298  
    299     end # module Constants 
    300  
    301     # Make the constants available under the WordNet namespace, too. 
    302     include Constants 
     115        HYPONYM_SYMBOLS = HYPONYM_TYPES.invert 
     116 
     117        # Meronym synset pointer types 
     118        MERONYM_TYPES = { 
     119            :member         => '%m', 
     120            :stuff          => '%s', 
     121            :portion        => '%o', 
     122            :component      => '%p', 
     123            :feature        => '%f', 
     124            :phase          => '%a', 
     125            :place          => '%l', 
     126        } 
     127 
     128        # Meronym indicator -> type map 
     129        MERONYM_SYMBOLS = MERONYM_TYPES.invert 
     130 
     131        # Map the meronym types into their own constants (eg., MemberMeronym) 
     132        MERONYM_TYPES.each do |sym,val| 
     133            cname = sym.to_s.capitalize + "Meronym" 
     134            const_set( cname, val ) 
     135        end 
     136 
     137        # Holonym synset pointer types 
     138        HOLONYM_TYPES = { 
     139            :member         => '#m', 
     140            :stuff          => '#s', 
     141            :portion        => '#o', 
     142            :component      => '#p', 
     143            :feature        => '#f', 
     144            :phase          => '#a', 
     145            :place          => '#l', 
     146        } 
     147 
     148        # Holonym indicator -> type map 
     149        HOLONYM_SYMBOLS = HOLONYM_TYPES.invert 
     150 
     151        # Map the holonym types into their own constants (eg., MemberHolonym) 
     152        HOLONYM_TYPES.each do |sym,val| 
     153            cname = sym.to_s.capitalize + "Holonym" 
     154            const_set( cname, val ) 
     155        end 
     156 
     157        # Domain synset pointer types 
     158        DOMAIN_TYPES = { 
     159            :category       => ';c', 
     160            :region         => ';r', 
     161            :usage          => ';u', 
     162        } 
     163 
     164        # Domain indicator -> type map 
     165        DomainSymbols = DOMAIN_TYPES.invert 
     166 
     167        # Map the domain types into their own constants (eg., CategoryDomain) 
     168        DOMAIN_TYPES.each do |sym,val| 
     169            cname = sym.to_s.capitalize + "Domain" 
     170            const_set( cname, val ) 
     171        end 
     172 
     173        # Member synset pointer types 
     174        MEMBER_TYPES = { 
     175            :category       => '-c', 
     176            :region         => '-r', 
     177            :usage          => '-u', 
     178        } 
     179 
     180        # Member indicator -> type map 
     181        MEMBER_SYMBOLS = MEMBER_TYPES.invert 
     182 
     183        # Map the member types into their own constants (eg., CategoryMember) 
     184        MEMBER_TYPES.each do |sym,val| 
     185            cname = sym.to_s.capitalize + "Member" 
     186            const_set( cname, val ) 
     187        end 
     188 
     189        # Map of primary types to maps of their subtypes  
     190        POINTER_SUBTYPES = { 
     191            :hyponym    => HYPONYM_TYPES, 
     192            :hypernym   => HYPERNYM_TYPES, 
     193            :meronym    => MERONYM_TYPES, 
     194            :holonym    => HOLONYM_TYPES, 
     195            :member     => MEMBER_TYPES, 
     196            :domain     => DOMAIN_TYPES, 
     197        } 
     198 
     199 
     200        # Record-part delimiter 
     201        DELIM = '||' 
     202        DELIM_RE = Regexp::new( Regexp::quote(DELIM) ) 
     203 
     204        # Record-subpart delimiter 
     205        SUB_DELIM = '|' 
     206        SUB_DELIM_RE = Regexp::new( Regexp::quote(SUB_DELIM) ) 
     207 
     208        # Lexicographer file index -- from lexnames(5WN) 
     209        LEXFILES = [ 
     210            "adj.all", 
     211            "adj.pert",          
     212            "adv.all",           
     213            "noun.Tops",         
     214            "noun.act",          
     215            "noun.animal",       
     216            "noun.artifact",         
     217            "noun.attribute",        
     218            "noun.body",         
     219            "noun.cognition",        
     220            "noun.communication",    
     221            "noun.event",        
     222            "noun.feeling",      
     223            "noun.food",         
     224            "noun.group",        
     225            "noun.location",         
     226            "noun.motive",       
     227            "noun.object",       
     228            "noun.person",       
     229            "noun.phenomenon",       
     230            "noun.plant",        
     231            "noun.possession",       
     232            "noun.process",      
     233            "noun.quantity",         
     234            "noun.relation",         
     235            "noun.shape",        
     236            "noun.state",        
     237            "noun.substance",        
     238            "noun.time",         
     239            "verb.body",         
     240            "verb.change",       
     241            "verb.cognition",        
     242            "verb.communication",    
     243            "verb.competition",      
     244            "verb.consumption",      
     245            "verb.contact",      
     246            "verb.creation",         
     247            "verb.emotion",      
     248            "verb.motion",       
     249            "verb.perception", 
     250            "verb.possession",       
     251            "verb.social",       
     252            "verb.stative",      
     253            "verb.weather",      
     254            "adj.ppl" 
     255        ] 
     256 
     257        # Verb sentences (?) -- used in building verb frames. 
     258        VERB_SENTS = [ 
     259            "", 
     260            "Something ----s", 
     261            "Somebody ----s", 
     262            "It is ----ing", 
     263            "Something is ----ing PP", 
     264            "Something ----s something Adjective/Noun", 
     265            "Something ----s Adjective/Noun", 
     266            "Somebody ----s Adjective", 
     267            "Somebody ----s something", 
     268            "Somebody ----s somebody", 
     269            "Something ----s somebody", 
     270            "Something ----s something", 
     271            "Something ----s to somebody", 
     272            "Somebody ----s on something", 
     273            "Somebody ----s somebody something", 
     274            "Somebody ----s something to somebody", 
     275            "Somebody ----s something from somebody", 
     276            "Somebody ----s somebody with something", 
     277            "Somebody ----s somebody of something", 
     278            "Somebody ----s something on somebody", 
     279            "Somebody ----s somebody PP", 
     280            "Somebody ----s something PP", 
     281            "Somebody ----s PP", 
     282            "Somebody's (body part) ----s", 
     283            "Somebody ----s somebody to INFINITIVE", 
     284            "Somebody ----s somebody INFINITIVE", 
     285            "Somebody ----s that CLAUSE", 
     286            "Somebody ----s to somebody", 
     287            "Somebody ----s to INFINITIVE", 
     288            "Somebody ----s whether INFINITIVE", 
     289            "Somebody ----s somebody into V-ing something", 
     290            "Somebody ----s something with something", 
     291            "Somebody ----s INFINITIVE", 
     292            "Somebody ----s VERB-ing", 
     293            "It ----s that CLAUSE", 
     294            "Something ----s INFINITIVE" 
     295        ] 
     296 
     297 
     298    end # module Constants 
     299 
     300    # Make the constants available under the WordNet namespace, too. 
     301    include Constants 
    303302 
    304303end # module WordNet