1 package jp.naist.se.stigmata.format.csv;
\r
7 import java.io.PrintWriter;
\r
8 import java.util.ArrayList;
\r
9 import java.util.HashMap;
\r
10 import java.util.LinkedHashMap;
\r
11 import java.util.List;
\r
12 import java.util.Map;
\r
14 import jp.naist.se.stigmata.ComparisonPair;
\r
15 import jp.naist.se.stigmata.ComparisonPairElement;
\r
16 import jp.naist.se.stigmata.ComparisonResultSet;
\r
17 import jp.naist.se.stigmata.format.AbstractBirthmarkComparisonResultFormat;
\r
18 import jp.naist.se.stigmata.result.CertainPairComparisonResultSet;
\r
24 * @author Haruaki TAMADA
\r
25 * @version $Revision$ $Date$
\r
27 public class BirthmarkComparisonResultCsvFormat extends AbstractBirthmarkComparisonResultFormat{
\r
28 private BirthmarkExtractionResultCsvFormat list;
\r
30 public BirthmarkComparisonResultCsvFormat(BirthmarkExtractionResultCsvFormat list){
\r
35 public void printResult(PrintWriter out, ComparisonPair pair){
\r
36 list.printBirthmarkSet(out, pair.getTarget1());
\r
37 list.printBirthmarkSet(out, pair.getTarget2());
\r
39 for(ComparisonPairElement element: pair){
\r
40 out.print("compare,");
\r
41 out.print(element.getType());
\r
43 out.println(element.getSimilarity());
\r
49 public void printResult(PrintWriter out, ComparisonResultSet resultset){
\r
50 if(resultset instanceof CertainPairComparisonResultSet){
\r
51 printResultImpl(out, (CertainPairComparisonResultSet)resultset);
\r
54 printResultImpl(out, resultset);
\r
58 private void printResultImpl(PrintWriter out, CertainPairComparisonResultSet resultset){
\r
59 for(ComparisonPair pair: resultset){
\r
60 out.print(pair.getTarget1().getName());
\r
62 out.print(pair.getTarget1().getName());
\r
64 out.println(pair.calculateSimilarity());
\r
68 private void printResultImpl(PrintWriter out, ComparisonResultSet resultset){
\r
69 Map<String, Map<String, Double>> map = new LinkedHashMap<String, Map<String, Double>>();
\r
70 List<String> names = new ArrayList<String>();
\r
72 for(ComparisonPair pair: resultset){
\r
73 Map<String, Double> val = map.get(pair.getTarget1().getName());
\r
75 val = new HashMap<String, Double>();
\r
77 val.put(pair.getTarget2().getName(), new Double(pair.calculateSimilarity()));
\r
78 if(!names.contains(pair.getTarget2().getName())){
\r
79 names.add(pair.getTarget2().getName());
\r
81 map.put(pair.getTarget1().getName(), val);
\r
84 for(String name: names){
\r
89 for(Map.Entry<String, Map<String, Double>> entry: map.entrySet()){
\r
90 out.print(entry.getKey());
\r
91 Map<String, Double> element = entry.getValue();
\r
92 for(String name: names){
\r
94 Double v = element.get(name);
\r
96 out.print(v.doubleValue());
\r