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 +33 -0
- data/Rakefile +1 -0
- data/crfpp.gemspec +1 -1
- data/ext/crfpp/native.cpp +1 -1
- data/lib/crfpp/feature.rb +4 -0
- data/lib/crfpp/template.rb +32 -5
- data/lib/crfpp/version.rb +1 -1
- data/test/crfpp/test_feature.rb +6 -0
- data/test/crfpp/test_template.rb +1 -1
- metadata +9 -9
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
data/crfpp.gemspec
CHANGED
@@ -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 = '
|
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'
|
data/ext/crfpp/native.cpp
CHANGED
data/lib/crfpp/feature.rb
CHANGED
data/lib/crfpp/template.rb
CHANGED
@@ -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 :
|
9
|
+
attr_reader :sentences
|
9
10
|
|
10
|
-
def_delegators :@
|
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
|
-
|
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
|
-
@
|
34
|
+
@sentences = [[]]
|
24
35
|
end
|
25
36
|
|
26
37
|
def to_s
|
38
|
+
return '' if empty?
|
39
|
+
|
27
40
|
i = -1
|
28
|
-
|
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
|
data/lib/crfpp/version.rb
CHANGED
data/test/crfpp/test_feature.rb
CHANGED
@@ -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
|
|
data/test/crfpp/test_template.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2011-08-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
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: *
|
24
|
+
version_requirements: *2156620200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake-compiler
|
27
|
-
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: *
|
35
|
+
version_requirements: *2156619700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ZenTest
|
38
|
-
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: *
|
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:
|
89
|
+
homepage: https://github.com/inukshuk/crfpp
|
90
90
|
licenses:
|
91
91
|
- FreeBSD
|
92
92
|
post_install_message:
|