demonstrator_updated.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. CertainTrust Demonstrator in JavaScript
  5. Demonstrates some capabilities of the CertainTrust SDK
  6. using a Java applet that interactively calculates
  7. AND and OR of two CertainTrust data objects and
  8. visually displays both the input objects and the output.
  9. @author Florian Volk <florian.volk@cased.de>
  10. -->
  11. <head>
  12. <meta charset="utf-8" />
  13. <title>CertainTrust Demonstrator in JavaScript</title>
  14. <style type="text/css">
  15. h1, p, td:nth-child(2n) { text-align: center; }
  16. table { margin: 50px 0; }
  17. </style>
  18. <!-- include these two scripts and the CSS to enable both CertainTrust and the HTI -->
  19. <script type="text/javascript" src="CertainTrust.js"></script>
  20. <script type="text/javascript" src="certainTrustHTI.js"></script>
  21. <link rel="stylesheet" type="text/css" href="certainTrustHTI.css"/>
  22. </head>
  23. <body>
  24. <h1>Demonstrator for CertainTrust</h1>
  25. <p>CertainTrust provides a means for the evaluation of propositional logic terms under uncertainty.</p>
  26. <table>
  27. <!-- Demonstrator for CertainTrust.AND -->
  28. <tr>
  29. <td id="and-operand1"></td>
  30. <td>AND</td>
  31. <td id="and-operand2"></td>
  32. <td>=</td>
  33. <td id="and-result"></td>
  34. <td></td>
  35. </tr>
  36. <!-- Demonstrator for CertainTrust.OR -->
  37. <tr>
  38. <td id="or-operand1"></td>
  39. <td>OR</td>
  40. <td id="or-operand2"></td>
  41. <td>=</td>
  42. <td id="or-result"></td>
  43. <td></td>
  44. </tr>
  45. <!-- Demonstrator for CertainTrust.cFusion -->
  46. <tr>
  47. <td id="cf-operand1"></td>
  48. <td>cFusion</td>
  49. <td id="cf-operand2"></td>
  50. <td>=</td>
  51. <td id="cf-result"></td>
  52. <td>DoC <input type="text" id="DoC" size="2"></td>
  53. </tr>
  54. <!-- Demonstrator for CertainTrust.wFusion -->
  55. <tr>
  56. <td id="wf-operand1"></td>
  57. <td>wFusion</td>
  58. <td id="wf-operand2"></td>
  59. <td>=</td>
  60. <td id="wf-result"></td>
  61. <td>Weight1 <select id = "weight1" onChange="selectW1(this.value);">
  62. <option value="0">0</option>
  63. <option value="1" selected="selected">1</option>
  64. <option value="2">2</option>
  65. <option value="3">3</option>
  66. <option value="4">4</option>
  67. <option value="5">5</option>
  68. </select><br><br>
  69. Weight2 <select id = "weight2" onChange="selectW2(this.value);">
  70. <option value="0">0</option>
  71. <option value="1" selected="selected">1</option>
  72. <option value="2">2</option>
  73. <option value="3">3</option>
  74. <option value="4">4</option>
  75. <option value="5">5</option>
  76. </select>
  77. </td>
  78. </tr>
  79. </table>
  80. <script type="text/javascript">
  81. // create an Array to hold the CertainTrust objects
  82. var CT_objects = [];
  83. var N = 10;
  84. var cweight = [1,1];
  85. var wweight = [1,1];
  86. var doc = 0.2;
  87. var CT_names = ['and-operand1', 'and-operand2', 'and-result',
  88. 'or-operand1', 'or-operand2', 'or-result',
  89. 'cf-operand1','cf-operand2','cf-result',
  90. 'wf-operand1','wf-operand2','wf-result'];
  91. function selectW1(value){
  92. wweight[0] = parseInt(value);
  93. WFObserver.update();
  94. }
  95. function selectW2(value){
  96. wweight[1] = parseInt(value);
  97. WFObserver.update();
  98. }
  99. // ANDObserver is used for the AND calculation
  100. var ANDObserver = {
  101. update: function() {
  102. // calculate the CertainTrust.AND for both values
  103. var CT_result = CT_objects['and-operand1'].AND(CT_objects['and-operand2']);
  104. // update the HTI which displays the result
  105. CT_objects['and-result'].setF(CT_result.getF());
  106. CT_objects['and-result'].setTC(CT_result.getT(), CT_result.getC());
  107. }
  108. };
  109. // ORObserver is used for the OR calculation
  110. var ORObserver = {
  111. update: function() {
  112. // calculate the CertainTrust.OR for both values
  113. var CT_result = CT_objects['or-operand1'].OR(CT_objects['or-operand2']);
  114. // update the HTI which displays the result
  115. CT_objects['or-result'].setF(CT_result.getF());
  116. CT_objects['or-result'].setTC(CT_result.getT(), CT_result.getC());
  117. }
  118. };
  119. // CFObserver is used for the conflicted fusion (cFusion) calculation
  120. var CFObserver = {
  121. update: function() {
  122. var fusTmp = new CertainTrust(5);
  123. var fusArray = [];
  124. fusArray.push(CT_objects['cf-operand1']);
  125. fusArray.push(CT_objects['cf-operand2']);
  126. //cFusion operation
  127. var CT_result = fusTmp.cFusion(fusArray,cweight);
  128. doc = CT_result.getDoC();
  129. // update the HTI which displays the result
  130. CT_objects['cf-result'].setF(CT_result.getF());
  131. CT_objects['cf-result'].setTC(CT_result.getT(), CT_result.getC());
  132. document.getElementById("DoC").value = doc;
  133. }
  134. };
  135. // WFObserver is used for the weighted fusion (wFusion) calculation
  136. var WFObserver = {
  137. update: function() {
  138. var fusTmp = new CertainTrust(5);
  139. var fusArray = [];
  140. fusArray.push(CT_objects['wf-operand1']);
  141. fusArray.push(CT_objects['wf-operand2']);
  142. //cFusion operation
  143. var CT_result = fusTmp.wFusion(fusArray,wweight);
  144. // update the HTI which displays the result
  145. CT_objects['wf-result'].setF(CT_result.getF());
  146. CT_objects['wf-result'].setTC(CT_result.getT(), CT_result.getC());
  147. }
  148. };
  149. // create the CertainTrust objects and the associated HTIs
  150. for (var i = 0, element; element = CT_names[i]; ++i) {
  151. var CT_object = new CertainTrust(N);
  152. // the result HTIs should be read-only
  153. var isResultHTI = (-1 !== element.indexOf('-result'));
  154. var HTI = new CertainTrustHTI(CT_object, {domParent: element, readonly: isResultHTI});
  155. // register our observers for the calculation
  156. if (!isResultHTI) {
  157. var isOR = (0 === element.indexOf('or-'));
  158. var isAND = (0 === element.indexOf('and-'));
  159. var isCF = (0 === element.indexOf('cf-'));
  160. var isWF = (0 === element.indexOf('wf-'));
  161. if(isOR){
  162. CT_object.addObserver(ORObserver);
  163. }
  164. else if(isAND){
  165. CT_object.addObserver(ANDObserver);
  166. }
  167. else if(isCF){
  168. CT_object.addObserver(CFObserver);
  169. }
  170. else{
  171. CT_object.addObserver(WFObserver);
  172. }
  173. }
  174. // store the created objects for easy access in the Arrays
  175. CT_objects[element] = CT_object;
  176. }
  177. // trigger initial update to the result HTIs
  178. ANDObserver.update();
  179. ORObserver.update();
  180. CFObserver.update();
  181. WFObserver.update();
  182. </script>
  183. <p>
  184. <img src="logo_tudarmstadt.png" alt="Technische Universität Darmstadt" width="176" height="73" />
  185. <img src="logo_softwarecluster.png" alt="Software-Cluster" width="212" height="73" />
  186. </p>
  187. </body>
  188. </html>