wordnet 0.0.5 → 1.0.0.pre.126

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gemtest +0 -0
  2. data/History.rdoc +5 -0
  3. data/LICENSE +9 -9
  4. data/Manifest.txt +39 -0
  5. data/README.rdoc +60 -0
  6. data/Rakefile +47 -267
  7. data/TODO +9 -0
  8. data/WordNet30-license.txt +31 -0
  9. data/examples/add-laced-boots.rb +35 -0
  10. data/examples/clothes-with-collars.rb +42 -0
  11. data/examples/clothesWithTongues.rb +0 -0
  12. data/examples/domainTree.rb +0 -0
  13. data/examples/memberTree.rb +0 -0
  14. data/lib/wordnet/constants.rb +259 -296
  15. data/lib/wordnet/lexicallink.rb +34 -0
  16. data/lib/wordnet/lexicon.rb +158 -386
  17. data/lib/wordnet/mixins.rb +62 -0
  18. data/lib/wordnet/model.rb +78 -0
  19. data/lib/wordnet/morph.rb +25 -0
  20. data/lib/wordnet/semanticlink.rb +52 -0
  21. data/lib/wordnet/sense.rb +55 -0
  22. data/lib/wordnet/sumoterm.rb +21 -0
  23. data/lib/wordnet/synset.rb +404 -859
  24. data/lib/wordnet/utils.rb +126 -0
  25. data/lib/wordnet/word.rb +119 -0
  26. data/lib/wordnet.rb +113 -76
  27. data/spec/lib/helpers.rb +102 -133
  28. data/spec/linguawordnet.tests.rb +38 -0
  29. data/spec/wordnet/lexicon_spec.rb +96 -186
  30. data/spec/wordnet/model_spec.rb +59 -0
  31. data/spec/wordnet/semanticlink_spec.rb +42 -0
  32. data/spec/wordnet/synset_spec.rb +27 -256
  33. data/spec/wordnet/word_spec.rb +58 -0
  34. data/spec/wordnet_spec.rb +52 -0
  35. data.tar.gz.sig +0 -0
  36. metadata +227 -188
  37. metadata.gz.sig +0 -0
  38. data/ChangeLog +0 -720
  39. data/README +0 -93
  40. data/Rakefile.local +0 -46
  41. data/convertdb.rb +0 -417
  42. data/examples/addLacedBoots.rb +0 -27
  43. data/examples/clothesWithCollars.rb +0 -36
  44. data/rake/dependencies.rb +0 -76
  45. data/rake/helpers.rb +0 -384
  46. data/rake/manual.rb +0 -755
  47. data/rake/packaging.rb +0 -112
  48. data/rake/publishing.rb +0 -303
  49. data/rake/rdoc.rb +0 -35
  50. data/rake/style.rb +0 -62
  51. data/rake/svn.rb +0 -469
  52. data/rake/testing.rb +0 -192
  53. data/rake/verifytask.rb +0 -64
  54. data/utils.rb +0 -838
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'logger'
4
+ require 'erb'
5
+
6
+ require 'wordnet' unless defined?( WordNet )
7
+
8
+
9
+ module WordNet
10
+
11
+ # A alternate formatter for Logger instances.
12
+ # @private
13
+ class LogFormatter < Logger::Formatter
14
+
15
+ # The format to output unless debugging is turned on
16
+ DEFAULT_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"
17
+
18
+ # The format to output if debugging is turned on
19
+ DEFAULT_DEBUG_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"
20
+
21
+
22
+ ### Initialize the formatter with a reference to the logger so it can check for log level.
23
+ def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
24
+ @logger = logger
25
+ @format = format
26
+ @debug_format = debug
27
+
28
+ super()
29
+ end
30
+
31
+ ######
32
+ public
33
+ ######
34
+
35
+ # The Logger object associated with the formatter
36
+ attr_accessor :logger
37
+
38
+ # The logging format string
39
+ attr_accessor :format
40
+
41
+ # The logging format string that's used when outputting in debug mode
42
+ attr_accessor :debug_format
43
+
44
+
45
+ ### Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or
46
+ ### using FORMAT if it's anything less verbose.
47
+ def call( severity, time, progname, msg )
48
+ args = [
49
+ time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
50
+ time.usec, # %2$d
51
+ Process.pid, # %3$d
52
+ Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
53
+ severity, # %5$s
54
+ progname, # %6$s
55
+ msg # %7$s
56
+ ]
57
+
58
+ if @logger.level == Logger::DEBUG
59
+ return self.debug_format % args
60
+ else
61
+ return self.format % args
62
+ end
63
+ end
64
+ end # class LogFormatter
65
+
66
+
67
+ # An alternate formatter for Logger instances that outputs +div+ HTML
68
+ # fragments.
69
+ # @private
70
+ class HtmlLogFormatter < Logger::Formatter
71
+ include ERB::Util # for html_escape()
72
+
73
+ # The default HTML fragment that'll be used as the template for each log message.
74
+ HTML_LOG_FORMAT = %q{
75
+ <div class="log-message %5$s">
76
+ <span class="log-time">%1$s.%2$06d</span>
77
+ [
78
+ <span class="log-pid">%3$d</span>
79
+ /
80
+ <span class="log-tid">%4$s</span>
81
+ ]
82
+ <span class="log-level">%5$s</span>
83
+ :
84
+ <span class="log-name">%6$s</span>
85
+ <span class="log-message-text">%7$s</span>
86
+ </div>
87
+ }
88
+
89
+ ### Override the logging formats with ones that generate HTML fragments
90
+ def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
91
+ @logger = logger
92
+ @format = format
93
+ super()
94
+ end
95
+
96
+
97
+ ######
98
+ public
99
+ ######
100
+
101
+ # The HTML fragment that will be used as a format() string for the log
102
+ attr_accessor :format
103
+
104
+
105
+ ### Return a log message composed out of the arguments formatted using the
106
+ ### formatter's format string
107
+ def call( severity, time, progname, msg )
108
+ args = [
109
+ time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
110
+ time.usec, # %2$d
111
+ Process.pid, # %3$d
112
+ Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
113
+ severity.downcase, # %5$s
114
+ progname, # %6$s
115
+ html_escape( msg ).gsub(/\n/, '<br />') # %7$s
116
+ ]
117
+
118
+ return self.format % args
119
+ end
120
+
121
+ end # class HtmlLogFormatter
122
+
123
+ end # module WordNet
124
+
125
+ # vim: set nosta noet ts=4 sw=4:
126
+
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'wordnet' unless defined?( WordNet )
4
+ require 'wordnet/mixins'
5
+ require 'wordnet/model'
6
+
7
+ # WordNet word model class
8
+ class WordNet::Word < WordNet::Model( :words )
9
+ include WordNet::Constants
10
+
11
+ # Table "public.words"
12
+ # Column | Type | Modifiers
13
+ # --------+-----------------------+--------------------
14
+ # wordid | integer | not null default 0
15
+ # lemma | character varying(80) | not null
16
+ # Indexes:
17
+ # "pk_words" PRIMARY KEY, btree (wordid)
18
+ # "unq_words_lemma" UNIQUE, btree (lemma)
19
+ # Referenced by:
20
+ # TABLE "adjpositions" CONSTRAINT "fk_adjpositions_wordid"
21
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
22
+ # TABLE "bncconvtasks" CONSTRAINT "fk_bncconvtasks_wordid"
23
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
24
+ # TABLE "bncimaginfs" CONSTRAINT "fk_bncimaginfs_wordid"
25
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
26
+ # TABLE "bncs" CONSTRAINT "fk_bncs_wordid"
27
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
28
+ # TABLE "bncspwrs" CONSTRAINT "fk_bncspwrs_wordid"
29
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
30
+ # TABLE "casedwords" CONSTRAINT "fk_casedwords_wordid"
31
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
32
+ # TABLE "lexlinks" CONSTRAINT "fk_lexlinks_word1id"
33
+ # FOREIGN KEY (word1id) REFERENCES words(wordid)
34
+ # TABLE "lexlinks" CONSTRAINT "fk_lexlinks_word2id"
35
+ # FOREIGN KEY (word2id) REFERENCES words(wordid)
36
+ # TABLE "morphmaps" CONSTRAINT "fk_morphmaps_wordid"
37
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
38
+ # TABLE "sensemaps2021" CONSTRAINT "fk_sensemaps2021_wordid"
39
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
40
+ # TABLE "sensemaps2130" CONSTRAINT "fk_sensemaps2130_wordid"
41
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
42
+ # TABLE "senses20" CONSTRAINT "fk_senses20_wordid"
43
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
44
+ # TABLE "senses21" CONSTRAINT "fk_senses21_wordid"
45
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
46
+ # TABLE "senses" CONSTRAINT "fk_senses_wordid"
47
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
48
+ # TABLE "vframemaps" CONSTRAINT "fk_vframemaps_wordid"
49
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
50
+ # TABLE "vframesentencemaps" CONSTRAINT "fk_vframesentencemaps_wordid"
51
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
52
+ # TABLE "vnclassmembers" CONSTRAINT "fk_vnclassmembers_wordid"
53
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
54
+ # TABLE "vnframemaps" CONSTRAINT "fk_vnframemaps_wordid"
55
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
56
+ # TABLE "vnrolemaps" CONSTRAINT "fk_vnrolemaps_wordid"
57
+ # FOREIGN KEY (wordid) REFERENCES words(wordid)
58
+
59
+
60
+ set_primary_key :wordid
61
+
62
+ ##
63
+ # The WordNet::Sense objects that relate the word with its Synsets
64
+ one_to_many :senses,
65
+ :key => :wordid,
66
+ :primary_key => :wordid
67
+
68
+ ##
69
+ # The WordNet::Synsets related to the word via its senses
70
+ many_to_many :synsets,
71
+ :join_table => :senses,
72
+ :left_key => :wordid,
73
+ :right_key => :synsetid
74
+
75
+ ##
76
+ # The WordNet::Morphs related to the word
77
+ many_to_many :morphs,
78
+ :join_table => :morphmaps,
79
+ :left_key => :wordid,
80
+ :right_key => :morphid
81
+
82
+
83
+ ### Return the stringified word; alias for #lemma.
84
+ def to_s
85
+ return self.lemma
86
+ end
87
+
88
+
89
+ ### Return a dataset for all of the Word's Synsets that are nouns.
90
+ def nouns
91
+ return synsets_dataset.nouns
92
+ end
93
+
94
+
95
+ ### Return a dataset for all of the Word's Synsets that are verbs.
96
+ def verbs
97
+ return synsets_dataset.verbs
98
+ end
99
+
100
+
101
+ ### Return a dataset for all of the Word's Synsets that are adjectives.
102
+ def adjectives
103
+ return synsets_dataset.adjectives
104
+ end
105
+
106
+
107
+ ### Return a dataset for all of the Word's Synsets that are adverbs.
108
+ def adverbs
109
+ return synsets_dataset.adverbs
110
+ end
111
+
112
+
113
+ ### Return a dataset for all of the Word's Synsets that are adjective satellites.
114
+ def adjective_satellites
115
+ return synsets_dataset.adjective_satellites
116
+ end
117
+
118
+ end # class WordNet::Word
119
+
data/lib/wordnet.rb CHANGED
@@ -1,87 +1,124 @@
1
- #
2
- # WordNet - A Ruby interface to the WordNet lexical database
3
- #
4
- # == Synopsis
5
- #
6
- # require "WordNet"
7
- #
8
- # # Create a new lexicon object
9
- # lex = WordNet::Lexicon::new
10
- #
11
- # # Look up the synsets for "language" and "computer program"
12
- # languageSynset = lex.lookup_synsets( "language", WordNet::Noun, 3 )
13
- # programSynset = lex.lookup_synsets( "program", WordNet::Noun, 3 )
14
- #
15
- # # Create a new synset for programming languages, set its gloss, link it to its
16
- # # hypernym and holonym, and save everything to the database.
17
- # progLangSynset = lex.create_synset( "programming language", WordNet::Noun )
18
- # progLangSynset.gloss = "a system of human-readable symbols and words "\
19
- # "for encoding instructions for a computer"
20
- # progLangSynset.hypernyms += languageSynset
21
- # languageSynset.hyponyms += progLangSynset
22
- # progLangSynset.holonyms += programSynset
23
- # programSynset.stuff_meronyms += progLangSynset
24
- # [ progLangSynset, programSynset, languageSynset ].each do |synset|
25
- # synset.store
26
- # end
27
- #
28
- # # Create a new synset for Ruby, link it, and save it
29
- # rubySynset = lex.create_synset( "Ruby", Wordnet::Noun )
30
- # rubySynset.gloss = "an interpreted scripting language for quick and easy object-oriented programming"
31
- # rubySynset.hypernyms += languageSyn ; languageSynset.hyponyms += rubySyn
32
- # rubySynset.write ; languageSynset.write
33
- #
34
- # == Description
35
- #
36
- # This is a Ruby interface to the WordNet lexical database. It's mostly a port
37
- # of Dan Brian's Lingua::Wordnet Perl module, modified a bit to be more
38
- # Ruby-ish.
39
- #
40
- # == Author
41
- #
42
- # The Lingua::Wordnet module by Dan Brian, on which this code is based, falls under
43
- # the following license:
44
- #
45
- # Copyright 1999,2000,2001 by Dan Brian.
46
- #
47
- # This program is free software; you can redistribute it and/or modify
48
- # it under the same terms as Perl itself.
49
- #
50
- # Written by Michael Granger <ged@FaerieMUD.org>
51
- #
52
- # Copyright (c) 2002,2003,2005 The FaerieMUD Consortium. All rights reserved.
53
- #
54
- # This module is free software. You may use, modify, and/or redistribute this
55
- # software under the terms of the Perl Artistic License. (See
56
- # http://language.perl.com/misc/Artistic.html)
57
- #
58
- # == Version
59
- #
60
- # $Id: wordnet.rb 90 2008-07-09 23:02:53Z deveiant $
61
- #
62
-
63
- # Try to provide underbarred alternatives for camelCased methods. Requires the
64
- # 'CrossCase' module.
65
- begin
66
- require 'crosscase'
67
- rescue LoadError
68
- end
69
-
70
- ### The main namespace for WordNet classes
71
- module WordNet
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
72
3
 
73
- # Revision tag
74
- SvnRev = %q$Rev: 90 $
4
+ require 'logger'
5
+ require 'sequel'
75
6
 
76
- # Id tag
77
- SvnId = %q$Id: wordnet.rb 90 2008-07-09 23:02:53Z deveiant $
7
+ # This is a Ruby interface to the WordNet® lexical database. It uses the WordNet-SQL
8
+ # project's databases instead of reading from the canonical flatfiles for speed and
9
+ # easy modification.
10
+ module WordNet
78
11
 
79
12
  # Release version
80
- VERSION = '0.0.5'
13
+ VERSION = '1.0.0'
14
+
15
+ # VCS revision
16
+ REVISION = %q$Revision: $
17
+
18
+ # Abort if not >=1.9.2
19
+ vvec = lambda {|version| version.split('.').collect {|v| v.to_i }.pack('N*') }
20
+ abort "This version of WordNet requires Ruby 1.9.2 or greater." unless
21
+ vvec[RUBY_VERSION] >= vvec['1.9.2']
22
+
23
+
24
+ ### Lexicon exception - something has gone wrong in the internals of the
25
+ ### lexicon.
26
+ class LexiconError < StandardError ; end
27
+
28
+ ### Lookup error - the object being looked up either doesn't exist or is
29
+ ### malformed
30
+ class LookupError < StandardError ; end
31
+
81
32
 
82
33
  require 'wordnet/constants'
34
+ include WordNet::Constants
35
+ require 'wordnet/utils'
36
+
37
+ #
38
+ # Logging
39
+ #
40
+
41
+ @default_logger = Logger.new( $stderr )
42
+ @default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
43
+
44
+ @default_log_formatter = WordNet::LogFormatter.new( @default_logger )
45
+ @default_logger.formatter = @default_log_formatter
46
+
47
+ @logger = @default_logger
48
+
49
+ class << self
50
+ # @return [Logger::Formatter] the log formatter that will be used when the logging
51
+ # subsystem is reset
52
+ attr_accessor :default_log_formatter
53
+
54
+ # @return [Logger] the logger that will be used when the logging subsystem is reset
55
+ attr_accessor :default_logger
56
+
57
+ # @return [Logger] the logger that's currently in effect
58
+ attr_accessor :logger
59
+ alias_method :log, :logger
60
+ alias_method :log=, :logger=
61
+ end
62
+
63
+
64
+ ### Reset the global logger object to the default
65
+ ### @return [void]
66
+ def self::reset_logger
67
+ self.logger = self.default_logger
68
+ self.logger.level = Logger::WARN
69
+ self.logger.formatter = self.default_log_formatter
70
+ end
71
+
72
+
73
+ ### Returns +true+ if the global logger has not been set to something other than
74
+ ### the default one.
75
+ def self::using_default_logger?
76
+ return self.logger == self.default_logger
77
+ end
78
+
79
+
80
+ ### Get the WordNet version.
81
+ ### @return [String] the library's version
82
+ def self::version_string( include_buildnum=false )
83
+ vstring = "%s %s" % [ self.name, VERSION ]
84
+ vstring << " (build %s)" % [ REVISION[/: ([[:xdigit:]]+)/, 1] || '0' ] if include_buildnum
85
+ return vstring
86
+ end
87
+
88
+
83
89
  require 'wordnet/lexicon'
90
+
91
+ require 'wordnet/model'
92
+ require 'wordnet/sense'
84
93
  require 'wordnet/synset'
94
+ require 'wordnet/semanticlink'
95
+ require 'wordnet/lexicallink'
96
+ require 'wordnet/word'
97
+ require 'wordnet/morph'
98
+ require 'wordnet/sumoterm'
99
+
100
+ #
101
+ # Backward-compatibility stuff
102
+ #
103
+
104
+ # :section: Backward-compatibility
105
+
106
+ # Backward-compatibility constant
107
+ Noun = :n
108
+
109
+ # Backward-compatibility constant
110
+ Verb = :v
111
+
112
+ # Backward-compatibility constant
113
+ Adjective = :a
114
+
115
+ # Backward-compatibility constant
116
+ Adverb = :r
117
+
118
+ # Backward-compatibility constant
119
+ Other = :s
120
+
121
+
85
122
 
86
123
  end # module WordNet
87
124
 
data/spec/lib/helpers.rb CHANGED
@@ -1,155 +1,124 @@
1
1
  #!/usr/bin/ruby
2
+ # coding: utf-8
2
3
 
3
- begin
4
- require 'wordnet'
5
- rescue LoadError
6
- unless Object.const_defined?( :Gem )
7
- require 'rubygems'
8
- retry
9
- end
10
- raise
11
- end
4
+ BEGIN {
5
+ require 'pathname'
6
+ basedir = Pathname.new( __FILE__ ).dirname.parent
7
+
8
+ libdir = basedir + "lib"
9
+
10
+ $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
11
+ $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
12
+ }
13
+
14
+ require 'rspec'
15
+ require 'wordnet'
12
16
 
17
+
18
+ ### RSpec helper functions.
13
19
  module WordNet::SpecHelpers
14
20
 
21
+ # A logger that logs to an array.
22
+ class ArrayLogger
23
+ ### Create a new ArrayLogger that will append content to +array+.
24
+ def initialize( array )
25
+ @array = array
26
+ end
27
+
28
+ ### Write the specified +message+ to the array.
29
+ def write( message )
30
+ @array << message
31
+ end
32
+
33
+ ### No-op -- this is here just so Logger doesn't complain
34
+ def close; end
35
+
36
+ end # class ArrayLogger
37
+
38
+
39
+ unless defined?( LEVEL )
40
+ LEVEL = {
41
+ :debug => Logger::DEBUG,
42
+ :info => Logger::INFO,
43
+ :warn => Logger::WARN,
44
+ :error => Logger::ERROR,
45
+ :fatal => Logger::FATAL,
46
+ }
47
+ end
48
+
49
+
15
50
  ###############
16
51
  module_function
17
52
  ###############
18
53
 
19
- ### Create a temporary working directory and return
20
- ### a Pathname object for it.
21
- def make_tempdir
22
- dirname = "%s.%d.%0.4f" % [
23
- 'wordnet_spec',
24
- Process.pid,
25
- (Time.now.to_f % 3600),
26
- ]
27
- tempdir = Pathname.new( Dir.tmpdir ) + dirname
28
- tempdir.mkpath
29
-
30
- return tempdir
54
+ ### Make an easily-comparable version vector out of +ver+ and return it.
55
+ def vvec( ver )
56
+ return ver.split('.').collect {|char| char.to_i }.pack('N*')
31
57
  end
32
-
33
- end
34
58
 
35
- # Override the badly-formatted output of the RSpec HTML formatter
36
- require 'spec/runner/formatter/html_formatter'
37
59
 
38
- class Spec::Runner::Formatter::HtmlFormatter
39
- def example_failed( example, counter, failure )
40
- failure_style = failure.pending_fixed? ? 'pending_fixed' : 'failed'
41
-
42
- unless @header_red
43
- @output.puts " <script type=\"text/javascript\">makeRed('rspec-header');</script>"
44
- @header_red = true
45
- end
46
-
47
- unless @example_group_red
48
- css_class = 'example_group_%d' % [current_example_group_number]
49
- @output.puts " <script type=\"text/javascript\">makeRed('#{css_class}');</script>"
50
- @example_group_red = true
51
- end
52
-
53
- move_progress()
54
-
55
- @output.puts " <dd class=\"spec #{failure_style}\">",
56
- " <span class=\"failed_spec_name\">#{h(example.description)}</span>",
57
- " <div class=\"failure\" id=\"failure_#{counter}\">"
58
- if failure.exception
59
- backtrace = format_backtrace( failure.exception.backtrace )
60
- message = failure.exception.message
61
-
62
- @output.puts " <div class=\"message\"><code>#{h message}</code></div>",
63
- " <div class=\"backtrace\"><pre>#{backtrace}</pre></div>"
60
+ ### Reset the logging subsystem to its default state.
61
+ def reset_logging
62
+ WordNet.reset_logger
63
+ end
64
+
65
+
66
+ ### Alter the output of the default log formatter to be pretty in SpecMate output
67
+ def setup_logging( level=Logger::FATAL )
68
+
69
+ # Turn symbol-style level config into Logger's expected Fixnum level
70
+ if LEVEL.key?( level )
71
+ level = LEVEL[ level ]
64
72
  end
65
73
 
66
- if extra = extra_failure_content( failure )
67
- @output.puts( extra )
74
+ logger = Logger.new( $stderr )
75
+ WordNet.logger = logger
76
+ WordNet.logger.level = level
77
+
78
+ # Only do this when executing from a spec in TextMate
79
+ if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
80
+ Thread.current['logger-output'] = []
81
+ logdevice = ArrayLogger.new( Thread.current['logger-output'] )
82
+ WordNet.logger = Logger.new( logdevice )
83
+ # WordNet.logger.level = level
84
+ WordNet.logger.formatter = WordNet::HtmlLogFormatter.new( logger )
68
85
  end
69
-
70
- @output.puts " </div>",
71
- " </dd>"
72
- @output.flush
73
86
  end
74
87
 
75
88
 
76
- alias_method :default_global_styles, :global_styles
77
-
78
- def global_styles
79
- css = default_global_styles()
80
- css << %Q{
81
- /* Stuff added by #{__FILE__} */
82
-
83
- /* Overrides */
84
- #rspec-header {
85
- -webkit-box-shadow: #333 0 2px 5px;
86
- margin-bottom: 1em;
87
- }
88
-
89
- .example_group dt {
90
- -webkit-box-shadow: #333 0 2px 3px;
91
- }
92
-
93
- /* Style for log output */
94
- dd.log-message {
95
- background: #eee;
96
- padding: 0 2em;
97
- margin: 0.2em 1em;
98
- border-bottom: 1px dotted #999;
99
- border-top: 1px dotted #999;
100
- text-indent: -1em;
101
- }
102
-
103
- /* Parts of the message */
104
- dd.log-message .log-time {
105
- font-weight: bold;
106
- }
107
- dd.log-message .log-time:after {
108
- content: ": ";
109
- }
110
- dd.log-message .log-level {
111
- font-variant: small-caps;
112
- border: 1px solid #ccc;
113
- padding: 1px 2px;
114
- }
115
- dd.log-message .log-name {
116
- font-size: 1.2em;
117
- color: #1e51b2;
118
- }
119
- dd.log-message .log-name:before { content: "«"; }
120
- dd.log-message .log-name:after { content: "»"; }
121
-
122
- dd.log-message .log-message-text {
123
- padding-left: 4px;
124
- font-family: Monaco, "Andale Mono", "Vera Sans Mono", mono;
125
- }
126
-
127
-
128
- /* Distinguish levels */
129
- dd.log-message.debug { color: #666; }
130
- dd.log-message.info {}
131
-
132
- dd.log-message.warn,
133
- dd.log-message.error {
134
- background: #ff9;
135
- }
136
- dd.log-message.error .log-level,
137
- dd.log-message.error .log-message-text {
138
- color: #900;
139
- }
140
- dd.log-message.fatal {
141
- background: #900;
142
- color: white;
143
- font-weight: bold;
144
- border: 0;
145
- }
146
- dd.log-message.fatal .log-name {
147
- color: white;
148
- }
149
- }
150
-
151
- return css
89
+ ### Make a WordNet::Directory that will use the given +conn+ object as its
90
+ ### LDAP connection. Also pre-loads the schema object and fixtures some other
91
+ ### external data.
92
+ def get_fixtured_directory( conn )
93
+ LDAP::SSLConn.stub( :new ).and_return( @conn )
94
+ conn.stub( :root_dse ).and_return( nil )
95
+ directory = WordNet.directory( TEST_LDAPURI )
96
+ directory.stub( :schema ).and_return( SCHEMA )
97
+
98
+ return directory
99
+ end
100
+
101
+ end
102
+
103
+
104
+ ### Mock with Rspec
105
+ RSpec.configure do |c|
106
+ c.mock_with :rspec
107
+ c.include( WordNet::SpecHelpers )
108
+
109
+ c.treat_symbols_as_metadata_keys_with_true_values = true
110
+
111
+ if Gem::Specification.find_all_by_name( 'pg' ).empty?
112
+ c.filter_run_excluding( :requires_pg )
113
+ end
114
+
115
+ begin
116
+ uri = WordNet::Lexicon.default_db_uri
117
+ WordNet.log.info "Database tests will use: #{uri}"
118
+ rescue WordNet::LexiconError
119
+ c.filter_run_excluding( :requires_database )
152
120
  end
153
121
  end
154
122
 
123
+ # vim: set nosta noet ts=4 sw=4:
155
124