Compare commits

...

7 Commits

Author SHA1 Message Date
Louis Mullie 65dfc01e74 Fix little bug. 2012-07-25 02:42:46 -04:00
Louis Mullie d40c6326b8 Renamed doable to chainable. 2012-07-25 02:30:32 -04:00
Louis Mullie 21dd3bf2f7 Rename do() to chain. 2012-07-25 02:07:07 -04:00
Louis Mullie c6c59d7dbe No need for this ugly patch anymore. 2012-07-25 02:06:57 -04:00
Louis Mullie f50718e647 Add support for lower case builders. 2012-07-25 02:06:48 -04:00
Louis Mullie 0bbcea4a6d Add comment on beauty of code. 2012-07-25 02:06:32 -04:00
Louis Mullie e069fa9248 Rename do() to chain() for more intuitive syntax. 2012-07-25 02:06:21 -04:00
9 changed files with 24 additions and 42 deletions

View File

@ -96,10 +96,13 @@ module Treat::Config
return if Treat.core.syntax.sweetened
Treat.core.syntax.sweetened = true
Treat.core.entities.list.each do |type|
next if type == :Symbol
kname = cc(type).intern
kname = type.to_s.capitalize.intern
klass = Treat::Entities.const_get(kname)
Object.class_eval do
define_method(kname.to_s.downcase.intern) do |val, opts={}|
klass.build(val, opts)
end
# THIS WILL BE DEPRECATED IN 2.0
define_method(kname) do |val, opts={}|
klass.build(val, opts)
end
@ -109,6 +112,10 @@ module Treat::Config
Treat::Core.constants.each do |kname|
Object.class_eval do
klass = Treat::Core.const_get(kname)
define_method(kname.to_s.downcase.intern) do |*args|
klass.new(*args)
end
# THIS WILL BE DEPRECATED IN 2.0
define_method(kname) do |*args|
klass.new(*args)
end
@ -123,7 +130,6 @@ module Treat::Config
Treat.core.syntax.sweetened = false
Treat.core.entities.list.each do |type|
name = cc(type).intern
next if type == :Symbol
Object.class_eval { remove_method(name) }
end

View File

@ -1,6 +1,6 @@
# Implement support for the functions #do and #do_task.
module Treat::Entities::Abilities::Doable
module Treat::Entities::Abilities::Chainable
# Perform the supplied tasks on the entity.
def do(*tasks)
tasks.each do |task|
@ -26,6 +26,8 @@ module Treat::Entities::Abilities::Doable
self
end
alias :chain :do
# Perform an individual task on an entity
# given a worker and options to pass to it.
def do_task(task, worker, options, group = nil)

View File

@ -31,7 +31,7 @@ module Treat::Entities
extend Abilities::Buildable
# Implement support for #do.
include Abilities::Doable
include Abilities::Chainable
# Implement support for #frequency,
# #frequency_in_parent and #position_in_parent.
@ -98,7 +98,7 @@ module Treat::Entities
# or can't be parsed, raises an exception.
#
# Also catches the "empty" method call (e.g.
# Word('hello') or Word 'hello') as syntactic
# word 'hello' or word 'hello' as syntactic
# sugar for the #self.build method.
def method_missing(sym, *args, &block)
return self.build(*args) if sym == nil

View File

@ -117,9 +117,9 @@ module Treat::Workers::Group
m = ucc(cl(self)).dup
if m[-4..-1] == 'zers'
if type == :annotator
m[-5..-1] = m[-6] == 'l' ? '' : 'y'
else
m = m[0..-3]
m[-5..-1] = m[-6] == 'l' ? '' : 'y' # THIS
else # IS
m = m[0..-3] # UGLY!
end
n = m
elsif m[-4..-1] == 'iers'

View File

@ -1,29 +1,3 @@
patch = false
begin
# This whole mess is required to deal with
# the fact that the 'rbtagger' gem defines
# a top-level module called 'Word', which
# will clash with the top-level class 'Word'
# we define when syntactic sugar is enabled.
rescue TypeError
if Treat.core.syntax.sweetened
patch = true
# Unset the class Word for the duration
# of loading the tagger.
Object.const_unset(:Word); retry
else
raise Treat::Exception,
'Something went wrong due to a name clash with the "rbtagger" gem.' +
'Turn off syntactic sugar to resolve this problem.'
end
ensure
# Reset the class Word if using syntactic sugar.
if Treat.core.syntax.sweetened && patch
Object.const_set(:Word, Treat::Entities::Word)
end
end
Brill::Tagger.class_eval do
def tag_tokens(tokens)

View File

@ -19,8 +19,8 @@ ds = DataSet(p)
text = Paragraph("Welcome to the zoo! This is a text.")
text2 = Paragraph("Welcome here my friend. This is well, a text.")
text.do :segment, :tokenize
text2.do :segment, :tokenize
text.chain :segment, :tokenize
text2.chain :segment, :tokenize
ds1 = text.export(p)
ds2 = text2.export(p2)

View File

@ -9,7 +9,7 @@ describe Treat::Entities::Document do
it "returns a list of general topics the document belongs to" do
#doc = Treat::Entities::Document.new(
#Treat.paths.spec + 'samples/mathematicians/archimedes.abw').read(:abw)
#doc.do(:chunk, :segment, :tokenize)
#doc.chain(:chunk, :segment, :tokenize)
#puts doc.topics.inspect
end

View File

@ -334,7 +334,7 @@ describe Treat::Entities::Entity do
next if ser == :mongo # Fix this!
f = Treat.paths.spec + 'test.' + ser.to_s
s = Treat::Entities::Paragraph.new(@txt)
s.do(:segment, :tokenize)
s.chain(:segment, :tokenize)
s.serialize(ser, :file => f)
File.delete(f)
end
@ -361,7 +361,7 @@ describe Treat::Entities::Entity do
s.set :test_sym, :hello
s.set :test_bool, false
s.do(:segment, :tokenize)
s.chain(:segment, :tokenize)
s.serialize(ser, :file => f)

View File

@ -102,7 +102,7 @@ describe Treat::Entities::Word do
it "returns the TF*IDF score of the word" do
#c = Treat::Entities::Collection.build(
#Treat.paths.spec + 'samples/mathematicians')
#c.do(:chunk, :segment, :tokenize)
#c.chain(:chunk, :segment, :tokenize)
#c.words[30].tf_idf.should eql 0.2231
end
end