opener-kaf-naf-parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +674 -0
  3. data/README.md +46 -0
  4. data/bin/kaf-naf-parser +8 -0
  5. data/bin/kaf-naf-parser-server +10 -0
  6. data/bin/kaf-to-naf +7 -0
  7. data/bin/naf-to-kaf +7 -0
  8. data/config.ru +4 -0
  9. data/core/kaf-naf-parser.py +42 -0
  10. data/core/packages/KafNafParser-1.2.tar.gz +0 -0
  11. data/core/packages/VUA_pylib-1.3.tar.gz +0 -0
  12. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/PKG-INFO +10 -0
  13. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/SOURCES.txt +22 -0
  14. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/dependency_links.txt +1 -0
  15. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/installed-files.txt +47 -0
  16. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/top_level.txt +1 -0
  17. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +338 -0
  18. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
  19. data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
  20. data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
  21. data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
  22. data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
  23. data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
  24. data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
  25. data/core/site-packages/pre_build/KafNafParser/dependency_data.py +80 -0
  26. data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
  27. data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
  28. data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
  29. data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
  30. data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
  31. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
  32. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
  33. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
  34. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
  35. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +300 -0
  36. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
  37. data/core/site-packages/pre_build/KafNafParser/features_data.py +71 -0
  38. data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
  39. data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
  40. data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
  41. data/core/site-packages/pre_build/KafNafParser/opinion_data.py +200 -0
  42. data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
  43. data/core/site-packages/pre_build/KafNafParser/references_data.py +15 -0
  44. data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
  45. data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
  46. data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
  47. data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
  48. data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
  49. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
  50. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
  51. data/core/site-packages/pre_build/KafNafParser/text_data.py +90 -0
  52. data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
  53. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/PKG-INFO +10 -0
  54. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/SOURCES.txt +14 -0
  55. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/dependency_links.txt +1 -0
  56. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/installed-files.txt +23 -0
  57. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/top_level.txt +1 -0
  58. data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
  59. data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
  60. data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
  61. data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
  62. data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
  63. data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
  64. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
  65. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
  66. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
  67. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
  68. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
  69. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
  70. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
  71. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
  72. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
  73. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
  74. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
  75. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
  76. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
  77. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
  78. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
  79. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
  80. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
  81. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
  82. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
  83. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
  84. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
  85. data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
  86. data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
  87. data/ext/hack/support.rb +38 -0
  88. data/lib/opener/kaf_naf_parser.rb +77 -0
  89. data/lib/opener/kaf_naf_parser/cli.rb +92 -0
  90. data/lib/opener/kaf_naf_parser/public/markdown.css +284 -0
  91. data/lib/opener/kaf_naf_parser/server.rb +16 -0
  92. data/lib/opener/kaf_naf_parser/version.rb +5 -0
  93. data/lib/opener/kaf_naf_parser/views/index.erb +103 -0
  94. data/lib/opener/kaf_naf_parser/views/result.erb +15 -0
  95. data/opener-kaf-naf-parser.gemspec +38 -0
  96. data/pre_build_requirements.txt +3 -0
  97. metadata +283 -0
@@ -0,0 +1,7 @@
1
+ ## version = 0.2
2
+ ## Added timestamp to function addLinguisitcProcessor
3
+ ## 24-april-2013 --> getSingleEntieies and getSingleProperties reads both entities/props in format
4
+ ## entities -> entity -> span -> target and entities -> entity -> references -> span
5
+ ####
6
+
7
+ from KafParserMod import KafParser
@@ -0,0 +1,38 @@
1
+ require 'opener/build-tools'
2
+
3
+ include Opener::BuildTools::Requirements
4
+ include Opener::BuildTools::Python
5
+ include Opener::BuildTools::Files
6
+
7
+ # Directory where packages will be installed to.
8
+ PYTHON_SITE_PACKAGES = File.expand_path(
9
+ '../../../core/site-packages',
10
+ __FILE__
11
+ )
12
+
13
+ # Directory containing the temporary files.
14
+ TMP_DIRECTORY = File.expand_path('../../../tmp', __FILE__)
15
+
16
+ # Path to the pip requirements file used to install requirements before
17
+ # packaging the Gem.
18
+ PRE_BUILD_REQUIREMENTS = File.expand_path(
19
+ '../../../pre_build_requirements.txt',
20
+ __FILE__
21
+ )
22
+
23
+ # Path to the pip requirements file used to install requirements upon Gem
24
+ # installation.
25
+ PRE_INSTALL_REQUIREMENTS = File.expand_path(
26
+ '../../../pre_install_requirements.txt',
27
+ __FILE__
28
+ )
29
+
30
+ ##
31
+ # Verifies the requirements to install thi Gem.
32
+ #
33
+ def verify_requirements
34
+ require_executable('python')
35
+ require_version('python', python_version, '2.7.0')
36
+ require_executable('pip')
37
+ require_version('pip', pip_version, '1.3.1')
38
+ end
@@ -0,0 +1,77 @@
1
+ require 'open3'
2
+ require 'optparse'
3
+
4
+ require_relative 'kaf_naf_parser/version'
5
+ require_relative 'kaf_naf_parser/cli'
6
+
7
+ module Opener
8
+ ##
9
+ # Ruby wrapper around the Python based KafNafParser.
10
+ #
11
+ # @!attribute [r] options
12
+ # @return [Hash]
13
+ #
14
+ class KafNafParser
15
+ attr_reader :options
16
+
17
+ ##
18
+ # Hash containing the default options to use.
19
+ #
20
+ # @return [Hash]
21
+ #
22
+ DEFAULT_OPTIONS = {
23
+ :args => [],
24
+ :conversion => "to-kaf"
25
+ }.freeze
26
+
27
+ ##
28
+ # @param [Hash] options
29
+ #
30
+ # @option options [Array] :args Collection of arbitrary arguments to pass
31
+ # to the underlying kernel.
32
+ #
33
+ def initialize(options = {})
34
+ @options = DEFAULT_OPTIONS.merge(options)
35
+ end
36
+
37
+ ##
38
+ # Returns a String containing the command to use for executing the kernel.
39
+ #
40
+ # @return [String]
41
+ #
42
+ def command
43
+ return "python -E -OO #{kernel} #{options[:args].join(' ')} #{conversion}"
44
+ end
45
+
46
+ def conversion
47
+ "--#{options[:conversion].gsub(/-/,'')}"
48
+ end
49
+
50
+ ##
51
+ # Processes the input and returns an Array containing the output of STDOUT,
52
+ # STDERR and an object containing process information.
53
+ #
54
+ # @param [String] input The text of which to detect the language.
55
+ # @return [Array]
56
+ #
57
+ def run(input)
58
+ return Open3.capture3(command, :stdin_data => input)
59
+ end
60
+
61
+ protected
62
+
63
+ ##
64
+ # @return [String]
65
+ #
66
+ def core_dir
67
+ return File.expand_path('../../../core', __FILE__)
68
+ end
69
+
70
+ ##
71
+ # @return [String]
72
+ #
73
+ def kernel
74
+ return File.join(core_dir, 'kaf-naf-parser.py')
75
+ end
76
+ end # KafNafParser
77
+ end # Opener
@@ -0,0 +1,92 @@
1
+ module Opener
2
+ class KafNafParser
3
+ ##
4
+ # CLI wrapper around {Opener::LanguageIdentifier} using OptionParser.
5
+ #
6
+ # @!attribute [r] options
7
+ # @return [Hash]
8
+ # @!attribute [r] option_parser
9
+ # @return [OptionParser]
10
+ #
11
+ class CLI
12
+ attr_reader :options, :option_parser
13
+
14
+ ##
15
+ # @param [Hash] options
16
+ #
17
+ def initialize(options = {})
18
+ @options = DEFAULT_OPTIONS.merge(options)
19
+
20
+ @option_parser = OptionParser.new do |opts|
21
+ opts.program_name = 'kaf-naf-parser'
22
+ opts.summary_indent = ' '
23
+
24
+ opts.on('-h', '--help', 'Shows this help message') do
25
+ show_help
26
+ end
27
+
28
+ opts.on('-v', '--version', 'Shows the current version') do
29
+ show_version
30
+ end
31
+
32
+ opts.on('-k', '--tokaf', 'Parses input to KAF') do
33
+ @options[:conversion] = "to-kaf"
34
+ end
35
+
36
+ opts.on('-n', '--tonaf', 'Parses input to NAF') do
37
+ @options[:conversion] = "to-naf"
38
+ end
39
+
40
+ opts.on('-l', '--log', 'Enable logging to STDERR') do
41
+ @options[:logging] = true
42
+ end
43
+
44
+ opts.separator <<-EOF
45
+
46
+ Examples:
47
+
48
+ cat example.kaf | #{opts.program_name} --tonaf # Basic usage
49
+ cat example.kaf | #{opts.program_name} --tonaf -l # Logs information to STDERR
50
+ EOF
51
+ end
52
+ end
53
+
54
+ ##
55
+ # @param [String] input
56
+ #
57
+ def run(input)
58
+ option_parser.parse!(options[:args])
59
+
60
+ tagger = KafNafParser.new(options)
61
+
62
+ stdout, stderr, process = tagger.run(input)
63
+
64
+ if process.success?
65
+ puts stdout
66
+
67
+ if options[:logging] and !stderr.empty?
68
+ STDERR.puts(stderr)
69
+ end
70
+ else
71
+ abort stderr
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ ##
78
+ # Shows the help message and exits the program.
79
+ #
80
+ def show_help
81
+ abort option_parser.to_s
82
+ end
83
+
84
+ ##
85
+ # Shows the version and exits the program.
86
+ #
87
+ def show_version
88
+ abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
89
+ end
90
+ end # CLI
91
+ end # KafNafParser
92
+ end # Opener
@@ -0,0 +1,284 @@
1
+
2
+ input[type="text"], textarea
3
+ {
4
+ width: 500px;
5
+ }
6
+
7
+ body {
8
+ font-family: Helvetica, arial, sans-serif;
9
+ font-size: 14px;
10
+ line-height: 1.6;
11
+ padding-top: 10px;
12
+ padding-bottom: 10px;
13
+ background-color: white;
14
+ padding: 30px; }
15
+
16
+ body > *:first-child {
17
+ margin-top: 0 !important; }
18
+ body > *:last-child {
19
+ margin-bottom: 0 !important; }
20
+
21
+ a {
22
+ color: #4183C4; }
23
+ a.absent {
24
+ color: #cc0000; }
25
+ a.anchor {
26
+ display: block;
27
+ padding-left: 30px;
28
+ margin-left: -30px;
29
+ cursor: pointer;
30
+ position: absolute;
31
+ top: 0;
32
+ left: 0;
33
+ bottom: 0; }
34
+
35
+ h1, h2, h3, h4, h5, h6 {
36
+ margin: 20px 0 10px;
37
+ padding: 0;
38
+ font-weight: bold;
39
+ -webkit-font-smoothing: antialiased;
40
+ cursor: text;
41
+ position: relative; }
42
+
43
+ h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
44
+ background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
45
+ text-decoration: none; }
46
+
47
+ h1 tt, h1 code {
48
+ font-size: inherit; }
49
+
50
+ h2 tt, h2 code {
51
+ font-size: inherit; }
52
+
53
+ h3 tt, h3 code {
54
+ font-size: inherit; }
55
+
56
+ h4 tt, h4 code {
57
+ font-size: inherit; }
58
+
59
+ h5 tt, h5 code {
60
+ font-size: inherit; }
61
+
62
+ h6 tt, h6 code {
63
+ font-size: inherit; }
64
+
65
+ h1 {
66
+ font-size: 28px;
67
+ color: black; }
68
+
69
+ h2 {
70
+ font-size: 24px;
71
+ border-bottom: 1px solid #cccccc;
72
+ color: black; }
73
+
74
+ h3 {
75
+ font-size: 18px; }
76
+
77
+ h4 {
78
+ font-size: 16px; }
79
+
80
+ h5 {
81
+ font-size: 14px; }
82
+
83
+ h6 {
84
+ color: #777777;
85
+ font-size: 14px; }
86
+
87
+ p, blockquote, ul, ol, dl, li, table, pre {
88
+ margin: 15px 0; }
89
+
90
+ hr {
91
+ background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
92
+ border: 0 none;
93
+ color: #cccccc;
94
+ height: 4px;
95
+ padding: 0; }
96
+
97
+ body > h2:first-child {
98
+ margin-top: 0;
99
+ padding-top: 0; }
100
+ body > h1:first-child {
101
+ margin-top: 0;
102
+ padding-top: 0; }
103
+ body > h1:first-child + h2 {
104
+ margin-top: 0;
105
+ padding-top: 0; }
106
+ body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
107
+ margin-top: 0;
108
+ padding-top: 0; }
109
+
110
+ a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
111
+ margin-top: 0;
112
+ padding-top: 0; }
113
+
114
+ h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
115
+ margin-top: 0; }
116
+
117
+ li p.first {
118
+ display: inline-block; }
119
+
120
+ ul, ol {
121
+ padding-left: 30px; }
122
+
123
+ ul :first-child, ol :first-child {
124
+ margin-top: 0; }
125
+
126
+ ul :last-child, ol :last-child {
127
+ margin-bottom: 0; }
128
+
129
+ dl {
130
+ padding: 0; }
131
+ dl dt {
132
+ font-size: 14px;
133
+ font-weight: bold;
134
+ font-style: italic;
135
+ padding: 0;
136
+ margin: 15px 0 5px; }
137
+ dl dt:first-child {
138
+ padding: 0; }
139
+ dl dt > :first-child {
140
+ margin-top: 0; }
141
+ dl dt > :last-child {
142
+ margin-bottom: 0; }
143
+ dl dd {
144
+ margin: 0 0 15px;
145
+ padding: 0 15px; }
146
+ dl dd > :first-child {
147
+ margin-top: 0; }
148
+ dl dd > :last-child {
149
+ margin-bottom: 0; }
150
+
151
+ blockquote {
152
+ border-left: 4px solid #dddddd;
153
+ padding: 0 15px;
154
+ color: #777777; }
155
+ blockquote > :first-child {
156
+ margin-top: 0; }
157
+ blockquote > :last-child {
158
+ margin-bottom: 0; }
159
+
160
+ table {
161
+ padding: 0; }
162
+ table tr {
163
+ border-top: 1px solid #cccccc;
164
+ background-color: white;
165
+ margin: 0;
166
+ padding: 0; }
167
+ table tr:nth-child(2n) {
168
+ background-color: #f8f8f8; }
169
+ table tr th {
170
+ font-weight: bold;
171
+ border: 1px solid #cccccc;
172
+ text-align: left;
173
+ margin: 0;
174
+ padding: 6px 13px; }
175
+ table tr td {
176
+ border: 1px solid #cccccc;
177
+ text-align: left;
178
+ margin: 0;
179
+ padding: 6px 13px; }
180
+ table tr th :first-child, table tr td :first-child {
181
+ margin-top: 0; }
182
+ table tr th :last-child, table tr td :last-child {
183
+ margin-bottom: 0; }
184
+
185
+ img {
186
+ max-width: 100%; }
187
+
188
+ span.frame {
189
+ display: block;
190
+ overflow: hidden; }
191
+ span.frame > span {
192
+ border: 1px solid #dddddd;
193
+ display: block;
194
+ float: left;
195
+ overflow: hidden;
196
+ margin: 13px 0 0;
197
+ padding: 7px;
198
+ width: auto; }
199
+ span.frame span img {
200
+ display: block;
201
+ float: left; }
202
+ span.frame span span {
203
+ clear: both;
204
+ color: #333333;
205
+ display: block;
206
+ padding: 5px 0 0; }
207
+ span.align-center {
208
+ display: block;
209
+ overflow: hidden;
210
+ clear: both; }
211
+ span.align-center > span {
212
+ display: block;
213
+ overflow: hidden;
214
+ margin: 13px auto 0;
215
+ text-align: center; }
216
+ span.align-center span img {
217
+ margin: 0 auto;
218
+ text-align: center; }
219
+ span.align-right {
220
+ display: block;
221
+ overflow: hidden;
222
+ clear: both; }
223
+ span.align-right > span {
224
+ display: block;
225
+ overflow: hidden;
226
+ margin: 13px 0 0;
227
+ text-align: right; }
228
+ span.align-right span img {
229
+ margin: 0;
230
+ text-align: right; }
231
+ span.float-left {
232
+ display: block;
233
+ margin-right: 13px;
234
+ overflow: hidden;
235
+ float: left; }
236
+ span.float-left span {
237
+ margin: 13px 0 0; }
238
+ span.float-right {
239
+ display: block;
240
+ margin-left: 13px;
241
+ overflow: hidden;
242
+ float: right; }
243
+ span.float-right > span {
244
+ display: block;
245
+ overflow: hidden;
246
+ margin: 13px auto 0;
247
+ text-align: right; }
248
+
249
+ code, tt {
250
+ margin: 0 2px;
251
+ padding: 0 5px;
252
+ white-space: nowrap;
253
+ border: 1px solid #eaeaea;
254
+ background-color: #f8f8f8;
255
+ border-radius: 3px; }
256
+
257
+ pre code {
258
+ margin: 0;
259
+ padding: 0;
260
+ white-space: pre;
261
+ border: none;
262
+ background: transparent; }
263
+
264
+ .highlight pre {
265
+ background-color: #f8f8f8;
266
+ border: 1px solid #cccccc;
267
+ font-size: 13px;
268
+ line-height: 19px;
269
+ overflow: auto;
270
+ padding: 6px 10px;
271
+ border-radius: 3px; }
272
+
273
+ pre {
274
+ background-color: #f8f8f8;
275
+ border: 1px solid #cccccc;
276
+ font-size: 13px;
277
+ line-height: 19px;
278
+ overflow: auto;
279
+ padding: 6px 10px;
280
+ border-radius: 3px; }
281
+ pre code, pre tt {
282
+ background-color: transparent;
283
+ border: none; }
284
+