Search in sources :

Example 1 with structures._ParentDoc

use of structures._ParentDoc in project IR_Base by Linda-sunshine.

the class ParentChildAnalyzer method filterParentAndChildDoc.

public void filterParentAndChildDoc() {
    System.out.println("Before filtering\t" + m_corpus.getSize());
    int corpusSize = m_corpus.getCollection().size();
    ArrayList<Integer> removeIndexList = new ArrayList<Integer>();
    int numberOfComments = 0;
    for (int i = corpusSize - 1; i > -1; i--) {
        // for (int i = 0; i < corpusSize; i++) {
        _Doc d = m_corpus.getCollection().get(i);
        if (d instanceof _ParentDoc) {
            _ParentDoc pDoc = (_ParentDoc) d;
            if (pDoc.m_childDocs.size() > 8) {
                numberOfComments += 1;
            }
            if (pDoc.m_childDocs.size() == 0)
                removeIndexList.add(i);
        }
    }
    System.out.println("number of comments > 8 \t" + numberOfComments);
    for (int i : removeIndexList) {
        _Doc d = m_corpus.getCollection().get(i);
        System.out.println("removing parent without child \t" + d.getName());
        m_corpus.getCollection().remove(i);
    }
    System.out.println("after filtering\t" + m_corpus.getSize());
}
Also used : structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) ArrayList(java.util.ArrayList)

Example 2 with structures._ParentDoc

use of structures._ParentDoc in project IR_Base by Linda-sunshine.

the class ParentChildAnalyzer method loadChildDoc.

public void loadChildDoc(String fileName) {
    if (fileName == null || fileName.isEmpty())
        return;
    JSONObject json = LoadJSON(fileName);
    String content = Utils.getJSONValue(json, "content");
    String name = Utils.getJSONValue(json, "name");
    String parent = Utils.getJSONValue(json, "parent");
    String title = Utils.getJSONValue(json, "title");
    // 
    // _ChildDoc4BaseWithPhi d = new _ChildDoc4BaseWithPhi(m_corpus.getSize(),
    // name, "", content, 0);
    // _ChildDoc4BaseWithPhi_Hard d = new _ChildDoc4BaseWithPhi_Hard(m_corpus.getSize(), name, "", content, 0) ;
    // _ChildDoc4ChildPhi d = new _ChildDoc4ChildPhi(m_corpus.getSize(),
    // name,
    // "", content, 0);
    // _ChildDoc4TwoPhi d = new _ChildDoc4TwoPhi(m_corpus.getSize(), name, "", content, 0);
    // _ChildDoc4ThreePhi d = new _ChildDoc4ThreePhi(m_corpus.getSize(), name,
    // "", content, 0);
    // _ChildDoc4OneTopicProportion d = new _ChildDoc4OneTopicProportion(m_corpus.getSize(), name, "", content, 0);
    _ChildDoc d = new _ChildDoc(m_corpus.getSize(), name, "", content, 0);
    if (parentHashMap.containsKey(parent)) {
        if (AnalyzeDoc(d)) {
            // this is a valid child document
            // if (parentHashMap.containsKey(parent)) {
            _ParentDoc pDoc = parentHashMap.get(parent);
            d.setParentDoc(pDoc);
            pDoc.addChildDoc(d);
        } else {
        // System.err.format("filtering comments %s!\n", parent);
        }
    } else {
    // System.err.format("[Warning]Missing parent document %s!\n", parent);
    }
}
Also used : structures._ChildDoc(structures._ChildDoc) JSONObject(json.JSONObject) structures._ParentDoc(structures._ParentDoc)

Example 3 with structures._ParentDoc

use of structures._ParentDoc in project IR_Base by Linda-sunshine.

the class LDAGibbs4AC method Evaluation.

public double Evaluation(int i) {
    m_collectCorpusStats = false;
    double perplexity = 0, loglikelihood, totalWords = 0, sumLikelihood = 0;
    System.out.println("In Normal");
    for (_Doc d : m_testSet) {
        loglikelihood = inference(d);
        sumLikelihood += loglikelihood;
        perplexity += loglikelihood;
        totalWords += d.getDocTestLength();
        for (_ChildDoc cDoc : ((_ParentDoc) d).m_childDocs) {
            totalWords += cDoc.getDocTestLength();
        }
    }
    System.out.println("total Words\t" + totalWords + "perplexity\t" + perplexity);
    infoWriter.println("total Words\t" + totalWords + "perplexity\t" + perplexity);
    perplexity /= totalWords;
    perplexity = Math.exp(-perplexity);
    sumLikelihood /= m_testSet.size();
    System.out.format("Test set perplexity is %.3f and log-likelihood is %.3f\n", perplexity, sumLikelihood);
    infoWriter.format("Test set perplexity is %.3f and log-likelihood is %.3f\n", perplexity, sumLikelihood);
    return perplexity;
}
Also used : structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc)

Example 4 with structures._ParentDoc

use of structures._ParentDoc in project IR_Base by Linda-sunshine.

the class LDAGibbs4AC method initialize_probability.

protected void initialize_probability(Collection<_Doc> collection) {
    createSpace();
    for (int i = 0; i < number_of_topics; i++) {
        Arrays.fill(topic_term_probabilty[i], 0);
        Arrays.fill(word_topic_sstat[i], d_beta);
    }
    Arrays.fill(m_sstat, d_beta * vocabulary_size);
    for (_Doc d : collection) {
        if (d instanceof _ParentDoc) {
            for (_Stn stnObj : d.getSentences()) {
                stnObj.setTopicsVct(number_of_topics);
            }
            d.setTopics4Gibbs(number_of_topics, d_alpha);
        } else if (d instanceof _ChildDoc) {
            ((_ChildDoc) d).setTopics4Gibbs_LDA(number_of_topics, d_alpha);
        }
        for (_Word w : d.getWords()) {
            word_topic_sstat[w.getTopic()][w.getIndex()]++;
            m_sstat[w.getTopic()]++;
        }
    }
    imposePrior();
}
Also used : structures._Stn(structures._Stn) structures._ChildDoc(structures._ChildDoc) structures._Doc(structures._Doc) structures._ParentDoc(structures._ParentDoc) structures._Word(structures._Word)

Example 5 with structures._ParentDoc

use of structures._ParentDoc in project IR_Base by Linda-sunshine.

the class LDAGibbs4AC method collectParentStats.

protected void collectParentStats(_Doc d) {
    _ParentDoc pDoc = (_ParentDoc) d;
    for (int k = 0; k < this.number_of_topics; k++) pDoc.m_topics[k] += pDoc.m_sstat[k];
    pDoc.collectTopicWordStat();
}
Also used : structures._ParentDoc(structures._ParentDoc)

Aggregations

structures._ParentDoc (structures._ParentDoc)72 structures._ChildDoc (structures._ChildDoc)50 structures._Doc (structures._Doc)39 structures._Stn (structures._Stn)30 File (java.io.File)29 PrintWriter (java.io.PrintWriter)22 FileNotFoundException (java.io.FileNotFoundException)20 HashMap (java.util.HashMap)17 structures._Word (structures._Word)17 structures._SparseFeature (structures._SparseFeature)14 structures._ChildDoc4BaseWithPhi (structures._ChildDoc4BaseWithPhi)8 Map (java.util.Map)7 ArrayList (java.util.ArrayList)6 structures._ParentDoc4DCM (structures._ParentDoc4DCM)4 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 JSONObject (json.JSONObject)2 Feature (Classifier.supervised.liblinear.Feature)1 FeatureNode (Classifier.supervised.liblinear.FeatureNode)1 Model (Classifier.supervised.liblinear.Model)1