opener-constituent-parser 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/opener/constituent_parser/error_layer.rb +88 -0
- data/lib/opener/constituent_parser/version.rb +1 -1
- data/lib/opener/constituent_parser.rb +15 -10
- data/opener-constituent-parser.gemspec +3 -4
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b8cef4632872ab1528b8212730436393bdb53f
|
4
|
+
data.tar.gz: f27400f191b588f9ed7f30d6f2725f56c7cca0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e01b010041e9318023958f7eea147822169d0044e0c56e2cf2b3b0259403f020d2f30e9bf9b37cae2c81d423271c8c35dc3f00e2baa9eee69e09de82d3e67aa7
|
7
|
+
data.tar.gz: a6e55ffd545526ca935ab65a6f792bc009d22882dc4c15aea89713af5e489084e36c3ed0c5d9e0e6ca24ff93640ba998e094a6b952a8f667d50674ed2bfc5c60
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ Language Extension
|
|
111
111
|
Where to go from here
|
112
112
|
---------------------
|
113
113
|
|
114
|
-
* [Check the project
|
114
|
+
* [Check the project website](http://opener-project.github.io)
|
115
115
|
* [Checkout the webservice](http://opener.olery.com/constituent-parser)
|
116
116
|
|
117
117
|
Report problem/Get help
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Opener
|
2
|
+
class ConstituentParser
|
3
|
+
##
|
4
|
+
# Add Error Layer to KAF file instead of throwing an error.
|
5
|
+
#
|
6
|
+
class ErrorLayer
|
7
|
+
attr_accessor :input, :document, :error, :klass
|
8
|
+
|
9
|
+
def initialize(input, error, klass)
|
10
|
+
@input = input.to_s
|
11
|
+
# Make sure there is always a document, even if it is empty.
|
12
|
+
@document = Nokogiri::XML(input) rescue Nokogiri::XML(nil)
|
13
|
+
@error = error
|
14
|
+
@klass = klass
|
15
|
+
end
|
16
|
+
|
17
|
+
def add
|
18
|
+
if is_xml?
|
19
|
+
unless has_errors_layer?
|
20
|
+
add_errors_layer
|
21
|
+
end
|
22
|
+
else
|
23
|
+
add_root
|
24
|
+
add_text
|
25
|
+
add_errors_layer
|
26
|
+
end
|
27
|
+
add_error
|
28
|
+
|
29
|
+
xml = !!document.encoding ? document.to_xml : document.to_xml(:encoding => "UTF-8")
|
30
|
+
|
31
|
+
return xml
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Check if the document is a valid XML file.
|
36
|
+
#
|
37
|
+
def is_xml?
|
38
|
+
!!document.root
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Add root element to the XML file.
|
43
|
+
#
|
44
|
+
def add_root
|
45
|
+
root = Nokogiri::XML::Node.new "KAF", document
|
46
|
+
document.add_child(root)
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Check if the document already has an errors layer.
|
51
|
+
#
|
52
|
+
def has_errors_layer?
|
53
|
+
!!document.at('errors')
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Add errors element to the XML file.
|
58
|
+
#
|
59
|
+
def add_errors_layer
|
60
|
+
node = Nokogiri::XML::Node.new "errors", document
|
61
|
+
document.root.add_child(node)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Add the text file incase it is not a valid XML document. More
|
66
|
+
# info for debugging.
|
67
|
+
#
|
68
|
+
def add_text
|
69
|
+
node = Nokogiri::XML::Node.new "raw", document
|
70
|
+
node.inner_html = input
|
71
|
+
document.root.add_child(node)
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Add the actual error to the errors layer.
|
77
|
+
#
|
78
|
+
def add_error
|
79
|
+
node = document.at('errors')
|
80
|
+
error_node = Nokogiri::XML::Node.new "error", node
|
81
|
+
error_node['class'] = "#{klass.to_s} #{klass::VERSION}"
|
82
|
+
error_node.inner_html = error
|
83
|
+
node.add_child(error_node)
|
84
|
+
end
|
85
|
+
|
86
|
+
end # ErrorLayer
|
87
|
+
end # ConstituentParser
|
88
|
+
end # Opener
|
@@ -5,6 +5,7 @@ require 'opener/constituent_parsers/base'
|
|
5
5
|
|
6
6
|
require_relative 'constituent_parser/version'
|
7
7
|
require_relative 'constituent_parser/cli'
|
8
|
+
require_relative 'constituent_parser/error_layer'
|
8
9
|
|
9
10
|
module Opener
|
10
11
|
##
|
@@ -41,18 +42,22 @@ module Opener
|
|
41
42
|
# @return [Array]
|
42
43
|
#
|
43
44
|
def run(input)
|
45
|
+
begin
|
44
46
|
args = options[:args].dup
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
language = language(input)
|
48
|
+
if language_constant_defined?(language)
|
49
|
+
kernel = language_constant(language).new(:args => args)
|
50
|
+
else
|
51
|
+
kernel = ConstituentParsers::Base.new(
|
52
|
+
:args => args,
|
53
|
+
:language => language
|
54
|
+
)
|
55
|
+
end
|
54
56
|
|
55
|
-
|
57
|
+
return kernel.run(input)
|
58
|
+
rescue Exception => error
|
59
|
+
return ErrorLayer.new(input, error.message, self.class).add
|
60
|
+
end
|
56
61
|
end
|
57
62
|
|
58
63
|
##
|
@@ -11,14 +11,14 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.required_ruby_version = '>= 1.9.2'
|
12
12
|
|
13
13
|
gem.files = Dir.glob([
|
14
|
-
'lib
|
14
|
+
'lib/**/*',
|
15
15
|
'*.gemspec',
|
16
16
|
'README.md',
|
17
17
|
'exec/**/*',
|
18
18
|
'config.ru'
|
19
|
-
])
|
19
|
+
]).select { |file| File.file?(file) }
|
20
20
|
|
21
|
-
gem.executables = Dir.glob('bin/*').map { |
|
21
|
+
gem.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
|
22
22
|
|
23
23
|
gem.add_dependency 'opener-webservice'
|
24
24
|
gem.add_dependency 'sinatra', '~>1.4.2'
|
@@ -29,6 +29,5 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.add_dependency 'opener-daemons'
|
30
30
|
gem.add_dependency 'opener-core', ['>= 0.1.2']
|
31
31
|
|
32
|
-
gem.add_development_dependency 'opener-build-tools'
|
33
32
|
gem.add_development_dependency 'rake'
|
34
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-constituent-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- development@olery.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opener-webservice
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
version: 0.1.2
|
123
123
|
prerelease: false
|
124
124
|
type: :runtime
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: opener-build-tools
|
127
|
-
version_requirements: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - '>='
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
requirement: !ruby/object:Gem::Requirement
|
133
|
-
requirements:
|
134
|
-
- - '>='
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: '0'
|
137
|
-
prerelease: false
|
138
|
-
type: :development
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: rake
|
141
127
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -167,6 +153,7 @@ files:
|
|
167
153
|
- exec/constituent-parser.rb
|
168
154
|
- lib/opener/constituent_parser.rb
|
169
155
|
- lib/opener/constituent_parser/cli.rb
|
156
|
+
- lib/opener/constituent_parser/error_layer.rb
|
170
157
|
- lib/opener/constituent_parser/public/markdown.css
|
171
158
|
- lib/opener/constituent_parser/server.rb
|
172
159
|
- lib/opener/constituent_parser/version.rb
|