Class: CRFPP::Feature

Inherits:
Struct
  • Object
show all
Defined in:
lib/crfpp/feature.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = Macro.new, type = :U, id = nil) ⇒ Feature

Returns a new instance of Feature.



15
16
17
# File 'lib/crfpp/feature.rb', line 15

def initialize(content = Macro.new, type = :U, id = nil)
  super
end

Instance Attribute Details

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



3
4
5
# File 'lib/crfpp/feature.rb', line 3

def content
  @content
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



3
4
5
# File 'lib/crfpp/feature.rb', line 3

def id
  @id
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/crfpp/feature.rb', line 3

def type
  @type
end

Class Method Details

.parse(string) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/crfpp/feature.rb', line 6

def parse(string)
  if string =~ /^([UB])(\d*):(.+)\s*$/
    Feature.new($3, $1.to_sym, $2)
  else
    string
  end
end

Instance Method Details

#identifier(base = id) ⇒ Object



19
20
21
# File 'lib/crfpp/feature.rb', line 19

def identifier(base = id)
  base.is_a?(Numeric) ? ('%02d' % base) : base
end

#to_s(number = id) ⇒ Object



23
24
25
# File 'lib/crfpp/feature.rb', line 23

def to_s(number = id)
  [type.to_s.upcase, identifier(number), ':', content].compact.join
end