# how to display calculated values in table form ?

Page 1 of 1

## 5 Replies - 5732 Views - Last Post: 19 March 2011 - 12:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=222872&amp;s=3b568ad4dfb129b059f725f1eeebbe30&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jasperFernandes

Reputation: 0
• Posts: 46
• Joined: 02-March 11

# how to display calculated values in table form ?

Posted 18 March 2011 - 09:52 AM

```int queryVector = 1;
double similarity = 0.0;
int wordPower;

for (a = 0; a < filename; a++) {
int totalwordPower = 0;
int totalWords = 0;
try {
System.out
.println(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  ");
System.out.println("\n");
System.out.println("The word inputted : " + word2);
File file = new File(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc" + a
+ ".txt");
System.out.println(" _________________");

System.out.print("| File = abc" + a + ".txt | \t\t \n");

for (int i = 0; i < array2.length; i++) {

totalCount = 0;
wordCount = 0;

Scanner s = new Scanner(file);
{
while (s.hasNext()) {
totalCount++;
if (s.next().equals(array2[i]))
wordCount++;

}

System.out.print(array2[i] + " --> Word count =  "
+ "\t " + "|" + wordCount + "|");
System.out.print("  Total count = " + "\t " + "|"
+ totalCount + "|");
System.out.printf("  Term Frequency =  | %8.4f |",
(double) wordCount / totalCount);

System.out.println("\t ");

double inverseTF = Math.log10((float) numDoc
/ (numofDoc[i]));
System.out.println("    --> IDF = " + inverseTF);

double TFIDF = (((double) wordCount / totalCount) * inverseTF);
System.out.println("    --> TF/IDF = " + TFIDF + "\n");

totalWords += wordCount;

wordPower = (int) Math.pow(wordCount, 2);

totalwordPower += wordPower;

System.out.println("Document Vector : " + wordPower);

similarity = (totalWords * queryVector)
/ ((Math.sqrt((totalwordPower)) * (Math
.sqrt(((queryVector * 3))))));

}
}
} catch (FileNotFoundException e) {
}
System.out.println("The total query frequency for this file is "
+ totalWords);
System.out.println("The total document vector : " + totalwordPower);

System.out.println("The similarity is " + similarity);
}

}
}
```

How do i display the calculated values automatically above into a table form ?

After the calculation, the data will be automatically mapped into a table.

each table for each data : Term frequency, IDF, word count, TF/IDF..

for example :
(Query)
Document "How" "are" "you"

abc01.txt values values values

abc02.txt " " "

abc03.txt " " "

abc04.txt " " "

abc05.txt

abc06.txt

abc07.txt

abc08.txt

Is This A Good Question/Topic? 0

## Replies To: how to display calculated values in table form ?

### #2 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: how to display calculated values in table form ?

Posted 18 March 2011 - 02:03 PM

It's hard to understand what you're trying to do from your "example." You talk about mapping the results to a table but then give a list of 7 text files that have no discernible relationship to the data or document. Can you expand on what you're trying to do?

### #3 jasperFernandes

Reputation: 0
• Posts: 46
• Joined: 02-March 11

## Re: how to display calculated values in table form ?

Posted 18 March 2011 - 11:38 PM

i am sorry for my poor display of my question. Basically i am trying to calculate all the occurrence of each query words in a text file. By calculating the frequency of each query words, i have managed to calculate the term frequency and inverse term frequency for each words of each text files. What i wanted to do is, i wanted to display a much user readable data in the form of table depicting the scores for each text files. Let me show you what is my current output.
This is the example run of first file.

The word inputted : how are you
_________________
| File = abc0.txt |
how --> Word count = |0| Total count = |1289| Term Frequency = | 0.0000 |
--> IDF = 1.0413926851582251
--> TF/IDF = 0.0

Document Vector : 0
are --> Word count = |0| Total count = |1289| Term Frequency = | 0.0000 |
--> IDF = 0.43933269383026263
--> TF/IDF = 0.0

Document Vector : 0
you --> Word count = |0| Total count = |1289| Term Frequency = | 0.0000 |
--> IDF = 0.1962946357308887
--> TF/IDF = 0.0

Document Vector : 0
The total query frequency for this file is 0
The total document vector : 0
The similarity is NaN

As you see, each words has their own word count, term total count, term frequency, IDF, TF/IDF.

What i wanted to do is to display the score in table form for each word count, term total count, term frequency, IDF, TF/IDF and the similarity. I couldn't figure how to display the scores for each in table form.

### #4 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: how to display calculated values in table form ?

Posted 19 March 2011 - 09:50 AM

To make sure I understand your desired result, would it look like:

```          a       b       c
file1     x       y       z
file2     x       y       z
file3     x       y       z
file4     x       y       z
file5     x       y       z
file6     x       y       z
...

```

where x, y, and z represent the number of times the words a, b, and c were found in the files in column 1?

If so, this is a fairly simple task to program. Roughly:
read each word in the file,
determine if the word is a, b, or c,
increment a, b, or c counters in 2D array (file -vs- word count) as words are found,
close file,
output results.

Start coding that, taking it a step at a time, breaking it down into smaller steps if necessary, and come back for help when needed.

Now that I've read your last post in this thread, I think my table above could still be used but there would be more columns for the other data you wanted to tabulate. For example, based on your response, it would look something like:

```File      Word     Word Count     Total Count     Term Freq     IDF          TF/IDF
abc0.txt   a           0             1289          0.0000     1.041392...     0.0
...

```

(view source to see properly formatted table)

Is that what you have in mind? Again, not that hard (though it may seem so to you, so I apologize if I'm over simplifying), but you'll follow (roughly) the same steps I outlined above and then use a formatted print statement to present the data in a table format.

In general, if a project seems too hard, break it down into the smallest possible pieces and design/code each piece at a time, sometimes breaking those even further down, as needed, to reduce complexity. Eventually, you'll get to pieces that seem easily accomplished, and the whole project won't seem so daunting.

This post has been edited by GregBrannon: 19 March 2011 - 09:51 AM

### #5 jasperFernandes

Reputation: 0
• Posts: 46
• Joined: 02-March 11

## Re: how to display calculated values in table form ?

Posted 19 March 2011 - 12:12 PM

```int queryVector = 1;
double similarity = 0.0;
int wordPower;
double [][] testData =  new double [array2.length][filename];
int row;
int col;

for (a = 0; a < filename; a++) {
int totalwordPower = 0;
int totalWords = 0;
try {
System.out
.println(" _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  ");
System.out.println("\n");
System.out.println("The word inputted : " + word2);
File file = new File(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc" + a
+ ".txt");
System.out.println(" _________________");

System.out.print("| File = abc" + a + ".txt | \t\t \n");

for (int i = 0; i < array2.length; i++) {

totalCount = 0;
wordCount = 0;

Scanner s = new Scanner(file);
{
while (s.hasNext()) {
totalCount++;
if (s.next().equals(array2[i]))
wordCount++;

}

System.out.print(array2[i] + " --> Word count =  "
+ "\t " + "|" + wordCount + "|");
System.out.print("  Total count = " + "\t " + "|"
+ totalCount + "|");
System.out.printf("  Term Frequency =  | %8.4f |",
(double) wordCount / totalCount);

System.out.println("\t ");

double inverseTF = Math.log10((float) numDoc
/ (numofDoc[i]));
System.out.println("    --> IDF = " + inverseTF);

double TFIDF = (((double) wordCount / totalCount) * inverseTF);
System.out.println("    --> TF/IDF = " + TFIDF + "\n");

totalWords += wordCount;

wordPower = (int) Math.pow(wordCount, 2);

totalwordPower += wordPower;

System.out.println("Document Vector : " + wordPower);

similarity = (totalWords * queryVector)
/ ((Math.sqrt((totalwordPower)) * (Math
.sqrt(((queryVector * 3))))));

}
}
} catch (FileNotFoundException e) {
}
System.out.println("The total query frequency for this file is "
+ totalWords);
System.out.println("The total document vector : " + totalwordPower);

System.out.println("The similarity is " + similarity);
}
for (row = 0; row < array2.length; row++) {

for (col = 0; col < filename; col++) {

testData [row][col] = wordCount;

System.out.println(testData);
}
}
}
}
```

this is my attempt to store the values into multidimensional array. I was trying to store the word count for each text files. However, i got unpleasant results which is :

[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]
[[[email protected]

Can anyone point my mistake ?

### #6 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12318
• Posts: 45,417
• Joined: 27-December 08

## Re: how to display calculated values in table form ?

Posted 19 March 2011 - 12:28 PM

Your problem lies here System.out.println(testData);. Arrays do not override the Object toString() method, so when you print them, you get the hash code output. You need to print out each element individually rather than an array.