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("i id y a c x ");
pw.print(" ");
String oldID = "";
boolean idClass = true;
for (int i=0;i");
else
pw.print("");
pw.print("" + (i + 1) + " ");
pw.print("" + inputSet.id(i) + " ");
pw.print("" + inputSet.y(i) + " ");
pw.print("" + a[i] + " ");
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("V ");
//total++;
}
else
{
pw.print("X ");
}
*/
if (v == 0)
{
if (target == 1)
{
fn++;
pw.print("fn ");
}
else if (target == 2)
{
fn++;
pw.print("fn ");
}
else
{
tn++;
pw.print("tn ");
}
}
else if (v == 1)
{
if (target == 0)
{
fp++;
pw.print("fp ");
}
else if (target == 1)
{
tp++;
pw.print("tp ");
}
else if (target == 2)
{
fp++;
fn++;
pw.print("fpn ");
}
}
else if (v == 2)
{
if (target == 0)
{
fp++;
pw.print("fp ");
}
else if (target == 1)
{
fp++;
fn++;
pw.print("fpn ");
}
else if (target == 2)
{
tp++;
pw.print("tp ");
}
}
pw.print("");
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.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("
");
pw.print("");
pw.print("");
//objects answers tp fp fn recall precision f-score
pw.print("tp fp fn total recall precision f-score acc baseline ");
pw.print(" ");
pw.print("");
//objects answers tp fp fn recall precision f-score
pw.print("" + (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("
");
pw.print("");
pw.print("