Permalink
Browse files

Started implementation of DependencyTree, need to figure out how to p…

…ercolate the heads of the tree
  • Loading branch information...
1 parent 031ffbb commit 9555d132a4709224bc5c2d21bfcc9a36acdf2a38 @jcwilk committed Aug 1, 2010
Showing with 56 additions and 13 deletions.
  1. +4 −4 Gemfile.lock
  2. +23 −4 examples/connection_finder.rb
  3. +28 −5 spec/connection_finder_spec.rb
  4. +1 −0 spec/spec_helper.rb
View
@@ -35,20 +35,20 @@ specs:
version: 4.3.3
- columnize:
version: 0.3.1
-- json_pure:
- version: 1.4.3
- gemcutter:
- version: 0.5.0
+ version: 0.6.1
- git:
version: 1.2.5
+- json_pure:
+ version: 1.4.3
- rubyforge:
version: 2.0.4
- jeweler:
version: 1.4.0
- linecache:
version: "0.43"
- rjb:
- version: 1.2.5
+ version: 1.2.6
- rspec:
version: 1.3.0
- ruby-debug-base:
@@ -27,19 +27,38 @@ def first(noun1, noun2)
private
- def parse(string)
- ParsedTree.new(parser.apply(string))
+ def parsed_java_obj(string)
+ @_parsed_hash ||= {}
+ @_parsed_hash[string] ||= parser.apply(string)
+ end
+
+ def parsed_tree(string)
+ ParsedTree.new(parsed_java_obj(string))
+ end
+
+ def dependency_tree(string)
+ DependencyTree.new(parsed_java_obj(string))
end
def parser
self.cached_parser ||= StanfordParser::LexicalizedParser.new(StanfordParser::ENGLISH_PCFG_MODEL, [])
end
+ class DependencyTree
+ attr_accessor :dependencies
+ attr_accessor :tree
+
+ def initialize(java_tree)
+ self.tree = java_tree
+ self.dependencies = java_tree.dependencies
+ end
+ end
+
class ParsedTree
attr_accessor :tree
- def initialize(_tree)
- self.tree = _tree
+ def initialize(java_tree)
+ self.tree = java_tree
end
def prune_for(targets)
@@ -59,7 +59,7 @@
before(:all) do
@sentence = "Few people know, though many assume, "+
"that a sentence is better than a phrase."
- @tree = @finder.send(:parse, @sentence)
+ @tree = @finder.send(:parsed_tree, @sentence)
end
it "has a tree object" do
@@ -87,12 +87,35 @@
end
end
- describe ConnectionFinder::DependencyTree do
- it 'has an array of dependencies'
+ describe 'ConnectionFinder::DependencyTree' do
+ before(:each) do
+ @sentence = "Few people know, though many assume, "+
+ "that a sentence is better than a phrase."
+ end
+
+ describe "initialization:" do
+ it 'percolates the heads before pulling the dependencies' do
+ java_tree = @finder.send(:parsed_java_obj, @sentence)
+ #TODO: see Tree#dependencies and SemanticHeadFinder in the javadocs
+ java_tree.should get_its_heads_percolated
+ java_tree.should_receive(:dependencies)
+ @finder.send(:dependency_tree, @sentence)
+ end
+ end
+
+ describe "instance stuff:" do
+ before(:each) do
+ @tree = @finder.send(:dependency_tree, @sentence)
+ end
- it 'can return the dependencies in the form of a tree'
+ it 'has a set of dependencies' do
+ @tree.dependencies.class.to_s.should == 'Set'
+ end
+
+ it 'can return the dependencies in the form of a tree'
- it 'returns the shortest path between two dependencies'
+ it 'returns the shortest path between two dependencies'
+ end
end
describe ConnectionFinder::TreeFilter do
View
@@ -4,6 +4,7 @@
require 'spec'
require 'spec/autorun'
require 'examples/connection_finder.rb'
+require 'ruby-debug'
$parser = StanfordParser::LexicalizedParser.new #(StanfordParser::ENGLISH_PCFG_MODEL, [])

0 comments on commit 9555d13

Please sign in to comment.