Skip to content

Commit 17f3231

Browse files
committed
first push
1 parent c490241 commit 17f3231

File tree

306 files changed

+257918
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+257918
-0
lines changed

.DS_Store

8 KB
Binary file not shown.
20.7 KB
Binary file not shown.
32.4 KB
Binary file not shown.
27.8 KB
Binary file not shown.
17 Bytes
Binary file not shown.

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
5+
env: TERM=dumb
6+
7+
script: timeout 600 gradle check

grades/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The 15-214 course staff will return grades and other feedback to you in
2+
this directory.
3+
4+
Please do not edit files in this directory. We have an independent
5+
record of your grades elsewhere, and you will only annoy the TAs if you
6+
edit our feedback. Annoyed TAs => Unhappy TAs, and you don't want an
7+
unhappy TA grading your work.

homework/.DS_Store

10 KB
Binary file not shown.

homework/1/.DS_Store

8 KB
Binary file not shown.

homework/1/.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/main/java"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

homework/1/build.gradle

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apply plugin: 'java'
2+
apply plugin: 'eclipse'
3+
apply plugin: 'cobertura'
4+
5+
test.testLogging { exceptionFormat "full"; events "failed", "passed", "skipped" }
6+
7+
configurations.all {
8+
resolutionStrategy {
9+
force 'org.ow2.asm:asm:5.0.3'
10+
forcedModules = [ 'org.ow2.asm:asm:5.0.3' ]
11+
}
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
dependencies {
19+
<<<<<<< HEAD
20+
compile files('lib/LinkedIntQueue.jar')
21+
testCompile group: 'junit', name: 'junit', version: '4.11'
22+
}
23+
24+
buildscript{
25+
repositories {
26+
mavenCentral()
27+
}
28+
29+
dependencies {
30+
classpath 'net.saliman:gradle-cobertura-plugin:2.2.5'
31+
}
32+
||||||| merged common ancestors
33+
testCompile 'junit:junit:4.10'
34+
}
35+
model {
36+
testSuites {
37+
test(JUnitTestSuiteSpec) {
38+
jUnitVersion '4.12'
39+
}
40+
}
41+
=======
42+
testCompile 'junit:junit:3.8.1'
43+
>>>>>>> 82933d660fed676cf65d0ac2ad4bf84bfa47184b
44+
}
45+
cobertura.coverageFormats = ['html', 'xml']
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<html>
2+
<head>
3+
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
4+
<style type="text/css">
5+
.bannercell {
6+
border: 0px;
7+
padding: 0px;
8+
}
9+
body {
10+
margin-left: 10;
11+
margin-right: 10;
12+
font:normal 80% arial,helvetica,sanserif;
13+
background-color:#FFFFFF;
14+
color:#000000;
15+
}
16+
.a td {
17+
background: #efefef;
18+
}
19+
.b td {
20+
background: #fff;
21+
}
22+
th, td {
23+
text-align: left;
24+
vertical-align: top;
25+
}
26+
th {
27+
font-weight:bold;
28+
background: #ccc;
29+
color: black;
30+
}
31+
table, th, td {
32+
font-size:100%;
33+
border: none
34+
}
35+
table.log tr td, tr th {
36+
37+
}
38+
h2 {
39+
font-weight:bold;
40+
font-size:140%;
41+
margin-bottom: 5;
42+
}
43+
h3 {
44+
font-size:100%;
45+
font-weight:bold;
46+
background: #525D76;
47+
color: white;
48+
text-decoration: none;
49+
padding: 5px;
50+
margin-right: 2px;
51+
margin-left: 2px;
52+
margin-bottom: 0;
53+
}
54+
</style>
55+
</head>
56+
<body>
57+
<a name="top"></a>
58+
<table border="0" cellpadding="0" cellspacing="0" width="100%">
59+
<tr>
60+
<td class="bannercell" rowspan="2"></td><td class="text-align:right">
61+
<h2>CheckStyle Audit</h2>
62+
</td>
63+
</tr>
64+
<tr>
65+
<td class="text-align:right">Designed for use with <a href="http://checkstyle.sourceforge.net/">CheckStyle</a> and <a href="http://jakarta.apache.org">Ant</a>.</td>
66+
</tr>
67+
</table>
68+
<hr size="1">
69+
<h3>Summary</h3>
70+
<table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
71+
<tr>
72+
<th>Files</th><th>Errors</th>
73+
</tr>
74+
<tr class="a">
75+
<td>3</td><td>5</td>
76+
</tr>
77+
</table>
78+
<hr size="1" width="100%" align="left">
79+
<h3>Files</h3>
80+
<table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
81+
<tr>
82+
<th>Name</th><th>Errors</th>
83+
</tr>
84+
<tr class="a">
85+
<td><a href="#f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/ClosestMatches.java">/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/ClosestMatches.java</a></td><td>3</td>
86+
</tr>
87+
<tr class="b">
88+
<td><a href="#f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/FindClosestMatch.java">/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/FindClosestMatch.java</a></td><td>2</td>
89+
</tr>
90+
<tr class="a">
91+
<td><a href="#f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/Document.java">/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/Document.java</a></td><td>0</td>
92+
</tr>
93+
</table>
94+
<hr size="1" width="100%" align="left">
95+
<a name="f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/ClosestMatches.java"></a>
96+
<h3>File /Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/ClosestMatches.java</h3>
97+
<table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
98+
<tr>
99+
<th>Error Description</th><th>Line</th>
100+
</tr>
101+
<tr class="a">
102+
<td>Missing a Javadoc comment.</td><td>7</td>
103+
</tr>
104+
<tr class="b">
105+
<td>Expected @param tag for 'args'.</td><td>14</td>
106+
</tr>
107+
<tr class="a">
108+
<td>Expected @throws tag for 'IOException'.</td><td>14</td>
109+
</tr>
110+
</table>
111+
<a href="#top">Back to top</a><a name="f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/Document.java"></a>
112+
<h3>File /Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/Document.java</h3>
113+
<table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
114+
<tr>
115+
<th>Error Description</th><th>Line</th>
116+
</tr>
117+
</table>
118+
<a href="#top">Back to top</a><a name="f-/Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/FindClosestMatch.java"></a>
119+
<h3>File /Users/haoxu/Desktop/15-214/haox1/homework/1/src/main/java/edu/cmu/cs/cs214/hw1/FindClosestMatch.java</h3>
120+
<table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
121+
<tr>
122+
<th>Error Description</th><th>Line</th>
123+
</tr>
124+
<tr class="a">
125+
<td>Expected @param tag for 'args'.</td><td>17</td>
126+
</tr>
127+
<tr class="b">
128+
<td>Expected @throws tag for 'IOException'.</td><td>17</td>
129+
</tr>
130+
</table>
131+
<a href="#top">Back to top</a>
132+
<hr size="1" width="100%" align="left">
133+
</body>
134+
</html>

homework/1/hw1.pdf

251 KB
Binary file not shown.

homework/1/lib/LinkedIntQueue.jar

84.7 KB
Binary file not shown.

homework/1/src/.DS_Store

6 KB
Binary file not shown.

homework/1/src/main/.DS_Store

6 KB
Binary file not shown.

homework/1/src/main/java/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
6 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

homework/1/src/main/java/edu/cmu/cs/cs214/hw1/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package edu.cmu.cs.cs214.hw1;
2+
3+
import java.io.IOException;
4+
5+
public class ClosestMatches {
6+
/**
7+
* main class.
8+
*
9+
* @param args
10+
* @throws IOException
11+
*/
12+
public static void main(String[] args) throws IOException {
13+
int numOfDocs = args.length;
14+
double[][] simNew = new double[numOfDocs][numOfDocs];
15+
16+
for (int i = 0; i < numOfDocs; i++) {
17+
Document doc1 = new Document(args[i]);
18+
for (int j = i + 1; j < numOfDocs; j++) {
19+
Document doc2 = new Document(args[j]);
20+
simNew[i][j] = doc1.getSimilarity(doc2.getMap());
21+
}
22+
}
23+
24+
for (int i = numOfDocs - 1; i >= 0; i--) {
25+
for (int j = i - 1; j >= 0; j--) {
26+
simNew[i][j] = simNew[j][i];
27+
}
28+
}
29+
30+
for (int i = 0; i < numOfDocs; i++) {
31+
double maxSim = 0;
32+
int index1 = 0;
33+
int index2 = 0;
34+
for (int j = 0; j < numOfDocs; j++) {
35+
if (maxSim < simNew[i][j]) {
36+
maxSim = simNew[i][j];
37+
index1 = i;
38+
index2 = j;
39+
}
40+
}
41+
System.out.printf("The max similarity for URL:\n%s\nis\n%s\n", args[index1], args[index2]);
42+
System.out.printf("Their similarity is: %s\n", maxSim);
43+
44+
}
45+
46+
}
47+
48+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package edu.cmu.cs.cs214.hw1;
2+
3+
import java.io.FileNotFoundException;
4+
import java.io.IOException;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
7+
import java.util.Scanner;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
/**
12+
* Document class is used to store the words read from URL, and compute the
13+
* cosine similarity against another document.
14+
* Designed for cmu 15-214 Principles of Software Construction.
15+
* @author haoxu
16+
*
17+
*/
18+
public class Document {
19+
20+
/**
21+
* words represent the document words.
22+
*/
23+
private Map<String, Integer> words;
24+
25+
/**
26+
* public constructor Document.
27+
* @param urlString for input
28+
* @throws MalformedURLException check if the URL is readable.
29+
* @throws IOException check if there is IO exception
30+
*/
31+
public Document(String urlString) throws MalformedURLException, IOException {
32+
33+
Scanner sc = null;
34+
35+
words = new HashMap<String, Integer>();
36+
37+
try {
38+
sc = new Scanner(new URL(urlString).openStream());
39+
//System.out.println(sc);
40+
while (sc.hasNext()) {
41+
String word = sc.next();
42+
//System.out.println(line);
43+
//String[] wordsFromText = line.split("\\W");
44+
//for (String word : wordsFromText) {
45+
//System.out.println(word);
46+
if (words.get(word) == null) {
47+
words.put(word, 1);
48+
} else {
49+
words.put(word, words.get(word) + 1);
50+
}
51+
//}
52+
}
53+
} catch (FileNotFoundException e) {
54+
System.err.println("Cannot find the file");
55+
} finally {
56+
if (sc != null) {
57+
sc.close();
58+
}
59+
}
60+
}
61+
62+
/**
63+
* getMap convert the stored words into Map.
64+
* @return Map
65+
*/
66+
public Map<String, Integer> getMap() {
67+
Map<String, Integer> newWords = new HashMap<String, Integer>(words);
68+
return newWords;
69+
}
70+
71+
/**
72+
* getSimilarity method computes the cosine similarity.
73+
* @param other for input
74+
* @return cosine similarity
75+
*/
76+
public double getSimilarity(Map<String, Integer> other) {
77+
double norm1 = getNorm(words);
78+
//System.out.println(norm1);
79+
double norm2 = getNorm(other);
80+
//System.out.println(norm2);
81+
double product = dotProduct(other);
82+
//System.out.println(product);
83+
return Math.acos(product / (norm1 * norm2));
84+
}
85+
86+
/**
87+
* getNorm method compute the norm of a map.
88+
* @param map for input
89+
* @return double
90+
*/
91+
private double getNorm(Map<String, Integer> map) {
92+
double sum = 0;
93+
for (String word : map.keySet()) {
94+
sum += Math.pow(map.get(word),2);
95+
}
96+
return Math.sqrt(sum);
97+
}
98+
99+
/**
100+
* dotProduct method computes the product between two maps.
101+
* @param map for input
102+
* @return product
103+
*/
104+
private double dotProduct(Map<String, Integer> map) {
105+
106+
double product = 0.0;
107+
for (String key : words.keySet()) {
108+
if (map.containsKey(key)) {
109+
product += words.get(key) * map.get(key);
110+
}
111+
}
112+
return product;
113+
}
114+
115+
@Override
116+
/**
117+
* toString returns a short string that identifies
118+
* the URL represented by the document.
119+
*/
120+
public String toString() {
121+
return words.toString();
122+
}
123+
}
Binary file not shown.

0 commit comments

Comments
 (0)