Class: Excite::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/excite/crfparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, part_of_speech = nil) ⇒ Token

Returns a new instance of Token.



280
281
282
283
# File 'lib/excite/crfparser.rb', line 280

def initialize(str, part_of_speech=nil)
  @str = str
  @part_of_speech = part_of_speech
end

Instance Attribute Details

#idx_in_nodeObject (readonly)

Returns the value of attribute idx_in_node.



277
278
279
# File 'lib/excite/crfparser.rb', line 277

def idx_in_node
  @idx_in_node
end

#labelObject

Returns the value of attribute label.



278
279
280
# File 'lib/excite/crfparser.rb', line 278

def label
  @label
end

#nodeObject (readonly)

Returns the value of attribute node.



277
278
279
# File 'lib/excite/crfparser.rb', line 277

def node
  @node
end

#node_token_countObject (readonly)

Returns the value of attribute node_token_count.



277
278
279
# File 'lib/excite/crfparser.rb', line 277

def node_token_count
  @node_token_count
end

#part_of_speechObject (readonly)

Returns the value of attribute part_of_speech.



277
278
279
# File 'lib/excite/crfparser.rb', line 277

def part_of_speech
  @part_of_speech
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


303
304
305
# File 'lib/excite/crfparser.rb', line 303

def empty?
  raw.strip.blank?
end

#for_join(prev) ⇒ Object



311
312
313
314
315
316
317
318
319
# File 'lib/excite/crfparser.rb', line 311

def for_join(prev)
  if ['pp','ppc','ppr','pps','rrb', 'pos'].include?(part_of_speech)
    raw
  elsif prev && ['ppd','ppl','lrb'].include?(prev.part_of_speech)
    raw
  else
    " "+raw
  end
end

#is_in_node!(node, idx_in_node, node_token_count) ⇒ Object



285
286
287
288
289
# File 'lib/excite/crfparser.rb', line 285

def is_in_node!(node, idx_in_node, node_token_count)
  @node = node
  @idx_in_node = idx_in_node
  @node_token_count = node_token_count
end

#lcnpObject



299
300
301
# File 'lib/excite/crfparser.rb', line 299

def lcnp
  @lcnp ||= np == "EMPTY" ? np : np.downcase
end

#npObject



295
296
297
# File 'lib/excite/crfparser.rb', line 295

def np
  @np ||= CRFParser.strip_punct(@str)
end

#rawObject



291
292
293
# File 'lib/excite/crfparser.rb', line 291

def raw
  @str
end

#to_sObject



307
308
309
# File 'lib/excite/crfparser.rb', line 307

def to_s
  "{#{raw}}"
end