各位大神求帮忙,java编的语料标注方面的程序初学看不懂求解释,自己一些注释忽略就好,多谢多谢!!
public EventCorpusEditFrame() {
    keyWords.add("出发");
    keyWords.add("开出");
    keyWords.add("驶出");
    keyWords.add("到达");
    keyWords.add("到");
    keyWords.add("抵达");
    keyWords.add("求");

    initComponents();                                 

    pack();
}

private void initComponents() {                           
    // TODO Auto-generated method stub

    jMenuBar1 = new javax.swing.JMenuBar();                    
    jMenu1 = new javax.swing.JMenu();                 
    loadDataItem = new javax.swing.JMenuItem();        
    saveFileItem = new javax.swing.JMenuItem();         
    jSeparator1 = new javax.swing.JSeparator();         
    exitItem = new javax.swing.JMenuItem();              
    new javax.swing.JMenu();
    new javax.swing.JCheckBoxMenuItem();              

    setTitle("Parser");                                                    
    addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent evt) {
            exitForm(evt);
        }
    });

    jMenu1.setText("File");
    loadDataItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_O,
            java.awt.event.InputEvent.ALT_MASK));
    loadDataItem.setMnemonic('o');
    loadDataItem.setText("Load File");
    loadDataItem.setToolTipText("Load a data file.");
    loadDataItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            loadFileItemActionPerformed(evt);
        }
    });

    jMenu1.add(loadDataItem);

    saveFileItem.setText("Save File");
    saveFileItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveFileItemActionPerformed(evt);
        }
    });

    jMenu1.add(saveFileItem);
    jMenu1.add(jSeparator1);
    exitItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
            java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.ALT_MASK));
    exitItem.setMnemonic('x');
    exitItem.setText("Exit");
    exitItem.setToolTipText("Exits the program.");
    exitItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitItemActionPerformed(evt);
        }
    });

    jMenu1.add(exitItem);
    jMenuBar1.add(jMenu1);

    setJMenuBar(jMenuBar1);

    panel = new Panel();
    initPanels();
    getContentPane().add("Center", panel);

    pack();
}// GEN-END:initComponents

protected void SaveFileItemActionPerformed(ActionEvent evt) {
    // TODO Auto-generated method stub

}

protected void loadFileItemActionPerformed(ActionEvent evt) {
    // TODO Auto-generated method stub

}

private void exitItemActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST:event_exitItemActionPerformed
{// GEN-HEADEREND:event_exitItemActionPerformed
    exitForm(null);
}// GEN-LAST:event_exitItemActionPerformed

/**
 * Exit the Application
 */
private void exitForm(java.awt.event.WindowEvent evt) {// GEN-FIRST:event_exitForm
    System.exit(0);
}// GEN-LAST:event_exitForm

/**
 * @param args
 *            the command line arguments
 */
public static void main(String args[]) {

    ecef = new EventCorpusEditFrame();

// ecef.setSize(new Dimension(1000,800));
double width = Toolkit.getDefaultToolkit().getScreenSize().width; //得到当前屏幕分辨率的高

double height = Toolkit.getDefaultToolkit().getScreenSize().height; //得到当前屏幕分辨率的宽

ecef.setSize((int)width,(int)height); //设置大小

ecef.setLocation(0,0); //设置窗体居中显示
ecef.setVisible(true);
}

private void initPanels()// GEN-BEGIN:initComponents
{
    directoryTextField = new javax.swing.JTextField(15);
    directoryTextField.setText("F:/event-extract/result");
    senteneList = new javax.swing.JTable(250,3);
    senteneList.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    TableColumn column = senteneList.getColumnModel().getColumn(0);                            //0是代表的第一列
    column.setPreferredWidth(30);                                                      //这个是设置列的宽度 
    column = senteneList.getColumnModel().getColumn(1);                   //0是代表的第一列
    column.setPreferredWidth(10);                                               //这个是设置列的宽度 
    column = senteneList.getColumnModel().getColumn(2);                                   //0是代表的第一列
    column.setPreferredWidth(200);                                              //这个是设置列的宽度 

// senteneList.setVisibleRowCount(5);
JScrollPane senteneListScrollPane = new javax.swing.JScrollPane(senteneList);
senteneListScrollPane.setViewportView(senteneList);
senteneListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    sourceFile= new javax.swing.JTextPane();
    sourceFile.setEditable(false);
    JButton OKButton = new javax.swing.JButton();

    OKButton.setText("确定");
    OKButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (directoryTextField.getText().length() > 0)
                directory = directoryTextField.getText();
            LinkedList<File> fileLists = (LinkedList<File>) FileUtils
                    .listFiles(new File(directory), new String[] { "xml" },
                            false);
            int rowIndex=0;
            for (File f : fileLists)
            {           

                try {
                    SAXReader sax = new SAXReader();
                Document doc = sax.read(f);
                List<DefaultElement> d = (List<DefaultElement>) doc.selectNodes("xml4nlp/doc");

                if(d.get(0).attribute("isEdited")!=null&&d.get(0).attributeValue("isEdited").equalsIgnoreCase("y"))
                    {
                    senteneList.getModel().setValueAt("√", rowIndex,1 );
                    } 
                }catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                senteneList.getModel().setValueAt(rowIndex, rowIndex,0 );
                senteneList.getModel().setValueAt(f.getName(), rowIndex,2 );
                rowIndex++;
            }
        }
    });

    senteneList.getSelectionModel().addListSelectionListener(new ListSelectionListener(){

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // TODO Auto-generated method stub
            if (senteneList.getSelectedRow() >= 0&&senteneList.getSelectedRow()!=currentRow) {
                try {
                    eventID=0;                                                     //每次更改xml文件都对事件id重新编号

                    currentRow = senteneList.getSelectedRow();
                    currentFilePath = directory + "/"+ senteneList.getModel().getValueAt(senteneList.getSelectedRow(),2);
                    getSourceFile().setText(FileUtils.readFileToString(
                            new File(currentFilePath),"UTF8"));

// List lines = FileUtils.readLines(
// new File(currentFilePath),"UTF8");
// cont = lines.get(3);
// if(cont.indexOf("cont=\"")==-1)
// cont = lines.get(4);
// cont = cont.substring(cont.indexOf("cont=\"") + 6,
// cont.indexOf(">") - 1);

                    SAXReader sax = new SAXReader();
                    document = sax.read(new File(currentFilePath));

                    List<DefaultElement> doc = (List<DefaultElement>) document.selectNodes("xml4nlp/doc");
                    if(doc.get(0).attribute("cont")!=null)
                    {
                    cont = doc.get(0).attributeValue("cont").trim();
                    content.setText(cont);
                    DecorateKeyWords(content);

                    startMapID.clear();
                    endMapID.clear();
                    computePosMap(cont);

                    System.out.println(startMapID);
                    System.out.println(endMapID);
                    }

                    System.out.println(cont);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (DocumentException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }


    });

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐