您好,可以打開。若打不開可能系統(tǒng)正在升級,你卸載后再重新下載看看。
新疆公安app最新版本是一款由新疆公安廳官方打造的便民辦事app,居民可在線辦理治安、出入境、邊防、法制等多項(xiàng)業(yè)務(wù)。
輔警(輔助警察)是指由政府出資,公安機(jī)關(guān)統(tǒng)一通過筆試、面試、政審、體檢招錄并與其建立勞動關(guān)系,在公安機(jī)關(guān)及其人民警察的指揮和監(jiān)督下從事警務(wù)輔助工作的人員。
所以輔警考試當(dāng)然要做公安輔警面試題了。
公安機(jī)關(guān)招聘輔警面試會考到以下這些要點(diǎn):
一、服從命令、聽從指揮、文明巡邏、依法執(zhí)勤,認(rèn)真做好小區(qū)的晝夜路面巡邏、守候工作,對發(fā)現(xiàn)的違法犯罪分子應(yīng)監(jiān)視、控制、盤查的扭送公安機(jī)關(guān)審查處理;
二、協(xié)助公安機(jī)關(guān)、社區(qū)居委會維護(hù)公共秩序,保衛(wèi)重點(diǎn)地區(qū)、公共場所和要害部位的安全;
三、發(fā)動、組織群眾,做好防盜、防破壞、防火、防治安災(zāi)害事故等“四防”工作,落實(shí)各項(xiàng)安全防范措施;
四、發(fā)生案件后及時(shí)報(bào)案,協(xié)助公安機(jī)關(guān)保護(hù)好現(xiàn)場,為偵察案件提供線索,協(xié)助公安機(jī)關(guān)查破案件;
五、協(xié)助社區(qū)居委會干部對違反居民共同制訂的“居民公約”等規(guī)范的行為,依照公約規(guī)定糾正各種違章行為;
六、對犯有違反治安管理行為的人,巡邏隊(duì)員有權(quán)勸阻、制止和批評教育,對需要行使罰款、沒收財(cái)物等處罰的,必須報(bào)告并移交公安機(jī)關(guān)處理,巡邏隊(duì)員不得行使上述權(quán)力。
1.執(zhí)行巡邏任務(wù)時(shí),白天要挺胸闊步,自然大方;夜間要保持肅靜,做到眼明、耳靈、腳輕,仔細(xì)判明各種聲響、氣味、光亮和可疑癥狀。
2.二人以上同時(shí)實(shí)施巡邏勤務(wù),遇有情況時(shí),要互相支援,發(fā)揮集體力量的優(yōu)勢。
3.巡邏必須采取走停結(jié)合,耳、目、鼻并用,時(shí)快、時(shí)慢和突然改變行進(jìn)方向的辦法。
4.在巡邏中,保安人員必須著裝整齊,儀表端正,精神飽滿。
5.巡邏要注意效果,防止走過場。
不論考什么類型的公務(wù)員,都沒有面試題庫。面試考察的是考生的應(yīng)變能力和答題思路等。
尊敬的考生:
您好!感謝您參加2016年新疆公安考試?,F(xiàn)在,您可以通過以下步驟查詢您的考試成績。
首先,您需要在瀏覽器中打開您的互聯(lián)網(wǎng)連接,并訪問新疆公安考試官方網(wǎng)站。
官方網(wǎng)站地址:www.xjgonganexam.com
在官方網(wǎng)站的首頁,您需要點(diǎn)擊“登錄”按鈕,并輸入您的賬戶信息。
如果您尚未注冊賬戶,您可以點(diǎn)擊“注冊”按鈕創(chuàng)建一個(gè)新賬戶。
請確保您的賬戶信息準(zhǔn)確無誤,以免造成查詢錯(cuò)誤。
一旦您成功登錄您的賬戶,您將進(jìn)入用戶中心。在用戶中心頁面上,您可以找到一個(gè)標(biāo)有“成績查詢”的鏈接。
點(diǎn)擊該鏈接,系統(tǒng)將跳轉(zhuǎn)到一個(gè)新頁面,顯示您的個(gè)人考試成績。您也可以下載成績單以備存檔。
請注意,為了保護(hù)您的個(gè)人隱私,網(wǎng)站將會要求您驗(yàn)證一些安全信息,例如您的身份證號碼和姓名。
一旦您查看您的考試成績,您還可以在用戶中心頁面上找到其他相關(guān)通知。這些通知可能包括錄取通知、面試通知以及后續(xù)步驟。
請務(wù)必仔細(xì)閱讀這些通知,并按照要求做出相應(yīng)的準(zhǔn)備和行動。
如果您在查詢考試成績的過程中遇到任何問題,您可以通過以下方式聯(lián)系新疆公安考試部門:
請?zhí)峁┠男彰⒆再~號以及具體問題的描述,以便工作人員能夠更好地幫助您。
通過以上步驟,您應(yīng)該能夠成功查詢您在2016年新疆公安考試中的成績。如果您取得了優(yōu)異的成績,恭喜您!這將是您在公安事業(yè)中邁出的重要一步。
如果您未能達(dá)到您預(yù)期的結(jié)果,不要灰心??荚囍皇且淮卧u估,您仍然有機(jī)會通過其他途徑實(shí)現(xiàn)您的職業(yè)目標(biāo)。
祝愿您取得您期望的成績!感謝您對公安事業(yè)的貢獻(xiàn)與支持!
追求公安夢想的小伙伴們注意了!2016年新疆喀什公安招警考試即將開始報(bào)名啦!作為國家安全與社會穩(wěn)定的守護(hù)者,公安警察是社會中不可或缺的力量。如果您對執(zhí)法工作充滿熱情,且有志于為社會貢獻(xiàn)力量,那么參加新疆喀什公安招警考試將是您實(shí)現(xiàn)夢想的第一步!
報(bào)名時(shí)間:
根據(jù)最新消息,2016年新疆喀什公安招警考試的報(bào)名時(shí)間為6月1日至6月30日。有意參加考試的考生需要在這個(gè)時(shí)間段內(nèi)完成報(bào)名手續(xù),逾期將不予受理。因此,希望考生們務(wù)必密切關(guān)注考試通知,并提前做好準(zhǔn)備。
報(bào)名條件:
參加新疆喀什公安招警考試需要滿足以下基本條件:
對于年齡和學(xué)歷條件的放寬,通常是針對退役士兵、優(yōu)秀體育選手、未婚的獨(dú)生子女等特殊情況,具體情況可根據(jù)考試通知中的規(guī)定進(jìn)行申請。希望有意參加考試的考生們在報(bào)名前務(wù)必詳細(xì)閱讀招警通知,并根據(jù)自身情況確認(rèn)是否符合報(bào)名條件。
報(bào)名步驟:
參加新疆喀什公安招警考試的報(bào)名步驟如下:
備考指南:
考試前的備考工作非常重要,它決定了您在考試中的發(fā)揮。為了幫助考生們順利通過考試,以下是一些備考指南供參考:
1. 制定合理的學(xué)習(xí)計(jì)劃:
根據(jù)考試大綱和考試內(nèi)容,制定一個(gè)合理的學(xué)習(xí)計(jì)劃是備考的首要任務(wù)。合理的學(xué)習(xí)計(jì)劃可以幫助你合理分配學(xué)習(xí)時(shí)間,有針對性地進(jìn)行備考。
2. 針對性復(fù)習(xí):
根據(jù)自己的薄弱科目,加大對這些科目的復(fù)習(xí)力度??梢酝ㄟ^參加培訓(xùn)班、購買相關(guān)考試資料、參加模擬考試等方式進(jìn)行有針對性的復(fù)習(xí)。
3. 注意模擬考試:
模擬考試是檢驗(yàn)自己備考效果的重要手段。參加模擬考試可以讓你熟悉考試的流程、提高答題速度和抓住時(shí)間節(jié)點(diǎn)。
4. 關(guān)注招警考試動態(tài):
隨時(shí)關(guān)注招警考試的最新動態(tài)和注意事項(xiàng),根據(jù)考試通知進(jìn)行準(zhǔn)備。掌握最新的考試大綱和考試要點(diǎn),確保備考方向正確。
5. 保持良好的心態(tài):
備考過程中,保持一顆積極向上的心態(tài)非常重要。相信自己的實(shí)力,不斷備考提升自己的能力,相信自己一定可以在考試中取得好成績!
新疆喀什公安招警考試對于參加考試的人員來說是一個(gè)重要的機(jī)會,通過考試可以進(jìn)入公安系統(tǒng),從事為社會提供安全保障的工作。希望每一位有志于從事警察工作的考生們都能夠認(rèn)真?zhèn)淇?,取得?yōu)異的成績。祝愿大家能夠順利通過考試,開啟屬于自己的公安之路!
作為公安系統(tǒng)的重要組成部分,公安輔警在維護(hù)社會穩(wěn)定、保護(hù)人民群眾生命財(cái)產(chǎn)安全等方面發(fā)揮著不可或缺的作用。近年來,公安輔警的招錄工作備受關(guān)注,尤其是面試環(huán)節(jié)更是考生們關(guān)注的重點(diǎn)。為幫助廣大考生順利通過公安輔警面試,我們特別整理了2020年公安輔警考試面試題庫,并對其中的重點(diǎn)問題進(jìn)行了詳細(xì)解析。
1. 為什么選擇成為公安輔警?
這是面試中最常見的一個(gè)問題??忌梢詮囊韵聨讉€(gè)方面進(jìn)行回答:
2. 你認(rèn)為公安輔警應(yīng)該具備哪些素質(zhì)?
公安輔警作為執(zhí)法人員,應(yīng)具備以下素質(zhì):
3. 如何看待公安輔警的工作性質(zhì)?
公安輔警的工作性質(zhì)主要體現(xiàn)在以下幾個(gè)方面:
除了對常見問題的回答,在公安輔警面試中還需要注意以下幾點(diǎn):
作為公安輔警,承擔(dān)著維護(hù)社會治安秩序、保護(hù)人民群眾生命財(cái)產(chǎn)安全的重要職責(zé)。為了幫助廣大考生順利通過公安輔警考試,我們特別整理了2023年公安輔警考試面試題目及答題技巧,希望能為您的應(yīng)試之路提供有價(jià)值的參考。
1. 為什么選擇成為公安輔警?
這是一個(gè)常見的面試問題,考官通過這個(gè)問題了解應(yīng)聘者的動機(jī)和對這份工作的認(rèn)知。在回答時(shí),可以從以下幾個(gè)方面入手:
2. 如何看待公安輔警工作的艱辛與風(fēng)險(xiǎn)?
公安輔警工作雖然具有一定的風(fēng)險(xiǎn),但也是一份光榮而有意義的工作。在回答這個(gè)問題時(shí),可以從以下幾個(gè)方面進(jìn)行闡述:
3. 如何看待公安輔警工作的職業(yè)發(fā)展前景?
公安輔警工作是一個(gè)可以長期發(fā)展的職業(yè),具有良好的職業(yè)發(fā)展前景。在回答這個(gè)問題時(shí),可以從以下幾個(gè)方面進(jìn)行闡述:
作為廣大公務(wù)員考生,了解考試時(shí)間是非常重要的。對于新疆公務(wù)員公安專業(yè)的考試時(shí)間,通常是在每年的{具體時(shí)間}。在備戰(zhàn)新疆公務(wù)員公安專業(yè)科目考試時(shí),熟悉考試時(shí)間可以幫助考生做好時(shí)間規(guī)劃,有意識地安排學(xué)習(xí)和復(fù)習(xí)計(jì)劃。
備戰(zhàn)新疆公務(wù)員公安專業(yè)科目考試,首先要對考試科目有充分的了解。該專業(yè)科目一般包括{具體科目1}、{具體科目2}、{具體科目3}等內(nèi)容??忌枰钊雽W(xué)習(xí)這些科目的理論知識,掌握相關(guān)的法律法規(guī)、公安業(yè)務(wù)知識等。此外,也需要關(guān)注一些熱點(diǎn)問題和實(shí)際應(yīng)用。
在備戰(zhàn)過程中,合理安排復(fù)習(xí)時(shí)間也是關(guān)鍵??梢愿鶕?jù)考試時(shí)間提前制定復(fù)習(xí)計(jì)劃,由深入淺出地復(fù)習(xí)各科目,并進(jìn)行重點(diǎn)突破,做到知識點(diǎn)全面覆蓋,鞏固知識點(diǎn)。
在備戰(zhàn)新疆公務(wù)員公安專業(yè)科目考試時(shí),考生可以采取一些技巧提高備考效率。比如,可以多做一些模擬試題,了解考試形式和題型,找準(zhǔn)自己的考試重點(diǎn)。此外,多參加一些專業(yè)培訓(xùn)班或者輔導(dǎo)課程,向?qū)<艺埥探獯鹨苫螅部梢蕴岣邆淇夹Ч?/p>
最后,備戰(zhàn)新疆公務(wù)員公安專業(yè)科目考試,還要有一個(gè)良好的心態(tài)。要保持平常心,充分相信自己的實(shí)力,相信經(jīng)過充分準(zhǔn)備一定能取得優(yōu)異成績。
感謝您閱讀本文,希望通過這篇文章可以助您更好地備戰(zhàn)新疆公務(wù)員公安專業(yè)科目考試。
今年的500分?按你說的公安大學(xué)的話,全國只有一所是叫公安大學(xué)的,中國人民公安大學(xué),其它都是xx警察學(xué)院.你的分?jǐn)?shù)比較尷尬,500分,可能上不了公安大學(xué),有點(diǎn)懸。去警察學(xué)院又虧了。體能測試過了么
之前看了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
檢測數(shù)據(jù):
sunny,hot,high,weak
結(jié)果:
Yes=》 0.007039
No=》 0.027418
于是使用Java代碼調(diào)用Mahout的工具類實(shí)現(xiàn)分類。
基本思想:
1. 構(gòu)造分類數(shù)據(jù)。
2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類器對vector數(shù)據(jù)進(jìn)行分類。
接下來貼下我的代碼實(shí)現(xiàn)=》
1. 構(gòu)造分類數(shù)據(jù):
在hdfs主要創(chuàng)建一個(gè)文件夾路徑 /zhoujainfeng/playtennis/input 并將分類文件夾 no 和 yes 的數(shù)據(jù)傳到hdfs上面。
數(shù)據(jù)文件格式,如D1文件內(nèi)容: Sunny Hot High Weak
2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類器對vector數(shù)據(jù)進(jìn)行分類。
這三步,代碼我就一次全貼出來;主要是兩個(gè)類 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";
/*
* 測試代碼
*/
public static void main(String[] args) {
//將訓(xùn)練數(shù)據(jù)轉(zhuǎn)換成 vector數(shù)據(jù)
makeTrainVector();
//產(chǎn)生訓(xùn)練模型
makeModel(false);
//測試檢測數(shù)據(jù)
BayesCheckData.printResult();
}
public static void makeCheckVector(){
//將測試數(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)換成向量失敗!");
System.out.println(2);
}
}
public static void makeTrainVector(){
//將測試數(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)練模型失?。?#34;);
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("檢測數(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);
}
// 利用貝葉斯算法開始分類,并提取得分最好的分類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("檢測所屬類別是:"+getCheckResult());
}
}