Skip to content

Commit

Permalink
Updated LICENSE file
Browse files Browse the repository at this point in the history
  • Loading branch information
denen99 committed Aug 7, 2012
1 parent 5bbc839 commit b327a21
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 33 deletions.
7 changes: 7 additions & 0 deletions 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.
10 changes: 10 additions & 0 deletions a.rb
@@ -0,0 +1,10 @@
module A

attr_accessor :newparams

def initialize(*params)
@newparams = params
end


end
Binary file added lib/.runit.rb.swp
Binary file not shown.
56 changes: 37 additions & 19 deletions lib/jruby-gate.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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

Expand Down
11 changes: 10 additions & 1 deletion lib/jruby-gate/controller.rb
Expand Up @@ -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",\
Expand All @@ -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
26 changes: 15 additions & 11 deletions lib/jruby-gate/corpus.rb
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions 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
10 changes: 8 additions & 2 deletions 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
11 changes: 11 additions & 0 deletions lib/jruby-gate/test/ca1.rb
@@ -0,0 +1,11 @@
require 'cm1'
require 'ca2'

class Ca1

include CM1

def initialize
end

end
13 changes: 13 additions & 0 deletions lib/jruby-gate/test/ca2.rb
@@ -0,0 +1,13 @@
class Ca1

class Ca2

include CM1

def initialize
end

end


end
10 changes: 10 additions & 0 deletions lib/jruby-gate/test/cm1.rb
@@ -0,0 +1,10 @@
class Ca1

module CM1

def test
end

end

end
Binary file added lib/runit.class
Binary file not shown.
20 changes: 20 additions & 0 deletions 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
}
Binary file added pkg/jruby-gate-0.3.0.gem
Binary file not shown.

0 comments on commit b327a21

Please sign in to comment.