opener-kaf-naf-parser 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +67 -8
  3. data/bin/kaf-naf-parser-daemon +10 -0
  4. data/core/kaf-naf-parser.py +5 -5
  5. data/exec/kaf-naf-parser.rb +9 -0
  6. data/ext/hack/Rakefile +13 -0
  7. data/lib/opener/kaf_naf_parser/version.rb +1 -1
  8. data/opener-kaf-naf-parser.gemspec +5 -1
  9. data/pre_install_requirements.txt +3 -0
  10. metadata +37 -51
  11. data/core/packages/KafNafParser-1.2.tar.gz +0 -0
  12. data/core/packages/VUA_pylib-1.3.tar.gz +0 -0
  13. data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +0 -338
  14. data/core/site-packages/pre_build/KafNafParser/__init__.py +0 -14
  15. data/core/site-packages/pre_build/KafNafParser/constituency_data.py +0 -125
  16. data/core/site-packages/pre_build/KafNafParser/coreference_data.py +0 -52
  17. data/core/site-packages/pre_build/KafNafParser/dependency_data.py +0 -80
  18. data/core/site-packages/pre_build/KafNafParser/entity_data.py +0 -59
  19. data/core/site-packages/pre_build/KafNafParser/external_references_data.py +0 -41
  20. data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +0 -2
  21. data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +0 -205
  22. data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +0 -300
  23. data/core/site-packages/pre_build/KafNafParser/features_data.py +0 -71
  24. data/core/site-packages/pre_build/KafNafParser/header_data.py +0 -127
  25. data/core/site-packages/pre_build/KafNafParser/opinion_data.py +0 -200
  26. data/core/site-packages/pre_build/KafNafParser/references_data.py +0 -15
  27. data/core/site-packages/pre_build/KafNafParser/span_data.py +0 -63
  28. data/core/site-packages/pre_build/KafNafParser/term_data.py +0 -111
  29. data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +0 -42
  30. data/core/site-packages/pre_build/KafNafParser/text_data.py +0 -90
  31. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/PKG-INFO +0 -10
  32. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/SOURCES.txt +0 -22
  33. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/dependency_links.txt +0 -1
  34. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/installed-files.txt +0 -47
  35. data/core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/top_level.txt +0 -1
  36. data/core/site-packages/pre_build/VUA_pylib/__init__.py +0 -1
  37. data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +0 -1
  38. data/core/site-packages/pre_build/VUA_pylib/common/common.py +0 -28
  39. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +0 -1
  40. data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +0 -156
  41. data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +0 -1
  42. data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +0 -121
  43. data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +0 -1
  44. data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +0 -72
  45. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/PKG-INFO +0 -10
  46. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/SOURCES.txt +0 -14
  47. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/dependency_links.txt +0 -1
  48. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/installed-files.txt +0 -23
  49. data/core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/top_level.txt +0 -1
  50. data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +0 -165
  51. data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +0 -439
  52. data/core/site-packages/pre_build/VUKafParserPy/__init__.py +0 -7
  53. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +0 -10
  54. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +0 -7
  55. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +0 -1
  56. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +0 -11
  57. data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +0 -1
  58. data/pre_build_requirements.txt +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e71d459ada19063793f0905e238ddfe438277da
4
- data.tar.gz: b1772e20cb49d33bb1202bf6419e3cdcc1c211e2
3
+ metadata.gz: 4da7b5e3c461558e2f52191daa6dace50c953144
4
+ data.tar.gz: fa8c4a239654f1b04c42ea735e781aec9589c857
5
5
  SHA512:
6
- metadata.gz: acc64adb41209ba2b4b10f2fcc162315b567fd408a9f6fc842bd78b71b61ee004e62ef09d8a80e391c911bd5ffe927fcaa82a1bd2939c9589da52bfd35a1648f
7
- data.tar.gz: 6677e7be9685c0efb7749759df67f37627cf04ca861cb09c0738687331e21075ac8213ec36acac86fccd9d188ae7876e984276d2e91a28f9abeaddd30645b43d
6
+ metadata.gz: e4d0ea293d50e961ea9e2b58bc643c553e77511fdb05f2fc1893d9cbaff6064ac07c08de9d93bb4eb3e6255762455a0daf4f0b92b9c7e1c4a519ff219bbf3c2b
7
+ data.tar.gz: 248ba180f04b3f4a7ccd3ec9b1411974d1a535f926b58a40b388e6407bd0ec3e78d4eb9a9fca4f548aba385575064fffc03b7ca5503856a6a4e563bcf017b68b
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
+ replace:
1
2
  kaf-naf-parser
2
- ==============
3
+ kaf-naf-parser
4
+
5
+ Introduction
6
+ ------------
3
7
 
4
8
  This library converts KAF to NAF and NAF to KAF. It also contains a webservice
5
9
  for doing exactly this.
@@ -8,8 +12,23 @@ It uses slightly altered
8
12
  distributions of the VUA_pylib and KafNafParserPy but it keeps the external
9
13
  libraries contained, so that shouldn't influence anything on your system.
10
14
 
11
- This does mean however, that changes to the VUA_pylib and KafNafParserPy are not
12
- automatically resembled in the kaf-naf-parser.
15
+ ### Confused by some terminology?
16
+
17
+ This software is part of a larger collection of natural language processing
18
+ tools known as "the OpeNER project". You can find more information about the
19
+ project at (the OpeNER portal)[http://opener-project.github.io]. There you can
20
+ also find references to terms like KAF (an XML standard to represent linguistic
21
+ annotations in texts), component, cores, scenario's and pipelines.
22
+
23
+ Quick Use Example
24
+ -----------------
25
+
26
+ Installing the kaf-naf-parser can be done by executing:
27
+
28
+ gem install opener-kaf-naf-parser
29
+
30
+ Please bare in mind that all components in OpeNER take KAF as an input and
31
+ output KAF by default.
13
32
 
14
33
  It ships with 3 command line tools and a webservice:
15
34
 
@@ -38,9 +57,49 @@ And can then be accessed at: http://localhost:9292
38
57
 
39
58
  Easiest way to install the gem:
40
59
 
41
- ```
42
- git clone git@github.com:opener-project/kaf-naf-parser.git
43
- cd kaf-naf-parser
44
- rake install
45
- ```
60
+ ### Daemon
61
+
62
+ Last but not least the kaf-naf-parser comes shipped with a daemon that
63
+ can read jobs (and write) jobs to and from Amazon SQS queues. For more
64
+ information type:
65
+
66
+ kaf-naf-parser-daemon -h
67
+
68
+
69
+ Description of dependencies
70
+ ---------------------------
71
+
72
+ This component runs best if you run it in an environment suited for OpeNER
73
+ components. You can find an installation guide and helper tools in the (OpeNER
74
+ installer)[https://github.com/opener-project/opener-installer] and (an
75
+ installation guide on the Opener
76
+ Website)[http://opener-project.github.io/getting-started/how-to/local-installation.html]
77
+
78
+ At least you need the following system setup:
79
+
80
+ ### Dependencies for normal use:
81
+
82
+ * Ruby 1.9.3 or newer
83
+ * Python 2.6
84
+
85
+ Where to go from here
86
+ ---------------------
87
+
88
+ * Check (the project website)[http://opener-project.github.io]
89
+ * (Checkout the webservice)[http://opener.olery.com/kaf-naf-parser]
90
+
91
+ Report problem/Get help
92
+ -----------------------
93
+
94
+ If you encounter problems, please email support@opener-project.eu or leave an
95
+ issue in the (issue tracker)[https://github.com/opener-project/kaf-naf-parser/issues].
96
+
97
+
98
+ Contributing
99
+ ------------
46
100
 
101
+ 1. Fork it ( http://github.com/opener-project/kaf-naf-parser/fork )
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'opener/daemons'
4
+
5
+ exec_path = File.expand_path('../../exec/kaf-naf-parser.rb', __FILE__)
6
+
7
+ Opener::Daemons::Controller.new(
8
+ :name => 'kaf-naf-parser',
9
+ :exec_path => exec_path
10
+ )
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env python
2
2
 
3
- # This updates the load path to ensure that the local site-packages directory
4
- # can be used to load packages (e.g. a locally installed copy of lxml).
5
-
6
3
  import sys, getopt, os
7
4
 
8
- sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'site-packages/pre_build'))
9
- sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'site-packages/pre_install'))
5
+ this_folder = os.path.dirname(os.path.realpath(__file__))
6
+
7
+ # This updates the load path to ensure that the local site-packages directory
8
+ # can be used to load packages (e.g. a locally installed copy of lxml).
9
+ sys.path.append(os.path.join(this_folder, 'site-packages/pre_install'))
10
10
 
11
11
  from KafNafParser import KafNafParser
12
12
 
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'opener/daemons'
4
+ require_relative '../lib/opener/kaf_naf_parser'
5
+
6
+ options = Opener::Daemons::OptParser.parse!(ARGV)
7
+ daemon = Opener::Daemons::Daemon.new(Opener::KafNafParser, options)
8
+
9
+ daemon.start
data/ext/hack/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rake'
2
+ require_relative 'support'
3
+
4
+ desc 'Verifies the requirements'
5
+ task :requirements do
6
+ verify_requirements
7
+ end
8
+
9
+ task :default => :requirements do
10
+ path = File.join(PYTHON_SITE_PACKAGES, 'pre_install')
11
+
12
+ pip_install(PRE_INSTALL_REQUIREMENTS, path)
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class KafNafParser
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end # KafNafVersion
5
5
  end # Opener
@@ -8,6 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.description = gem.summary
9
9
  gem.homepage = "http://github.com/cltl/KafNafParserPy"
10
10
  gem.required_ruby_version = '>= 1.9.2'
11
+ gem.extensions = ['ext/hack/Rakefile']
11
12
 
12
13
  gem.files = Dir.glob([
13
14
  'core/packages/**/*',
@@ -19,7 +20,8 @@ Gem::Specification.new do |gem|
19
20
  '*.gemspec',
20
21
  'LICENSE',
21
22
  '*_requirements.txt',
22
- 'README.md'
23
+ 'README.md',
24
+ 'exec/**/*'
23
25
  ]).select { |file| File.file?(file) }
24
26
 
25
27
  gem.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
@@ -31,6 +33,8 @@ Gem::Specification.new do |gem|
31
33
  gem.add_dependency 'uuidtools'
32
34
  gem.add_dependency 'opener-webservice'
33
35
  gem.add_dependency 'puma'
36
+ gem.add_dependency 'opener-daemons'
37
+ gem.add_dependency 'opener-core', ['>= 0.1.2']
34
38
 
35
39
  gem.add_development_dependency 'rspec'
36
40
  gem.add_development_dependency 'cucumber'
@@ -0,0 +1,3 @@
1
+ https://github.com/opener-project/VU-kaf-parser/archive/master.zip#egg=VUKafParserPy
2
+ https://github.com/opener-project/VUA_pylib/archive/v1.6.zip#egg=VUA_pylib
3
+ https://github.com/opener-project/KafNafParserPy/archive/v1.5.zip#egg=KafNafParserPy
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-kaf-naf-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ruben.izquierdobevia@vu.nl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-20 00:00:00.000000000 Z
12
+ date: 2014-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -109,6 +109,34 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: opener-daemons
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: opener-core
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.1.2
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 0.1.2
112
140
  - !ruby/object:Gem::Dependency
113
141
  name: rspec
114
142
  requirement: !ruby/object:Gem::Requirement
@@ -168,68 +196,26 @@ dependencies:
168
196
  description: Parser to translate KAF to NAF and back.
169
197
  email:
170
198
  executables:
199
+ - kaf-naf-parser-daemon
171
200
  - naf-to-kaf
172
201
  - kaf-naf-parser
173
202
  - kaf-to-naf
174
203
  - kaf-naf-parser-server
175
- extensions: []
204
+ extensions:
205
+ - ext/hack/Rakefile
176
206
  extra_rdoc_files: []
177
207
  files:
178
208
  - LICENSE
179
209
  - README.md
180
210
  - bin/kaf-naf-parser
211
+ - bin/kaf-naf-parser-daemon
181
212
  - bin/kaf-naf-parser-server
182
213
  - bin/kaf-to-naf
183
214
  - bin/naf-to-kaf
184
215
  - config.ru
185
216
  - core/kaf-naf-parser.py
186
- - core/packages/KafNafParser-1.2.tar.gz
187
- - core/packages/VUA_pylib-1.3.tar.gz
188
- - core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/PKG-INFO
189
- - core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/SOURCES.txt
190
- - core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/dependency_links.txt
191
- - core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/installed-files.txt
192
- - core/site-packages/pre_build/KafNafParser-1.2-py2.7.egg-info/top_level.txt
193
- - core/site-packages/pre_build/KafNafParser/KafNafParserMod.py
194
- - core/site-packages/pre_build/KafNafParser/__init__.py
195
- - core/site-packages/pre_build/KafNafParser/constituency_data.py
196
- - core/site-packages/pre_build/KafNafParser/coreference_data.py
197
- - core/site-packages/pre_build/KafNafParser/dependency_data.py
198
- - core/site-packages/pre_build/KafNafParser/entity_data.py
199
- - core/site-packages/pre_build/KafNafParser/external_references_data.py
200
- - core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py
201
- - core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py
202
- - core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py
203
- - core/site-packages/pre_build/KafNafParser/features_data.py
204
- - core/site-packages/pre_build/KafNafParser/header_data.py
205
- - core/site-packages/pre_build/KafNafParser/opinion_data.py
206
- - core/site-packages/pre_build/KafNafParser/references_data.py
207
- - core/site-packages/pre_build/KafNafParser/span_data.py
208
- - core/site-packages/pre_build/KafNafParser/term_data.py
209
- - core/site-packages/pre_build/KafNafParser/term_sentiment_data.py
210
- - core/site-packages/pre_build/KafNafParser/text_data.py
211
- - core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/PKG-INFO
212
- - core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/SOURCES.txt
213
- - core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/dependency_links.txt
214
- - core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/installed-files.txt
215
- - core/site-packages/pre_build/VUA_pylib-1.3-py2.7.egg-info/top_level.txt
216
- - core/site-packages/pre_build/VUA_pylib/__init__.py
217
- - core/site-packages/pre_build/VUA_pylib/common/__init__.py
218
- - core/site-packages/pre_build/VUA_pylib/common/common.py
219
- - core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py
220
- - core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py
221
- - core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py
222
- - core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py
223
- - core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py
224
- - core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py
225
- - core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO
226
- - core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt
227
- - core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt
228
- - core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt
229
- - core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt
230
- - core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py
231
- - core/site-packages/pre_build/VUKafParserPy/KafParserMod.py
232
- - core/site-packages/pre_build/VUKafParserPy/__init__.py
217
+ - exec/kaf-naf-parser.rb
218
+ - ext/hack/Rakefile
233
219
  - ext/hack/support.rb
234
220
  - lib/opener/kaf_naf_parser.rb
235
221
  - lib/opener/kaf_naf_parser/cli.rb
@@ -239,7 +225,7 @@ files:
239
225
  - lib/opener/kaf_naf_parser/views/index.erb
240
226
  - lib/opener/kaf_naf_parser/views/result.erb
241
227
  - opener-kaf-naf-parser.gemspec
242
- - pre_build_requirements.txt
228
+ - pre_install_requirements.txt
243
229
  homepage: http://github.com/cltl/KafNafParserPy
244
230
  licenses: []
245
231
  metadata: {}
Binary file
Binary file
@@ -1,338 +0,0 @@
1
- ## LIST OF CHANGES
2
- # Ruben 8-nov-2013
3
- # + included layers for entities, properties, opinions
4
- # + renamed all classes to Cnameoftheclass
5
- # Ruben 15-nov-2013
6
- # + included constituency layer
7
- #
8
- # Ruben 19-nov-2013
9
- # + included dependency layer
10
- # Ruben 17-dec-2013
11
- # + modified all to red/write NAF and KAF
12
- #
13
- # Ruben 21-Feb-2014
14
- # + Included coreference layer
15
-
16
-
17
- __last_modified = '17dec2013'
18
-
19
- from lxml import etree
20
- from header_data import *
21
- from text_data import *
22
- from term_data import *
23
- from entity_data import *
24
- from features_data import *
25
- from opinion_data import *
26
- from constituency_data import *
27
- from dependency_data import *
28
- from feature_extractor import Cdependency_extractor, Cconstituency_extractor
29
- from coreference_data import *
30
- from references_data import Creferences
31
-
32
- import sys
33
-
34
-
35
-
36
- class KafNafParser:
37
- def __init__(self,filename):
38
- self.tree = None
39
- self.filename = filename
40
- self.tree = etree.parse(filename,etree.XMLParser(remove_blank_text=True))
41
- self.root = self.tree.getroot()
42
- self.type = self.root.tag # KAF NAF
43
-
44
- self.header = None
45
- self.text_layer = None
46
- self.term_layer = None
47
- self.entity_layer = None
48
- self.features_layer = None
49
- self.opinion_layer = None
50
- self.constituency_layer = None
51
- self.dependency_layer = None
52
- self.coreference_layer = None
53
-
54
- ## Specific feature extractor for complicated layers
55
- self.my_dependency_extractor = None
56
- self.my_constituency_extractor = None
57
- ##################################################
58
-
59
- #######
60
- self.dict_tokens_for_tid = None
61
- ##
62
-
63
- self.lang = self.root.get('{http://www.w3.org/XML/1998/namespace}lang')
64
- self.version = self.root.get('version')
65
-
66
- if self.type == 'NAF':
67
- node_header = self.root.find('nafHeader')
68
- elif self.type == 'KAF':
69
- node_header = self.root.find('kafHeader')
70
-
71
- if node_header is not None:
72
- self.header = CHeader(node_header,self.type)
73
-
74
- # Text layer adapted to naf/kaf
75
- node_text = self.root.find('text')
76
- if node_text is not None:
77
- self.text_layer = Ctext(node=node_text,type=self.type)
78
-
79
- node_term = self.root.find('terms')
80
- if node_term is not None:
81
- self.term_layer = Cterms(node=node_term,type=self.type)
82
-
83
- node_entity = self.root.find('entities')
84
- if node_entity is not None:
85
- self.entity_layer = Centities(node_entity,type=self.type)
86
-
87
- node_features = self.root.find('features')
88
- if node_features is not None:
89
- self.features_layer = Cfeatures(node_features,type=self.type)
90
-
91
- node_opinions = self.root.find('opinions')
92
- if node_opinions is not None:
93
- self.opinion_layer = Copinions(node_opinions,type=self.type)
94
-
95
- # Definition KAF/NAF is the same
96
- node_constituency = self.root.find('constituency')
97
- if node_constituency is not None:
98
- self.constituency_layer = Cconstituency(node_constituency)
99
-
100
- # Definition KAF/NAF is the same
101
- node_dependency = self.root.find('deps')
102
- if node_dependency is not None:
103
- self.dependency_layer = Cdependencies(node_dependency)
104
-
105
- node_coreferences = self.root.find('coreferences')
106
- if node_coreferences is not None:
107
- self.coreference_layer = Ccoreferences(node_coreferences,type=self.type)
108
-
109
- def get_type(self):
110
- return self.type
111
-
112
- def get_filename(self):
113
- return self.filename
114
-
115
- def to_kaf(self):
116
- #Convert the root
117
- if self.type == 'NAF':
118
- self.root.tag = 'KAF'
119
- self.type = 'KAF'
120
-
121
- ## Convert the header
122
- if self.header is not None:
123
- self.header.to_kaf()
124
-
125
- ## Convert the token layer
126
- if self.text_layer is not None:
127
- self.text_layer.to_kaf()
128
-
129
- ## Convert the term layer
130
- if self.term_layer is not None:
131
- self.term_layer.to_kaf()
132
-
133
- ## Convert the entity layer
134
- if self.entity_layer is not None:
135
- self.entity_layer.to_kaf()
136
-
137
- ## Convert the features layer
138
- ## There is no feature layer defined in NAF, but we assumed
139
- ## that is defined will be followin the same rules
140
- if self.features_layer is not None:
141
- self.features_layer.to_kaf()
142
-
143
-
144
- ##Convert the opinion layer
145
- if self.opinion_layer is not None:
146
- self.opinion_layer.to_kaf()
147
-
148
- ## Convert the constituency layer
149
- ## This layer is exactly the same in KAF/NAF
150
- if self.constituency_layer is not None:
151
- self.constituency_layer.to_kaf() #Does nothing...
152
-
153
-
154
- ## Convert the dedepency layer
155
- ## It is not defined on KAF so we assme both will be similar
156
- if self.dependency_layer is not None:
157
- self.dependency_layer.to_kaf()
158
-
159
- if self.coreference_layer is not None:
160
- self.coreference_layer.to_kaf()
161
-
162
-
163
- def to_naf(self):
164
- #Convert the root
165
- if self.type == 'KAF':
166
- self.root.tag = self.type = 'NAF'
167
-
168
- ## Convert the header
169
- if self.header is not None:
170
- self.header.to_naf()
171
-
172
- ## Convert the token layer
173
- if self.text_layer is not None:
174
- self.text_layer.to_naf()
175
-
176
-
177
- ## Convert the term layer
178
- if self.term_layer is not None:
179
- self.term_layer.to_naf()
180
-
181
-
182
- ## Convert the entity layer
183
- if self.entity_layer is not None:
184
- self.entity_layer.to_naf()
185
-
186
- ## Convert the features layer
187
- ## There is no feature layer defined in NAF, but we assumed
188
- ## that is defined will be followin the same rules
189
- if self.features_layer is not None:
190
- self.features_layer.to_naf()
191
-
192
-
193
- ##Convert the opinion layer
194
- if self.opinion_layer is not None:
195
- self.opinion_layer.to_naf()
196
-
197
-
198
- ## Convert the constituency layer
199
- ## This layer is exactly the same in KAF/NAF
200
- if self.constituency_layer is not None:
201
- self.constituency_layer.to_naf() #Does nothing...
202
-
203
-
204
- ## Convert the dedepency layer
205
- ## It is not defined on KAF so we assume both will be similar
206
- if self.dependency_layer is not None:
207
- self.dependency_layer.to_naf() #Does nothing...
208
-
209
- if self.coreference_layer is not None:
210
- self.coreference_layer.to_naf()
211
-
212
-
213
-
214
- def print_constituency(self):
215
- print self.constituency_layer
216
-
217
- def get_trees(self):
218
- if self.constituency_layer is not None:
219
- for tree in self.constituency_layer.get_trees():
220
- yield tree
221
-
222
-
223
- def get_dependencies(self):
224
- if self.dependency_layer is not None:
225
- for dep in self.dependency_layer.get_dependencies():
226
- yield dep
227
-
228
- def get_language(self):
229
- return self.lang
230
-
231
- def get_tokens(self):
232
- for token in self.text_layer:
233
- yield token
234
-
235
- def get_terms(self):
236
- for term in self.term_layer:
237
- yield term
238
-
239
- def get_token(self,token_id):
240
- if self.text_layer is not None:
241
- return self.text_layer.get_wf(token_id)
242
- else:
243
- return None
244
-
245
- def get_term(self,term_id):
246
- if self.term_layer is not None:
247
- return self.term_layer.get_term(term_id)
248
- else:
249
- return None
250
-
251
- def get_properties(self):
252
- if self.features_layer is not None:
253
- for property in self.features_layer.get_properties():
254
- yield property
255
-
256
- def get_entities(self):
257
- if self.entity_layer is not None:
258
- for entity in self.entity_layer:
259
- yield entity
260
-
261
- def get_opinions(self):
262
- if self.opinion_layer is not None:
263
- for opinion in self.opinion_layer.get_opinions():
264
- yield opinion
265
-
266
-
267
- def dump(self,filename=sys.stdout):
268
- self.tree.write(filename,encoding='UTF-8',pretty_print=True,xml_declaration=True)
269
-
270
-
271
- def remove_opinion_layer(self):
272
- if self.opinion_layer is not None:
273
- this_node = self.opinion_layer.get_node()
274
- self.root.remove(this_node)
275
- self.opinion_layer = None
276
-
277
- def remove_term_layer(self):
278
- if self.term_layer is not None:
279
- this_node = self.term_layer.get_node()
280
- self.root.remove(this_node)
281
- self.term_layer = None
282
-
283
- if self.header is not None:
284
- self.header.remove_lp('terms')
285
-
286
- def get_constituency_extractor(self):
287
- if self.constituency_layer is not None: ##Otherwise there are no constituens
288
- if self.my_constituency_extractor is None:
289
- self.my_constituency_extractor = Cconstituency_extractor(self)
290
- return self.my_constituency_extractor
291
- else:
292
- return None
293
-
294
- def get_dependency_extractor(self):
295
- if self.dependency_layer is not None: #otherwise there are no dependencies
296
- if self.my_dependency_extractor is None:
297
- self.my_dependency_extractor = Cdependency_extractor(self)
298
- return self.my_dependency_extractor
299
- else:
300
- return None
301
-
302
- ## ADDING METHODS
303
- def add_wf(self,wf_obj):
304
- if self.text_layer is None:
305
- self.text_layer = Ctext(type=self.type)
306
- self.root.append(self.text_layer.get_node())
307
- self.text_layer.add_wf(wf_obj)
308
-
309
- def add_opinion(self,opinion_obj):
310
- if self.opinion_layer is None:
311
- self.opinion_layer = Copinions()
312
- self.root.append(self.opinion_layer.get_node())
313
- self.opinion_layer.add_opinion(opinion_obj)
314
-
315
- def add_linguistic_processor(self, layer ,my_lp):
316
- self.header.add_linguistic_processor(layer,my_lp)
317
-
318
-
319
- def add_dependency(self,my_dep):
320
- if self.dependency_layer is None:
321
- self.dependency_layer = Cdependencies()
322
- self.root.append(self.dependency_layer.get_node())
323
- self.dependency_layer.add_dependency(my_dep)
324
-
325
-
326
- ## EXTRA FUNCTIONS
327
- ## Gets the token identifiers in the span of a term id
328
- def get_dict_tokens_for_termid(self, term_id):
329
- if self.dict_tokens_for_tid is None:
330
- self.dict_tokens_for_tid = {}
331
- for term in self.get_terms():
332
- self.dict_tokens_for_tid[term.get_id()] = term.get_span().get_span_ids()
333
-
334
- return self.dict_tokens_for_tid.get(term_id,[])
335
-
336
-
337
-
338
-
@@ -1,14 +0,0 @@
1
- from KafNafParserMod import *
2
- from header_data import *
3
- from external_references_data import *
4
- from span_data import *
5
- from term_data import *
6
- from term_sentiment_data import *
7
- from text_data import *
8
- from entity_data import *
9
- from features_data import *
10
- from opinion_data import *
11
- from dependency_data import *
12
- from constituency_data import *
13
- from references_data import *
14
- from coreference_data import *