laue huang

Greenhorn
+ Follow
since Nov 19, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by laue huang

thank you Dave,
sorry, I am a new java beginner. The program has been compiled, no mistake. but the result isn't right.
So I want to use it to connect with oracle database and execute some sql statements. I have writen 3 class Document, Sentence, Token which help me to analyse the elements(terms). I should get the IDF(each word has its idf, then I caculate the summe of the whole sentence if it mets the end-token) for each sentence. As the result I should check all the documents.
just like
---------
doc_id idf sentence
1 20.9 hallo...world!
1 22 dddd...connection.
By now I got some problems to detect new document_id because there are more documents in the database. I have tried to use ArrayList to save the documentList, but it didn't work,
what's the problems and how to slove them, thanks in advance.
public class DBTopicExtraction extends DBSimpleConnector {
int documentID;
// document list is used for saving documents
ArrayList documentList = new ArrayList();
// new document
Document doc = new Document( documentID );
//Constructor
public DBTopicExtraction() {
super(
"Lexikon",
DBConfig.getConnectionDriver(),
DBConfig.getConnectionURL(),
DBConfig.getUser(),
DBConfig.getPassword());
this.open();
}
public void getIDF() {
try {
//execute SQL statements
StringBuffer sql = new StringBuffer();
sql.append("SELECT ")
.append("TTD.DOCUMENT_ID, ")
.append("IT.TERM, ")
.append("TTD.IDF ")
.append(" FROM INDEX_TERMS IT, TERM_TO_DOCUMENT TTD ")
.append("WHERE TTD.TERM_ID = IT.TERM_ID");
//.append("ORDER BY TTD.DOCUMENT_ID");
// process the statement
ResultSet result = this.executeQuery(sql.toString());
Token token = null;
// new sentence
Sentence sentence = new Sentence();
//process the following results
while (result.next()) {

// get document id
//int documentID = result.getInt(1);
// insert document to list
//documentList.add(doc);
String term = result.getString(2);
double idf = result.getDouble(3);
token = new Token(term, idf);
sentence.addToken(token);
if (doc.checkEndSentence(token.getTerm())) {
// add sentence to document
doc.addSentence(sentence);
// new sentence
sentence = new Sentence();
}
}
//System.out.print(document_id + "\t");
System.out.println(sentence.toString() + "\t =Sentence=");
result.close();
} catch (SQLException e) {
Log.errorOut(this, "Error", e);
}
}
public ArrayList getDocumentList() {
try {
//execute SQL statements
StringBuffer sql = new StringBuffer();
sql
.append("SELECT ")
.append("TTD.DOCUMENT_ID")
.append(" FROM INDEX_TERMS IT, TERM_TO_DOCUMENT TTD ")
.append("WHERE TTD.TERM_ID = IT.TERM_ID ")
.append("ORDER BY TTD.DOCUMENT_ID");
// process the statement
ResultSet result = this.executeQuery(sql.toString());
while (result.next()) {
// get document id
int documentID = result.getInt(1);
// check if it mets new documenten id
//for (int i = 0; i < documentID; i++) {
// insert document to list
//documentList.add(doc);
//}
}
result.close();
} catch (SQLException e) {
Log.errorOut(this, "Error", e);
}
return documentList;
}
// main method
public static void main(String[] args) {
DBTopicExtraction db = new DBTopicExtraction();
// output the results
System.out.println("===Result===");
ArrayList documentList = db.getDocumentList();
// for each element of documentList
Iterator it = documentList.listIterator();
Document document;
while (it.hasNext()) {
document = (Document) it.next();

//insert document to list
documentList.add(doc);
db.getIDF();
}
}
}