stanford-core-nlp 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ require 'stanford-core-nlp/config'
2
2
 
3
3
  module StanfordCoreNLP
4
4
 
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
 
7
7
  require 'bind-it'
8
8
  extend BindIt::Binding
@@ -51,6 +51,9 @@ module StanfordCoreNLP
51
51
  # Stanford Core NLP bindings #
52
52
  # ########################### #
53
53
 
54
+ require 'stanford-core-nlp/bridge'
55
+ extend StanfordCoreNLP::Bridge
56
+
54
57
  class << self
55
58
  # The model file names for a given language.
56
59
  attr_accessor :model_files
@@ -64,18 +67,6 @@ module StanfordCoreNLP
64
67
  # with the individual models inside. By default, this
65
68
  # is the same as the JAR path.
66
69
  self.model_path = self.jar_path
67
-
68
- # ########################### #
69
- # Annotation bridge (Rjb/Jrb) #
70
- # ########################### #
71
-
72
- if RUBY_PLATFORM =~ /java/
73
- require 'stanford-core-nlp/jruby_bridge'
74
- extend StanfordCoreNLP::JrubyBridge
75
- else
76
- require 'stanford-core-nlp/rjb_bridge'
77
- extend StanfordCoreNLP::RjbBridge
78
- end
79
70
 
80
71
  # ########################### #
81
72
  # Public configuration params #
@@ -0,0 +1,61 @@
1
+ module StanfordCoreNLP::Bridge
2
+
3
+ unless RUBY_PLATFORM =~ /java/
4
+ StanfordCoreNLP.default_classes << ['AnnotationBridge', '']
5
+ end
6
+
7
+ def inject_get_method(klass)
8
+
9
+ klass.class_eval do
10
+
11
+ if RUBY_PLATFORM =~ /java/
12
+ return unless method_defined?(:get)
13
+ alias_method :get_without_casting, :get
14
+ end
15
+
16
+ # Dynamically defined on all proxied annotation classes.
17
+ # Get an annotation using the annotation bridge.
18
+ def get(annotation, anno_base = nil)
19
+
20
+ unless RUBY_PLATFORM =~ /java/
21
+ return unless java_methods.include?('get(Ljava.lang.Class;)')
22
+ end
23
+
24
+ anno_class = "#{StanfordCoreNLP.camel_case(annotation)}Annotation"
25
+ if anno_base
26
+ unless StanfordNLP::Config::Annotations[anno_base]
27
+ raise "The path #{anno_base} doesn't exist."
28
+ end
29
+ anno_bases = [anno_base]
30
+ else
31
+ anno_bases = StanfordCoreNLP::Config::AnnotationsByName[anno_class]
32
+ raise "The annotation #{anno_class} doesn't exist." unless anno_bases
33
+ end
34
+ if anno_bases.size > 1
35
+ msg = "There are many different annotations bearing the name #{anno_class}." +
36
+ "\nPlease specify one of the following base classes as second parameter to disambiguate: "
37
+ msg << anno_bases.join(',')
38
+ raise msg
39
+ else
40
+ base_class = anno_bases[0]
41
+ end
42
+
43
+ if RUBY_PLATFORM =~ /java/
44
+ fqcn = "edu.stanford.#{base_class}"
45
+ class_path = fqcn.split(".")
46
+ class_name = class_path.pop
47
+ path = StanfordCoreNLP.camel_case(class_path.join("."))
48
+ jruby_class = "Java::#{path}::#{class_name}::#{anno_class}"
49
+ get_without_casting(Object.module_eval(jruby_class))
50
+ else
51
+ url = "edu.stanford.#{base_class}$#{anno_class}"
52
+ StanfordCoreNLP::AnnotationBridge.getAnnotation(self, url)
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: stanford-core-nlp
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Louis Mullie
@@ -38,9 +38,8 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - lib/stanford-core-nlp.rb
41
+ - lib/stanford-core-nlp/bridge.rb
41
42
  - lib/stanford-core-nlp/config.rb
42
- - lib/stanford-core-nlp/jruby_bridge.rb
43
- - lib/stanford-core-nlp/rjb_bridge.rb
44
43
  - bin/AnnotationBridge.java
45
44
  - bin/bridge.jar
46
45
  - bin/Stanford.java
@@ -1,41 +0,0 @@
1
- module StanfordCoreNLP::JrubyBridge
2
-
3
- def inject_get_method(klass)
4
- return unless klass.method_defined?(:get)
5
- klass.class_eval do
6
-
7
- # Dynamically defined on all proxied annotation classes.
8
- # Get an annotation using the annotation bridge.
9
- def get_with_casting(annotation, anno_base = nil)
10
- anno_class = "#{StanfordCoreNLP.camel_case(annotation)}Annotation"
11
- if anno_base
12
- unless StanfordNLP::Config::Annotations[anno_base]
13
- raise "The path #{anno_base} doesn't exist."
14
- end
15
- anno_bases = [anno_base]
16
- else
17
- anno_bases = StanfordCoreNLP::Config::AnnotationsByName[anno_class]
18
- raise "The annotation #{anno_class} doesn't exist." unless anno_bases
19
- end
20
- if anno_bases.size > 1
21
- msg = "There are many different annotations bearing the name #{anno_class}. \nPlease specify one of the following base classes as second parameter to disambiguate: "
22
- msg << anno_bases.join(',')
23
- raise msg
24
- else
25
- base_class = anno_bases[0]
26
- end
27
-
28
- fqcn = "edu.stanford.#{base_class}"
29
- class_path = fqcn.split(".")
30
- class_name = class_path.pop
31
- jruby_class = "Java::#{StanfordCoreNLP.camel_case(class_path.join("."))}::#{class_name}::#{anno_class}"
32
-
33
- get_without_casting(Object.module_eval(jruby_class))
34
- end
35
-
36
- alias_method :get_without_casting, :get
37
- alias_method :get, :get_with_casting
38
- end
39
- end
40
-
41
- end
@@ -1,42 +0,0 @@
1
- module StanfordCoreNLP::RjbBridge
2
-
3
- StanfordCoreNLP.default_classes << ['AnnotationBridge', '']
4
-
5
- def inject_get_method(klass)
6
- klass.class_eval do
7
-
8
- # Dynamically defined on all proxied annotation classes.
9
- # Get an annotation using the annotation bridge.
10
- def get(annotation, anno_base = nil)
11
- if !java_methods.include?('get(Ljava.lang.Class;)')
12
- raise 'No annotation can be retrieved on this object.'
13
- else
14
- anno_class = "#{StanfordCoreNLP.camel_case(annotation)}Annotation"
15
- if anno_base
16
- unless StanfordNLP::Config::Annotations[anno_base]
17
- raise "The path #{anno_base} doesn't exist."
18
- end
19
- anno_bases = [anno_base]
20
- else
21
- anno_bases = StanfordCoreNLP::Config::AnnotationsByName[anno_class]
22
- raise "The annotation #{anno_class} doesn't exist." unless anno_bases
23
- end
24
- if anno_bases.size > 1
25
- msg = "There are many different annotations " +
26
- "bearing the name #{anno_class}. \nPlease specify " +
27
- "one of the following base classes as second " +
28
- "parameter to disambiguate: "
29
- msg << anno_bases.join(',')
30
- raise msg
31
- else
32
- base_class = anno_bases[0]
33
- end
34
- url = "edu.stanford.#{base_class}$#{anno_class}"
35
- StanfordCoreNLP::AnnotationBridge.getAnnotation(self, url)
36
- end
37
- end
38
-
39
- end
40
-
41
- end
42
- end