1)司法公正是指司法權(quán)運(yùn)作過(guò)程中各種因素達(dá)到的理想狀態(tài),是現(xiàn)代社會(huì)政治民主、進(jìn)步的重要標(biāo)志,也是現(xiàn)代國(guó)家經(jīng)濟(jì)發(fā)展和社會(huì)穩(wěn)定的重要保證。它是法律的自身要求,也是依法治國(guó)的要求,其基本內(nèi)涵是要在司法活動(dòng)的過(guò)程和結(jié)果中體現(xiàn)公平、平等、正當(dāng)、正義的精神。其主體是以法官為主的司法人員。司法公正的對(duì)象包括各類(lèi)案件的當(dāng)事人及其他訴訟參與人。司法公正包括實(shí)體公正和程序公正,前者是司法公正的根本目標(biāo),后者是司法公正的重要保障。整體公正與個(gè)體公正的關(guān)系反映了司法公正的價(jià)值定位和取向。
2)司法公正既要求法院的審判過(guò)程堅(jiān)持正當(dāng)平等的原則,也要求法院的審判結(jié)果體現(xiàn)公平正義的精神。前者可以稱(chēng)為程序公正,后者可以稱(chēng)為實(shí)體公正。它們共同構(gòu)成了司法公正的基本內(nèi)容。
司法公正,是指司法權(quán)運(yùn)作過(guò)程中各種因素達(dá)到的理想狀態(tài),是現(xiàn)代社會(huì)政治民主、進(jìn)步的重要標(biāo)志,也是現(xiàn)代國(guó)家經(jīng)濟(jì)發(fā)展和社會(huì)穩(wěn)定的重要保證。
司法公正基本內(nèi)涵是要在司法活動(dòng)的過(guò)程和結(jié)果中體現(xiàn)公平、平等、正當(dāng)、正義的精神。對(duì)象包括各類(lèi)案件的當(dāng)事人及其他訴訟參與人。司法公正包括實(shí)體公正和程序公正,前者是司法公正的根本目標(biāo),后者是司法公正的重要保障。
司法公正,或曰公正司法,其基本內(nèi)涵就是要在司法活動(dòng)的過(guò)程和結(jié)果中堅(jiān)持和體現(xiàn)公平與正義的原則。從狹義上講,司法主要指法院的審判活動(dòng);公正的含義則包括公平、平等、正當(dāng)、正義等。司法公正既要求法院的審判過(guò)程遵循平等和正當(dāng)?shù)脑瓌t,也要求法院的審判結(jié)果體現(xiàn)公平和正義的精神。
政策主要包括以下幾個(gè)方面:
1. 加強(qiáng)司法獨(dú)立:中央政府要求各級(jí)法院和檢察機(jī)關(guān)充分發(fā)揮獨(dú)立審判權(quán)和檢察權(quán),保障司法工作的公正、公平和獨(dú)立性。
2. 推進(jìn)司法透明:中央政府鼓勵(lì)各級(jí)法院和檢察機(jī)關(guān)加強(qiáng)信息公開(kāi),提高公眾對(duì)司法工作的了解度。同時(shí),加強(qiáng)對(duì)司法過(guò)程的監(jiān)督,確保司法程序的公開(kāi)、公正和透明。
3. 構(gòu)建司法保障體系:中央政府鼓勵(lì)各級(jí)法院和檢察機(jī)關(guān)積極推進(jìn)司法改革,建設(shè)現(xiàn)代化司法制度和司法保障體系,加快建設(shè)法治國(guó)家。
4. 建立懲治腐敗的長(zhǎng)效機(jī)制:中央政府重視打擊司法腐敗行為,強(qiáng)化反貪腐斗爭(zhēng)力度,并加強(qiáng)對(duì)司法工作人員的管理和監(jiān)督。
5. 保障司法權(quán)益:中央政府重視維護(hù)律師、當(dāng)事人等司法參與者的合法權(quán)益,保障他們?cè)谒痉ㄟ^(guò)程中的權(quán)利和利益。
需要注意的是,司法公正是一個(gè)復(fù)雜的系統(tǒng)性問(wèn)題,需要社會(huì)各方面的共同努力才能夠?qū)崿F(xiàn)。中央政府推動(dòng)司法公正的政策必須與基層機(jī)構(gòu)的落實(shí)和改進(jìn)相結(jié)合,以保障司法工作的公正、公平和透明。
司法公正作為一個(gè)社會(huì)正義的指標(biāo),是任何一個(gè)健康民主社會(huì)的基石之一。它確保了每個(gè)人都能夠在法律面前受到公平對(duì)待,不受任何歧視。司法公正關(guān)乎法治國(guó)家的根本原則,也是法治社會(huì)的核心價(jià)值。
在現(xiàn)代社會(huì)中,司法公正不僅僅是一個(gè)法律概念,更是民眾對(duì)公平正義的期許和追求。當(dāng)人們對(duì)司法系統(tǒng)失去信心,就會(huì)打擊社會(huì)的穩(wěn)定和公眾對(duì)法治的認(rèn)同感。因此,確保司法公正的實(shí)施對(duì)于社會(huì)的可持續(xù)發(fā)展至關(guān)重要。
司法公正是法治社會(huì)的重要組成部分。在一個(gè)法治社會(huì)中,法律不僅僅是權(quán)威的象征,更是保護(hù)公民權(quán)益和保障社會(huì)穩(wěn)定的法定準(zhǔn)則。司法公正確保法律的透明和平等執(zhí)行,進(jìn)一步鞏固了法治社會(huì)的基礎(chǔ)。
司法公正對(duì)于法治社會(huì)的影響是多方面的。首先,它確保了公權(quán)力的行使受到限制和監(jiān)督。司法公正使政府和其他權(quán)力機(jī)構(gòu)在行使權(quán)力時(shí)受到法律約束,不得濫用職權(quán)或脅迫個(gè)人。這種制約力量有助于維護(hù)社會(huì)的平等性和公正性。
其次,司法公正提供了一個(gè)公平的司法程序,確保了每個(gè)人在面對(duì)法律時(shí)都能夠享有適當(dāng)?shù)姆沙绦蚝蜋?quán)利保障。這有助于保護(hù)個(gè)人的權(quán)益,并避免了司法系統(tǒng)的偏見(jiàn)和不公正。
另外,司法公正也為社會(huì)帶來(lái)了積極的效果。一個(gè)有司法公正的社會(huì)能夠吸引更多的投資和商業(yè)機(jī)會(huì),因?yàn)槠髽I(yè)和個(gè)人都希望他們的利益能夠在法律框架下得到保護(hù)。司法公正也激發(fā)了公民的參與感和社會(huì)責(zé)任感,促進(jìn)了社會(huì)的和諧與穩(wěn)定。
然而,盡管司法公正的重要性被廣泛認(rèn)可,但實(shí)現(xiàn)司法公正仍面臨許多挑戰(zhàn)。其中之一是司法系統(tǒng)的繁瑣程序和復(fù)雜性。這可能導(dǎo)致案件處理時(shí)間過(guò)長(zhǎng)和審判結(jié)果的不確定性,從而削弱了司法公正的實(shí)施。
此外,司法腐敗也是司法公正面臨的一大難題。當(dāng)司法系統(tǒng)中存在貪污和濫用職權(quán)行為時(shí),司法公正很難被真正實(shí)施。為了解決這個(gè)問(wèn)題,打擊腐敗和提高司法機(jī)構(gòu)的透明度至關(guān)重要。
此外,法律的不平等和部分人群的受害也是司法公正的一個(gè)挑戰(zhàn)。一些邊緣化和弱勢(shì)群體可能面臨著法律援助的不足,導(dǎo)致他們難以獲得公正的司法處理。通過(guò)加強(qiáng)對(duì)弱勢(shì)群體的保護(hù)和提供充足的法律支持,可以提高司法公正的可及性和效果。
為了提高司法公正的水平,我們可以采取以下措施:
通過(guò)以上措施的實(shí)施,我們可以更好地保障司法公正的實(shí)現(xiàn),推動(dòng)社會(huì)正義的發(fā)展。司法公正是一個(gè)復(fù)雜而關(guān)鍵的問(wèn)題,需要社會(huì)各界的共同努力和持續(xù)關(guān)注。
在網(wǎng)絡(luò)時(shí)代,網(wǎng)絡(luò)輿論已經(jīng)成為了一個(gè)不可忽視的力量。然而,這并不意味著我們可以忽視司法公正的重要性。司法公正與網(wǎng)絡(luò)輿論之間存在著密切的關(guān)系,如何平衡兩者之間的關(guān)系,成為了當(dāng)今社會(huì)一個(gè)重要的議題。
網(wǎng)絡(luò)輿論的力量在于其傳播速度快、覆蓋面廣的特點(diǎn)。一旦某個(gè)事件在網(wǎng)絡(luò)上引發(fā)了廣泛的討論和關(guān)注,就會(huì)形成一股強(qiáng)大的輿論壓力。這種壓力有時(shí)會(huì)對(duì)司法機(jī)關(guān)的決策產(chǎn)生影響,迫使其采取相應(yīng)的行動(dòng)。因此,網(wǎng)絡(luò)輿論在某種程度上可以推動(dòng)司法公正的實(shí)現(xiàn)。
然而,我們不能忽視的是,網(wǎng)絡(luò)輿論并非萬(wàn)能。它不能代替司法機(jī)關(guān)做出公正的判斷。司法機(jī)關(guān)必須依據(jù)法律和事實(shí)進(jìn)行裁決,不受外界輿論的影響。司法公正才是社會(huì)公正的基石,是維護(hù)社會(huì)穩(wěn)定和公平正義的重要保障。
要平衡司法公正與網(wǎng)絡(luò)輿論之間的關(guān)系,需要社會(huì)各界的共同努力。首先,加強(qiáng)網(wǎng)絡(luò)監(jiān)管,規(guī)范網(wǎng)絡(luò)言論,防止惡意攻擊和誹謗。其次,提高公眾的法律意識(shí),引導(dǎo)公眾以理性、客觀的態(tài)度看待網(wǎng)絡(luò)輿論。最后,司法機(jī)關(guān)應(yīng)公開(kāi)透明地處理案件,及時(shí)回應(yīng)社會(huì)關(guān)切,增強(qiáng)公眾對(duì)司法公正的信心。
綜上所述,司法公正與網(wǎng)絡(luò)輿論之間存在著既對(duì)立又統(tǒng)一的關(guān)系。我們不能忽視任何一個(gè)方面。為了構(gòu)建一個(gè)更加公正、和諧的社會(huì),我們需要平衡兩者之間的關(guān)系,充分發(fā)揮網(wǎng)絡(luò)輿論在推動(dòng)司法公正方面的積極作用,同時(shí)確保司法機(jī)關(guān)獨(dú)立、公正地行使職權(quán)。
通過(guò)了解澳門(mén)法律體系的運(yùn)作,我們可以深入了解該地區(qū)司法公正的維護(hù)和發(fā)展情況。澳門(mén)法律作為該地區(qū)的法律框架,對(duì)于維護(hù)司法公正起著至關(guān)重要的作用。但是,在實(shí)踐中,有時(shí)候會(huì)出現(xiàn)一些妨礙司法公正的因素,這就需要加強(qiáng)監(jiān)督和改善法律體系來(lái)解決。
澳門(mén)的法律體系主要以《澳門(mén)基本法》為基礎(chǔ),同時(shí)還涵蓋了一系列澳門(mén)特別行政區(qū)的相關(guān)法律法規(guī)?!栋拈T(mén)基本法》是澳門(mén)的基本法律文件,確立了澳門(mén)的法律地位和憲政框架,保障了澳門(mén)的司法獨(dú)立和法治精神。
司法公正是法治社會(huì)的核心價(jià)值觀之一,它體現(xiàn)了法律的公平性和威信性,確保了公民的合法權(quán)益得到尊重和保護(hù)。在司法公正的框架下,每個(gè)人都應(yīng)當(dāng)受到公平審判,不受特殊待遇或歧視,這是一個(gè)民主社會(huì)的重要標(biāo)志。
在澳門(mén)的司法實(shí)踐中,有時(shí)候也會(huì)出現(xiàn)一些妨礙司法公正的因素。例如,可能會(huì)存在司法腐敗、濫權(quán)現(xiàn)象,以及法律執(zhí)行環(huán)節(jié)的不透明、不公正等問(wèn)題,這些因素都會(huì)影響司法公正的實(shí)現(xiàn)和維護(hù)。
為了解決妨礙司法公正的問(wèn)題,澳門(mén)需要加強(qiáng)對(duì)司法機(jī)關(guān)和法律系統(tǒng)的監(jiān)督,建立健全的司法獨(dú)立和監(jiān)督機(jī)制,確保法律的執(zhí)行符合法治精神。此外,還需要改善法律體系,完善相關(guān)法律法規(guī),提升司法公正的效果和水平。
總的來(lái)說(shuō),澳門(mén)的法律體系為司法公正的維護(hù)提供了重要的法律基礎(chǔ),但在實(shí)際實(shí)踐中仍然面臨一些挑戰(zhàn)。通過(guò)加強(qiáng)監(jiān)督和改善法律體系,可以更好地解決妨礙司法公正的問(wèn)題,推動(dòng)司法公正不斷提升和完善。
之前看了Mahout官方示例 20news 的調(diào)用實(shí)現(xiàn);于是想根據(jù)示例的流程實(shí)現(xiàn)其他例子。網(wǎng)上看到了一個(gè)關(guān)于天氣適不適合打羽毛球的例子。
訓(xùn)練數(shù)據(jù):
Day Outlook Temperature Humidity Wind PlayTennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No
檢測(cè)數(shù)據(jù):
sunny,hot,high,weak
結(jié)果:
Yes=》 0.007039
No=》 0.027418
于是使用Java代碼調(diào)用Mahout的工具類(lèi)實(shí)現(xiàn)分類(lèi)。
基本思想:
1. 構(gòu)造分類(lèi)數(shù)據(jù)。
2. 使用Mahout工具類(lèi)進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類(lèi)器對(duì)vector數(shù)據(jù)進(jìn)行分類(lèi)。
接下來(lái)貼下我的代碼實(shí)現(xiàn)=》
1. 構(gòu)造分類(lèi)數(shù)據(jù):
在hdfs主要?jiǎng)?chuàng)建一個(gè)文件夾路徑 /zhoujainfeng/playtennis/input 并將分類(lèi)文件夾 no 和 yes 的數(shù)據(jù)傳到hdfs上面。
數(shù)據(jù)文件格式,如D1文件內(nèi)容: Sunny Hot High Weak
2. 使用Mahout工具類(lèi)進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類(lèi)器對(duì)vector數(shù)據(jù)進(jìn)行分類(lèi)。
這三步,代碼我就一次全貼出來(lái);主要是兩個(gè)類(lèi) PlayTennis1 和 BayesCheckData = =》
package myTesting.bayes;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.classifier.naivebayes.training.TrainNaiveBayesJob;
import org.apache.mahout.text.SequenceFilesFromDirectory;
import org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles;
public class PlayTennis1 {
private static final String WORK_DIR = "hdfs://192.168.9.72:9000/zhoujianfeng/playtennis";
/*
* 測(cè)試代碼
*/
public static void main(String[] args) {
//將訓(xùn)練數(shù)據(jù)轉(zhuǎn)換成 vector數(shù)據(jù)
makeTrainVector();
//產(chǎn)生訓(xùn)練模型
makeModel(false);
//測(cè)試檢測(cè)數(shù)據(jù)
BayesCheckData.printResult();
}
public static void makeCheckVector(){
//將測(cè)試數(shù)據(jù)轉(zhuǎn)換成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"testinput";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失??!");
System.exit(1);
}
//將序列化文件轉(zhuǎn)換成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件轉(zhuǎn)換成向量失?。?#34;);
System.out.println(2);
}
}
public static void makeTrainVector(){
//將測(cè)試數(shù)據(jù)轉(zhuǎn)換成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"input";
String output = WORK_DIR+Path.SEPARATOR+"tennis-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失??!");
System.exit(1);
}
//將序列化文件轉(zhuǎn)換成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件轉(zhuǎn)換成向量失?。?#34;);
System.out.println(2);
}
}
public static void makeModel(boolean completelyNB){
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-vectors"+Path.SEPARATOR+"tfidf-vectors";
String model = WORK_DIR+Path.SEPARATOR+"model";
String labelindex = WORK_DIR+Path.SEPARATOR+"labelindex";
Path in = new Path(input);
Path out = new Path(model);
Path label = new Path(labelindex);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
if(fs.exists(label)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(label, true);
}
TrainNaiveBayesJob tnbj = new TrainNaiveBayesJob();
String[] params =null;
if(completelyNB){
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow","-c"};
}else{
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow"};
}
ToolRunner.run(tnbj, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("生成訓(xùn)練模型失??!");
System.exit(3);
}
}
}
package myTesting.bayes;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.mahout.classifier.naivebayes.BayesUtils;
import org.apache.mahout.classifier.naivebayes.NaiveBayesModel;
import org.apache.mahout.classifier.naivebayes.StandardNaiveBayesClassifier;
import org.apache.mahout.common.Pair;
import org.apache.mahout.common.iterator.sequencefile.PathType;
import org.apache.mahout.common.iterator.sequencefile.SequenceFileDirIterable;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.Vector.Element;
import org.apache.mahout.vectorizer.TFIDF;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;
public class BayesCheckData {
private static StandardNaiveBayesClassifier classifier;
private static Map<String, Integer> dictionary;
private static Map<Integer, Long> documentFrequency;
private static Map<Integer, String> labelIndex;
public void init(Configuration conf){
try {
String modelPath = "/zhoujianfeng/playtennis/model";
String dictionaryPath = "/zhoujianfeng/playtennis/tennis-vectors/dictionary.file-0";
String documentFrequencyPath = "/zhoujianfeng/playtennis/tennis-vectors/df-count";
String labelIndexPath = "/zhoujianfeng/playtennis/labelindex";
dictionary = readDictionnary(conf, new Path(dictionaryPath));
documentFrequency = readDocumentFrequency(conf, new Path(documentFrequencyPath));
labelIndex = BayesUtils.readLabelIndex(conf, new Path(labelIndexPath));
NaiveBayesModel model = NaiveBayesModel.materialize(new Path(modelPath), conf);
classifier = new StandardNaiveBayesClassifier(model);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("檢測(cè)數(shù)據(jù)構(gòu)造成vectors初始化時(shí)報(bào)錯(cuò)。。。。");
System.exit(4);
}
}
/**
* 加載字典文件,Key: TermValue; Value:TermID
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<String, Integer> readDictionnary(Configuration conf, Path dictionnaryDir) {
Map<String, Integer> dictionnary = new HashMap<String, Integer>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
String name = path.getName();
return name.startsWith("dictionary.file");
}
};
for (Pair<Text, IntWritable> pair : new SequenceFileDirIterable<Text, IntWritable>(dictionnaryDir, PathType.LIST, filter, conf)) {
dictionnary.put(pair.getFirst().toString(), pair.getSecond().get());
}
return dictionnary;
}
/**
* 加載df-count目錄下TermDoc頻率文件,Key: TermID; Value:DocFreq
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<Integer, Long> readDocumentFrequency(Configuration conf, Path documentFrequencyDir) {
Map<Integer, Long> documentFrequency = new HashMap<Integer, Long>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
return path.getName().startsWith("part-r");
}
};
for (Pair<IntWritable, LongWritable> pair : new SequenceFileDirIterable<IntWritable, LongWritable>(documentFrequencyDir, PathType.LIST, filter, conf)) {
documentFrequency.put(pair.getFirst().get(), pair.getSecond().get());
}
return documentFrequency;
}
public static String getCheckResult(){
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String classify = "NaN";
BayesCheckData cdv = new BayesCheckData();
cdv.init(conf);
System.out.println("init done...............");
Vector vector = new RandomAccessSparseVector(10000);
TFIDF tfidf = new TFIDF();
//sunny,hot,high,weak
Multiset<String> words = ConcurrentHashMultiset.create();
words.add("sunny",1);
words.add("hot",1);
words.add("high",1);
words.add("weak",1);
int documentCount = documentFrequency.get(-1).intValue(); // key=-1時(shí)表示總文檔數(shù)
for (Multiset.Entry<String> entry : words.entrySet()) {
String word = entry.getElement();
int count = entry.getCount();
Integer wordId = dictionary.get(word); // 需要從dictionary.file-0文件(tf-vector)下得到wordID,
if (StringUtils.isEmpty(wordId.toString())){
continue;
}
if (documentFrequency.get(wordId) == null){
continue;
}
Long freq = documentFrequency.get(wordId);
double tfIdfValue = tfidf.calculate(count, freq.intValue(), 1, documentCount);
vector.setQuick(wordId, tfIdfValue);
}
// 利用貝葉斯算法開(kāi)始分類(lèi),并提取得分最好的分類(lèi)label
Vector resultVector = classifier.classifyFull(vector);
double bestScore = -Double.MAX_VALUE;
int bestCategoryId = -1;
for(Element element: resultVector.all()) {
int categoryId = element.index();
double score = element.get();
System.out.println("categoryId:"+categoryId+" score:"+score);
if (score > bestScore) {
bestScore = score;
bestCategoryId = categoryId;
}
}
classify = labelIndex.get(bestCategoryId)+"(categoryId="+bestCategoryId+")";
return classify;
}
public static void printResult(){
System.out.println("檢測(cè)所屬類(lèi)別是:"+getCheckResult());
}
}