📄 classifyconfig.java
字号:
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Jul 17, 2003
* Time: 1:42:32 PM
* To change this template use Options | File Templates.
*/
package Classification;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import java.util.*;
import DBConnection.DBBean;
public class ClassifyConfig {
private static ClassifyConfig instance = null;
String ConfigFile = "ClassifyConfig.xml";
private Document doc;
Vector SaleTypeWords = new Vector();
Vector BuyTypeWords = new Vector();
Vector LeaseTypeWords = new Vector();
Vector WantLeaseTypeWords = new Vector();
Hashtable CommodityKeyWords = null;
Vector HouseCommodityWords = new Vector();
Vector AllKeyWords = new Vector();
Vector AllTypeWords = new Vector();
Vector ContactKeyWords = new Vector();
Vector ContactNumberBefore = new Vector();
Vector ContactNumberLength = new Vector();
Vector BBSName = new Vector();
Vector OnlyLeaseWords = new Vector();
String XMLLocale = null;
String DE[] = {"的","得","地"};
String punctuation[] = {".",";","!","?","。",";","!","?","\n"};
public static ClassifyConfig getInstance(){
if (instance==null)
instance = new ClassifyConfig();
return instance;
}
public String getXMLLocale() {
return XMLLocale;
}
public String getBBSName() {
String bbsStr = "";
for (Enumeration e = this.BBSName.elements(); e.hasMoreElements();) {
bbsStr = bbsStr +(String)e.nextElement() + "|";
}
bbsStr = bbsStr.substring(0,bbsStr.length()-1);
return bbsStr;
}
public ClassifyConfig(){
freshFromFile();
doParse();
getCommodityKeyWords();
getAllKeyword();
getAllTypeword();
}
private void freshFromFile(){
try {
DocumentBuilderFactory docbuilderfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = docbuilderfactory.newDocumentBuilder();
doc = docbuilder.parse(ConfigFile);
doc.normalize();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void parseXMLLocate(){
//XMLLocate
XMLLocale = doc.getElementsByTagName("XMLLocale").item(0).getFirstChild().getNodeValue();
}
private void parseBBS(){
//BBS
Element BBS = (Element)doc.getElementsByTagName("BBS").item(0);
NodeList BBSNAME = BBS.getElementsByTagName("BBSNAME");
for (int i=0;i<BBSNAME.getLength();i++){
String bbsName = BBSNAME.item(i).getFirstChild().getNodeValue();
BBSName.add(bbsName);
}
}
private void parseTradeType(){
//TradeType
Element TradeType = (Element)doc.getElementsByTagName("TradeType").item(0);
Element KeyWords = (Element)TradeType.getElementsByTagName("KeyWords").item(0);
String Sale_keywords = KeyWords.getElementsByTagName("Sale").item(0).getFirstChild().getNodeValue();
String Buy_keywords = KeyWords.getElementsByTagName("Buy").item(0).getFirstChild().getNodeValue();
String Lease_keywords = KeyWords.getElementsByTagName("Lease").item(0).getFirstChild().getNodeValue();
String WantLease_keywords = KeyWords.getElementsByTagName("WantLease").item(0).getFirstChild().getNodeValue();
String OnlyLease_keywords = KeyWords.getElementsByTagName("OnlyLease").item(0).getFirstChild().getNodeValue();
String HouseKind = KeyWords.getElementsByTagName("HouseKind").item(0).getFirstChild().getNodeValue();
DBBean DBbean = new DBBean();
HouseCommodityWords = DBbean.getHouseCommodityWords(HouseKind);
StringTokenizer st = new StringTokenizer(Sale_keywords,"#");
while(st.hasMoreTokens())
SaleTypeWords.add(st.nextToken());
st = new StringTokenizer(Buy_keywords,"#");
while(st.hasMoreTokens())
BuyTypeWords.add(st.nextToken());
st = new StringTokenizer(Lease_keywords,"#");
while(st.hasMoreTokens())
LeaseTypeWords.add(st.nextToken());
st = new StringTokenizer(WantLease_keywords,"#");
while(st.hasMoreTokens())
WantLeaseTypeWords.add(st.nextToken());
st = new StringTokenizer(OnlyLease_keywords,"#");
while(st.hasMoreTokens())
OnlyLeaseWords.add(st.nextToken());
}
private void parseContact(){
//Contact
Element contact = (Element)doc.getElementsByTagName("Contact").item(0);
String KeyWords = contact.getElementsByTagName("KeyWords").item(0).getFirstChild().getNodeValue();
for (StringTokenizer st = new StringTokenizer(KeyWords,"#"); st.hasMoreTokens();) {
String s = st.nextToken();
ContactKeyWords.add(s);
}
String NumberBefore = contact.getElementsByTagName("NumberBefore").item(0).getFirstChild().getNodeValue();
for (StringTokenizer st = new StringTokenizer(NumberBefore,"#"); st.hasMoreTokens();) {
String s = st.nextToken();
ContactNumberBefore.add(s);
}
String NumberLength = contact.getElementsByTagName("NumberLength").item(0).getFirstChild().getNodeValue();
for (StringTokenizer st = new StringTokenizer(NumberLength,"#"); st.hasMoreTokens();) {
String s = st.nextToken();
ContactNumberLength.add(s);
}
}
private void doParse() {
parseXMLLocate();
parseBBS();
parseTradeType();
parseContact();
}
private void getCommodityKeyWords(){
DBBean DBbean = new DBBean();
CommodityKeyWords = DBbean.getCommodityKeywords();
}
private void getAllKeyword(){
DBBean DBbean = new DBBean();
AllKeyWords = DBbean.getAllKeywords();
}
private Vector mergeVector(Vector vec1,Vector vec2){
int buyCount = 0;
Vector tempvec = new Vector();
for (Enumeration e = vec1.elements();e.hasMoreElements();){
String saleStr = (String)e.nextElement();
for (int i =buyCount; i<vec2.size();i++){
String buyStr = (String)vec2.get(i);
if (saleStr.length() <= buyStr.length()){
tempvec.add(buyStr);
}else{
buyCount = i;
break;
}
}
tempvec.add(saleStr);
}
return tempvec;
}
public void getAllTypeword(){
Vector tempVec1 = new Vector();
Vector tempVec2 = new Vector();
tempVec1 = mergeVector(this.SaleTypeWords,this.BuyTypeWords);
tempVec2 = mergeVector(this.LeaseTypeWords,this.WantLeaseTypeWords);
this.AllTypeWords = mergeVector(tempVec1,tempVec2);
}
public static void main(String args[]){
ClassifyConfig cc = new ClassifyConfig();
System.out.println(cc.getXMLLocale());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -