⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicsentencewritecontroller.java

📁 用java实现的关联规则算法Apriori算法
💻 JAVA
字号:
package dragon.ir.index.sentence;

import dragon.ir.index.*;
import dragon.nlp.*;
import dragon.onlinedb.*;
import java.util.ArrayList;

/**
 * <p>The basic controller for writting sentence indexing information to disk </p>
 * <p> </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: IST, Drexel University</p>
 * @author Davis Zhou
 * @version 1.0
 */

public class BasicSentenceWriteController extends AbstractIndexWriteController{
    private IndexWriter indexWriter;
    private BasicCollectionWriter rawBW;
    private FileIndex fileIndex;

    public BasicSentenceWriteController(String directory, boolean relationSupported, boolean indexConceptEntry) {
        super(relationSupported, indexConceptEntry);
        fileIndex=new FileIndex(directory,relationSupported);
    }

    public void initialize(){
        if(initialized)
            return;

        docKeyList=new SimpleElementList(fileIndex.getDocKeyListFilename(),true);
        termKeyList = new SimpleElementList(fileIndex.getTermKeyListFilename(), true);
        if (relationSupported)
            relationKeyList = new SimplePairList(fileIndex.getRelationKeyListFilename(), true);
        indexWriter = new BasicIndexWriter(fileIndex.getDirectory(), relationSupported);
        indexWriter.initialize();
        initialized=true;
    }

    public void flush(){
         indexWriter.flush();
    }

    public void close(){
        try{
            docKeyList.close();
            termKeyList.close();
            if (relationSupported)
                relationKeyList.close();
            indexWriter.close();
            initialized=false;
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    public boolean addRawSentence(Sentence sent){
        BasicArticle article;

        try{
            article=new BasicArticle();
            article.setKey(curDocKey);
            article.setTitle(sent.toString());
            rawBW.add(article);
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public boolean write(ArrayList conceptList){
        IRTerm[] arrTerms;
        IRDoc curDoc;
        try{
            if (curDocKey ==null)
                return false;

            curDoc = new IRDoc(curDocKey);
            curDoc.setIndex(curDocIndex);
            arrTerms = getIRTermArray(generateIRTermList(conceptList), curDoc);
            return indexWriter.write(curDoc, arrTerms);
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public boolean write(ArrayList conceptList, ArrayList tripleList){
        IRTerm[] arrTerms;
        IRRelation[] arrRelations;
        IRDoc curDoc;
        try{
            if (curDocKey==null)
                return false;

            curDoc = new IRDoc(curDocKey);
            curDoc.setIndex(curDocIndex);
            arrTerms = getIRTermArray(generateIRTermList(conceptList), curDoc);
            arrRelations = getIRRelationArray(generateIRRelationList(tripleList), curDoc);
            return indexWriter.write(curDoc, arrTerms, arrRelations);
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -