/*
 * Copyright 2008 Novamente LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package relex.chunk;

import java.util.ArrayList;

import relex.ParsedSentence;
import relex.feature.FeatureNode;
import relex.feature.FeatureNodeCallback;
import relex.tree.PhraseTree;

/**
 * Discover phrase chunks
 *
 * Copyright (C) 2008 Linas Vepstas <linas@linas.org>
 */

public class FindChunks implements FeatureNodeCallback
{
	private ArrayList<Chunk> chunks;
	
	public FindChunks()
	{
		chunks = new ArrayList<Chunk>();
	}

	public void findChunks(ParsedSentence parse)
	{
		PhraseTree pt = parse.getPhraseTree();
		pt.foreach(this);
	}

	public ArrayList<Chunk> getChunks()
	{
		return chunks;
	}

	public Boolean FNCallback(FeatureNode fn)
	{
		PhraseTree pt = new PhraseTree(fn);

		String type = pt.getPhraseType();
		if (!type.equals("NP") && !type.equals("VP")) return false;

		int depth = pt.getDepth();
		if (depth > 3) return false;

		int breadth = pt.getBreadth();
		if (breadth < 2) return false;


		Chunk chunk = new Chunk();
		chunks.add(chunk);

		ArrayList<FeatureNode> words = pt.getWordList();
		chunk.addWords(words);

System.out.println("candidate phrase " +  pt.toString());
System.out.println("strintcly: "+chunk.toString());

		return false;
	}
}

@@ -897,39 +897,8 @@
 unks
- implements FeatureNodeCallback
 %0A%7B%0A%09
@@ -1085,16 +1085,56 @@
 Tree();%0A
+%09%09PhraseChunks pc = new PhraseChunks();%0A
 %09%09pt.for
@@ -1138,20 +1138,18 @@
 foreach(
-this
+pc
 );%0A%09%7D%0A%0A%09
@@ -1204,24 +1204,87 @@
 chunks;%0A%09%7D%0A%0A
+%09private class PhraseChunks implements FeatureNodeCallback%0A%09%7B%0A%09
 %09public Bool
@@ -1314,21 +1314,23 @@
 ode fn)%0A
+%09
 %09%7B%0A%09%09
+%09
 PhraseTr
@@ -1358,16 +1358,17 @@
 e(fn);%0A%0A
+%09
 %09%09String
@@ -1393,24 +1393,25 @@
 seType();%0A%09%09
+%09
 if (!type.eq
@@ -1457,24 +1457,25 @@
 n false;%0A%0A%09%09
+%09
 int depth = 
@@ -1485,24 +1485,25 @@
 getDepth();%0A
+%09
 %09%09if (depth 
@@ -1524,16 +1524,17 @@
 lse;%0A%0A%09%09
+%09
 int brea
@@ -1556,16 +1556,17 @@
 adth();%0A
+%09
 %09%09if (br
@@ -1594,16 +1594,17 @@
 se;%0A%0A%0A%09%09
+%09
 Chunk ch
@@ -1618,24 +1618,25 @@
 ew Chunk();%0A
+%09
 %09%09chunks.add
@@ -1647,16 +1647,17 @@
 nk);%0A%0A%09%09
+%09
 ArrayLis
@@ -1697,16 +1697,17 @@
 List();%0A
+%09
 %09%09chunk.
@@ -1837,16 +1837,17 @@
 ());%0A%0A%09%09
+%09
 return f
@@ -1852,13 +1852,17 @@
  false;%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

restructure to make the callback private