Skip to content
Browse files

Updated LICENSE file

  • Loading branch information...
1 parent 5bbc839 commit b327a21728bffe3c31d2f581fc2931483ad4c4b6 @denen99 committed Aug 6, 2012
View
7 LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2010 Adam Denenberg <adam@dberg.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
10 a.rb
@@ -0,0 +1,10 @@
+module A
+
+ attr_accessor :newparams
+
+ def initialize(*params)
+ @newparams = params
+ end
+
+
+end
View
BIN lib/.runit.rb.swp
Binary file not shown.
View
56 lib/jruby-gate.rb
@@ -22,12 +22,7 @@
require 'jruby-gate/xmlparse'
require 'jruby-gate/log'
require 'jruby-gate/javaio'
-
- module JRGate
- include_package "gate"
- include_package "gate.creole"
- include_package "gate.util"
- end
+require 'jruby-gate/jrgate'
class JrubyGate
@@ -40,7 +35,8 @@ class JrubyGate
include XMLParse
- attr_accessor :debug, :pluginsHome, :corpus, :resources, :controller
+ attr_accessor :debug, :pluginsHome, :corpus, :resources
+ attr_accessor :controller, :controllerObject, :corpusObject, :corpus
def Gate
JRGate::Gate
@@ -49,20 +45,23 @@ def Gate
def Factory
JRGate::Factory
end
+
+ def GateException
+ JRGate::GateException
+ end
def initialize(*params)
@debug = true
@resources = Array.new
+ @@logger = Logger.
log_msg("About to initialize Gate")
startup_gate
+ @entity_types = ["Person", "Location","Organization", "Date",\
+ "Money", "Temperature", "Length", "Area",\
+ "Volume", "Weight", "Speed", "urlAddress"]
log_msg("Initialize complete")
end
- #def controller
- #JrubyGate::GateController.controller
- # @controller.controller
- #end
-
def startup_gate
log_msg("Calling Gate.init")
@@ -80,28 +79,47 @@ def add_plugin_dirs(*dirs)
end
def create_corpus
- self.corpus = JrubyGate::GateCorpus.new
+ log_msg("Creating new corpus")
+ @corpusObject = JrubyGate::GateCorpus.new
+ self.corpus = @corpusObject.corpus
+ log_msg("Corpus creation complete")
+ @corpusObject
+ end
+
+ def entity_types
+ self.entity_types
+ end
+
+ def entity_types=(e)
+ raise("Entity types parameter must be an array!") unless e.is_a?(Array)
+ self.entity_types = e
end
def create_controller(controller_name="JrubyGateController")
- self.controller = JrubyGate::GateController.new(controller_name)
+ log_msg("Creating new controller --> " + controller_name)
+ @controllerObject = JrubyGate::GateController.new(controller_name)
+ self.controller = @controllerObject.controller
+ log_msg("Controller creation complete")
+ @controllerObject
end
def add_resource(name)
+ log_msg("Adding new resource " + name )
### NEED TO SUPPORT FEATUREMAP OPTIONS !!
- self.controller.add(self.Factory.createResource(name,self.Factory.newFeatureMap))
+ @controller.add(self.Factory.createResource(name,self.Factory.newFeatureMap))
@resources.push(name)
+ log_msg("Resource addition complete")
end
+ def get_annotations
+ @corpus.document.getAnnotations.get.each { |ann|
- def add_document(d)
- @document = Factory.newDocument(d)
- @corpus.add(@document)
+ }
end
def execute
raise("You can not execute without setting a corpus first or adding at least 1 document !!") unless @corpus || @corpus.isEmpty
- @controller.setCorpus(@corpus)
+ #@controller.setCorpus(@corpus)
@controller.execute
end
View
11 lib/jruby-gate/controller.rb
@@ -2,7 +2,7 @@ class JrubyGate
class GateController < JrubyGate
- attr_accessor :controller
+ #attr_accessor :controller
def initialize(name)
@controller = self.Factory.createResource("gate.creole.SerialAnalyserController",\
@@ -20,10 +20,19 @@ def set_corpus(c)
@controller.setCorpus(c)
end
+ def clear_corpus(c)
+ log_msg("Clearing out the corpus")
+ c.clear
+ end
+
def execute
+ begin
@controller.execute
+ rescue => e
+ end
end
+
end
end
View
26 lib/jruby-gate/corpus.rb
@@ -8,20 +8,24 @@ def initialize
@corpus = self.Factory.createResource("gate.corpora.CorpusImpl")
end
- def add_document_file(f)
+ def add_document(input,controller,type='file')
raise("Can not add document until you create a corpus!") unless @corpus
- f = File.open(f)
- @content = f.read
- f.close
- @document = self.Factory.newDocument(@content)
- @corpus.add(@document)
+
+ if type == 'file'
+ f = File.open(input)
+ @content = f.read
+ f.close
+ @document = self.Factory.newDocument(@content)
+ @corpus.add(@document)
+ controller.set_corpus(@corpus)
+ else
+ @content = input
+ @document = self.Factory.newDocument(input)
+ @corpus.add(@document)
+ controller.set_corpus(@corpus)
+ end
end
- def add_document_string(s)
- @content = s
- @document = self.Factory.newDocument(s)
- @corpus.add(@document)
- end
end
View
6 lib/jruby-gate/jrgate.rb
@@ -0,0 +1,6 @@
+ module JRGate
+ include_package "gate"
+ include_package "gate.creole"
+ include_package "gate.util"
+ include_package "gate.util.GateException"
+ end
View
10 lib/jruby-gate/log.rb
@@ -1,7 +1,13 @@
module Logger
+ include_package 'org.apache.log4j.Logger'
- def log_msg(msg)
- puts "DEBUG: " + msg
+ def log_msg(msg,level=debug)
+ @@logger.info(formatted_date + " DEBUG: " + msg)
end
+ def formatted_date
+ sprintf("%.0f/%.2f/%.2f %.2f:%.2f:%.2f",Time.now.year.to_s,Time.now.day.to_s,\
+ Time.now.mon.to_s, Time.now.hour.to_s,
+ Time.now.min.to_s, Time.now.sec.to_s)
+ end
end
View
11 lib/jruby-gate/test/ca1.rb
@@ -0,0 +1,11 @@
+require 'cm1'
+require 'ca2'
+
+class Ca1
+
+include CM1
+
+ def initialize
+ end
+
+end
View
13 lib/jruby-gate/test/ca2.rb
@@ -0,0 +1,13 @@
+class Ca1
+
+ class Ca2
+
+ include CM1
+
+ def initialize
+ end
+
+ end
+
+
+end
View
10 lib/jruby-gate/test/cm1.rb
@@ -0,0 +1,10 @@
+class Ca1
+
+ module CM1
+
+ def test
+ end
+
+ end
+
+end
View
BIN lib/runit.class
Binary file not shown.
View
20 lib/runit.rb
@@ -0,0 +1,20 @@
+$LOAD_PATH << '/Users/adamd/dev/projects/jruby-gate/lib'
+
+require 'jruby-gate'
+
+ a = JrubyGate.new
+ a.add_plugin_dirs('ANNIE')
+ corp = a.create_corpus
+ ctrl = a.create_controller
+ ctrl.add_resource('gate.creole.tokeniser.DefaultTokeniser')
+ corp.add_document("This is a string about Barack Obama",ctrl.controller,'string')
+ ctrl.execute
+
+ #corp.document.getAnnotations.get(a.entity_types).each { |ann|
+ corp.document.getAnnotations.get.each { |ann|
+ next if ann.type == 'SpaceToken'
+ # next unless a.type == 'NounChunk'
+ puts "Found annotation type: " + ann.type + ' s:' + ann.startNode.offset.to_s + ' e:' + ann.endNode.offset.to_s + \
+ ' -->' + corp.content.slice(ann.startNode.offset,ann.endNode.offset - ann.startNode.offset + 1)
+ # puts a.toString
+ }
View
BIN pkg/jruby-gate-0.3.0.gem
Binary file not shown.

0 comments on commit b327a21

Please sign in to comment.
Something went wrong with that request. Please try again.