java:导入数据无法解析 - 导入data.Frame

时间:2014-03-31 03:18:06

标签: java eclipse import dataframe

我使用了我大学讲师的一些代码来完成一个新项目,一切似乎都在起作用,除了那一小块,我想要导入" data.Frame&#34 ;而且我只是不知道缺少了什么,所以我的代码会起作用。如果有人知道解决方案或者可以给我一个替代方案,那么我可以导入所需的" Frame" - 太棒了!

我正在使用eclipse!

代码是:

import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import data.Frame; // HERE IS THE PROBLEM!


/**
 * Compares the annotations of two or more annotators and groups them together,
 * before they are written to a csv file.
 */
 public class ComparisonWriter
{
private String content;

private final int A1 = 1;
private final int A2 = 2;
private final int A3 = 3;
//  private final int A4 = 4;

private int numberOfAnnotators = 3;

String outputFileName = "data/200Saetze/Gruppe 1/comparison_buchpreis2_alle.csv";

String inputA1 = "data/200Saetze/Gruppe 1/Daniela/buchpreis2.xml";
String inputA2 = "data/200Saetze/Gruppe 1/Inga/buchpreis2.xml";
String inputA3 = "data/200Saetze/Gruppe 1/Stefan/buchpreis2.xml";

public ComparisonWriter()
{
    content = "SatzID;Annotator;Frame;SE;exact;partial;Source;Annotator;SourceString;" +
            "exact;exact ohne leer;exact ohne leer (SE);partial;koreferent;SourceFlag;exact;Target;Annotator;" +
            "TargetString;exact;exact ohne leer;exact ohne leer (SE);partial;koreferent;TargetFlag;;FrameFlag";

    AnnotationReader annotationReaderA1 = new AnnotationReader(inputA1);
    Map<String, List<Frame>> seAnnotator1 = annotationReaderA1.getAllSubjectiveExpressions();
    AnnotationReader annotationReaderA2 = new AnnotationReader(inputA2);
    Map<String, List<Frame>> seAnnotator2 = annotationReaderA2.getAllSubjectiveExpressions();
    AnnotationReader annotationReaderA3 = new AnnotationReader(inputA3);
    Map<String, List<Frame>> seAnnotator3 = annotationReaderA3.getAllSubjectiveExpressions();

    Set<String> sentences = seAnnotator1.keySet();
    for (String sentence : sentences)
    {
        //add leading zeros
        content += "\n\n" + sentence + ";" + annotationReaderA1.sentenceStrings.get(sentence);

        //add the annotations in a sorted order
        Map<Integer, List<Frame>> allFramesInSentence = new HashMap<Integer, List<Frame>>();
        allFramesInSentence.put(A1, seAnnotator1.get(sentence));
        allFramesInSentence.put(A2, seAnnotator2.get(sentence));
        allFramesInSentence.put(A3, seAnnotator3.get(sentence));
 //         allFramesInSentence.put(A4, seAnnotator4.get(sentence));
 //         
        //get the one with the most annotations
        int largest = getIndexOfLargestList(allFramesInSentence);

        if(largest == 0)
            continue;

        for (int i = 0; i < allFramesInSentence.get(largest).size(); i++)
        {
            Frame frame = allFramesInSentence.get(largest).get(i);
            content += "\n\n;A" + largest + ";" + frame;
            frame.setConsidered(true);
            findOverlappingAnnotations(allFramesInSentence, largest, frame);
        }

        //Check, if there are not considered annotations in one of the frame lists for that sentence.
        for (int a = 1; a <= 4; a++)
        {
            List<Frame> frameList = allFramesInSentence.get(a);
            if(a != largest && frameList != null)
            {
                for (Frame frame : frameList)
                {
                    if(frame.isConsidered() == false)
                    {
                        content += "\n\n;A" + a + ";" + frame;
                        frame.setConsidered(true);
                        findOverlappingAnnotations(allFramesInSentence, a, frame);
                    }
                }
            }
        }
    }

    writeContentToFile(content, outputFileName, false);
}

/**
 * Find overlapping annotations.
 * @param frames - list of frames, potentially overlapping with the given one.
 * @param largest
 * @param frame - frame in question.
 */
private void findOverlappingAnnotations(Map<Integer, List<Frame>> frames,
        int largest, Frame frame)
{
    for (int a = 1; a <= 4; a++)
    {
        //If j is not the current largest frame list and there are annotated frames 
        //in from this annotator (a)
        if(a != largest && frames.get(a) != null)
        {
            for (Frame compareFrame : frames.get(a))
            {
                addOverlappingAnnotations2Conent(frame, a, compareFrame);
            }
        }
    }
}

/**
 * Add overlapping Annotations (measured by matching ids) to the content attribute.
 * @param frame
 * @param a - Annotator index
 * @param compareFrame
 */
private void addOverlappingAnnotations2Conent(Frame frame, int a,
        Frame compareFrame)
{
    List<String> terminalIDs = compareFrame.getTerminalIDs();
    for (String id : terminalIDs)
    {
        if(compareFrame.isConsidered())
            break;
        if(frame.getTerminalIDs().contains(id))
        {
            //Write it to the content
            content += "\n;A" + a + ";" + compareFrame;
            compareFrame.setConsidered(true);
            break;
        }
    }
}

/**
 * Get the index of the largest frame list in the map.
 * @param frames -  a map with all the frames for each annotator (key: annotator)
 * @return The index of the largest frame list.
 */
private int getIndexOfLargestList(Map<Integer, List<Frame>> frames)
{
    int size = 0;
    int largest = 0;

    for(int a = 0; a <= numberOfAnnotators; a++)
    {
        if(frames.get(a) != null)
        {
            if(frames.get(a).size() > size)
                largest = a;
        }
    }

    return largest;
}

2 个答案:

答案 0 :(得分:0)

您需要获取Frame类的源代码或类文件的副本,并将其添加到项目中。源代码应该在一个名为Frame.java的文件中。

答案 1 :(得分:0)

你的类路径中基本上需要Frame类。如果你在某个jar中有这个类,那么将该jar添加到你的类路径中。