def blp_en(pTrains,pTests): trains=[CDocument(label,p.en) for label,p in pTrains] tests=[CDocument(label,p.en) for label,p in pTests] for d in trains+tests: d.words['SMOOTH']=1 blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def classify_translate_cerelation(pTrains,pTests): dict=CEDict() pmi=PMI() trains=[] tests=[] for label,p in pTrains: words=getTranlateFeaturesCERelation(p,dict,pmi) trains.append(CDocument(label,words)) for label,p in pTests: words=getTranlateFeaturesCERelation(p,dict,pmi) tests.append(CDocument(label,words)) return me_classify(trains,tests)
def classify_sentiment(pTrains,pTests): cn_lexicon=CnSentimentLexicon() en_lexicon=EnSentimentLexicon() trains=[] tests=[] for label,p in pTrains: words=getSentimentFeatures(p,cn_lexicon,en_lexicon) trains.append(CDocument(label,words)) for label,p in pTests: words=getSentimentFeatures(p,cn_lexicon,en_lexicon) tests.append(CDocument(label,words)) return me_classify(trains,tests)
def blp_translate_simple(pTrains,pTests): dict=CEDict() trains=[] tests=[] for label,p in pTrains: words=getTranlateFeatures(p,dict) trains.append(CDocument(label,words)) for label,p in pTests: words=getTranlateFeatures(p,dict) tests.append(CDocument(label,words)) blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def classify_translate_simple(pTrains,pTests): dict=CEDict() syn=Synonym() # lm=LanguageModel() trains=[] tests=[] for label,p in pTrains: words=getTranlateFeatures(p,dict) trains.append(CDocument(label,words)) for label,p in pTests: words=getTranlateFeatures(p,dict) tests.append(CDocument(label,words)) return me_classify(trains,tests)
def blp_sentiment(pTrains,pTests): cn_lexicon=CnSentimentLexicon() en_lexicon=EnSentimentLexicon() trains=[] tests=[] for label,p in pTrains: words=getSentimentFeatures(p,cn_lexicon,en_lexicon) trains.append(CDocument(label,words)) for label,p in pTests: words=getSentimentFeatures(p,cn_lexicon,en_lexicon) tests.append(CDocument(label,words)) blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def blp_translate_pmi(pTrains,pTests): dict=CEDict() syn=Synonym() pmi=PMI() trains=[] tests=[] for label,p in pTrains: words= getTranlateFeaturesPMI(p,dict,pmi) trains.append(CDocument(label,words)) for label,p in pTests: words= getTranlateFeaturesPMI(p,dict,pmi) tests.append(CDocument(label,words)) blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def blp_translate_lm(pTrains,pTests): dict=CEDict() syn=Synonym() lm=LanguageModel() trains=[] tests=[] for label,p in pTrains: words=getTranslateFeaturesByLM(p,dict,lm) trains.append(CDocument(label,words)) for label,p in pTests: words=getTranslateFeaturesByLM(p,dict,lm) tests.append(CDocument(label,words)) blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def mMakeBooks(self, mynBooks): # A collection has lots of books for icoll in xrange(mynBooks): ndocsize = util.fnnCalcDocSize(self.nValue) cDoc = CDocument(ndocsize, self.sClientID, self.ID) self.lDocIDs.append(cDoc.ID) self.lDocIDsRemaining.append(cDoc.ID) self.nDocsRemaining += 1 return self.ID
def blp_sense_sentiment(pTrains,pTests): dict=CEDict() pmi=PMI() cn_lexicon=CnSentimentLexicon() en_lexicon=EnSentimentLexicon() trains=[] tests=[] for label,p in pTrains: words=getFeaturesSenseAndSentiment(p,dict,pmi,cn_lexicon,en_lexicon) trains.append(CDocument(label,words)) for label,p in pTests: words=getFeaturesSenseAndSentiment(p,dict,pmi,cn_lexicon,en_lexicon) tests.append(CDocument(label,words)) blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def blp_translate_cerelation(pTrains,pTests): dict=CEDict() pmi=PMI() trains=[] tests=[] for label,p in pTrains: words=getTranlateFeaturesCERelation(p,dict,pmi) trains.append(CDocument(label,words)) for label,p in pTests: words=getTranlateFeaturesCERelation(p,dict,pmi) tests.append(CDocument(label,words)) # for d in trains+tests: # d.words['SMOOTH']=1 blp=BLP(trains+tests) blp.LP_Classify(trains,tests)
def classify_en(pTrains,pTests): trains=[CDocument(label,p.en) for label,p in pTrains] tests=[CDocument(label,p.en) for label,p in pTests] return me_classify(trains,tests)
def classify_all(pTrains,pTests): trains=[CDocument(label,p.words) for label,p in pTrains] tests=[CDocument(label,p.words) for label,p in pTests] return me_classify(trains,tests)