All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.itc.irst.tcc.sre.data.SentenceSetToHTML2 Maven / Gradle / Ivy

/*
 * Copyright 2005 FBK-irst (http://www.fbk.eu)
 *
 * 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 org.itc.irst.tcc.sre.data;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Loads an example set for relation extraction.
 *
 * @author 	Claudio Giuliano
 * @version %I%, %G%
 * @since		1.0
 */
public class SentenceSetToHTML2
{
	/**
	 * Define a static logger variable so that it references the
	 * Logger instance named SentenceSetToHTML2.
	 */
	static Logger logger = LoggerFactory.getLogger(SentenceSetToHTML2.class.getName());

	//
	private ExampleSet inputSet;

	//
	public SentenceSetToHTML2(File in, File out, File ans) throws Exception
	{

		//
		inputSet = new SentenceSetCopy();
		inputSet.read(new BufferedReader(new FileReader(in)));


		String[] a = readAnswer(ans, inputSet.size());

		PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(out)));
		toHtml(pw, a);
		pw.flush();
		pw.close();
	} // end constructor

	//
	public SentenceSetToHTML2(File in, File out) throws Exception
	{

		//
		inputSet = new SentenceSetCopy();
		inputSet.read(new BufferedReader(new FileReader(in)));


		String[] a = new String[inputSet.size()];
		for (int i=0;i");
		pw.print("");
		pw.print("");
		pw.print("");
		pw.print("");
		pw.print("");

		pw.print("");
		pw.print("");
		pw.print("");
		String oldID = "";
		boolean idClass = true;
		for (int i=0;i");
			else
				pw.print("");

			pw.print("");
			pw.print("");
			pw.print("");
			pw.print("");

			double v = Double.parseDouble(a[i]);
			//double target = ((Double) inputSet.y(i)).doubleValue();
			double target = Double.parseDouble((String) inputSet.y(i));

			if (target == 1.0)
			{
				baseline++;
			}
			/*
			if (target == v)
			{
				pw.print("");
				//total++;

			}
			else
			{
				pw.print("");
			}
			*/
		if (v == 0)
		{
			if (target == 1)
			{
				fn++;
				pw.print("");
			}
			else if (target == 2)
			{
				fn++;
				pw.print("");
			}
			else
			{
				tn++;
				pw.print("");
			}

		}
		else if (v == 1)
		{
			if (target == 0)
			{
				fp++;
				pw.print("");
			}
			else if (target == 1)
			{
				tp++;
				pw.print("");
			}
			else if (target == 2)
			{
				fp++;
				fn++;
				pw.print("");
			}
		}
		else if (v == 2)
		{
			if (target == 0)
			{
				fp++;
				pw.print("");
			}
			else if (target == 1)
			{
				fp++;
				fn++;
				pw.print("");
			}
			else if (target == 2)
			{
				tp++;
				pw.print("");
			}

		}



			pw.print("");
			pw.print("");
			pw.flush();
		} // end for i

		double p = tp / (tp + fp);
		double r = tp / (tp + fn);
		double f1 = (2 * p * r) / (p + r);
		double acc = (tp + tn) / (tp + tn + fp + fn);
		baseline /= (tp + tn + fp + fn);
		pw.print("
iidyacx
" + (i + 1) + "" + inputSet.id(i) + "" + inputSet.y(i) + "" + a[i] + "VXfnfntnfptpfpnfpfpntp

"); Sentence sent = (Sentence) inputSet.x(i); for (int j=0;j[" + f.getOffset() + "]"); pw.print(""); pw.print(f.getForm(true) + "[" + f.getType() + "]"); pw.print(""); } else if (f.getRole().equals(Word.TARGET_LABEL)) { pw.print("[" + f.getOffset() + "]"); pw.print(""); pw.print(f.getForm(true) + "[" + f.getType() + "]"); pw.print(""); } else pw.print(f.getForm(true)); /* if (f.getType().equals("PER")) pw.print("" + f.getForm(true) + "[" + f.getType() + "]"); else if (f.getType().equals("LOC")) pw.print("" + f.getForm(true) + "[" + f.getType() + "]"); else if (f.getType().equals("ORG")) pw.print("" + f.getForm(true) + "[" + f.getType() + "]"); else pw.print(f.getForm(true));*/ /* if (!f.getType().equals("O")) pw.print("" + f.getForm(true) + "[" + f.getType() + "]"); else pw.print(f.getForm(true)); */ /* if (f.getRole().equals(Word.AGENT_LABEL)) pw.print(""); else if (f.getRole().equals(Word.TARGET_LABEL)) pw.print(""); */ pw.print(" "); } // end for j int k = ((String) inputSet.id(i)).indexOf('-'); oldID = ((String) inputSet.id(i)).substring(0, k); pw.print("

"); pw.print(""); pw.print(""); //objects answers tp fp fn recall precision f-score pw.print(""); pw.print(""); pw.print(""); //objects answers tp fp fn recall precision f-score pw.print(""); pw.print(""); pw.print("
tpfpfntotalrecallprecisionf-scoreaccbaseline
" + (int) tp + "" + (int) fp + "" + (int) fn + "" + total + "" + myFormatter.format(r) + "" + myFormatter.format(p) + "" + myFormatter.format(f1) + "" + myFormatter.format(acc) + "" + myFormatter.format(baseline) + "
"); pw.print(""); pw.print(""); } // end toHtml // private String[] readAnswer(File ans, int size) throws Exception { LineNumberReader lr = new LineNumberReader(new FileReader(ans)); int i = 0; String line = null; String[] a = new String[size]; while ((line = lr.readLine()) != null) a[i++] = line; return a; } // end readAnswer // // // public static void main(String args[]) throws Exception // { // String logConfig = System.getProperty("log-config"); // if (logConfig == null) // logConfig = "log-config.txt"; // // PropertyConfigurator.configure(logConfig); // // if (args.length < 1) // { // System.err.println("java -mx512M org.itc.irst.tcc.sre.data.SentenceSetToHTML2 test-file [ans-file]"); // System.exit(-1); // } // // File in = new File(args[0]); // File out = new File(args[0] + ".html"); // // if (args.length == 1) // { // new SentenceSetToHTML2(in, out); // } // else if (args.length == 2) // { // File ans = new File(args[1]); // new SentenceSetToHTML2(in, out, ans); // } // // // } // end main } // end class SentenceSetToHTML2




© 2015 - 2025 Weber Informatics LLC | Privacy Policy