///////////////////////////////////////////////////////////////////////////////
//Copyright (C) 2014 Joliciel Informatique
//
//This file is part of Talismane.
//
//Talismane is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Talismane 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 Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with Talismane.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////
package com.joliciel.talismane.utils;

public class CoNLLFormatter {
	/**
	 * Convert a string to CoNLL format.
	 */
	public static String toCoNLL(String text) {
		String conllText = text.replace("_", "&und;");
		conllText = conllText.replace(' ', '_');
		if (conllText.length()==0)
			conllText = "_";
		return conllText;
	}
	
	/**
	 * Convert a string from CoNLL format.
	 */
	public static String fromCoNLL(String conllText) {
		String text = null;
		if (conllText.equals("_")) {
			text = "";
		} else {
			text = conllText.replace('_', ' ');
			text = text.replace("&und;", "_");
		}
		return text;
	}
}

@@ -1074,77 +1074,70 @@
 text
-.replace(%22_%22, %22&und;%22);%0A%09%09conllText = conllText.replace(' ', '_');%0A%09%09
+;%0A%09%09if (conllText.equals(%22_%22))%0A%09%09%09conllText = %22&und;%22;%0A%09%09else 
 if (
@@ -1158,10 +1158,12 @@
 th()
+ 
 ==
+ 
 0)%0A%09
@@ -1204,17 +1204,16 @@
 ext;%0A%09%7D%0A
-%09
 %0A%09/**%0A%09 
@@ -1327,12 +1327,17 @@
 t = 
-null
+conllText
 ;%0A%09%09
@@ -1362,18 +1362,16 @@
 ls(%22_%22))
- %7B
 %0A%09%09%09text
@@ -1383,97 +1383,58 @@
 ;%0A%09%09
-%7D 
 else 
-%7B%0A%09%09%09text = conllText.replace('_', ' ');%0A%09%09%09text = text.replace(%22&und;%22, %22_%22);%0A%09%09%7D
+if (conllText.equals(%22&und;%22))%0A%09%09%09text = %22_%22;
 %0A%09%09r

Allow spaces in CoNLL words, rather than replacing with underscores