-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
321 lines (277 loc) · 13.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#hide1").click(function(){
$("#1").hide();
});
$("#show1").click(function(){
$("#1").show();
});
$("#hide2").click(function(){
$("#2").hide();
});
$("#show2").click(function(){
$("#2").show();
});
$("#hide3").click(function(){
$("#3").hide();
});
$("#show3").click(function(){
$("#3").show();
});
$("#hide4").click(function(){
$("#4").hide();
});
$("#show4").click(function(){
$("#4").show();
});
$("#hide5").click(function(){
$("#5").hide();
});
$("#show5").click(function(){
$("#5").show();
});
$("#hide6").click(function(){
$("#6").hide();
});
$("#show6").click(function(){
$("#6").show();
});
$("#hide7").click(function(){
$("#7").hide();
});
$("#show7").click(function(){
$("#7").show();
});
$("#hide8").click(function(){
$("#8").hide();
});
$("#show8").click(function(){
$("#8").show();
});
$("#hide9").click(function(){
$("#9").hide();
});
$("#show9").click(function(){
$("#9").show();
});
$("#hide10").click(function(){
$("#10").hide();
});
$("#show10").click(function(){
$("#10").show();
});
});
</script>
</head>
<body>
<p>Welcome to user query based recommendations</p>
<p>Following are the content</p>
<p>Query 1</p>
<div id ="rec1">One way to implement deep copy is to add copy constructors to each associated class. A copy constructor takes an instance of 'this' as its single argument and copies all the values from it. Quite some work, but pretty straightforward and safe. EDIT: note that you don't need to use accessor methods to read fields. You can access all fields directly because the source instance is always of the same type as the instance with the copy constructor. Obvious but might be overlooked. Example: Edit: Note that when using copy constructors you need to know the runtime type of the object you are copying. With the above approach you cannot easily copy a mixed list (you might be able to do it with some reflection code).</div>
<p>public class Order {private long number;public Order() {}/** * Copy constructor */public Order(Order source) {number = source.number;}}public class Customer {private String name;private List<Order> orders = new ArrayList<Order>();public Customer() {}/** * Copy constructor */public Customer(Customer source) {name = source.name;for (Order sourceOrder : source.orders) {orders.add(new Order(sourceOrder));}}public String getName() {return name;}public void setName(String name) {this.name = name;}}</p>
<div>Recommendation option <button id="hide1" >Hide</button> <button id="show1" type = "button" value="rec1" onclick="queryContent(this.value)">Show</button></div>
<div id='1'>
1st Query Recommendations
<div id ="rec_rec1">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec1">
</tbody>
</thead>
</table>
</div>
</div>
<p>Query 2</p>
<div id ="rec2">I was presented with this question in an end of module open book exam today and found myself lost. i was reading Head first Javaand both definitions seemed to be exactly the same. i was just wondering what the MAIN difference was for my own piece of mind. i know there are a number of similar questions to this but, none i have seen which provide a definitive answer.Thanks, Darren</div>
<div>Recommendation option <button id="hide2">Hide</button><button id="show2"type = "button" value="rec2" onclick="queryContent(this.value)">Show</button></div>
<div id='2'>2nd Query Recommendations
<div id ="rec_rec2">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec2">
</tbody>
</thead>
</table>
</div></div>
<p>Query 3</p>
<div id ="rec3">Inheritance is when a 'class' derives from an existing 'class'.So if you have a Person class, then you have a Student class that extends Person, Student inherits all the things that Person has.There are some details around the access modifiers you put on the fields/methods in Person, but that's the basic idea.For example, if you have a private field on Person, Student won't see it because its private, and private fields are not visible to subclasses.Polymorphism deals with how the program decides which methods it should use, depending on what type of thing it has.If you have a Person, which has a read method, and you have a Student which extends Person, which has its own implementation of read, which method gets called is determined for you by the runtime, depending if you have a Person or a Student.It gets a bit tricky, but if you do something likePerson p = new Student();p.read();the read method on Student gets called.Thats the polymorphism in action.You can do that assignment because a Student is a Person, but the runtime is smart enough to know that the actual type of p is Student.Note that details differ among languages.You can do inheritance in javascript for example, but its completely different than the way it works in Java.</div>
<div>Recommendation option<button id="hide3">Hide</button><button id="show3"type = "button" value="rec3" onclick="queryContent(this.value)">Show</button></div>
<div id='3'>3rd Query Recommendations
<div id ="rec_rec3">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec3">
</tbody>
</thead>
</table>
</div>
</div>
<p>Query 4</p>
<div id ="rec4">Polymorphism: The ability to treat objects of different types in a similar manner.Example: Giraffe and Crocodile are both Animals, and animals can Move.If you have an instance of an Animal then you can call Move without knowing or caring what type of animal it is.Inheritance: This is one way of achieving both Polymorphism and code reuse at the same time.Other forms of polymorphism:There are other way of achieving polymorphism, such as interfaces, which provide only polymorphism but no code reuse (sometimes the code is quite different, such as Move for a Snake would be quite different from Move for a Dog, in which case an Interface would be the better polymorphic choice in this case.In other dynamic languages polymorphism can be achieved with Duck Typing, which is the classes don't even need to share the same base class or interface, they just need a method with the same name.Or even more dynamic like Javascript, you don't even need classes at all, just an object with the same method name can be used polymorphically.</div>
<p></p>
<div id='4'>4th Query Recommendations
<div>Recommendation option<button id="hide4">Hide</button><button id="show4" type = "button" value="rec4" onclick="queryContent(this.value)">Show</button></div>
<div id ="rec_rec4">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec4">
</tbody>
</thead>
</table>
</div></div>
<p>Query 5</p>
<div id ="rec5">I found out that the above piece of code is perfectly legal in Java. I have the following questions. ThanksAdded one more question regarding Abstract method classes.
public class TestClass{public static void main(String[] args) {TestClass t = new TestClass();}private static void testMethod(){abstract class TestMethod{int a;int b;int c;abstract void implementMe();}class DummyClass extends TestMethod{void implementMe(){}}DummyClass dummy = new DummyClass();}}</div>
<div>Recommendation option<button id="hide5">Hide</button><button id="show5"type = "button" value="rec5" onclick="queryContent(this.value)">Show</button></div>
<div id='5'>5th Query Recommendations
<div id ="rec_rec5">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec5">
</tbody>
</thead>
</table>
</div></div>
<p>Query 6</p>
<div id ="rec6">In java it's a bit difficult to implement a deep object copy function. What steps you take to ensure the original object and the cloned one share no reference? </div>
<p></p>
<div>Recommendation option<button id="hide6">Hide</button><button id="show6" type = "button" value="rec6" onclick="queryContent(this.value)">Show</button></div>
<div id='6'>6th Query Recommendations
<div id ="rec_rec6">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec6">
</tbody>
</thead>
</table>
</div></div>
<p>Query 7</p>
<div id ="rec7">You can make a deep copy serialization without creating some files. Copy: Restore:
ByteArrayOutputStream bos = new ByteArrayOutputStream();ObjectOutputStream oos = new ObjectOutputStream(bos);oos.writeObject(object);oos.flush();oos.close();bos.close();byte[] byteData = bos.toByteArray();; ByteArrayInputStream bais = new ByteArrayInputStream(byteData);(Object) object = (Object) new ObjectInputStream(bais).readObject();</div>
<div>Recommendation option<button id="hide7">Hide</button><button id="show7" type = "button" value="rec7" onclick="queryContent(this.value)">Show</button></div>
<div id='7'>7th Query Recommendations
<div id ="rec_rec7">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec7">
</tbody>
</thead>
</table>
</div></div>
<p>Query 8</p>
<div id ="rec8">Java has the ability to create classes at runtime. These classes are known as Synthetic Classes or Dynamic Proxies. See for more information. Other open-source libraries, such as and also allow you to generate synthetic classes, and are more powerful than the libraries provided with the JRE. Synthetic classes are used by AOP (Aspect Oriented Programming) libraries such as Spring AOP and AspectJ, as well as ORM libraries such as Hibernate. </div>
<div>Recommendation option<button id="hide8"> Hide </button><button id="show8" type = "button" value="rec8" onclick="queryContent(this.value)"> Show </button></div>
<div id='8'>8th Query Recommendations
<div id ="rec_rec8">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec8">
</tbody>
</thead>
</table>
</div></div>
<p></p>
<p>Query 9</p>
<div id ="rec9">In short: the web server issues a unique identifier to on his visit. The visitor must bring back that ID for him to be recognised next time around. This identifier also allows the server to properly segregate objects owned by one session against that of another. If is: If is: Once he's on the service mode and on the groove, the servlet will work on the requests from all other clients.Why isn't it a good idea to have one instance per client? Think about this: Will you hire one pizza guy for every order that came? Do that and you'd be out of business in no time. It comes with a small risk though. Remember: this single guy holds all the order information in his pocket: so if you're not cautious about, he may end up giving the wrong order to a certain client.</div>
<div>Recommendation option <button id="hide9"> Hide </button><button id="show9" type = "button" value="rec9" onclick="queryContent(this.value)"> Show </button></div>
<div id='9'>9th Query Recommendations
<div id ="rec_rec9">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec9">
</tbody>
</thead>
</table>
</div></div>
<p></p>
<p>Query 10</p>
<div id ="rec10">A safe way is to serialize the object, then deserialize.This ensures everything is a brand new reference.about how to do this efficiently. Caveats: It's possible for classes to override serialization such that new instances are created, e.g. for singletons.Also this of course doesn't work if your classes aren't Serializable.</div>
<p></p>
<div>Recommendation option<button id="hide10">Hide</button><button id="show10"type = "button" value="rec10" onclick="queryContent(this.value)">Show</button></div>
<div id='10'>10th Query Recommendations
<div id ="rec_rec10">
<table>
<thead>
<tr>
</tr>
<tbody id= "rec_rec10">
</tbody>
</thead>
</table>
</div></div>
<script>
function recListing(data, id) {
console.log(id)
var tbody = document.getElementById('rec_' + id);
var max_length = Math.min(data.length, 10)
for(var i=0; i< max_length;i++) {
var tr = "<tr>";
var content = data[i]._source.content.replace(/<img[^>]*>/g,"")
tr += "<th>" + (i + 1) + "</th><td><h4>" + data[i]._source.heading.bold() + "<br>Score:" + data[i]._score + "</h4><hr/>" + content + "</td></tr>";
tbody.innerHTML += tr;
}
}
function queryContent(postNo){
var content_matter = document.getElementById(postNo).textContent;
var query = {
"query": {
"match": {
"content": content_matter,
}
}
};
$.ajax({
url: 'http://localhost:9200/try1/_search',
type: 'POST',
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(query),
success: function(data) {
recListing(data.hits.hits, postNo);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
},
});
}
</script>
<b>
<p>Indexing Technique</p></b>
<ul>
<li>Java Wikibooks was scrappped using beautifulSoup python based webscraping tool</li>
<li>As seen above headings that are in bold in the recommendations are actual headlines in the Javabooks</li>
<li>Followed by it is the content within that headline </li>
<li>Content was indexed using Elasticsearch, a Lucene based search engine. </li>
<li>To properly make use of inherent Elasticsearch query processing, all the contents were indexed under a common index with different id's. This ensured sort of scalability within our indexed content, as queries may combine two or more concepts at a time and retrieving results for such queries requires granularity in the indexed content.</li>
</ul>
<b>
<p>Originality</p></b>
<ul>
<li>Added Scoring Scale to the list of recommended items.</li>
<li>The scoring represents conceptually the document-document similairty between the query and our knowledge dataset.</li>
<li>A quantified Matching Score along with the content resonates a whole lot more with the user in terms of usefullness of the content.</li>
</ul>
</body>
</html>