Class: Tokenizer::Operation
- Inherits:
-
Object
- Object
- Tokenizer::Operation
show all
- Defined in:
- lib/rbbt/ner/rnorm/tokens.rb
Instance Method Summary
collapse
Constructor Details
#initialize(comparison) ⇒ Operation
Returns a new instance of Operation.
24
25
26
27
|
# File 'lib/rbbt/ner/rnorm/tokens.rb', line 24
def initialize(comparison)
@comparison = comparison
@ignore_case = Tokenizer::ignore_case
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &bloc) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/rbbt/ner/rnorm/tokens.rb', line 34
def method_missing(name, *args, &bloc)
@token = name.to_sym
value = args.first
@value = value
self
end
|
Instance Method Details
#eval(list1, list2) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rbbt/ner/rnorm/tokens.rb', line 41
def eval(list1, list2)
toks1 = list1.select{|p| p[1] == @token}.collect{|t| @ignore_case ? t[0].to_s.downcase : t[0].to_s}
toks2 = list2.select{|p| p[1] == @token}.collect{|t| @ignore_case ? t[0].to_s.downcase : t[0].to_s}
value = 0
case @comparison.to_s
when 'same'
if toks1 == toks2 && toks1.any?
value = @value
end
when 'diff'
if toks1 != toks2
value = @value
end
when 'common'
if toks1.to_set.intersection(toks2.to_set).length > 0
value = @value
end
when 'distinct'
if toks1.to_set.intersection(toks2.to_set).length == 0
value = @value
end
when 'miss'
missing = (toks1 - toks2)
if missing.length > 0
value = @value * missing.length
end
when 'extr'
extr = (toks2 - toks1)
if extr.length > 0
value = @value * extr.length
end
end
return value
end
|
#ignore_case(ignore = true) ⇒ Object
29
30
31
32
|
# File 'lib/rbbt/ner/rnorm/tokens.rb', line 29
def ignore_case(ignore = true)
@ignore_case = ignore
self
end
|