crfpp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,2 +1,35 @@
1
1
  CRFPP
2
2
  =====
3
+
4
+ CRFPP is a Ruby API for the [CRF++](http://crfpp.sourceforge.net/) library
5
+ for [Conditional Random Fields](http://en.wikipedia.org/wiki/Conditional_random_field).
6
+
7
+ Installation
8
+ ------------
9
+
10
+ You will need to install [CRF++](http://crfpp.sourceforge.net/) prior to
11
+ installing the CRFPP gem; simply download the sources, unpack them, and then
12
+ execute the following commands:
13
+
14
+ $ cd CRF++-0.54
15
+ $ make
16
+ $ [sudo] make install
17
+ $ [sudo] gem install crfpp
18
+
19
+ Alternatively, if you are using [homebrew](http://mxcl.github.com/homebrew/)
20
+ on OS X you may prefer to:
21
+
22
+ $ brew install crf++
23
+ $ gem install crfpp
24
+
25
+ NB: if you installed CRF++ yourself make sure to not install (or not to
26
+ load) the Ruby extensions that are packaged with the sources as they may
27
+ interfere with the crfpp gem.
28
+
29
+
30
+ Credits
31
+ -------
32
+
33
+ Copyright 2011 [Sylvester Keil](http://sylvester.keil.or.at). All rights reserved.
34
+
35
+ CRFPP is published under a BSD License; see the LICENSE file for details.
data/Rakefile CHANGED
@@ -26,3 +26,4 @@ Rake::TestTask.new :test => [:compile] do |test|
26
26
  test.verbose = true
27
27
  end
28
28
 
29
+ CLEAN.include('*.gem')
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = ['Sylvester Keil']
12
12
  s.email = ['http://sylvester.keil.or.at']
13
- s.homepage = 'http://inukshuk.github.com/crfpp'
13
+ s.homepage = 'https://github.com/inukshuk/crfpp'
14
14
  s.summary = 'Conditional Random Fields for Ruby.'
15
15
  s.description = 'A Ruby extension to interface with CRF++, the Conditional Random Fields library written in C++. You need to install libcrfpp to use this gem.'
16
16
  s.license = 'FreeBSD'
@@ -40,5 +40,5 @@ extern "C" void Init_native() {
40
40
 
41
41
  Init_tagger(crfpp);
42
42
 
43
- rb_define_const(native, "VERSION", rb_str_new_cstr("0.54"));
43
+ rb_define_const(native, "VERSION", rb_str_new2("0.54"));
44
44
  }
@@ -24,6 +24,10 @@ module CRFPP
24
24
  [type.to_s.upcase, identifier(number), ':', content].compact.join
25
25
  end
26
26
 
27
+ def identified?
28
+ !id.nil?
29
+ end
30
+
27
31
  end
28
32
 
29
33
  end
@@ -3,11 +3,12 @@ module CRFPP
3
3
 
4
4
  extend Forwardable
5
5
 
6
+ include Enumerable
6
7
  include Filelike
7
8
 
8
- attr_reader :features
9
+ attr_reader :sentences
9
10
 
10
- def_delegators :@features, :<<, :length
11
+ def_delegators :@sentences, :each, :[]
11
12
 
12
13
  def initialize(path = nil)
13
14
  @path = path
@@ -15,17 +16,43 @@ module CRFPP
15
16
  end
16
17
 
17
18
  def open
18
- @features = read.lines.map { |line| Feature.parse(line) }
19
+ clear
20
+
21
+ read.lines.each do |line|
22
+ line.chomp!
23
+ if line.strip.empty?
24
+ new_sentence
25
+ else
26
+ push Feature.parse(line)
27
+ end
28
+ end
29
+
19
30
  self
20
31
  end
21
32
 
22
33
  def clear
23
- @features = []
34
+ @sentences = [[]]
24
35
  end
25
36
 
26
37
  def to_s
38
+ return '' if empty?
39
+
27
40
  i = -1
28
- features.map { |f| f.is_a?(Feature) ? f.to_s(i += 1) : f.chomp }.join("\n")
41
+ map { |s| s.map { |f| f.respond_to?(:identified?) && !f.identified? ? f.to_s(i += 1) : f }.join("\n") }.zip([]).flatten.join("\n")
42
+ end
43
+
44
+ def push(feature)
45
+ @sentences.last << feature
46
+ end
47
+
48
+ alias << push
49
+
50
+ def empty?
51
+ [@sentences].flatten(2).compact.empty?
52
+ end
53
+
54
+ def new_sentence
55
+ @sentences << []
29
56
  end
30
57
 
31
58
  end
@@ -1,3 +1,3 @@
1
1
  module CRFPP
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -17,8 +17,14 @@ module CRFPP
17
17
 
18
18
  def test_parse_feature_strings
19
19
  assert_equal 'U:%x[42,23]/AB', Feature.parse('U:%x[42,23]/AB').to_s
20
+ assert_equal 'U101:%x[42,23]/AB', Feature.parse('U101:%x[42,23]/AB').to_s
20
21
  end
21
22
 
23
+ def test_identifier
24
+ assert_equal '01', Feature.new(nil,nil,1).identifier
25
+ assert_equal '02', Feature.new(nil,nil,1).identifier(2)
26
+ assert_equal '002', Feature.new(nil,nil,1).identifier('002')
27
+ end
22
28
 
23
29
  end
24
30
 
@@ -14,7 +14,7 @@ module CRFPP
14
14
 
15
15
  def test_load_template_from_file
16
16
  path = "#{FixturesRoot}/template"
17
- assert_equal Template.new(path).to_s.chomp, File.open(path).read.chomp
17
+ assert_equal File.open(path).read.chomp, Template.new(path).to_s.chomp
18
18
  end
19
19
 
20
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crfpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-08-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2156849560 !ruby/object:Gem::Requirement
16
+ requirement: &2156620200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.9'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156849560
24
+ version_requirements: *2156620200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake-compiler
27
- requirement: &2156849000 !ruby/object:Gem::Requirement
27
+ requirement: &2156619700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156849000
35
+ version_requirements: *2156619700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ZenTest
38
- requirement: &2156848460 !ruby/object:Gem::Requirement
38
+ requirement: &2156619200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '4.6'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2156848460
46
+ version_requirements: *2156619200
47
47
  description: A Ruby extension to interface with CRF++, the Conditional Random Fields
48
48
  library written in C++. You need to install libcrfpp to use this gem.
49
49
  email:
@@ -86,7 +86,7 @@ files:
86
86
  - test/fixtures/test.data
87
87
  - test/fixtures/train.data
88
88
  - test/helper.rb
89
- homepage: http://inukshuk.github.com/crfpp
89
+ homepage: https://github.com/inukshuk/crfpp
90
90
  licenses:
91
91
  - FreeBSD
92
92
  post_install_message: