stanford_corenlp_xml_adapter 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6656655d80da112c54ff784c96fba02aac24f8b
4
- data.tar.gz: 9b213f477670f597b1c1b4eea8c9fadf036491fa
3
+ metadata.gz: c2be2c79f133a2556c4fd2351b37ed383b537073
4
+ data.tar.gz: 3f0de226512b553bf5f6d9c190608934fd36d406
5
5
  SHA512:
6
- metadata.gz: fd0c3d1f030a7f3eb38c6b13a566106d2953203f0548d4ac57e41d576a592c58ecdf00ba885d546448fb719937b89fdc0f8a5946c2aae6f4b933aebbf983d847
7
- data.tar.gz: 2db9102c1e9588f11f286f9c11a9521ce401ba6f3e2322025697142fbb161c9a86fb2ba59bf41b42904d8930eb82ac83e5c8758848105611c9ecd24849645b2a
6
+ metadata.gz: 9b6fa7dd046a0a32c9b663ad9c135cda38c7cd0abd48f422d4d602891986d6d429c6486e960ee00c4d01c57a02e5062211ea6384bd2184e864494e30ae24ede6
7
+ data.tar.gz: f862e73ab5c4816790fe7914f90da9a75f8105d911355bdc56fd0a5cbe132581513648a87d02b2a4d676d0ba6a10e2c84f8f3a4c46291bdb1e3ab56712e107d5
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ end
@@ -1,5 +1,7 @@
1
- sudo: false
1
+ sudo: required
2
+ dist: trusty
2
3
  language: ruby
3
4
  rvm:
4
- - 2.3.4
5
- before_install: gem install bundler -v 1.15.4
5
+ - 2.3.1
6
+ before_install:
7
+ - gem install bundler -v 1.14.6
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # stanford-corenlp-xml-adapter
2
+
3
+ [![Build Status](https://travis-ci.org/joshweir/stanford-corenlp-xml-adapter.svg?branch=master)](https://travis-ci.org/joshweir/stanford-corenlp-xml-adapter) [![Coverage Status](https://coveralls.io/repos/github/joshweir/stanford-corenlp-xml-adapter/badge.svg?branch=master)](https://coveralls.io/github/joshweir/stanford-corenlp-xml-adapter?branch=master)
4
+
2
5
  Nokogiri based Ruby adapter to the output returned by Stanford CoreNLP XML Server.
3
6
 
4
7
  ## Installation
@@ -1,13 +1,17 @@
1
- require "stanford_corenlp_xml_adapter/version"
2
- require "stanford_corenlp_xml_adapter/nokogiri_mixins"
3
1
  require "nokogiri"
2
+ require "stanford_corenlp_xml_adapter/version"
3
+ require "stanford_corenlp_xml_adapter/nokogiri_misc_mixins"
4
+ require "stanford_corenlp_xml_adapter/coreference"
5
+ require "stanford_corenlp_xml_adapter/dependency_parse"
4
6
 
5
7
  class Nokogiri::XML::Document
6
- include NokogiriMixins
8
+ include NokogiriMiscellaneousMixins
9
+ include Coreference
7
10
  end
8
11
 
9
12
  class Nokogiri::XML::Element
10
- include NokogiriMixins
13
+ include NokogiriMiscellaneousMixins
14
+ include DependencyParse
11
15
  end
12
16
 
13
17
  module StanfordCorenlpXmlAdapter
@@ -0,0 +1,59 @@
1
+ module Coreference
2
+ def coreferences
3
+ self.xpath("//coreference//coreference").map{|c| coref_nok_to_blob(c)}
4
+ end
5
+
6
+ def coref_nok_to_blob input
7
+ {
8
+ representative: coref_representative_nok_to_blob(input),
9
+ mentions: coref_mentions_nok_to_blob(input)
10
+ }
11
+ end
12
+
13
+ def coref_representative_nok_to_blob input
14
+ coref_mention_nok_to_blob(
15
+ input
16
+ .children
17
+ .select{|m|
18
+ m.name == 'mention' && m.attributes['representative']
19
+ }
20
+ .first
21
+ )
22
+ end
23
+
24
+ def coref_mentions_nok_to_blob input
25
+ input
26
+ .children
27
+ .select{|m|
28
+ m.name == 'mention'
29
+ }
30
+ .map{|m| coref_mention_nok_to_blob(m, true)}
31
+ end
32
+
33
+ def coref_mention_nok_to_blob input, add_representative_flag=nil
34
+ add_representative_flag ?
35
+ with_representative_flag(
36
+ coref_mention(input),
37
+ input
38
+ ) :
39
+ coref_mention(input)
40
+ end
41
+
42
+ def coref_mention input
43
+ Hash[
44
+ input
45
+ .children
46
+ .select{|v| v.class == Nokogiri::XML::Element}
47
+ .map{|v| [v.name.to_sym, to_i_based_on_field_name(v.text, v.name)]}
48
+ ]
49
+ end
50
+
51
+ def with_representative_flag input, parent
52
+ parent.name == 'mention' && parent.attributes['representative'] ?
53
+ input.merge({ representative: true }) : input
54
+ end
55
+
56
+ def to_i_based_on_field_name input, field_name
57
+ field_name == 'text' ? input : input.to_i
58
+ end
59
+ end
@@ -0,0 +1,56 @@
1
+ module DependencyParse
2
+ def basic_dependencies
3
+ dependencies_for_type 'basic-dependencies'
4
+ end
5
+
6
+ def collapsed_dependencies
7
+ dependencies_for_type 'collapsed-dependencies'
8
+ end
9
+
10
+ def collapsed_ccprocessed_dependencies
11
+ dependencies_for_type 'collapsed-ccprocessed-dependencies'
12
+ end
13
+
14
+ def collapsed_ccprocessed_dependencies
15
+ dependencies_for_type 'collapsed-ccprocessed-dependencies'
16
+ end
17
+
18
+ def enhanced_dependencies
19
+ dependencies_for_type 'enhanced-dependencies'
20
+ end
21
+
22
+ def enhanced_plus_plus_dependencies
23
+ dependencies_for_type 'enhanced-plus-plus-dependencies'
24
+ end
25
+
26
+ def dependencies_for_type type
27
+ dependency_parse_nok_to_blob(
28
+ self.xpath(".//dependencies[@type=\"#{type}\"]")
29
+ )
30
+ end
31
+
32
+ def dependency_parse_nok_to_blob input
33
+ input
34
+ .children
35
+ .select{|dep| dep.name == 'dep'}
36
+ .map{|dep| dependency_nok_to_blob(dep)}
37
+ end
38
+
39
+ def dependency_nok_to_blob input
40
+ {
41
+ type: input.attributes['type'].value,
42
+ governor: dependency_slice_nok_to_blob('governor', input),
43
+ dependent: dependency_slice_nok_to_blob('dependent', input)
44
+ }
45
+ end
46
+
47
+ def dependency_slice_nok_to_blob name, input
48
+ dep = input.children
49
+ .select{|dep| dep.name == name}
50
+ .first
51
+ {
52
+ idx: dep.attributes['idx'].value.to_i,
53
+ value: dep.text
54
+ }
55
+ end
56
+ end
@@ -1,4 +1,4 @@
1
- module NokogiriMixins
1
+ module NokogiriMiscellaneousMixins
2
2
  def sentences
3
3
  self.xpath("//sentences//sentence")
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module StanfordCorenlpXmlAdapter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "gem-release"
28
28
  spec.add_development_dependency "rb-fsevent"
29
29
  spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "coveralls"
31
+ spec.add_development_dependency "simplecov"
30
32
  spec.add_dependency "activesupport"
31
33
  spec.add_dependency "nokogiri"
32
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stanford_corenlp_xml_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joshweir
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-19 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: activesupport
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +173,7 @@ files:
145
173
  - ".dockerignore"
146
174
  - ".gitignore"
147
175
  - ".rspec"
176
+ - ".simplecov"
148
177
  - ".travis.yml"
149
178
  - Dockerfile
150
179
  - Gemfile
@@ -160,7 +189,9 @@ files:
160
189
  - docker-compose.yml
161
190
  - docker-entrypoint.sh
162
191
  - lib/stanford_corenlp_xml_adapter.rb
163
- - lib/stanford_corenlp_xml_adapter/nokogiri_mixins.rb
192
+ - lib/stanford_corenlp_xml_adapter/coreference.rb
193
+ - lib/stanford_corenlp_xml_adapter/dependency_parse.rb
194
+ - lib/stanford_corenlp_xml_adapter/nokogiri_misc_mixins.rb
164
195
  - lib/stanford_corenlp_xml_adapter/version.rb
165
196
  - stanford_corenlp_xml_adapter.gemspec
166
197
  homepage: https://github.com/joshweir/stanford-corenlp-xml-adapter
@@ -183,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
214
  version: '0'
184
215
  requirements: []
185
216
  rubyforge_project:
186
- rubygems_version: 2.6.13
217
+ rubygems_version: 2.5.2.3
187
218
  signing_key:
188
219
  specification_version: 4
189
220
  summary: Ruby adapter to the output returned by Stanford CoreNLP XML Server.