/**
 *  wrongPowder is developed by wrong-entertainment & powder
 *
 *
 *  Copyright 2011 Paul Vollmer & Tim Pulver
 *  paulvollmer.net
 *  vollmerpaul@yahoo.de
 *  timpulver.de
 *  pulver.tim@googlemail.com
 * 
 *  This file is part of wrongPowder library.
 *
 *  wrongPowder is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with wrongPowder. If not, see <http://www.gnu.org/licenses/>.
 * 
 *  @author		##author##
 *  @modified	##date##
 *  @version	##version##
 */

package wrongPowder.util.string;

import java.io.BufferedReader;
import java.io.InputStream;

import processing.core.PApplet;
import wrongPowder.io.Reader;





/**
 * DudenAnalyse class will help
 * 
 * @example config_basic 
 */
public class DudenAnalyse {
	
	PApplet p5;
	Reader reader;
	
	public String[] sourcecode;
	
	public String wordtype;
	public String frequency;
	public String worttrennung;
	public String herkunft;
	
	
	
	
	
	/**
	 * A Constructor, usually called in the setup() method in your sketch to
	 * initialize and start the library.
	 * 
	 * @example config_basic
	 */
	public DudenAnalyse(PApplet p) {
		p5 = p;
		reader = new Reader(p);
	}
	
	
	
	
	
	/**
	 * Initailize a text array and save string to variable text.
	 *
	 * @param txt Filename
	 */
	public void search(String url) {
		System.out.println("Start searching duden.de");		  
	}
	
	
	public void checkWord(String word) {
		// Load the sourcecode
		String tempSourcecode = reader.load("http://www.duden.de/rechtschreibung/"+word);
		//System.out.println(tempSourcecode);
		
		wordtype = htmlParse(tempSourcecode, "wortart\">", 2, "<");
		frequency = htmlParse(tempSourcecode, "frequenzklasse_", 1, "\">");
		worttrennung = htmlParse(tempSourcecode, "Worttrennung:</dt><dd class=\"content\">", 1, "</dd>");
		herkunft = htmlParse(tempSourcecode, "Herkunft</a></h2><dl><dd class=\"content\">", 1, "</dd></dl></div>");
	}




	/**
	 * 
	 * @param content The content to parse
	 * @param keyIn The String to begin parsing.
	 * @param a Set the array iterator of the parsed temp string.
	 * @param keyOut
	 * @return Parsed string content.
	 */
	public String htmlParse(String content, String keyIn, int a, String keyOut) {
		String finalParse = "Not available";
		
		String[] tempParse1 = p5.split(content, keyIn);
		/*System.out.println("\nKEYIN\n");
		for (int i = 0; i < tempParse1.length; i++) {
			System.out.println("["+i+"]\t"+tempParse1[i]);
		}*/
		
		String[] tempParse2 = p5.split(tempParse1[a], keyOut);
		/*System.out.println("\nKEYOUT\n");
		for (int i = 0; i < temp2.length; i++) {
			System.out.println("["+i+"]\t"+temp2[i]);
		}*/
		
		finalParse = tempParse2[0];
		return finalParse;
	}
	
	

}
@@ -900,16 +900,55 @@
 Reader;%0A
+import wrongPowder.util.string.Parser;%0A
 %0A%0A%0A%0A%0A/**
@@ -1073,16 +1073,46 @@
 reader;%0A
+%09Parser parse = new Parser();%0A
 %09%0A%09publi
@@ -1885,21 +1885,23 @@
 dtype = 
-htmlP
+parse.p
 arse(tem
@@ -1931,14 +1931,14 @@
 %3E%22, 
-2, 
 %22%3C%22
+, 2
 );%0A%09
@@ -1950,21 +1950,23 @@
 uency = 
-htmlP
+parse.p
 arse(tem
@@ -2000,17 +2000,17 @@
 e_%22,
- 1,
  %22%5C%22%3E%22
+, 1
 );%0A%09
@@ -2025,21 +2025,23 @@
 nnung = 
-htmlP
+parse.p
 arse(tem
@@ -2100,19 +2100,16 @@
 %22%3E%22,
- 1,
  %22%3C/dd%3E%22
 );%0A%09
@@ -2104,16 +2104,19 @@
  %22%3C/dd%3E%22
+, 1
 );%0A%09%09her
@@ -2123,21 +2123,23 @@
 kunft = 
-htmlP
+parse.p
 arse(tem
@@ -2201,11 +2201,8 @@
 %22%3E%22,
- 1,
  %22%3C/
@@ -2220,797 +2220,16 @@
 iv%3E%22
+, 1
 );%0A%09%7D
-%0A%0A%0A%0A%0A%09/**%0A%09 * %0A%09 * @param content The content to parse%0A%09 * @param keyIn The String to begin parsing.%0A%09 * @param a Set the array iterator of the parsed temp string.%0A%09 * @param keyOut%0A%09 * @return Parsed string content.%0A%09 */%0A%09public String htmlParse(String content, String keyIn, int a, String keyOut) %7B%0A%09%09String finalParse = %22Not available%22;%0A%09%09%0A%09%09String%5B%5D tempParse1 = p5.split(content, keyIn);%0A%09%09/*System.out.println(%22%5CnKEYIN%5Cn%22);%0A%09%09for (int i = 0; i %3C tempParse1.length; i++) %7B%0A%09%09%09System.out.println(%22%5B%22+i+%22%5D%5Ct%22+tempParse1%5Bi%5D);%0A%09%09%7D*/%0A%09%09%0A%09%09String%5B%5D tempParse2 = p5.split(tempParse1%5Ba%5D, keyOut);%0A%09%09/*System.out.println(%22%5CnKEYOUT%5Cn%22);%0A%09%09for (int i = 0; i %3C temp2.length; i++) %7B%0A%09%09%09System.out.println(%22%5B%22+i+%22%5D%5Ct%22+temp2%5Bi%5D);%0A%09%09%7D*/%0A%09%09%0A%09%09finalParse = tempParse2%5B0%5D;%0A%09%09return finalParse;%0A%09%7D%0A%09
 %0A%09%0A%0A

Test Parser class at DudenAnalyse class