// Path: src/main/java/it/unipi/di/acube/smaph/datasets/wikitofreebase/WikipediaLabelToFreebaseRecord.java
// public class WikipediaLabelToFreebaseRecord {
// 
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(WikipediaLabelToFreebaseRecord.class);
// 
// 	private String freebaseId;
// 	private String label;
// 	private String wikipediaLabel;
// 
// 	public WikipediaLabelToFreebaseRecord() {
// 		super();
// 	}
// 
// 	public String getCleanWikipediaLabel() {
// 		return convert(wikipediaLabel).replaceAll("/wikipedia/en_title/", "");
// 	}
// 
// 	public String getFreebaseId() {
// 		return freebaseId;
// 	}
// 
// 	public void setFreebaseId(String freebaseId) {
// 		this.freebaseId = freebaseId;
// 	}
// 
// 	public String getLabel() {
// 		return label;
// 	}
// 
// 	public void setLabel(String label) {
// 		this.label = label;
// 	}
// 
// 	public String getWikipediaLabel() {
// 		return wikipediaLabel;
// 	}
// 
// 	public void setWikipediaLabel(String wikipediaLabel) {
// 		this.wikipediaLabel = wikipediaLabel;
// 	}
// 
// 	final static private Pattern quotedCharPattern = Pattern
// 			.compile("\\$([0-9A-Fa-f]{4})");
// 
// 	protected String convert(String s) {
// 		// see
// 		// https://github.com/OpenRefine/OpenRefine/blob/master/extensions/freebase/src/com/google/refine/freebase/expr/MqlKeyUnquote.java
// 		StringBuffer sb = new StringBuffer();
// 
// 		int last = 0;
// 		Matcher m = quotedCharPattern.matcher(s);
// 		while (m.find()) {
// 			int start = m.start();
// 			int end = m.end();
// 			if (start > last) {
// 				sb.append(s.substring(last, start));
// 			}
// 			last = end;
// 
// 			sb.append((char) Integer.parseInt(s.substring(start + 1, end), 16));
// 		}
// 
// 		if (last < s.length()) {
// 			sb.append(s.substring(last));
// 		}
// 
// 		return sb.toString();
// 	}
// 
// 	public static WikipediaLabelToFreebaseRecord parse(String tsvString) {
// 		Scanner scanner = new Scanner(tsvString).useDelimiter("\t");
// 		WikipediaLabelToFreebaseRecord record = new WikipediaLabelToFreebaseRecord();
// 		record.setFreebaseId(scanner.next());
// 		String label = scanner.next();
// 		// removes the first " and the final "@en
// 		if (!label.isEmpty()) {
// 			label = label.substring(1, label.length() - 4);
// 		} else {
// 			// empty label
// 			logger.warn("not label for line \n {}", tsvString);
// 		}
// 		record.setLabel(label);
// 		String wikilabel = scanner.next();
// 		scanner.close();
// 		wikilabel = wikilabel.substring(1, wikilabel.length() - 1);
// 		record.setWikipediaLabel(wikilabel);
// 		return record;
// 	}
// 
// 	protected String decode(String utf8endodedLabel) {
// 		return convert(utf8endodedLabel);
// 	}
// 
// 	public static class Parser implements
// 			RecordParser<WikipediaLabelToFreebaseRecord> {
// 
// 		public WikipediaLabelToFreebaseRecord decode(String record) {
// 			return WikipediaLabelToFreebaseRecord.parse(record);
// 		}
// 
// 		public String encode(WikipediaLabelToFreebaseRecord obj) {
// 			// TODO Auto-generated method stub
// 			return null;
// 		}
// 
// 	}
// 
// }


import static org.junit.Assert.assertEquals;
import org.junit.Test;
import it.unipi.di.acube.smaph.datasets.wikitofreebase.WikipediaLabelToFreebaseRecord;
/**
 *  Copyright 2014 Diego Ceccarelli
 *
 *  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.
 */

/**
 *  Copyright 2014 Diego Ceccarelli
 *
 *  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 it.unipi.di.acube.smaph.datasets.wikitofreebase;




/**
 * @author Diego Ceccarelli <diego.ceccarelli@isti.cnr.it>
 * 
 *         Created on Mar 15, 2014
 */
public class WikipediaLabelToFreebaseIdTest {

	@Test
	public void test() {
		WikipediaLabelToFreebaseRecord converter = new WikipediaLabelToFreebaseRecord();

		assertEquals(
				"/wikipedia/en_title/101_Dalmatians_(1996_film)",
				converter
						.convert("/wikipedia/en_title/101_Dalmatians_$00281996_film$0029"));
		assertEquals("/wikipedia/en_title/C._Z._Guest",
				converter.convert("/wikipedia/en_title/C$002E_Z$002E_Guest"));
		assertEquals("/wikipedia/en_title/Takashi_Kondō",
				converter.convert("/wikipedia/en_title/Takashi_Kond$014D"));

	}

	@Test
	public void parse() {
// Path: src/main/java/it/unipi/di/acube/smaph/datasets/wikitofreebase/WikipediaLabelToFreebaseRecord.java
// public class WikipediaLabelToFreebaseRecord {
// 
// 	private static final Logger logger = LoggerFactory
// 			.getLogger(WikipediaLabelToFreebaseRecord.class);
// 
// 	private String freebaseId;
// 	private String label;
// 	private String wikipediaLabel;
// 
// 	public WikipediaLabelToFreebaseRecord() {
// 		super();
// 	}
// 
// 	public String getCleanWikipediaLabel() {
// 		return convert(wikipediaLabel).replaceAll("/wikipedia/en_title/", "");
// 	}
// 
// 	public String getFreebaseId() {
// 		return freebaseId;
// 	}
// 
// 	public void setFreebaseId(String freebaseId) {
// 		this.freebaseId = freebaseId;
// 	}
// 
// 	public String getLabel() {
// 		return label;
// 	}
// 
// 	public void setLabel(String label) {
// 		this.label = label;
// 	}
// 
// 	public String getWikipediaLabel() {
// 		return wikipediaLabel;
// 	}
// 
// 	public void setWikipediaLabel(String wikipediaLabel) {
// 		this.wikipediaLabel = wikipediaLabel;
// 	}
// 
// 	final static private Pattern quotedCharPattern = Pattern
// 			.compile("\\$([0-9A-Fa-f]{4})");
// 
// 	protected String convert(String s) {
// 		// see
// 		// https://github.com/OpenRefine/OpenRefine/blob/master/extensions/freebase/src/com/google/refine/freebase/expr/MqlKeyUnquote.java
// 		StringBuffer sb = new StringBuffer();
// 
// 		int last = 0;
// 		Matcher m = quotedCharPattern.matcher(s);
// 		while (m.find()) {
// 			int start = m.start();
// 			int end = m.end();
// 			if (start > last) {
// 				sb.append(s.substring(last, start));
// 			}
// 			last = end;
// 
// 			sb.append((char) Integer.parseInt(s.substring(start + 1, end), 16));
// 		}
// 
// 		if (last < s.length()) {
// 			sb.append(s.substring(last));
// 		}
// 
// 		return sb.toString();
// 	}
// 
// 	public static WikipediaLabelToFreebaseRecord parse(String tsvString) {
// 		Scanner scanner = new Scanner(tsvString).useDelimiter("\t");
// 		WikipediaLabelToFreebaseRecord record = new WikipediaLabelToFreebaseRecord();
// 		record.setFreebaseId(scanner.next());
// 		String label = scanner.next();
// 		// removes the first " and the final "@en
// 		if (!label.isEmpty()) {
// 			label = label.substring(1, label.length() - 4);
// 		} else {
// 			// empty label
// 			logger.warn("not label for line \n {}", tsvString);
// 		}
// 		record.setLabel(label);
// 		String wikilabel = scanner.next();
// 		scanner.close();
// 		wikilabel = wikilabel.substring(1, wikilabel.length() - 1);
// 		record.setWikipediaLabel(wikilabel);
// 		return record;
// 	}
// 
// 	protected String decode(String utf8endodedLabel) {
// 		return convert(utf8endodedLabel);
// 	}
// 
// 	public static class Parser implements
// 			RecordParser<WikipediaLabelToFreebaseRecord> {
// 
// 		public WikipediaLabelToFreebaseRecord decode(String record) {
// 			return WikipediaLabelToFreebaseRecord.parse(record);
// 		}
// 
// 		public String encode(WikipediaLabelToFreebaseRecord obj) {
// 			// TODO Auto-generated method stub
// 			return null;
// 		}
// 
// 	}
// 
// }


// Path: src/test/java/it/unipi/di/acube/smaph/datasets/wikitofreebase/WikipediaLabelToFreebaseIdTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import it.unipi.di.acube.smaph.datasets.wikitofreebase.WikipediaLabelToFreebaseRecord;

/**
 *  Copyright 2014 Diego Ceccarelli
 *
 *  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.
 */

/**
 *  Copyright 2014 Diego Ceccarelli
 *
 *  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 it.unipi.di.acube.smaph.datasets.wikitofreebase;




/**
 * @author Diego Ceccarelli <diego.ceccarelli@isti.cnr.it>
 * 
 *         Created on Mar 15, 2014
 */
public class WikipediaLabelToFreebaseIdTest {

	@Test
	public void test() {
		WikipediaLabelToFreebaseRecord converter = new WikipediaLabelToFreebaseRecord();

		assertEquals(
				"/wikipedia/en_title/101_Dalmatians_(1996_film)",
				converter
						.convert("/wikipedia/en_title/101_Dalmatians_$00281996_film$0029"));
		assertEquals("/wikipedia/en_title/C._Z._Guest",
				converter.convert("/wikipedia/en_title/C$002E_Z$002E_Guest"));
		assertEquals("/wikipedia/en_title/Takashi_Kondō",
				converter.convert("/wikipedia/en_title/Takashi_Kond$014D"));

	}

	@Test
	public void parse() {
		WikipediaLabelToFreebaseRecord record = WikipediaLabelToFreebaseRecord