區(qū)別
一.設(shè)計(jì)思想
react
1 函數(shù)式思想,all in js ,jsx語法,js操控css
2 單項(xiàng)數(shù)據(jù)流
3 setState重新渲染
4 每當(dāng)應(yīng)用的狀態(tài)被改變時(shí),全部子組件都會重新渲染。當(dāng)然,這可以通過shouldComponentUpdate這個(gè)生命周期方法來進(jìn)行控制,如果為true繼續(xù)渲染、false不渲染,但Vue將此視為默認(rèn)的優(yōu)化。
vue
1 響應(yīng)式思想,也就是基于數(shù)據(jù)可變的。把html、js、css、組合到一起,也可以通過標(biāo)簽引擎組合到一個(gè)頁面中
2 雙向綁定,每一個(gè)屬性都需要建立watch監(jiān)聽(頁面不用,涉及到組件更新的話需要)
3 Vue宣稱可以更快地計(jì)算出Virtual DOM的差異,這是由于它在渲染過程中,會跟蹤每一個(gè)組件的依賴關(guān)系,不需要重新渲染整個(gè)組件樹
二、性能
react ----大型項(xiàng)目
優(yōu)化需要手動去做,狀態(tài)可控
vue ------中小型項(xiàng)目
狀態(tài)改變需要watch監(jiān)聽,數(shù)據(jù)量太大的話會卡頓
三、擴(kuò)展性
react
1 類式寫法api少,更容易結(jié)合ts
2 可以通過高階組件來擴(kuò)展
vue
1 聲明式寫法,結(jié)合ts比較復(fù)雜
2 需要通過mixin方式來擴(kuò)展
React剛開始也有mixin的寫法,通過React.createClass的api,不過現(xiàn)在很少用了。
Vue也不是不能實(shí)現(xiàn)高階組件,只是特別麻煩,因?yàn)閂ue對與組件的option做了各種處理,想實(shí)現(xiàn)高階組件就要知道每一個(gè)option是怎么處理的,然后正確的設(shè)置。
1、 Spring的 IOC和AOP機(jī)制 ?
2、 Spring中 `@Autowired` 和 `@Resource` 注解的區(qū)別?
3、依賴注入的方式有幾種,各是什么?
4、講一下什么是 Spring ?
5、 Spring的AOP理解:
6、Spring的IOC理解
7、解釋一下 Spring bean的生命周期
8、 解釋Spring支持的幾種bean的作用域
9、 Spring基于xml注入bean的幾種方式:
10、Spring框架中都用到了哪些設(shè)計(jì)模式?
11、聊一聊Spring中@Transactional注解及其失效的六種場景
12、Spring AOP(思想)以及AspectJ框架(重點(diǎn))
在Java開發(fā)領(lǐng)域中,Java IO(輸入輸出)和NIO(New IO,非阻塞IO)是非常重要的主題。掌握這兩個(gè)概念不僅可以幫助開發(fā)人員更好地理解Java的IO操作,還可以在面試過程中展現(xiàn)自己的技術(shù)能力。本文將介紹一些常見的Java IO和NIO面試題,希望可以幫助讀者進(jìn)一步了解這兩個(gè)關(guān)鍵概念。
Java IO是Java編程中最常用的一部分,涉及到文件、網(wǎng)絡(luò)等數(shù)據(jù)的輸入輸出操作。以下是一些常見的Java IO面試題:
Java IO(輸入輸出)是Java提供的用于處理輸入輸出的API。它提供了一套用于讀取和寫入數(shù)據(jù)的類和接口,包括文件操作、網(wǎng)絡(luò)操作等。
Java IO通過流(Stream)的方式進(jìn)行數(shù)據(jù)的讀取和寫入。輸入數(shù)據(jù)流向程序的過程稱為輸入流,輸出數(shù)據(jù)從程序流向外部的過程稱為輸出流。
Java NIO是Java提供的新的IO模型,相比于傳統(tǒng)的Java IO,NIO提供了更高效的IO操作。以下是一些關(guān)于Java NIO的面試題:
Java NIO是一種非阻塞IO模型,通過通道(Channel)和緩沖區(qū)(Buffer)來進(jìn)行數(shù)據(jù)的讀取和寫入。相比于傳統(tǒng)的Java IO,NIO提供了更高效的IO操作。
Java NIO和Java IO相比,Java NIO具有更高的性能和更好的可擴(kuò)展性。Java NIO是基于通道和緩沖區(qū)的操作模型,而Java IO是基于流的操作模型。
總的來說,Java IO和NIO都是Java中重要的IO操作模型,不同場景下可以根據(jù)需求選擇合適的IO模型。在面試過程中,對Java IO和NIO的了解可以展現(xiàn)出你的專業(yè)知識和技術(shù)能力,希望以上內(nèi)容可以幫助讀者更好地準(zhǔn)備相關(guān)面試題目。
勞動檔案是跟隨者你的工作移動的,有的公司并不接收你的勞動檔案,那就在人才中心保管著。
蔚藍(lán)檔案和碧藍(lán)檔案是塞爾達(dá)傳說系列游戲中的兩個(gè)不同的檔案系統(tǒng)。蔚藍(lán)檔案是游戲《塞爾達(dá)傳說:蔚藍(lán)之瞳》中的檔案系統(tǒng),玩家可以創(chuàng)建多個(gè)不同的檔案,每個(gè)檔案都有獨(dú)立的游戲進(jìn)度和存檔記錄。玩家可以在不同的檔案間切換,體驗(yàn)不同的故事線、角色發(fā)展和游戲進(jìn)度。碧藍(lán)檔案則是游戲《塞爾達(dá)傳說:碧之軌跡》中的檔案系統(tǒng),與蔚藍(lán)檔案不同的是,碧藍(lán)檔案是線性的,玩家不能創(chuàng)建多個(gè)檔案,只能在同一個(gè)檔案中進(jìn)行游戲。此外,碧藍(lán)檔案中的進(jìn)度保存也比較簡單,不同于蔚藍(lán)檔案中的頻繁手動存檔,碧藍(lán)檔案會在玩家完成特定篇章后自動保存進(jìn)度。總之,蔚藍(lán)檔案和碧藍(lán)檔案是兩個(gè)不同的游戲中的檔案系統(tǒng),擁有不同的功能和特點(diǎn)。
業(yè)務(wù)檔案是跑業(yè)務(wù)的,科技檔案是科學(xué)
1.Dubbo的工作流程是什么?
答:Dubbo的工作流程包括:provider向注冊中心去注冊自己為一個(gè)服務(wù),consumer去注冊中心訂閱服務(wù),注冊中心會通知consumer注冊好的服務(wù),consumer會將provider的地址等信息拉取到本地緩存,consumer去調(diào)用provider,consumer和provider都異步的通知監(jiān)控中心。
2.Dubbo的通信原理是什么?
答:Dubbo底層使用hessian2進(jìn)行二進(jìn)制序列化進(jìn)行遠(yuǎn)程調(diào)用,Dubbo底層使用Netty框架進(jìn)行異步通信。
3.Dubbo負(fù)載均衡策略有哪些?
答:Dubbo負(fù)載均衡策略包括:random loadbalance、roundrobin loadbalance、leastactive loadbalance、consistanthash loadbalance等。
4.ZooKeeper是什么?有什么作用?
答:ZooKeeper是一個(gè)分布式協(xié)調(diào)服務(wù),可以用于分布式應(yīng)用程序的協(xié)調(diào)和管理。它提供了一個(gè)分布式的、開放的、可靠的數(shù)據(jù)存儲,用于存儲和管理分布式應(yīng)用程序的配置信息、命名服務(wù)、狀態(tài)信息等。
5.ZooKeeper的特點(diǎn)是什么?
答:ZooKeeper的特點(diǎn)包括:高可用性、高性能、數(shù)據(jù)一致性、順序訪問、可靠性、容錯(cuò)性等。
6.ZooKeeper的工作原理是什么?
答:ZooKeeper的工作原理是基于ZAB協(xié)議,它將數(shù)據(jù)存儲在內(nèi)存中,并將數(shù)據(jù)同步到所有的ZooKeeper服務(wù)器上,保證數(shù)據(jù)的一致性。ZooKeeper使用了一種基于觀察者模式的機(jī)制,當(dāng)數(shù)據(jù)發(fā)生變化時(shí),會通知所有的觀察者。
7.ZooKeeper的節(jié)點(diǎn)類型有哪些?
答:ZooKeeper的節(jié)點(diǎn)類型包括:持久節(jié)點(diǎn)、臨時(shí)節(jié)點(diǎn)、持久順序節(jié)點(diǎn)、臨時(shí)順序節(jié)點(diǎn)。
8.ZooKeeper如何保證數(shù)據(jù)的一致性?
答:ZooKeeper使用了ZAB協(xié)議來保證數(shù)據(jù)的一致性,它將數(shù)據(jù)存儲在內(nèi)存中,并將數(shù)據(jù)同步到所有的ZooKeeper服務(wù)器上,保證數(shù)據(jù)的一致性。
在現(xiàn)代社會中,各行各業(yè)都有許多不同的職稱,這些職稱反映了一個(gè)人在特定領(lǐng)域中的專業(yè)知識和技能水平。職稱一般由相關(guān)的行業(yè)組織或政府機(jī)構(gòu)頒發(fā),以認(rèn)可和獎(jiǎng)勵(lì)個(gè)人在特定領(lǐng)域的成就和貢獻(xiàn)。
在檔案行業(yè)和圖書行業(yè)中,同樣存在著職稱制度。檔案職稱是指在檔案領(lǐng)域內(nèi),根據(jù)個(gè)人的學(xué)歷、工作經(jīng)驗(yàn)和成績評定出來的專業(yè)職稱。而圖書職稱則是指在圖書館和出版領(lǐng)域內(nèi)的職業(yè)資格認(rèn)證,也是評定個(gè)人在該領(lǐng)域中專業(yè)能力的一種方式。
雖然檔案職稱和圖書職稱看似是兩個(gè)不同的概念,但事實(shí)上它們之間存在著一定的通用性。首先,檔案工作和圖書工作都是以信息管理為核心的職業(yè),都需要掌握相應(yīng)的專業(yè)知識和技能。因此,無論是從事檔案工作還是從事圖書工作,都需要具備一定的學(xué)術(shù)背景和技術(shù)能力。
其次,檔案和圖書在實(shí)際工作中有很多交叉點(diǎn),比如數(shù)字化文獻(xiàn)的管理和檢索、信息資源的整理和編目等。在這些共同的領(lǐng)域里,檔案職稱和圖書職稱所要求的能力和素質(zhì)是相似的。因此,一些人員可能會同時(shí)擁有檔案職稱和圖書職稱,以增加自己在職場上的競爭力和適應(yīng)不同的工作環(huán)境。
此外,檔案職稱和圖書職稱的獲取方法也有一定的相似之處。一般來說,都需要通過相關(guān)考試或職稱評定機(jī)構(gòu)認(rèn)證,符合一定的條件才能獲得職稱。這些條件可能包括學(xué)歷、工作經(jīng)驗(yàn)、學(xué)術(shù)成果等方面的要求。
綜上所述,盡管檔案職稱和圖書職稱是針對不同領(lǐng)域的職業(yè)資格認(rèn)證,但它們之間存在一定的交叉點(diǎn)和通用性。這為從事檔案工作或圖書工作的人員提供了更廣泛的發(fā)展空間和職業(yè)選擇。無論選擇哪一種職稱,只要不斷學(xué)習(xí)和提升自己的專業(yè)能力,相信都能在相關(guān)領(lǐng)域中取得良好的職業(yè)發(fā)展。
個(gè)人人事檔案分別在組織部和人社局管理,組織部和人社局專門設(shè)有檔案室。機(jī)關(guān)事業(yè)單位的副科級以上人員的檔案在組織部管理。機(jī)關(guān)事業(yè)單位的一般干部檔案在人社局管理。黨員的檔案在各級黨委或縣委組織部管理,包括有入黨申請書、入黨志愿書或受過黨組織表彰獎(jiǎng)勵(lì)或處分等。
共青團(tuán)員的檔案在黨政機(jī)關(guān)或鄉(xiāng)鎮(zhèn),本人所在的團(tuán)委存檔。
之前看了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主要?jiǎng)?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)換成向量失敗!");
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("檢測數(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());
}
}