• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

help! how to detect new document_id

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Laue
Firstly, can you edit your post and use the UBB code tags so that the code you posted is more readable.
Second, what is wrong with your program? does it compile? Does it run at all and just give you the wrong results. It looks like your class extends another class and calls methods in that one, depending on what is wrong with your code they may or may not be relevant. Let us know exactly hat is wrong and then we can go from there.
 
laue huang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic