├── README.md ├── lib ├── codemirror │ ├── codemirror.css │ └── codemirror.js ├── cyc │ ├── CycI.java │ ├── build-cyci.sh │ ├── cbm-cyc-kb.ke │ ├── run-cyc.sh │ └── run-cyci.sh └── fabric │ └── dist │ └── fabric.js ├── src ├── canvas.js └── cbm.js └── tests ├── clock1 ├── index.html └── test.js ├── clock2 ├── index.html └── test.js ├── clock3 ├── index.html └── test.js ├── clock4 ├── index.html └── test.js ├── clock5 ├── index.html └── test.js ├── home.css ├── home.html ├── zodiac1 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png ├── zodiac2 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png ├── zodiac3 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png ├── zodiac4 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png ├── zodiac5 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png └── zodiac6 ├── aquarius.png ├── aries.png ├── blank.png ├── cancer.png ├── capricorn.png ├── cs-adi-shamir.png ├── cs-alan-kay.png ├── cs-alan-turing.png ├── cs-alonzo-church.png ├── cs-anita-borg.png ├── cs-david-patterson.png ├── cs-guy-steele.png ├── cs-jospeh-licklider.png ├── cs-marvin-minsky.png ├── cs-stephen-cook.png ├── cs-stephen-wolfram.png ├── cs-wesley-clark.png ├── gemini.png ├── index.html ├── leo.png ├── libra.png ├── pisces.png ├── sagittarius.png ├── scorpio.png ├── taurus.png ├── test.js └── virgo.png /README.md: -------------------------------------------------------------------------------- 1 | # cbmjslib 2 | 3 | This is a JavaScript implementation of the "Call by Meaning" programming model for automated 4 | semantic discovery and data adaption as described in this [paper](http://www.hesam.us/callbymeaning/). 5 | 6 | ## Blog Entry 7 | 8 | Read the [blog post](http://www.cdglabs.org/cbmjslib/blog) about it 9 | 10 | # Instructions 11 | 12 | In order to use CbMJS library first launch Cyc and its interface server: 13 | 14 | * 1) Obtain ResearchCyc (placed in a directory, say $CYCDIR): 15 | * http://www.cyc.com/platform/researchcyc 16 | 17 | * 2) Obtain the following jar files and place in lib/jar/: 18 | * javax.servlet-5.1.11.jar 19 | * servlet-api-3.0.jar 20 | * jetty-http-9.0.6.v20130930.jar 21 | * websocket-api-9.0.6.v20130930.jar 22 | * jetty-io-9.0.6.v20130930.jar 23 | * websocket-client-9.0.6.v20130930.jar 24 | * jetty-server-9.0.6.v20130930.jar 25 | * websocket-common-9.0.6.v20130930.jar 26 | * jetty-util-9.0.6.v20130930.jar 27 | * websocket-server-9.0.6.v20130930.jar 28 | * opencyc-4.0-nighthawk.145797.jar 29 | * websocket-servlet-9.0.6.v20130930.jar 30 | 31 | * 3) Build Java based Cyc API CycI.java by running: 32 | * $ cd lib/cyc 33 | * $ mkdir classes 34 | * $ ./build-cyci.sh 35 | 36 | * 4) In one terminal run Cyc: 37 | * $ cd $CYCDIR/server/cyc/run/bin/ ; ./run-cyc.sh 38 | 39 | * 5) Load the extra Call-by-Meaning ontology into base Cyc KB by following steps: 40 | * a. Open up the Cyc browser in your web browser by noting the URL given in the terminal where you ran step (4) above, seen on line saying "Connect via URL ..." 41 | * b. Log in as "CycAdministrator". 42 | * c. On top pane click on Tools > Navigator > Load KE File 43 | * d. Enter full pathname: "$HERE/lib/cyc/cbm-cyc-kb.ke" and click on "Load File". 44 | * e. Click on "Add Forms to Agenda". 45 | 46 | * 6) In another terminal run CycI interface server: 47 | * $ ./run-cyci.sh 48 | 49 | # API (package: cbm.KB) 50 | 51 | addComponent(object) 52 | 53 | add object to KB repository 54 | 55 | findByName(name) 56 | 57 | find an object in KB repository with the name of 58 | 59 | findByAPIName(name) 60 | 61 | find an object in KB repository having a property named 62 | 63 | findByMeaning(query, asker, onFound) 64 | 65 | object asks the KB to find an object in repository matching with query and 66 | callback function(foundObject) { ... } to be invoked on response 67 | 68 | askByMeaning(query, isBoolean, onReturn, asker, askee) 69 | 70 | object asks the KB query about object and callback 71 | function(answer) { ... } is invoked on response. boolean value says whether 72 | (if true) this is a "yes/no" question or (if false) asking for a dictionary model as 73 | the answer 74 | -------------------------------------------------------------------------------- /lib/codemirror/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | } 8 | .CodeMirror-scroll { 9 | /* Set scrolling behaviour here */ 10 | overflow: auto; 11 | } 12 | 13 | /* PADDING */ 14 | 15 | .CodeMirror-lines { 16 | padding: 4px 0; /* Vertical padding around content */ 17 | } 18 | .CodeMirror pre { 19 | padding: 0 4px; /* Horizontal padding of content */ 20 | } 21 | 22 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 23 | background-color: white; /* The little square between H and V scrollbars */ 24 | } 25 | 26 | /* GUTTER */ 27 | 28 | .CodeMirror-gutters { 29 | border-right: 1px solid #ddd; 30 | background-color: #f7f7f7; 31 | white-space: nowrap; 32 | } 33 | .CodeMirror-linenumbers {} 34 | .CodeMirror-linenumber { 35 | padding: 0 3px 0 5px; 36 | min-width: 20px; 37 | text-align: right; 38 | color: #999; 39 | -moz-box-sizing: content-box; 40 | box-sizing: content-box; 41 | } 42 | 43 | .CodeMirror-guttermarker { color: black; } 44 | .CodeMirror-guttermarker-subtle { color: #999; } 45 | 46 | /* CURSOR */ 47 | 48 | .CodeMirror div.CodeMirror-cursor { 49 | border-left: 1px solid black; 50 | } 51 | /* Shown when moving in bi-directional text */ 52 | .CodeMirror div.CodeMirror-secondarycursor { 53 | border-left: 1px solid silver; 54 | } 55 | .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor { 56 | width: auto; 57 | border: 0; 58 | background: #7e7; 59 | } 60 | .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursors { 61 | z-index: 1; 62 | } 63 | 64 | .cm-animate-fat-cursor { 65 | width: auto; 66 | border: 0; 67 | -webkit-animation: blink 1.06s steps(1) infinite; 68 | -moz-animation: blink 1.06s steps(1) infinite; 69 | animation: blink 1.06s steps(1) infinite; 70 | } 71 | @-moz-keyframes blink { 72 | 0% { background: #7e7; } 73 | 50% { background: none; } 74 | 100% { background: #7e7; } 75 | } 76 | @-webkit-keyframes blink { 77 | 0% { background: #7e7; } 78 | 50% { background: none; } 79 | 100% { background: #7e7; } 80 | } 81 | @keyframes blink { 82 | 0% { background: #7e7; } 83 | 50% { background: none; } 84 | 100% { background: #7e7; } 85 | } 86 | 87 | /* Can style cursor different in overwrite (non-insert) mode */ 88 | div.CodeMirror-overwrite div.CodeMirror-cursor {} 89 | 90 | .cm-tab { display: inline-block; } 91 | 92 | .CodeMirror-ruler { 93 | border-left: 1px solid #ccc; 94 | position: absolute; 95 | } 96 | 97 | /* DEFAULT THEME */ 98 | 99 | .cm-s-default .cm-keyword {color: #708;} 100 | .cm-s-default .cm-atom {color: #219;} 101 | .cm-s-default .cm-number {color: #164;} 102 | .cm-s-default .cm-def {color: #00f;} 103 | .cm-s-default .cm-variable, 104 | .cm-s-default .cm-punctuation, 105 | .cm-s-default .cm-property, 106 | .cm-s-default .cm-operator {} 107 | .cm-s-default .cm-variable-2 {color: #05a;} 108 | .cm-s-default .cm-variable-3 {color: #085;} 109 | .cm-s-default .cm-comment {color: #a50;} 110 | .cm-s-default .cm-string {color: #a11;} 111 | .cm-s-default .cm-string-2 {color: #f50;} 112 | .cm-s-default .cm-meta {color: #555;} 113 | .cm-s-default .cm-qualifier {color: #555;} 114 | .cm-s-default .cm-builtin {color: #30a;} 115 | .cm-s-default .cm-bracket {color: #997;} 116 | .cm-s-default .cm-tag {color: #170;} 117 | .cm-s-default .cm-attribute {color: #00c;} 118 | .cm-s-default .cm-header {color: blue;} 119 | .cm-s-default .cm-quote {color: #090;} 120 | .cm-s-default .cm-hr {color: #999;} 121 | .cm-s-default .cm-link {color: #00c;} 122 | 123 | .cm-negative {color: #d44;} 124 | .cm-positive {color: #292;} 125 | .cm-header, .cm-strong {font-weight: bold;} 126 | .cm-em {font-style: italic;} 127 | .cm-link {text-decoration: underline;} 128 | 129 | .cm-s-default .cm-error {color: #f00;} 130 | .cm-invalidchar {color: #f00;} 131 | 132 | /* Default styles for common addons */ 133 | 134 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 135 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 136 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); } 137 | .CodeMirror-activeline-background {background: #e8f2ff;} 138 | 139 | /* STOP */ 140 | 141 | /* The rest of this file contains styles related to the mechanics of 142 | the editor. You probably shouldn't touch them. */ 143 | 144 | .CodeMirror { 145 | line-height: 1; 146 | position: relative; 147 | overflow: hidden; 148 | background: white; 149 | color: black; 150 | } 151 | 152 | .CodeMirror-scroll { 153 | /* 30px is the magic margin used to hide the element's real scrollbars */ 154 | /* See overflow: hidden in .CodeMirror */ 155 | margin-bottom: -30px; margin-right: -30px; 156 | padding-bottom: 30px; 157 | height: 100%; 158 | outline: none; /* Prevent dragging from highlighting the element */ 159 | position: relative; 160 | -moz-box-sizing: content-box; 161 | box-sizing: content-box; 162 | } 163 | .CodeMirror-sizer { 164 | position: relative; 165 | border-right: 30px solid transparent; 166 | -moz-box-sizing: content-box; 167 | box-sizing: content-box; 168 | } 169 | 170 | /* The fake, visible scrollbars. Used to force redraw during scrolling 171 | before actuall scrolling happens, thus preventing shaking and 172 | flickering artifacts. */ 173 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { 174 | position: absolute; 175 | z-index: 6; 176 | display: none; 177 | } 178 | .CodeMirror-vscrollbar { 179 | right: 0; top: 0; 180 | overflow-x: hidden; 181 | overflow-y: scroll; 182 | } 183 | .CodeMirror-hscrollbar { 184 | bottom: 0; left: 0; 185 | overflow-y: hidden; 186 | overflow-x: scroll; 187 | } 188 | .CodeMirror-scrollbar-filler { 189 | right: 0; bottom: 0; 190 | } 191 | .CodeMirror-gutter-filler { 192 | left: 0; bottom: 0; 193 | } 194 | 195 | .CodeMirror-gutters { 196 | position: absolute; left: 0; top: 0; 197 | padding-bottom: 30px; 198 | z-index: 3; 199 | } 200 | .CodeMirror-gutter { 201 | white-space: normal; 202 | height: 100%; 203 | -moz-box-sizing: content-box; 204 | box-sizing: content-box; 205 | padding-bottom: 30px; 206 | margin-bottom: -32px; 207 | display: inline-block; 208 | /* Hack to make IE7 behave */ 209 | *zoom:1; 210 | *display:inline; 211 | } 212 | .CodeMirror-gutter-elt { 213 | position: absolute; 214 | cursor: default; 215 | z-index: 4; 216 | } 217 | 218 | .CodeMirror-lines { 219 | cursor: text; 220 | min-height: 1px; /* prevents collapsing before first draw */ 221 | } 222 | .CodeMirror pre { 223 | /* Reset some styles that the rest of the page might have set */ 224 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0; 225 | border-width: 0; 226 | background: transparent; 227 | font-family: inherit; 228 | font-size: 18; 229 | margin: 0; 230 | white-space: pre; 231 | word-wrap: normal; 232 | line-height: inherit; 233 | color: inherit; 234 | z-index: 2; 235 | position: relative; 236 | overflow: visible; 237 | } 238 | .CodeMirror-wrap pre { 239 | word-wrap: break-word; 240 | white-space: pre-wrap; 241 | word-break: normal; 242 | } 243 | 244 | .CodeMirror-linebackground { 245 | position: absolute; 246 | left: 0; right: 0; top: 0; bottom: 0; 247 | z-index: 0; 248 | } 249 | 250 | .CodeMirror-linewidget { 251 | position: relative; 252 | z-index: 2; 253 | overflow: auto; 254 | } 255 | 256 | .CodeMirror-widget {} 257 | 258 | .CodeMirror-wrap .CodeMirror-scroll { 259 | overflow-x: hidden; 260 | } 261 | 262 | .CodeMirror-measure { 263 | position: absolute; 264 | width: 100%; 265 | height: 0; 266 | overflow: hidden; 267 | visibility: hidden; 268 | } 269 | .CodeMirror-measure pre { position: static; } 270 | 271 | .CodeMirror div.CodeMirror-cursor { 272 | position: absolute; 273 | border-right: none; 274 | width: 0; 275 | } 276 | 277 | div.CodeMirror-cursors { 278 | visibility: hidden; 279 | position: relative; 280 | z-index: 3; 281 | } 282 | .CodeMirror-focused div.CodeMirror-cursors { 283 | visibility: visible; 284 | } 285 | 286 | .CodeMirror-selected { background: #d9d9d9; } 287 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 288 | .CodeMirror-crosshair { cursor: crosshair; } 289 | 290 | .cm-searching { 291 | background: #ffa; 292 | background: rgba(255, 255, 0, .4); 293 | } 294 | 295 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */ 296 | .CodeMirror span { *vertical-align: text-bottom; } 297 | 298 | /* Used to force a border model for a node */ 299 | .cm-force-border { padding-right: .1px; } 300 | 301 | @media print { 302 | /* Hide the cursor when printing */ 303 | .CodeMirror div.CodeMirror-cursors { 304 | visibility: hidden; 305 | } 306 | } 307 | 308 | /* Help users use markselection to safely style text background */ 309 | span.CodeMirror-selectedtext { background: none; } -------------------------------------------------------------------------------- /lib/cyc/CycI.java: -------------------------------------------------------------------------------- 1 | import java.io.ByteArrayInputStream; 2 | import java.io.ByteArrayOutputStream; 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.InputStreamReader; 9 | import java.io.OutputStreamWriter; 10 | import java.io.PrintWriter; 11 | import java.net.ConnectException; 12 | import java.net.MalformedURLException; 13 | import java.net.URL; 14 | import java.net.UnknownHostException; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.HashSet; 18 | import java.util.HashMap; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | import java.util.Locale; 22 | import java.util.Map; 23 | import java.util.Random; 24 | import java.util.logging.Level; 25 | import java.util.logging.Logger; 26 | import org.opencyc.api.CycAccess; 27 | import org.opencyc.api.CycObjectFactory; 28 | import org.opencyc.comm.SocketComm; 29 | import org.opencyc.comm.SocketCommRoundRobin; 30 | import org.opencyc.cycobject.ByteArray; 31 | import org.opencyc.cycobject.CycAssertion; 32 | import org.opencyc.cycobject.CycConstant; 33 | import org.opencyc.cycobject.CycFormulaSentence; 34 | import org.opencyc.cycobject.CycFort; 35 | import org.opencyc.cycobject.CycList; 36 | import org.opencyc.cycobject.CycListParser; 37 | import org.opencyc.cycobject.CycNart; 38 | import org.opencyc.cycobject.CycNaut; 39 | import org.opencyc.cycobject.CycObject; 40 | import org.opencyc.cycobject.CycSymbol; 41 | import org.opencyc.cycobject.CycVariable; 42 | import org.opencyc.cycobject.DefaultCycObject; 43 | import org.opencyc.cycobject.ELMt; 44 | import org.opencyc.cycobject.Guid; 45 | import org.opencyc.inference.InferenceResultSet; 46 | import org.opencyc.inference.params.DefaultInferenceParameters; 47 | import org.opencyc.inference.params.InferenceParameters; 48 | import org.opencyc.util.StringUtils; 49 | 50 | import org.eclipse.jetty.server.Server; 51 | import org.eclipse.jetty.websocket.server.WebSocketHandler; 52 | import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; 53 | 54 | import java.io.IOException; 55 | import org.eclipse.jetty.websocket.api.Session; 56 | import org.eclipse.jetty.websocket.api.RemoteEndpoint; 57 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; 58 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; 59 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; 60 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; 61 | import org.eclipse.jetty.websocket.api.annotations.WebSocket; 62 | 63 | @WebSocket 64 | public class CycI { 65 | 66 | // options: 67 | public static HashMap Options = new HashMap(); 68 | static { 69 | Options.put("BooleanQuery_MaxTransformationDepth", 1); 70 | Options.put("BooleanQuery_MaxProofDepth", 0); 71 | Options.put("BooleanQuery_MaxTime", 30); 72 | Options.put("ValueQuery_MaxTransformationDepth", 1); 73 | Options.put("ValueQuery_MaxProofDepth", 0); 74 | Options.put("ValueQuery_MaxTime", 30); 75 | } 76 | public static String HostName = "localhost"; 77 | public static int HostPort = 3600; 78 | 79 | int BooleanQuery_MaxTransformationDepth;; 80 | int BooleanQuery_MaxProofDepth; 81 | int BooleanQuery_MaxTime; 82 | int ValueQuery_MaxTransformationDepth; 83 | int ValueQuery_MaxProofDepth; 84 | int ValueQuery_MaxTime; 85 | 86 | CycAccess cyc; 87 | CycFormulaSentence query; 88 | ELMt mt; 89 | InferenceParameters queryPropertiesBooleanQuery, queryPropertiesValueQuery; 90 | RemoteEndpoint client; 91 | 92 | 93 | void setOption(String option, String valueString) { 94 | try { 95 | int value = Integer.parseInt(valueString); 96 | CycI.Options.put(option, value); 97 | cyc = null; 98 | } catch (Exception e) { 99 | System.exit(1); 100 | } 101 | } 102 | 103 | void setUp(String queryMt) throws Exception { 104 | BooleanQuery_MaxTransformationDepth = Options.get("BooleanQuery_MaxTransformationDepth"); 105 | BooleanQuery_MaxProofDepth = Options.get("BooleanQuery_MaxProofDepth"); 106 | BooleanQuery_MaxTime = Options.get("BooleanQuery_MaxTime"); 107 | ValueQuery_MaxTransformationDepth = Options.get("ValueQuery_MaxTransformationDepth"); 108 | ValueQuery_MaxProofDepth = Options.get("ValueQuery_MaxProofDepth"); 109 | ValueQuery_MaxTime = Options.get("ValueQuery_MaxTime"); 110 | 111 | cyc = new CycAccess(HostName, HostPort); 112 | cyc.setCyclist("#$CycAdministrator"); 113 | mt = cyc.makeELMt(queryMt.equals("") ? cyc.everythingPSC : cyc.getKnownConstantByName(queryMt)); 114 | queryPropertiesBooleanQuery = new DefaultInferenceParameters(cyc); 115 | queryPropertiesBooleanQuery.setMaxNumber(1); 116 | queryPropertiesBooleanQuery.put(CycObjectFactory.makeCycSymbol(":max-transformation-depth"), BooleanQuery_MaxTransformationDepth); 117 | if (BooleanQuery_MaxProofDepth > 0) 118 | queryPropertiesBooleanQuery.put(CycObjectFactory.makeCycSymbol(":max-proof-depth"), BooleanQuery_MaxProofDepth); 119 | queryPropertiesBooleanQuery.put(CycObjectFactory.makeCycSymbol(":max-time"), BooleanQuery_MaxTime); 120 | 121 | queryPropertiesValueQuery = new DefaultInferenceParameters(cyc); 122 | queryPropertiesValueQuery.setMaxNumber(1); 123 | queryPropertiesValueQuery.put(CycObjectFactory.makeCycSymbol(":max-transformation-depth"), ValueQuery_MaxTransformationDepth); 124 | if (ValueQuery_MaxProofDepth > 0) 125 | queryPropertiesValueQuery.put(CycObjectFactory.makeCycSymbol(":max-proof-depth"), ValueQuery_MaxProofDepth); 126 | queryPropertiesValueQuery.put(CycObjectFactory.makeCycSymbol(":max-time"), ValueQuery_MaxTime); 127 | 128 | } 129 | 130 | void close() { 131 | cyc.close(); 132 | } 133 | 134 | InferenceResultSet executeQuery(String querySentence, String queryMt) { 135 | try { 136 | if (cyc == null) 137 | setUp(queryMt); 138 | CycFormulaSentence query = cyc.makeCycSentence(querySentence); 139 | InferenceResultSet response = cyc.executeQuery(query, mt, queryPropertiesBooleanQuery, BooleanQuery_MaxTime * 1000); 140 | return response; 141 | } catch (Throwable e) { 142 | e.printStackTrace(); 143 | return null; 144 | } 145 | } 146 | 147 | InferenceResultSet queryVariable(String querySentence, String queryMt) { 148 | try { 149 | if (cyc == null) 150 | setUp(queryMt); 151 | //CycFormulaSentence query = cyc.makeCycSentence(querySentence); 152 | //CycVariable variable = CycObjectFactory.makeCycVariable("?RETURN"); 153 | //CycList response = cyc.queryVariable(variable, query, cyc.makeELMt(mt), queryProperties); 154 | CycFormulaSentence query = cyc.makeCycSentence(querySentence); 155 | InferenceResultSet response = cyc.executeQuery(query, mt, queryPropertiesValueQuery, ValueQuery_MaxTime * 1000); 156 | return response; 157 | } catch (Throwable e) { 158 | e.printStackTrace(); 159 | return null; 160 | } 161 | } 162 | 163 | @OnWebSocketClose 164 | public void onClose(int statusCode, String reason) { 165 | System.out.println("Close: statusCode=" + statusCode + ", reason=" + reason); 166 | } 167 | 168 | @OnWebSocketError 169 | public void onError(Throwable t) { 170 | System.out.println("Error: " + t.getMessage()); 171 | } 172 | 173 | @OnWebSocketConnect 174 | public void onConnect(Session session) { 175 | System.out.println("Connect: " + session.getRemoteAddress().getAddress()); 176 | // try { 177 | client = session.getRemote(); 178 | //client.sendString("Hello client"); 179 | // } catch (IOException e) { 180 | // e.printStackTrace(); 181 | // } 182 | } 183 | 184 | private String parseModel(String responseString) { 185 | int i1 = 0; 186 | int i2 = 0; 187 | int i3 = 0; 188 | String res = ""; 189 | String addr = ""; 190 | while (i1 >= 0) { 191 | i1 = responseString.indexOf("{?", i3); 192 | if (i1 >= 0) { 193 | i2 = responseString.indexOf("->", i1); 194 | i3 = responseString.indexOf("}", i2); 195 | String varName = responseString.substring(i1+2, i2); 196 | if (varName.indexOf("TMPVAR") < 0) { 197 | String varValue = responseString.substring(i2+2, i3); 198 | if (varValue.indexOf("HYP-") < 0) { 199 | res += addr + varName + ":" + varValue; 200 | addr = ","; 201 | } 202 | } 203 | } 204 | } 205 | return res; 206 | } 207 | 208 | @OnWebSocketMessage 209 | public void onMessage(String message) { 210 | //System.out.println("message: " + message); 211 | String[] parts = message.split("\\|"); 212 | String command = parts[0]; 213 | String one = parts[1]; 214 | String two = parts[2]; 215 | if (command.equals("option")) { 216 | // an option set 217 | System.out.println("set option: " + one + " value: " + two); 218 | setOption(one, two); 219 | } else { 220 | // a query 221 | String id = one; 222 | String kind = two; 223 | boolean isBooleanQuery = kind.equals("boolean"); 224 | String queryMt = parts[3]; 225 | String query = parts[4]; 226 | System.out.println("query id: " + id + " kind: " + kind + " mt: " + queryMt + " query: " + query); 227 | long startMilliseconds = System.currentTimeMillis(); 228 | //HS FIXME 229 | try { 230 | String answer = ""; 231 | InferenceResultSet response; 232 | if (isBooleanQuery) { 233 | response = executeQuery(query, queryMt); 234 | String responseString = response.toString(); 235 | //System.out.println("query id: " + id + " result: " + responseString); 236 | boolean isTrue = responseString.equals("true") || response.next(); //HACK FIXME! 237 | answer = isTrue ? "true" : "false"; 238 | } else { 239 | //FIXME 240 | //CycList response = queryVariable(query); 241 | //HACK FIXME 242 | response = queryVariable(query, queryMt); 243 | String responseString = response.toString(); 244 | //System.out.println("query id: " + id + " result: " + responseString); 245 | try { 246 | answer = parseModel(responseString); 247 | } catch (Exception e) { 248 | e.printStackTrace(); 249 | } 250 | } 251 | client.sendString(id + "|" + answer); 252 | long endMilliseconds = System.currentTimeMillis(); 253 | System.out.println("query id: " + id + " answer: " + answer + " elapsed time: " + (endMilliseconds - startMilliseconds) + " ms.\n"); 254 | } catch (IOException e) { 255 | e.printStackTrace(); 256 | } 257 | } 258 | } 259 | 260 | public static void main(String[] args) throws Exception { 261 | Server server = new Server(8080); 262 | WebSocketHandler wsHandler = new WebSocketHandler() { 263 | @Override 264 | public void configure(WebSocketServletFactory factory) { 265 | factory.register(CycI.class); 266 | } 267 | }; 268 | server.setHandler(wsHandler); 269 | server.start(); 270 | server.join(); 271 | } 272 | } 273 | 274 | -------------------------------------------------------------------------------- /lib/cyc/build-cyci.sh: -------------------------------------------------------------------------------- 1 | javac -cp classes:../jar/jetty-util-9.0.6.v20130930.jar:../jar/servlet-api-3.0.jar:../jar/websocket-api-9.0.6.v20130930.jar:../jar/jetty-server-9.0.6.v20130930.jar:../jar/websocket-servlet-9.0.6.v20130930.jar:../jar/websocket-server-9.0.6.v20130930.jar:../jar/javax.servlet-5.1.11.jar:../jar/opencyc-4.0-nighthawk.145797.jar -d classes CycI.java 2 | -------------------------------------------------------------------------------- /lib/cyc/cbm-cyc-kb.ke: -------------------------------------------------------------------------------- 1 | in Mt: UniversalVocabularyMt . 2 | 3 | constant: ProgramVariable-CBM . 4 | 5 | in Mt: UniversalVocabularyMt . 6 | 7 | isa: ObjectType . 8 | isa: TemporalStuffType . 9 | comment: "The collection of program variables in CBM." . 10 | 11 | constant: programUsed-CBM . 12 | 13 | in Mt: UniversalVocabularyMt . 14 | 15 | isa: BinaryPredicate . 16 | isa: ActorSlot . 17 | arg1Isa: ComputerActivity . 18 | arg2Isa: ProgramVariable-CBM . 19 | comment: "(programUsed-CBM ACT PROG) means that a copy of PROG is used in the activity ACT." . 20 | 21 | constant: programVariableHasName . 22 | 23 | in Mt: UniversalVocabularyMt . 24 | 25 | isa: BinaryPredicate . 26 | arg1Isa: ProgramVariable-CBM . 27 | arg2Isa: CharacterString . 28 | comment: "(programVariableHasName VAR NAME) means program variable VAR is named string NAME" . 29 | 30 | constant: programVariableRepresents . 31 | 32 | in Mt: UniversalVocabularyMt . 33 | 34 | isa: TernaryPredicate . 35 | arg1Isa: ProgramVariable-CBM . 36 | arg2Isa: Individual . 37 | arg3Isa: Thing . 38 | comment: "(programVariableRepresents VAR INDIV COLL) means program variable VAR semantically represents an individual thing INDIV which is an instance of collection thing COLL" . 39 | 40 | constant: programVariableHasProperty . 41 | 42 | in Mt: UniversalVocabularyMt . 43 | 44 | isa: BinaryPredicate . 45 | arg1Isa: ProgramVariable-CBM . 46 | arg2Isa: ProgramVariable-CBM . 47 | comment: "(programVariableHasProperty VAR PROPVAR) means ProgramVariable-CBM VAR has another programVariable PROPVAR as its property (field)" . 48 | 49 | constant: programVariableIsaFunctionWithArg1 . 50 | 51 | in Mt: UniversalVocabularyMt . 52 | 53 | isa: TernaryPredicate . 54 | arg1Isa: ProgramVariable-CBM . 55 | arg2Isa: Thing . 56 | arg3Isa: Thing . 57 | comment: "(programVariableIsaFunctionWithArg1 VAR THING COL) means program variable VAR is a function that inputs thing THING of type COL" . 58 | 59 | in Mt: UniversalVocabularyMt . 60 | 61 | constant: programVariableIsaFunctionWithOutput . 62 | 63 | in Mt: UniversalVocabularyMt . 64 | 65 | isa: TernaryPredicate . 66 | arg1Isa: ProgramVariable-CBM . 67 | arg2Isa: Thing . 68 | arg3Isa: Thing . 69 | comment: "(programVariableIsaFunctionWithOutput VAR THING COL) means program variable VAR is a function that outputs thing THING of type COL" . 70 | 71 | constant: programParsesInputInto . 72 | 73 | in Mt: UniversalVocabularyMt . 74 | 75 | isa: TernaryPredicate . 76 | arg1Isa: ProgramVariable-CBM . 77 | arg2Isa: Thing . 78 | arg3Isa: Thing . 79 | comment: "(programParsesInputInto VAR COL1 COL2) means program variable VAR is a function that inputs thing of type COL1 and parses into something of type COL2." . 80 | 81 | in Mt: UniversalVocabularyMt . 82 | 83 | f:(implies 84 | (and (isa ?THIS ProgramVariable-CBM) 85 | (primaryFunction ?THIS SemanticParsing programUsed) 86 | (programVariableIsaFunctionWithArg1 ?THIS ?I ?IT) 87 | (programVariableIsaFunctionWithOutput ?THIS ?O ?OT)) 88 | (programParsesInputInto ?THIS ?IT ?OT)). 89 | 90 | constant: ImageSearchEngine . 91 | 92 | in Mt: UniversalVocabularyMt . 93 | 94 | isa: FirstOrderCollection . 95 | genls: SearchEngine . 96 | comment: "The collection of search engines used for finding images." . 97 | 98 | in Mt: UniversalVocabularyMt . 99 | 100 | f:(implies 101 | (isa ?THIS ImageSearchEngine) 102 | (behaviorCapable ?THIS (SubcollectionOfWithRelationToTypeFn ElectronicDataSearching informationSought VisualImage) searchEngineUsed)). 103 | -------------------------------------------------------------------------------- /lib/cyc/run-cyc.sh: -------------------------------------------------------------------------------- 1 | cd /Users/hesam/research/cdg-c/lib/cyc/researchcyc-4.0-nighthawk/server/cyc/run/bin/;./run-cyc.sh 2 | -------------------------------------------------------------------------------- /lib/cyc/run-cyci.sh: -------------------------------------------------------------------------------- 1 | java -cp classes:../jar/servlet-api-3.1.jar:../jar/websocket-api-9.0.6.v20130930.jar:../jar/jetty-server-9.0.6.v20130930.jar:../jar/websocket-servlet-9.0.6.v20130930.jar:../jar/websocket-server-9.0.6.v20130930.jar:../jar/jetty-http-9.0.6.v20130930.jar:../jar/jetty-io-9.0.6.v20130930.jar:../jar/websocket-client-9.0.6.v20130930.jar:../jar/websocket-common-9.0.6.v20130930.jar:../jar/servlet-api-3.0.jar:../jar/jetty-util-9.0.6.v20130930.jar:../jar/opencyc-4.0-nighthawk.145797.jar CycI 2 | -------------------------------------------------------------------------------- /src/canvas.js: -------------------------------------------------------------------------------- 1 | // --------------------------- API -------------------------------------- 2 | 3 | cbm.Canvas = function(canvasId) { 4 | this.canvas = new fabric.Canvas(canvasId) 5 | this.init() 6 | } 7 | 8 | cbm.Canvas.prototype.add = function(element, object) { 9 | this.addCanvasElement(element) 10 | var id = this.nextId++ 11 | element.id = id 12 | this.components[id] = {element: element, object: object} 13 | if (object && object.name) 14 | this.componentsNameToIdMap[object.name] = id 15 | element.on('selected', function() { 16 | this.updateInspectorWithObject(id) 17 | }.bind(this)) 18 | } 19 | 20 | cbm.Canvas.prototype.getElementByName = function(name) { 21 | return this.componentsNameToIdMap[name] ? 22 | this.components[this.componentsNameToIdMap[name]].element : undefined 23 | } 24 | 25 | cbm.Canvas.prototype.setInterval = function(stepFn, interval) { 26 | setInterval(function() { 27 | for (id in this.components) { 28 | var component = this.components[id] 29 | var object = component.object 30 | if (object && object[stepFn]) { 31 | object[stepFn]() 32 | this.refreshObjectValue(id) 33 | } 34 | } 35 | this.canvas.renderAll() 36 | }.bind(this), interval) 37 | } 38 | 39 | // --------------------------- Implementation -------------------------------------- 40 | 41 | cbm.Canvas.prototype.addCanvasElement = function(obj, name) { 42 | this.canvas.add(obj) 43 | } 44 | 45 | // focus inspector to 46 | cbm.Canvas.prototype.updateInspectorWithObject = function(id) { 47 | this.activeObjectId = id 48 | var component = this.components[id] 49 | //var frms = obj.formulas 50 | var element = component.element 51 | this.setObjectFormulaInspectorText(codeToString(component.object)) 52 | this.setObjectValueInspectorText(valueToString(component.object)) 53 | if (this.canvas.getActiveObject() !== element) 54 | this.canvas.setActiveObject(element) 55 | this.canvas.renderAll() 56 | } 57 | 58 | cbm.Canvas.prototype.setObjectFormulaInspectorText = function(text) { 59 | this.objectFormulaInspector.setValue(text) 60 | } 61 | 62 | cbm.Canvas.prototype.setObjectValueInspectorText = function(text) { 63 | this.objectValueInspector.setValue(text) 64 | } 65 | 66 | cbm.Canvas.prototype.refreshObjectValue = function(id) { 67 | var component = this.components[id] 68 | var actId = this.activeObjectId 69 | if (actId == id) 70 | this.setObjectValueInspectorText(valueToString(component.object)) 71 | } 72 | 73 | cbm.Canvas.prototype.init = function() { 74 | 75 | this.components = {} 76 | this.componentsNameToIdMap = {} 77 | this.nextId = 1 78 | this.codeView = true 79 | 80 | var buttonPos = 5 81 | 82 | // buttons 83 | var button = new fabric.LabeledRect({visible: true, 84 | left: 5, 85 | top: buttonPos, 86 | fill: '#aaa', 87 | width: 110, 88 | height: 25, 89 | label: 'Code View'}) 90 | this.addCanvasElement(button, 'code-view') 91 | button.on('mouseup', function() { 92 | var x = 700, y = 200 93 | if (!this.codeView) 94 | y = 700 95 | this.codeView = !this.codeView 96 | this.objectFormulaInspector.setSize(x, y) 97 | this.objectValueInspector.setSize(x, y) 98 | }.bind(this)) 99 | 100 | // inspectors 101 | var objectFormulaInspectorWidth = 1000 102 | var objectFormulaInspectorHeight = this.codeView ? 700 : 200 103 | this.objectFormulaInspector = CodeMirror.fromTextArea(document.getElementById('code-inspector')) 104 | this.objectFormulaInspector.setSize(objectFormulaInspectorWidth, objectFormulaInspectorHeight) 105 | this.objectValueInspector = CodeMirror.fromTextArea(document.getElementById('value-inspector')) 106 | this.objectValueInspector.setSize(this.canvas.width - objectFormulaInspectorWidth, objectFormulaInspectorHeight) 107 | this.objectFormulaInspectorTitle = new fabric.Text('Code', {visible: true, left: 20, top: 530, fontFamily: 'Monaco', fontSize: 14, fill: 'black'}) 108 | this.addCanvasElement(this.objectFormulaInspectorTitle, 'formula-inspector-title') 109 | this.objectValueInspectorTitle = new fabric.Text('Values', {visible: true, left: this.objectFormulaInspectorTitle.left + objectFormulaInspectorWidth, top: 530, fontFamily: 'Monaco', fontSize: 14, fill: 'black'}) 110 | this.addCanvasElement(this.objectValueInspectorTitle, 'value-inspector-title') 111 | 112 | } 113 | 114 | codeToString = function(obj) { 115 | var res = '' 116 | for (p in obj) { 117 | if (p.charAt(0) === '_') 118 | break 119 | var v = obj[p] 120 | var t = typeof v 121 | if (t === 'function') 122 | res += p + ': ' + v + "\n\n" 123 | } 124 | return res 125 | } 126 | 127 | valueToString = function(obj) { 128 | var res = '' 129 | for (p in obj) { 130 | if (p.charAt(0) === '_') 131 | break 132 | var v = obj[p] 133 | var t = typeof v 134 | if (t !== 'function') 135 | res += p + ': ' + JSON.stringify(v) + "\n" 136 | } 137 | return res 138 | } 139 | -------------------------------------------------------------------------------- /src/cbm.js: -------------------------------------------------------------------------------- 1 | cbm = {} 2 | 3 | // --------------------------- API -------------------------------------- 4 | 5 | cbm.KB = function(initCommonSenseKB) { 6 | this.components = {} 7 | if (initCommonSenseKB) 8 | this.initCommonSenseKB() 9 | } 10 | 11 | cbm.KB.prototype.addComponent = function(component) { 12 | var name = component.name 13 | if (!this.components[name]) { 14 | this.components[name] = component 15 | // if component has property specs add implicit specs once here... 16 | var implicitThisSpec, implicitPropSpecs = [], specProps = [] 17 | if (component.spec) 18 | implicitThisSpec = '(isa ?THIS ProgramVariable-CBM) ' 19 | for (p in component) { 20 | var specP = p + '_spec' 21 | if (component[specP]) { 22 | var pU = p.toUpperCase() 23 | specProps.push(p) 24 | var pSpecVar = '?' + pU 25 | implicitPropSpecs.push('(isa ' + pSpecVar + ' ProgramVariable-CBM) (programVariableHasProperty ?THIS ' + pSpecVar + ') (programVariableHasName ' + pSpecVar + ' "' + p + '") ') 26 | } 27 | } 28 | if (implicitThisSpec || implicitPropSpecs.length > 0) { 29 | component.spec = component.spec || function() { return '' } 30 | var fnCode = "(function() { return '(and ' + '" + (implicitThisSpec || '') + "' + this.spec() " + (implicitPropSpecs.length > 0 ? (" + ' " + implicitPropSpecs.join(' ') + "'") : "") 31 | specProps.forEach(function(p) { 32 | var specP = p + '_spec' 33 | var pU = p.toUpperCase() 34 | fnCode += " + this." + specP + "().replace(/\\?(\\w+)/g, function(match, a) { return '?' + ((a === '_' || a === '" + pU + "') ? '' : '" + pU + "-') + a }) + ' '" 35 | }) 36 | fnCode += "+ ')' })" 37 | //console.log(fnCode) 38 | component._fullSpec = eval(fnCode) 39 | } 40 | } 41 | } 42 | 43 | cbm.KB.prototype.findByName = function(name) { 44 | for (n in this.components) { 45 | var c = this.components[n] 46 | if (c.name === name) 47 | return c 48 | } 49 | return undefined 50 | } 51 | 52 | cbm.KB.prototype.findByAPIName = function(name) { 53 | for (n in this.components) { 54 | var c = this.components[n] 55 | for (p in c) { 56 | if (p === name) 57 | return c 58 | } 59 | } 60 | return undefined 61 | } 62 | 63 | cbm.KB.prototype.findByMeaning = function(query, asker, onFound) { 64 | if (this.commonSenseKBUninitiated()) 65 | return undefined 66 | var checkComponents = [] 67 | for (n in this.components) { 68 | var c = this.components[n] 69 | if (c._fullSpec) 70 | checkComponents.push(c) 71 | } 72 | if (this.opt_debugOn) 73 | console.log("findByMeaning issued. query: " + query) 74 | return this.findByMeaningH(query, asker, onFound, checkComponents) 75 | } 76 | 77 | cbm.KB.prototype.findByMeaningH = function(query, asker, onFound, checkComponents) { 78 | var self = this 79 | if (checkComponents.length == 0) 80 | return undefined 81 | var component = checkComponents.pop() 82 | var onReturn = function(answer) { 83 | //console.log('a:' + answer + ' q:' + query) 84 | if (answer) 85 | onFound.call(asker, component) 86 | else 87 | self.findByMeaningH(query, asker, onFound, checkComponents) } 88 | this.askProver(query, true, onReturn, asker, component) 89 | return undefined 90 | } 91 | 92 | cbm.KB.prototype.askByMeaning = function(query, asker, askee, isBoolean, onReturn) { 93 | if (this.commonSenseKBUninitiated()) 94 | return undefined 95 | return this.askProver(query, isBoolean, onReturn, asker, askee) 96 | } 97 | 98 | // --------------------------- Implementation -------------------------------------- 99 | 100 | cbm.KB.prototype.commonSenseKBUninitiated = function() { 101 | if (this.commonSenseReady) 102 | return false 103 | if (!this.commonSenseErrorReported) { 104 | this.commonSenseErrorReported = true 105 | alert('Common sense server is not running!') 106 | } 107 | return true 108 | } 109 | 110 | // following code to interface with Prover to run a spec query: 111 | cbm.KB.prototype.initCommonSenseKB = function() { 112 | //console.log('defining specQuery') 113 | var proverI = new WebSocket("ws://127.0.0.1:8080/") 114 | proverI.queryId = 0 115 | proverI.nextQueryId = function() { var res = this.queryId++; return res } 116 | this.queries = {} 117 | this.proverI = proverI 118 | this.specQueriesMt = '' 119 | 120 | proverI.onopen = function() { 121 | //console.log("WS connection opened!") 122 | this.commonSenseReady = true 123 | }.bind(this) 124 | 125 | proverI.onmessage = function (evt) { 126 | var message = evt.data 127 | var parts = message.split('|') 128 | var queryId = parts[0] 129 | var res = parts[1] 130 | var queryInfo = this.queries[queryId] 131 | if (queryInfo) { 132 | var isBoolean = queryInfo.isBoolean 133 | if (isBoolean) 134 | res = res === 'true' 135 | else 136 | res = parseSpecQueryModel(res) 137 | if (this.opt_debugOn) { 138 | console.log("query id: " + queryId + " is boolean: " + isBoolean + " result: " + res) 139 | console.log('res: ' + JSON.stringify(res) + ' reattmpt=' + queryInfo.reattempt) 140 | } 141 | var asker = queryInfo.asker 142 | var onReturn = queryInfo.onReturn 143 | 144 | if (!res && /*isBoolean &&*/ !queryInfo.reattempt && !this.opt_untautologizeSpecs && this.opt_alsoTryUntautologizedSpecs) { 145 | var proverlQuery = '(#$and ' + queryInfo.query + ' ?TMPVAR0)' 146 | this.askProverHelper({queryId: this.proverI.nextQueryId(), query: proverlQuery, asker: asker, isBoolean: isBoolean, onReturn: onReturn, reattempt: true}) 147 | } else 148 | onReturn.call(asker, res) 149 | delete this.queries[queryId] 150 | } 151 | }.bind(this) 152 | 153 | proverI.onclose = function() { 154 | console.log("WS connection closed!") 155 | this.commonSenseReady = false 156 | this.commonSenseKBUninitiated() 157 | }.bind(this) 158 | 159 | proverI.onerror = function(err) { 160 | console.log("WS error!") 161 | this.commonSenseReady = false 162 | this.commonSenseKBUninitiated() 163 | }.bind(this) 164 | } 165 | 166 | cbm.KB.prototype.askProver = function(query, isBoolean, onReturn, asker, askee, queryId) { 167 | if (!this.commonSenseReady) 168 | return undefined 169 | onReturn = onReturn || function(answer) { console.log('answer is: ' + answer) } 170 | queryId = queryId || this.proverI.nextQueryId() 171 | var thisModel, specs, objectHasSpecs, proverlQueryOrig 172 | if (asker && asker._fullSpec) { 173 | var thisSpecs = asker._fullSpec() 174 | if (thisSpecs) 175 | specs = //'(and ' + 176 | thisSpecs 177 | //+ ')' 178 | } 179 | if (askee) { 180 | var askeeSpecs = askee._fullSpec() 181 | //console.log(askeeSpecs) 182 | askeeSpecs = askeeSpecs.replace(/\?(\w)/g, function(match, a) { return '?' + (a === '_' ? '' : 'THAT-') + a }).replace(/\?THAT\-THIS/g, '?THAT') 183 | //console.log(askeeSpecs) 184 | if (askeeSpecs) 185 | specs = specs ? ('(and ' + askeeSpecs + ')') : askeeSpecs 186 | //console.log('replace: ' + askeeSpecs.replace(/\?THAT\-THAT/g, '?THAT')) 187 | //console.log('specs: ' + specs) 188 | } 189 | // for boolean query just return false if no askee specs: 190 | if (specs) { 191 | var opStr = (!isBoolean && this.opt_conjoinGivenSpecsAndQuery) ? 'and' : 'implies' 192 | proverlQueryOrig = '(' + opStr + ' ' + specs + ' ' + query + ')' 193 | } else 194 | proverlQueryOrig = query 195 | // add annoying prefix '#$': 196 | proverlQueryOrig = proverlQueryOrig.replace(/(\s|\()([a-zA-Z])/g, function(match, a, b) { return a + '#$' + b }) 197 | // remove wild card symbol '$_': 198 | var proverlQuerySplit = proverlQueryOrig.split('\?_') 199 | var tmpVarCtr = 1 200 | var proverlQuery = proverlQuerySplit[0] 201 | for (var i = 1; i < proverlQuerySplit.length; i++) 202 | proverlQuery += '?TMPVAR' + i + proverlQuerySplit[i] 203 | // Prover API is silly and returns false on a Tautology: 204 | if (this.opt_untautologizeSpecs/* && isBoolean*/) 205 | proverlQuery = '(#$and ' + proverlQuery + ' ?TMPVAR0)' 206 | if (this.opt_debugOn) 207 | console.log('asker: ' + JSON.stringify(asker) + ' askee: ' + JSON.stringify(askee) + 'asker/askees specs: ' + specs + ' isBoolean: ' + isBoolean + ' spec query: ' + query + ' proverl query (' + queryId + '): ' + proverlQuery) 208 | this.askProverHelper({queryId: queryId, query: proverlQuery, asker: asker, isBoolean: isBoolean, onReturn: onReturn}) 209 | return undefined 210 | } 211 | 212 | cbm.KB.prototype.askProverHelper = function(queryInfo) { 213 | //console.log(queryInfo) 214 | var queryId = queryInfo.queryId 215 | this.queries[queryId] = queryInfo 216 | this.proverI.send('query|' + queryId + '|' + (queryInfo.isBoolean ? 'boolean' : 'value') + '|' + this.specQueriesMt + '|' + queryInfo.query) 217 | } 218 | 219 | //HACK FIXME: need a parser... 220 | parseStringToJSValue = function(val) { 221 | //if (proverToValueMap) 222 | // val = proverToValueMap[val] || val 223 | var res = Number(val) 224 | if (res) 225 | return res 226 | return val 227 | } 228 | 229 | parseSpecQueryModel = function(model) { 230 | var res = undefined 231 | var bindings = model == '' ? [] : model.split(',') 232 | for (var i = 0; i < bindings.length; i++) { 233 | var binding = bindings[i].split(':') 234 | var varName = binding[0] 235 | var varValue = parseStringToJSValue(binding[1]) 236 | if (!res) res = {} 237 | res[varName] = varValue 238 | } 239 | return res 240 | } 241 | -------------------------------------------------------------------------------- /tests/clock1/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/clock1/test.js: -------------------------------------------------------------------------------- 1 | kb = new cbm.KB() 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var clockGUIComponent = { 5 | name: 'wallClock', 6 | getTime: function() { return new Date().getTime() }, 7 | run: function() { 8 | this.epoch = this.getTime() 9 | this.date = new Date(this.epoch) 10 | this.seconds = this.date.getSeconds() 11 | this.minutes = this.date.getMinutes() 12 | this.hours = this.date.getHours() % 12 13 | this.hourAngle = (this.hours + this.minutes / 60) * 30 14 | this.minuteAngle = ((this.minutes + this.seconds / 60) * 6) 15 | this.secondAngle = this.seconds * 6 16 | canvas.getElementByName('hourHand').angle = this.hourAngle 17 | canvas.getElementByName('minuteHand').angle = this.minuteAngle 18 | canvas.getElementByName('secondHand').angle = this.secondAngle 19 | } 20 | } 21 | 22 | canvas.add(new fabric.Circle({radius: 175, left: 625, top: 125, fill: 'gray'}), clockGUIComponent) 23 | canvas.add(new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'hourHand'}) 24 | canvas.add(new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'minuteHand'}) 25 | canvas.add(new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}), {name: 'secondHand'}) 26 | canvas.add(new fabric.Text('12', {left: 783, top: 130, fill: 'black', textBackgroundColor: 'gray'})) 27 | canvas.add(new fabric.Text('3', {left: 940, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 28 | canvas.add(new fabric.Text('6', {left: 790, top: 420, fill: 'black', textBackgroundColor: 'gray'})) 29 | canvas.add(new fabric.Text('9', {left: 640, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 30 | 31 | canvas.setInterval('run', 1000) 32 | 33 | -------------------------------------------------------------------------------- /tests/clock2/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/clock2/test.js: -------------------------------------------------------------------------------- 1 | kb = new cbm.KB() 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var timeSourceComponent = { 5 | name: 'Time Authority', 6 | getTime: function() { return new Date().getTime() } 7 | } 8 | 9 | kb.addComponent(timeSourceComponent) 10 | canvas.add(new fabric.LabeledRect({label: 'Time Authority', width: 200, height: 200, left: 300, top: 200, fill: 'green'}), timeSourceComponent) 11 | 12 | var hourHandE = new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 13 | var minuteHandE = new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 14 | var secondHandE = new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}) 15 | 16 | var clockGUIComponent = { 17 | name: 'wallClock', 18 | run: function() { 19 | this.clock = kb.findByAPIName('getTime') 20 | this.epoch = this.clock.getTime() 21 | this.date = new Date(this.epoch) 22 | this.seconds = this.date.getSeconds() 23 | this.minutes = this.date.getMinutes() 24 | this.hours = this.date.getHours() % 12 25 | this.hourAngle = (this.hours + this.minutes / 60) * 30 26 | this.minuteAngle = ((this.minutes + this.seconds / 60) * 6) 27 | this.secondAngle = this.seconds * 6 28 | canvas.getElementByName('hourHand').angle = this.hourAngle 29 | canvas.getElementByName('minuteHand').angle = this.minuteAngle 30 | canvas.getElementByName('secondHand').angle = this.secondAngle 31 | } 32 | } 33 | 34 | canvas.add(new fabric.Circle({radius: 175, left: 625, top: 125, fill: 'gray'}), clockGUIComponent) 35 | canvas.add(new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'hourHand'}) 36 | canvas.add(new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'minuteHand'}) 37 | canvas.add(new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}), {name: 'secondHand'}) 38 | canvas.add(new fabric.Text('12', {left: 783, top: 130, fill: 'black', textBackgroundColor: 'gray'})) 39 | canvas.add(new fabric.Text('3', {left: 940, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 40 | canvas.add(new fabric.Text('6', {left: 790, top: 420, fill: 'black', textBackgroundColor: 'gray'})) 41 | canvas.add(new fabric.Text('9', {left: 640, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 42 | 43 | canvas.setInterval('run', 1000) 44 | 45 | -------------------------------------------------------------------------------- /tests/clock3/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/clock3/test.js: -------------------------------------------------------------------------------- 1 | kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var timeSourceComponent = { 5 | name: 'Time Authority', 6 | spec: function() { 7 | return '(programVariableRepresents ?THIS ?_ Clock)' 8 | }, 9 | getTime: function() { return new Date().getTime() } 10 | } 11 | 12 | kb.addComponent(timeSourceComponent) 13 | canvas.add(new fabric.LabeledRect({label: 'Time Authority', width: 200, height: 200, left: 300, top: 200, fill: 'green'}), timeSourceComponent) 14 | 15 | var hourHandE = new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 16 | var minuteHandE = new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 17 | var secondHandE = new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}) 18 | 19 | var clockGUIComponent = { 20 | run: function() { 21 | kb.findByMeaning( 22 | '(and (programVariableRepresents ?THAT ?_ ?SOMETYPE)' 23 | + '(typeBehaviorCapable-DeviceUsed ?SOMETYPE (MeasuringFn Time-Quantity)))', 24 | this, this.onFindByMeaningResponse) }, 25 | onFindByMeaningResponse: function(found) { 26 | this.clock = found 27 | this.epoch = this.clock.getTime() 28 | this.date = new Date(this.epoch) 29 | this.seconds = this.date.getSeconds() 30 | this.minutes = this.date.getMinutes() 31 | this.hours = this.date.getHours() % 12 32 | this.hourAngle = (this.hours + this.minutes / 60) * 30 33 | this.minuteAngle = ((this.minutes + this.seconds / 60) * 6) 34 | this.secondAngle = this.seconds * 6 35 | canvas.getElementByName('hourHand').angle = this.hourAngle 36 | canvas.getElementByName('minuteHand').angle = this.minuteAngle 37 | canvas.getElementByName('secondHand').angle = this.secondAngle 38 | } 39 | } 40 | 41 | canvas.add(new fabric.Circle({radius: 175, left: 625, top: 125, fill: 'gray'}), clockGUIComponent) 42 | canvas.add(new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'hourHand'}) 43 | canvas.add(new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'minuteHand'}) 44 | canvas.add(new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}), {name: 'secondHand'}) 45 | canvas.add(new fabric.Text('12', {left: 783, top: 130, fill: 'black', textBackgroundColor: 'gray'})) 46 | canvas.add(new fabric.Text('3', {left: 940, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 47 | canvas.add(new fabric.Text('6', {left: 790, top: 420, fill: 'black', textBackgroundColor: 'gray'})) 48 | canvas.add(new fabric.Text('9', {left: 640, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 49 | 50 | canvas.setInterval('run', 1000) 51 | -------------------------------------------------------------------------------- /tests/clock4/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/clock4/test.js: -------------------------------------------------------------------------------- 1 | kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var timeSourceComponent = { 5 | name: 'Time Authority', 6 | spec: function() { 7 | return '(programVariableRepresents ?THIS ?_ Clock)' 8 | }, 9 | getTime: function() { return new Date().getTime() }, 10 | getTime_spec: function() { 11 | return '(programVariableRepresents ?GETTIME ?_' 12 | + '(SubcollectionOfWithRelationToFn Integer secondsSince1970ToDate Now))' 13 | } 14 | } 15 | 16 | kb.addComponent(timeSourceComponent) 17 | canvas.add(new fabric.LabeledRect({label: 'Time Authority', width: 200, height: 200, left: 300, top: 200, fill: 'green'}), timeSourceComponent) 18 | 19 | var hourHandE = new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 20 | var minuteHandE = new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 21 | var secondHandE = new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}) 22 | 23 | var clockGUIComponent = { 24 | name: 'wallClock', 25 | run: function() { 26 | kb.findByMeaning( 27 | '(and (programVariableRepresents ?THAT ?_ ?SOMETYPE)' 28 | + '(typeBehaviorCapable-DeviceUsed ?SOMETYPE (MeasuringFn Time-Quantity)))', 29 | this, this.onComponentDiscovered) }, 30 | onComponentDiscovered: function(found) { 31 | this.clock = found 32 | kb.askByMeaning( 33 | '(and (programVariableHasProperty ?THAT ?P)' 34 | + '(programVariableRepresents ?P ?_' 35 | + '(SubcollectionOfWithRelationToFn Integer secondsSince1970ToDate Now))' 36 | + '(programVariableHasName ?P ?NAME))', 37 | this, found, false, this.onAPIDiscovered) }, 38 | onAPIDiscovered: function(answer) { 39 | this.foundAPI = answer.NAME 40 | this.epoch = this.clock[this.foundAPI]() 41 | this.date = new Date(this.epoch) 42 | this.seconds = this.date.getSeconds() 43 | this.minutes = this.date.getMinutes() 44 | this.hours = this.date.getHours() % 12 45 | this.hourAngle = (this.hours + this.minutes / 60) * 30 46 | this.minuteAngle = ((this.minutes + this.seconds / 60) * 6) 47 | this.secondAngle = this.seconds * 6 48 | canvas.getElementByName('hourHand').angle = this.hourAngle 49 | canvas.getElementByName('minuteHand').angle = this.minuteAngle 50 | canvas.getElementByName('secondHand').angle = this.secondAngle 51 | } 52 | } 53 | 54 | canvas.add(new fabric.Circle({radius: 175, left: 625, top: 125, fill: 'gray'}), clockGUIComponent) 55 | canvas.add(new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'hourHand'}) 56 | canvas.add(new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'minuteHand'}) 57 | canvas.add(new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}), {name: 'secondHand'}) 58 | canvas.add(new fabric.Text('12', {left: 783, top: 130, fill: 'black', textBackgroundColor: 'gray'})) 59 | canvas.add(new fabric.Text('3', {left: 940, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 60 | canvas.add(new fabric.Text('6', {left: 790, top: 420, fill: 'black', textBackgroundColor: 'gray'})) 61 | canvas.add(new fabric.Text('9', {left: 640, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 62 | 63 | canvas.setInterval('run', 1000) 64 | -------------------------------------------------------------------------------- /tests/clock5/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/clock5/test.js: -------------------------------------------------------------------------------- 1 | kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var timeSourceComponent = { 5 | name: 'Time Authority', 6 | spec: function() { 7 | return '(and (programVariableRepresents ?THIS ?_ Clock)' + 8 | '(secondsSince1970ToDate ' + this.getTime() + ' Now)' + ')' 9 | }, 10 | getTime: function() { return new Date().getTime() }, 11 | getTime_spec: function() { 12 | return '(programVariableRepresents ?GETTIME ?_' 13 | + '(SubcollectionOfWithRelationToFn Integer secondsSince1970ToDate Now))' 14 | } 15 | } 16 | 17 | kb.addComponent(timeSourceComponent) 18 | canvas.add(new fabric.LabeledRect({label: 'Time Authority', width: 200, height: 200, left: 300, top: 200, fill: 'green'}), timeSourceComponent) 19 | 20 | var hourHandE = new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 21 | var minuteHandE = new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}) 22 | var secondHandE = new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}) 23 | 24 | var clockGUIComponent = { 25 | name: 'wallClock', 26 | run: function() { 27 | kb.findByMeaning( 28 | '(and (programVariableRepresents ?THAT ?_ ?SOMETYPE)' 29 | + '(typeBehaviorCapable-DeviceUsed ?SOMETYPE (MeasuringFn Time-Quantity)))', 30 | this, this.onComponentDiscovered) }, 31 | onComponentDiscovered: function(found) { 32 | kb.askByMeaning( 33 | '(indexicalReferent Now' 34 | + '(SecondFn ?SEC (MinuteFn ?MIN (HourFn ?HR ?DAY))))', 35 | this, found, false, this.onTimeDiscovered) }, 36 | onTimeDiscovered: function(answer) { 37 | this.seconds = answer.SEC 38 | this.minutes = answer.MIN 39 | this.hours = answer.HR 40 | this.hourAngle = (this.hours + this.minutes / 60) * 30 41 | this.minuteAngle = ((this.minutes + this.seconds / 60) * 6) 42 | this.secondAngle = this.seconds * 6 43 | canvas.getElementByName('hourHand').angle = this.hourAngle 44 | canvas.getElementByName('minuteHand').angle = this.minuteAngle 45 | canvas.getElementByName('secondHand').angle = this.secondAngle 46 | } 47 | } 48 | 49 | canvas.add(new fabric.Circle({radius: 175, left: 625, top: 125, fill: 'gray'}), clockGUIComponent) 50 | canvas.add(new fabric.Triangle({width: 15, height: 50, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'hourHand'}) 51 | canvas.add(new fabric.Triangle({width: 10, height: 100, left: 800, top: 300, fill: 'black', originX: 'center', originY: 'bottom'}), {name: 'minuteHand'}) 52 | canvas.add(new fabric.Triangle({width: 5, height: 150, left: 800, top: 300, fill: 'red', originX: 'center', originY: 'bottom'}), {name: 'secondHand'}) 53 | canvas.add(new fabric.Text('12', {left: 783, top: 130, fill: 'black', textBackgroundColor: 'gray'})) 54 | canvas.add(new fabric.Text('3', {left: 940, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 55 | canvas.add(new fabric.Text('6', {left: 790, top: 420, fill: 'black', textBackgroundColor: 'gray'})) 56 | canvas.add(new fabric.Text('9', {left: 640, top: 275, fill: 'black', textBackgroundColor: 'gray'})) 57 | 58 | canvas.setInterval('run', 1000) 59 | -------------------------------------------------------------------------------- /tests/home.css: -------------------------------------------------------------------------------- 1 | textarea { 2 | /*resize: none;*/ 3 | } 4 | 5 | .CodeMirror { 6 | border: 1px solid black; 7 | } -------------------------------------------------------------------------------- /tests/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | CbMJS Library 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 |
15 |





16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/zodiac1/aquarius.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac1/aries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac1/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac1/cancer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac1/capricorn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-adi-shamir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-alan-kay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-alan-turing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-alonzo-church.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-anita-borg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-david-patterson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-guy-steele.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-marvin-minsky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-stephen-cook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac1/cs-wesley-clark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac1/gemini.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac1/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac1/leo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac1/libra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac1/pisces.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac1/sagittarius.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac1/scorpio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac1/taurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac1/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB() 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var myAppComponent = { 5 | name: 'myApp', 6 | run: function(userInput) { 7 | // parse the input 8 | this.userDateArray = this.getDate(userInput) 9 | if (this.userDateArray) { 10 | // convert into date object 11 | this.userDate = this.dateArrayToDate(this.userDateArray) 12 | // compute zodiac sign 13 | this.userSign = this.getZodiacSign(this.userDate) 14 | canvas.getElementByName('signName').text = this.userSign 15 | // get a url to img of zoadiac sign 16 | this.signImgUrl = this.getZodiacSignImg(this.userSign) 17 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 18 | // get a uri to img of a CS person with that sign 19 | this.csPersonImgUrl = this.getCSPersonImg(this.userSign) 20 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 21 | } 22 | }, 23 | getDate: function(date) { 24 | var dateObj = undefined 25 | if (date) { 26 | date = date.match(/\//) ? date.split('/') : date.split('.') 27 | if (date.length == 3) { 28 | var y = Number(date[2]) 29 | var m = Number(date[1]) 30 | var d = Number(date[0]) 31 | if (y && m && d) { 32 | m = m - 1 33 | dateObj = [y, m, d] 34 | } 35 | } 36 | } 37 | return dateObj 38 | }, 39 | dateArrayToDate: function(dateArray) { 40 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 41 | }, 42 | getZodiacSign: function(born) { 43 | var zodiac = { 44 | 'Capricorn1':{'m':0,'d':20}, 45 | 'Aquarius':{'m':1,'d':19}, 46 | 'Pisces':{'m':2,'d':20}, 47 | 'Aries':{'m':3,'d':20}, 48 | 'Taurus':{'m':4,'d':21}, 49 | 'Gemini':{'m':5,'d':21}, 50 | 'Cancer':{'m':6,'d':22}, 51 | 'Leo':{'m':7,'d':22}, 52 | 'Virgo':{'m':8,'d':23}, 53 | 'Libra':{'m':9,'d':23}, 54 | 'Scorpio':{'m':10,'d':22}, 55 | 'Sagittarius':{'m':11,'d':21}, 56 | 'Capricorn2':{'m':11,'d':31} 57 | } 58 | var astrologicalSign = '', zodiacEnd, astrologicalSign 59 | for(z in zodiac) { 60 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 61 | if (born <= zodiacEnd) { astrologicalSign = z; break } 62 | } 63 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 64 | return astrologicalSign 65 | }, 66 | getZodiacSignImg: function(zodiac) { 67 | return zodiac ? (zodiac + '.png') : '' 68 | }, 69 | getCSPersonImg: function(zodiac) { 70 | var zodiacCSPersons = { 71 | Capricorn: 'anita-borg', 72 | Aquarius: 'alan-turing', 73 | Pisces: 'jospeh-licklider', 74 | Aries: 'wesley-clark', 75 | Taurus: 'alan-kay', 76 | Gemini: 'alonzo-church', 77 | Cancer: 'adi-shamir', 78 | Leo: 'marvin-minsky', 79 | Virgo: 'stephen-wolfram', 80 | Libra: 'guy-steele', 81 | Scorpio: 'david-patterson', 82 | Sagittarius: 'stephen-cook' 83 | } 84 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 85 | } 86 | } 87 | 88 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 89 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 90 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 91 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 92 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 93 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 94 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 95 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 96 | 97 | canvas.getElementByName('input').on('editing:exited', function() { myAppComponent.run(this.text) }) 98 | 99 | function newImageElement(name, imgSrc) { 100 | var divE = document.getElementById('dynamically-added') 101 | var imgE = document.createElement('img') 102 | var imgEId = 'element-' + name 103 | imgE.setAttribute('id', imgEId) 104 | imgE.setAttribute('src', imgSrc) 105 | divE.appendChild(imgE) 106 | return imgE 107 | } 108 | -------------------------------------------------------------------------------- /tests/zodiac1/virgo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cdglabs/cbmjslib/c3d1856954562c9ffe75520c71065f3e0a364ca1/tests/zodiac1/virgo.png -------------------------------------------------------------------------------- /tests/zodiac2/aquarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac2/aries.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac2/blank.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac2/cancer.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac2/capricorn.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-adi-shamir.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-alan-kay.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-alan-turing.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-alonzo-church.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-anita-borg.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-david-patterson.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-guy-steele.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-marvin-minsky.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-stephen-cook.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac2/cs-wesley-clark.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac2/gemini.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac2/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac2/leo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac2/libra.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac2/pisces.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac2/sagittarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac2/scorpio.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac2/taurus.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac2/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB() 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 5 | 6 | var myAppComponent = { 7 | name: 'myApp', 8 | run: function(userInput) { 9 | // parse the input 10 | this.userDateArray = (kb.findByAPIName('getDate').getDate)(userInput) 11 | if (this.userDateArray) { 12 | // convert into date object 13 | this.userDate = this.dateArrayToDate(this.userDateArray) 14 | // compute zodiac sign 15 | this.userSign = (kb.findByAPIName('getZodiacSign').getZodiacSign)(this.userDate) 16 | canvas.getElementByName('signName').text = this.userSign 17 | // get a url to img of zoadiac sign 18 | this.signImgUrl = (kb.findByAPIName('getImgUrl').getImgUrl)(this.userSign) 19 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 20 | // get a uri to img of a CS person with that sign 21 | this.csPersonImgUrl = (kb.findByAPIName('getCSPersonImgUrl').getCSPersonImgUrl)(this.userSign) 22 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 23 | } 24 | }, 25 | dateArrayToDate: function(dateArray) { 26 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 27 | } 28 | } 29 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 30 | 31 | var dateParserComponent = { 32 | name: 'dateParser', 33 | getDate: function(date) { 34 | var dateObj = undefined 35 | if (date) { 36 | date = date.match(/\//) ? date.split('/') : date.split('.') 37 | if (date.length == 3) { 38 | var y = Number(date[2]) 39 | var m = Number(date[1]) 40 | var d = Number(date[0]) 41 | if (y && m && d) { 42 | m = m - 1 43 | dateObj = [y, m, d] 44 | } 45 | } 46 | } 47 | return dateObj 48 | } 49 | } 50 | 51 | kb.addComponent(dateParserComponent) 52 | canvas.add(new fabric.LabeledRect({label: dateParserComponent.name, top: oTop + 50, left: oLeft - 50, width: 200, height: 200, fill: '#f0f0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), dateParserComponent) 53 | 54 | var zodiacExpertComponent = { 55 | name: 'zodiacExpert', 56 | getZodiacSign: function(born) { 57 | var zodiac = { 58 | 'Capricorn1':{'m':0,'d':20}, 59 | 'Aquarius':{'m':1,'d':19}, 60 | 'Pisces':{'m':2,'d':20}, 61 | 'Aries':{'m':3,'d':20}, 62 | 'Taurus':{'m':4,'d':21}, 63 | 'Gemini':{'m':5,'d':21}, 64 | 'Cancer':{'m':6,'d':22}, 65 | 'Leo':{'m':7,'d':22}, 66 | 'Virgo':{'m':8,'d':23}, 67 | 'Libra':{'m':9,'d':23}, 68 | 'Scorpio':{'m':10,'d':22}, 69 | 'Sagittarius':{'m':11,'d':21}, 70 | 'Capricorn2':{'m':11,'d':31} 71 | } 72 | var astrologicalSign = '', zodiacEnd, astrologicalSign 73 | for(z in zodiac) { 74 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 75 | if (born <= zodiacEnd) { astrologicalSign = z; break } 76 | } 77 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 78 | return astrologicalSign 79 | } 80 | } 81 | 82 | kb.addComponent(zodiacExpertComponent) 83 | canvas.add(new fabric.LabeledRect({label: zodiacExpertComponent.name, top: oTop + 300, left: oLeft, width: 200, height: 200, fill: '#b0b0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), zodiacExpertComponent) 84 | 85 | var imageSearchComponent = { 86 | name: 'imageSearchEngine', 87 | getImgUrl: function(zodiac) { 88 | return zodiac ? (zodiac + '.png') : '' 89 | } 90 | } 91 | 92 | kb.addComponent(imageSearchComponent) 93 | canvas.add(new fabric.LabeledRect({label: imageSearchComponent.name, top: oTop + 50, left: oLeft + 950, width: 200, height: 250, fill: '#23f0aa', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), imageSearchComponent) 94 | 95 | var csPersonsZodiacExpertComponent = { 96 | name: 'csPersonsZodiacExpert', 97 | getCSPersonImgUrl: function(zodiac) { 98 | var zodiacCSPersons = { 99 | Capricorn: 'anita-borg', 100 | Aquarius: 'alan-turing', 101 | Pisces: 'jospeh-licklider', 102 | Aries: 'wesley-clark', 103 | Taurus: 'alan-kay', 104 | Gemini: 'alonzo-church', 105 | Cancer: 'adi-shamir', 106 | Leo: 'marvin-minsky', 107 | Virgo: 'stephen-wolfram', 108 | Libra: 'guy-steele', 109 | Scorpio: 'david-patterson', 110 | Sagittarius: 'stephen-cook' 111 | } 112 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 113 | } 114 | } 115 | 116 | kb.addComponent(csPersonsZodiacExpertComponent) 117 | canvas.add(new fabric.LabeledRect({label: csPersonsZodiacExpertComponent.name, top: oTop + 325, left: oLeft + 925, width: 300, height: 200, fill: '#4080e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), csPersonsZodiacExpertComponent) 118 | 119 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 120 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 121 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 122 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 123 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 124 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 125 | 126 | canvas.getElementByName('input').on('editing:exited', function() { myAppComponent.run(this.text) }) 127 | 128 | function newImageElement(name, imgSrc) { 129 | var divE = document.getElementById('dynamically-added') 130 | var imgE = document.createElement('img') 131 | var imgEId = 'element-' + name 132 | imgE.setAttribute('id', imgEId) 133 | imgE.setAttribute('src', imgSrc) 134 | divE.appendChild(imgE) 135 | return imgE 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /tests/zodiac2/virgo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/virgo.png -------------------------------------------------------------------------------- /tests/zodiac3/aquarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac3/aries.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac3/blank.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac3/cancer.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac3/capricorn.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-adi-shamir.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-alan-kay.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-alan-turing.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-alonzo-church.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-anita-borg.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-david-patterson.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-guy-steele.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-marvin-minsky.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-stephen-cook.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac3/cs-wesley-clark.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac3/gemini.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac3/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac3/leo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac3/libra.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac3/pisces.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac3/sagittarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac3/scorpio.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac3/taurus.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac3/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | //kb.opt_debugOn = true 5 | //kb.opt_alsoTryUntautologizedSpecs = true 6 | 7 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 8 | 9 | var myAppComponent = { 10 | name: 'myApp', 11 | run: function(userInput) { 12 | this.userInput = userInput 13 | kb.findByMeaning( 14 | '(programParsesInputInto ?THAT CharacterString Date)', 15 | this, this.dateParserFound) 16 | }, 17 | dateParserFound: function(dateParser) { 18 | // parse the input 19 | this.dateParser = dateParser 20 | this.userDateArray = dateParser.getDate(this.userInput) 21 | if (this.userDateArray) { 22 | // convert into date object 23 | this.userDate = this.dateArrayToDate(this.userDateArray) 24 | kb.findByMeaning( 25 | '(and (programVariableRepresents ?THAT ?THING ?_)' 26 | + '(knowsAbout ?THING' 27 | + '(SubcollectionOfWithRelationToFn Astrology focusOfTheory ZodiacConstellation)))', 28 | this, this.zodiacExpertFound) 29 | } 30 | }, 31 | zodiacExpertFound: function(zodiacExpert) { 32 | this.zodiacExpert = zodiacExpert 33 | // compute zodiac sign 34 | this.userSign = zodiacExpert.getZodiacSign(this.userDate) 35 | canvas.getElementByName('signName').text = this.userSign 36 | kb.findByMeaning( 37 | '(and (isa ?THAT ?TYPE)' 38 | + '(typePrimaryFunction ?TYPE InternetSearching programUsed-Generic)' 39 | + '(behaviorCapable ?THING' 40 | + '(SubcollectionOfWithRelationToTypeFn ElectronicDataSearching ' 41 | + 'informationSought VisualImage) searchEngineUsed))', 42 | this, this.imageSearchEngineFound) 43 | }, 44 | imageSearchEngineFound: function(imageSearchEngine) { 45 | this.imageSearchEngine = imageSearchEngine 46 | // get a url to img of zoadiac sign 47 | this.signImgUrl = imageSearchEngine.getImgUrl(this.userSign) 48 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 49 | kb.findByMeaning( 50 | '(and (programVariableRepresents ?THAT ?THING ?_)' 51 | + '(knowsAbout ?THING ZodiacConstellation)' 52 | + '(knowsAbout ?THING' 53 | + '(SubcollectionOfWithRelationFromTypeFn CalendarDay birthDay' 54 | + '(CollectionIntersection2Fn FamousHuman ComputerScientist))))', 55 | this, this.csFamousPeopleExpertFound) 56 | }, 57 | csFamousPeopleExpertFound: function(csFamousPeopleExpert) { 58 | this.csFamousPeopleExpert = csFamousPeopleExpert 59 | // get a uri to img of a CS person with that sign 60 | this.csPersonImgUrl = csFamousPeopleExpert.getCSPersonImgUrl(this.userSign) 61 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 62 | }, 63 | dateArrayToDate: function(dateArray) { 64 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 65 | } 66 | } 67 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 68 | 69 | var dateParserComponent = { 70 | name: 'dateParser', 71 | spec: function() { 72 | return '(and (primaryFunction ?THIS SemanticParsing programUsed)' 73 | + '(programVariableIsaFunctionWithArg1 ?THIS ?Y CharacterString)' 74 | + '(programVariableIsaFunctionWithOutput ?THIS ?Z Date))' 75 | }, 76 | getDate: function(date) { 77 | var dateObj = undefined 78 | if (date) { 79 | date = date.match(/\//) ? date.split('/') : date.split('.') 80 | if (date.length == 3) { 81 | var y = Number(date[2]) 82 | var m = Number(date[1]) 83 | var d = Number(date[0]) 84 | if (y && m && d) { 85 | m = m - 1 86 | dateObj = [y, m, d] 87 | } 88 | } 89 | } 90 | return dateObj 91 | } 92 | } 93 | 94 | canvas.add(new fabric.LabeledRect({label: dateParserComponent.name, top: oTop + 50, left: oLeft - 50, width: 200, height: 200, fill: '#f0f0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), dateParserComponent) 95 | 96 | var zodiacExpertComponent = { 97 | name: 'zodiacExpert', 98 | spec: function() { 99 | return '(and (programVariableRepresents ?THIS ?THING ?_)' 100 | + '(expertRegarding ?THING' 101 | + '(SubcollectionOfWithRelationToFn Astrology focusOfTheory ZodiacConstellation)))' 102 | }, 103 | getZodiacSign: function(born) { 104 | var zodiac = { 105 | 'Capricorn1':{'m':0,'d':20}, 106 | 'Aquarius':{'m':1,'d':19}, 107 | 'Pisces':{'m':2,'d':20}, 108 | 'Aries':{'m':3,'d':20}, 109 | 'Taurus':{'m':4,'d':21}, 110 | 'Gemini':{'m':5,'d':21}, 111 | 'Cancer':{'m':6,'d':22}, 112 | 'Leo':{'m':7,'d':22}, 113 | 'Virgo':{'m':8,'d':23}, 114 | 'Libra':{'m':9,'d':23}, 115 | 'Scorpio':{'m':10,'d':22}, 116 | 'Sagittarius':{'m':11,'d':21}, 117 | 'Capricorn2':{'m':11,'d':31} 118 | } 119 | var astrologicalSign = '', zodiacEnd, astrologicalSign 120 | for(z in zodiac) { 121 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 122 | if (born <= zodiacEnd) { astrologicalSign = z; break } 123 | } 124 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 125 | return astrologicalSign 126 | } 127 | } 128 | 129 | canvas.add(new fabric.LabeledRect({label: zodiacExpertComponent.name, top: oTop + 300, left: oLeft, width: 200, height: 200, fill: '#b0b0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), zodiacExpertComponent) 130 | 131 | var imageSearchComponent = { 132 | name: 'imageSearchEngine', 133 | spec: function() { 134 | return '(isa ?THIS ImageSearchEngine)' 135 | }, 136 | getImgUrl: function(zodiac) { 137 | return zodiac ? (zodiac + '.png') : '' 138 | } 139 | } 140 | 141 | canvas.add(new fabric.LabeledRect({label: imageSearchComponent.name, top: oTop + 50, left: oLeft + 950, width: 200, height: 250, fill: '#ff6666', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), imageSearchComponent) 142 | 143 | var csPersonsZodiacExpertComponent = { 144 | name: 'csPersonsZodiacExpert', 145 | spec: function() { 146 | return '(and (programVariableRepresents ?THIS ?THING ?_)' 147 | + '(knowsAbout ?THING ZodiacConstellation)' 148 | + '(knowsAbout ?THING (SubcollectionOfWithRelationFromTypeFn CalendarDay birthDay' 149 | + '(CollectionIntersection2Fn FamousHuman ComputerScientist))))' 150 | }, 151 | getCSPersonImgUrl: function(zodiac) { 152 | var zodiacCSPersons = { 153 | Capricorn: 'anita-borg', 154 | Aquarius: 'alan-turing', 155 | Pisces: 'jospeh-licklider', 156 | Aries: 'wesley-clark', 157 | Taurus: 'alan-kay', 158 | Gemini: 'alonzo-church', 159 | Cancer: 'adi-shamir', 160 | Leo: 'marvin-minsky', 161 | Virgo: 'stephen-wolfram', 162 | Libra: 'guy-steele', 163 | Scorpio: 'david-patterson', 164 | Sagittarius: 'stephen-cook' 165 | } 166 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 167 | } 168 | } 169 | 170 | kb.addComponent(csPersonsZodiacExpertComponent) 171 | kb.addComponent(imageSearchComponent) 172 | kb.addComponent(zodiacExpertComponent) 173 | kb.addComponent(dateParserComponent) 174 | 175 | canvas.add(new fabric.LabeledRect({label: csPersonsZodiacExpertComponent.name, top: oTop + 325, left: oLeft + 925, width: 300, height: 200, fill: '#4080e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), csPersonsZodiacExpertComponent) 176 | 177 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 178 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 179 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 180 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 181 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 182 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 183 | 184 | var once = true 185 | canvas.getElementByName('input').on('editing:exited', function() { if (once) { once = false; myAppComponent.run(this.text) } }) 186 | 187 | function newImageElement(name, imgSrc) { 188 | var divE = document.getElementById('dynamically-added') 189 | var imgE = document.createElement('img') 190 | var imgEId = 'element-' + name 191 | imgE.setAttribute('id', imgEId) 192 | imgE.setAttribute('src', imgSrc) 193 | divE.appendChild(imgE) 194 | return imgE 195 | } 196 | 197 | 198 | -------------------------------------------------------------------------------- /tests/zodiac3/virgo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/virgo.png -------------------------------------------------------------------------------- /tests/zodiac4/aquarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac4/aries.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac4/blank.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac4/cancer.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac4/capricorn.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-adi-shamir.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-alan-kay.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-alan-turing.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-alonzo-church.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-anita-borg.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-david-patterson.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-guy-steele.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-marvin-minsky.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-stephen-cook.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac4/cs-wesley-clark.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac4/gemini.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac4/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac4/leo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac4/libra.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac4/pisces.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac4/sagittarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac4/scorpio.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac4/taurus.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac4/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | //kb.opt_debugOn = true 5 | //kb.opt_untautologizeSpecs = true 6 | //kb.opt_alsoTryUntautologizedSpecs = true 7 | 8 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 9 | 10 | var myAppComponent = { 11 | name: 'myApp', 12 | run: function(userInput) { 13 | this.userInput = userInput 14 | kb.findByMeaning( 15 | '(and (programVariableHasProperty ?THAT ?THAT-P)' 16 | + '(programParsesInputInto ?THAT-P CharacterString Date))', 17 | this, this.dateParserFound) 18 | }, 19 | dateParserFound: function(dateParser) { 20 | // parse the input 21 | this.dateParser = dateParser 22 | kb.askByMeaning( 23 | '(and (programVariableHasProperty ?THAT ?THAT-P)' 24 | + '(behaviorCapable ?THAT-P SemanticParsing programUsed)' 25 | + '(programVariableIsaFunctionWithArg1 ?THAT-P ?THAT-Y CharacterString)' 26 | + '(programVariableIsaFunctionWithOutput ?THAT-P ?THAT-Z Date)' 27 | + '(programVariableHasName ?THAT-P ?NAME))', 28 | this, dateParser, false, this.onParserAPIDiscovered) 29 | }, 30 | onParserAPIDiscovered: function(answer) { 31 | this.dateParserAPI = answer.NAME 32 | this.userDateArray = this.dateParser[this.dateParserAPI](this.userInput) 33 | if (this.userDateArray) { 34 | // convert into date object 35 | this.userDate = this.dateArrayToDate(this.userDateArray) 36 | kb.findByMeaning( 37 | '(and (programVariableRepresents ?THAT ?THING ?_)' 38 | + '(knowsAbout ?THING' 39 | + '(SubcollectionOfWithRelationToFn Astrology focusOfTheory ZodiacConstellation)))', 40 | this, this.zodiacExpertFound) 41 | } 42 | }, 43 | zodiacExpertFound: function(zodiacExpert) { 44 | this.zodiacExpert = zodiacExpert 45 | kb.askByMeaning( 46 | '(and (programVariableHasProperty ?THAT ?P)' 47 | + '(programVariableIsaFunctionWithArg1 ?P ?Y Date)' 48 | + '(programVariableIsaFunctionWithOutput ?P ?Z PersonTypeByEuropeanZodiacSign)' 49 | + '(programVariableHasName ?P ?NAME))', 50 | this, zodiacExpert, false, this.onZodiacExpertAPIDiscovered) 51 | }, 52 | onZodiacExpertAPIDiscovered: function(answer) { 53 | this.zodiacExpertAPI = answer.NAME 54 | // compute zodiac sign 55 | this.userSign = this.zodiacExpert[this.zodiacExpertAPI](this.userDate) 56 | canvas.getElementByName('signName').text = this.userSign 57 | kb.findByMeaning( 58 | '(and (isa ?THAT ?TYPE)' 59 | + '(typePrimaryFunction ?TYPE InternetSearching programUsed-Generic)' 60 | + '(behaviorCapable ?THING' 61 | + '(SubcollectionOfWithRelationToTypeFn ElectronicDataSearching ' 62 | + 'informationSought VisualImage) searchEngineUsed))', 63 | this, this.imageSearchEngineFound) 64 | }, 65 | imageSearchEngineFound: function(imageSearchEngine) { 66 | this.imageSearchEngine = imageSearchEngine 67 | kb.askByMeaning( 68 | '(and (programVariableHasProperty ?THAT ?P)' 69 | + '(programVariableHasName ?P ?NAME)' 70 | + '(programVariableIsaFunctionWithArg1 ?P ?Y CharacterString)' 71 | + '(programVariableIsaFunctionWithOutput ?P ?Z (SubcollectionOfWithRelationFromTypeFn UniformResourceLocator salientURL VisualImage)))', 72 | this, imageSearchEngine, false, this.onImageSearchEngineAPIDiscovered) 73 | }, 74 | onImageSearchEngineAPIDiscovered: function(answer) { 75 | this.searchEngineAPI = answer.NAME 76 | // get a url to img of zoadiac sign 77 | this.signImgUrl = this.imageSearchEngine[this.searchEngineAPI](this.userSign) 78 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 79 | kb.findByMeaning( 80 | '(and (programVariableRepresents ?THAT ?THING ?_)' 81 | + '(knowsAbout ?THING ZodiacConstellation)' 82 | + '(knowsAbout ?THING' 83 | + '(SubcollectionOfWithRelationFromTypeFn CalendarDay birthDay' 84 | + '(CollectionIntersection2Fn FamousHuman ComputerScientist))))', 85 | this, this.csFamousPeopleExpertFound) 86 | }, 87 | csFamousPeopleExpertFound: function(csFamousPeopleExpert) { 88 | this.csFamousPeopleExpert = csFamousPeopleExpert 89 | kb.askByMeaning( 90 | '(and (programVariableHasProperty ?THAT ?P)' 91 | + '(programVariableHasName ?P ?NAME)' 92 | + '(programVariableIsaFunctionWithArg1 ?P ?Y CharacterString)' 93 | + '(programVariableIsaFunctionWithOutput ?P ?Z (SubcollectionOfWithRelationFromTypeFn UniformResourceLocator salientURL VisualImage)))', 94 | this, csFamousPeopleExpert, false, this.onFamousPeopleExpertAPIDiscovered) 95 | }, 96 | onFamousPeopleExpertAPIDiscovered: function(answer) { 97 | this.famousPeopleExpertAPI = answer.NAME 98 | // get a uri to img of a CS person with that sign 99 | this.csPersonImgUrl = this.csFamousPeopleExpert[this.famousPeopleExpertAPI](this.userSign) 100 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 101 | }, 102 | dateArrayToDate: function(dateArray) { 103 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 104 | } 105 | } 106 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 107 | 108 | var dateParserComponent = { 109 | name: 'dateParser', 110 | getDate: function(date) { 111 | var dateObj = undefined 112 | if (date) { 113 | date = date.match(/\//) ? date.split('/') : date.split('.') 114 | if (date.length == 3) { 115 | var y = Number(date[2]) 116 | var m = Number(date[1]) 117 | var d = Number(date[0]) 118 | if (y && m && d) { 119 | m = m - 1 120 | dateObj = [y, m, d] 121 | } 122 | } 123 | } 124 | return dateObj 125 | }, 126 | getDate_spec: function() { 127 | return '(and (primaryFunction ?GETDATE SemanticParsing programUsed)' 128 | + '(programVariableIsaFunctionWithArg1 ?GETDATE ?Y CharacterString)' 129 | + '(programVariableIsaFunctionWithOutput ?GETDATE ?Z Date))' 130 | } 131 | } 132 | 133 | canvas.add(new fabric.LabeledRect({label: dateParserComponent.name, top: oTop + 50, left: oLeft - 50, width: 200, height: 200, fill: '#f0f0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), dateParserComponent) 134 | 135 | var zodiacExpertComponent = { 136 | name: 'zodiacExpert', 137 | spec: function() { 138 | return '(and (programVariableRepresents ?THIS ?THING ?_)' 139 | + '(expertRegarding ?THING' 140 | + '(SubcollectionOfWithRelationToFn Astrology focusOfTheory ZodiacConstellation)))' 141 | }, 142 | getZodiacSign: function(born) { 143 | var zodiac = { 144 | 'Capricorn1':{'m':0,'d':20}, 145 | 'Aquarius':{'m':1,'d':19}, 146 | 'Pisces':{'m':2,'d':20}, 147 | 'Aries':{'m':3,'d':20}, 148 | 'Taurus':{'m':4,'d':21}, 149 | 'Gemini':{'m':5,'d':21}, 150 | 'Cancer':{'m':6,'d':22}, 151 | 'Leo':{'m':7,'d':22}, 152 | 'Virgo':{'m':8,'d':23}, 153 | 'Libra':{'m':9,'d':23}, 154 | 'Scorpio':{'m':10,'d':22}, 155 | 'Sagittarius':{'m':11,'d':21}, 156 | 'Capricorn2':{'m':11,'d':31} 157 | } 158 | var astrologicalSign = '', zodiacEnd, astrologicalSign 159 | for(z in zodiac) { 160 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 161 | if (born <= zodiacEnd) { astrologicalSign = z; break } 162 | } 163 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 164 | return astrologicalSign 165 | }, 166 | getZodiacSign_spec: function() { 167 | return '(and (programVariableIsaFunctionWithArg1 ?GETZODIACSIGN ?Y Date)' 168 | + '(programVariableIsaFunctionWithOutput ?GETZODIACSIGN ?Z PersonTypeByEuropeanZodiacSign))' 169 | } 170 | } 171 | 172 | canvas.add(new fabric.LabeledRect({label: zodiacExpertComponent.name, top: oTop + 300, left: oLeft, width: 200, height: 200, fill: '#b0b0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), zodiacExpertComponent) 173 | 174 | var imageSearchComponent = { 175 | name: 'imageSearchEngine', 176 | spec: function() { 177 | return '(isa ?THIS ImageSearchEngine)' 178 | }, 179 | getImgUrl: function(zodiac) { 180 | return zodiac ? (zodiac + '.png') : '' 181 | }, 182 | getImgUrl_spec: function() { 183 | return '(and (programVariableIsaFunctionWithArg1 ?GETIMGURL ?Y CharacterString)' 184 | + '(programVariableIsaFunctionWithOutput ?GETIMGURL ?Z (SubcollectionOfWithRelationFromTypeFn UniformResourceLocator salientURL VisualImage)))' 185 | } 186 | } 187 | 188 | canvas.add(new fabric.LabeledRect({label: imageSearchComponent.name, top: oTop + 50, left: oLeft + 950, width: 200, height: 250, fill: '#ff6666', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), imageSearchComponent) 189 | 190 | var csPersonsZodiacExpertComponent = { 191 | name: 'csPersonsZodiacExpert', 192 | spec: function() { 193 | return '(and (programVariableRepresents ?THIS ?THING ?_)' 194 | + '(knowsAbout ?THING ZodiacConstellation)' 195 | + '(knowsAbout ?THING (SubcollectionOfWithRelationFromTypeFn CalendarDay birthDay' 196 | + '(CollectionIntersection2Fn FamousHuman ComputerScientist))))' 197 | }, 198 | getCSPersonImgUrl: function(zodiac) { 199 | var zodiacCSPersons = { 200 | Capricorn: 'anita-borg', 201 | Aquarius: 'alan-turing', 202 | Pisces: 'jospeh-licklider', 203 | Aries: 'wesley-clark', 204 | Taurus: 'alan-kay', 205 | Gemini: 'alonzo-church', 206 | Cancer: 'adi-shamir', 207 | Leo: 'marvin-minsky', 208 | Virgo: 'stephen-wolfram', 209 | Libra: 'guy-steele', 210 | Scorpio: 'david-patterson', 211 | Sagittarius: 'stephen-cook' 212 | } 213 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 214 | }, 215 | getCSPersonImgUrl_spec: function() { 216 | return '(and (programVariableIsaFunctionWithArg1 ?GETCSPERSONIMGURL ?Y CharacterString)' 217 | + '(programVariableIsaFunctionWithOutput ?GETCSPERSONIMGURL ?Z (SubcollectionOfWithRelationFromTypeFn UniformResourceLocator salientURL VisualImage)))' 218 | } 219 | } 220 | 221 | canvas.add(new fabric.LabeledRect({label: csPersonsZodiacExpertComponent.name, top: oTop + 325, left: oLeft + 925, width: 300, height: 200, fill: '#4080e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), csPersonsZodiacExpertComponent) 222 | 223 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 224 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 225 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 226 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 227 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 228 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 229 | 230 | kb.addComponent(csPersonsZodiacExpertComponent) 231 | kb.addComponent(imageSearchComponent) 232 | kb.addComponent(zodiacExpertComponent) 233 | kb.addComponent(dateParserComponent) 234 | 235 | var once = true 236 | canvas.getElementByName('input').on('editing:exited', function() { if (once) { once = false; myAppComponent.run(this.text) } }) 237 | 238 | function newImageElement(name, imgSrc) { 239 | var divE = document.getElementById('dynamically-added') 240 | var imgE = document.createElement('img') 241 | var imgEId = 'element-' + name 242 | imgE.setAttribute('id', imgEId) 243 | imgE.setAttribute('src', imgSrc) 244 | divE.appendChild(imgE) 245 | return imgE 246 | } 247 | 248 | 249 | -------------------------------------------------------------------------------- /tests/zodiac4/virgo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/virgo.png -------------------------------------------------------------------------------- /tests/zodiac5/aquarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac5/aries.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac5/blank.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac5/cancer.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac5/capricorn.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-adi-shamir.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-alan-kay.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-alan-turing.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-alonzo-church.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-anita-borg.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-david-patterson.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-guy-steele.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-marvin-minsky.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-stephen-cook.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac5/cs-wesley-clark.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac5/gemini.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac5/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac5/leo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac5/libra.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac5/pisces.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac5/sagittarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac5/scorpio.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac5/taurus.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac5/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 5 | var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 6 | 7 | var myAppComponent = { 8 | name: 'myApp', 9 | run: function(userInput) { 10 | // parse the input 11 | this.dateParser = kb.findByAPIName('getDate') 12 | this.dateParser.getDate(userInput) 13 | kb.askByMeaning( 14 | '(and (programVariableHasProperty ?THAT ?GETDATE)' 15 | + '(programVariableIsaFunctionWithOutput ?GETDATE ?DATE ?_)' 16 | + '(dayNumberOfDate ?DAY ?DATE)' 17 | + '(monthOfDate ?MONTH ?DATE)' 18 | + '(yearOfDate ?YEAR ?DATE))', 19 | this, this.dateParser, false, this.dateParserInfoReceived) 20 | }, 21 | dateParserInfoReceived: function(answer) { 22 | if (answer) { 23 | this.answer = answer 24 | this.year = Number(answer.YEAR) 25 | this.month = monthNames.indexOf(answer.MONTH) 26 | this.day = Number(answer.DAY) 27 | // convert into date object 28 | this.userDate = new Date(this.year, this.month, this.day) 29 | // compute zodiac sign 30 | this.userSign = (kb.findByAPIName('getZodiacSign').getZodiacSign)(this.userDate) 31 | canvas.getElementByName('signName').text = this.userSign 32 | // get a url to img of zoadiac sign 33 | this.signImgUrl = (kb.findByAPIName('getImgUrl').getImgUrl)(this.userSign) 34 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 35 | // get a uri to img of a CS person with that sign 36 | this.csPersonImgUrl = (kb.findByAPIName('getCSPersonImgUrl').getCSPersonImgUrl)(this.userSign) 37 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 38 | } 39 | }, 40 | dateArrayToDate: function(dateArray) { 41 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 42 | } 43 | } 44 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 45 | 46 | var dateParserComponent = { 47 | name: 'dateParser', 48 | input: undefined, 49 | output: undefined, 50 | getDate: function(date) { 51 | this.input = date 52 | var dateObj = undefined 53 | if (date) { 54 | date = date.match(/\//) ? date.split('/') : date.split('.') 55 | if (date.length == 3) { 56 | var y = Number(date[2]) 57 | var m = Number(date[1]) 58 | var d = Number(date[0]) 59 | if (y && m && d) { 60 | m = m - 1 61 | dateObj = [y, m, d] 62 | } 63 | } 64 | } 65 | this.output = dateObj 66 | return dateObj 67 | }, 68 | getDate_spec: function() { 69 | return this.output ? 70 | '(programVariableIsaFunctionWithOutput ?GETDATE' 71 | + ' (DayFn ' + this.output[2] 72 | + ' (MonthFn ' + monthNames[this.output[1]] 73 | + ' (YearFn ' + this.output[0] + '))) Date)' 74 | : undefined 75 | } 76 | } 77 | 78 | canvas.add(new fabric.LabeledRect({label: dateParserComponent.name, top: oTop + 50, left: oLeft - 50, width: 200, height: 200, fill: '#f0f0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), dateParserComponent) 79 | 80 | var zodiacExpertComponent = { 81 | name: 'zodiacExpert', 82 | getZodiacSign: function(born) { 83 | var zodiac = { 84 | 'Capricorn1':{'m':0,'d':20}, 85 | 'Aquarius':{'m':1,'d':19}, 86 | 'Pisces':{'m':2,'d':20}, 87 | 'Aries':{'m':3,'d':20}, 88 | 'Taurus':{'m':4,'d':21}, 89 | 'Gemini':{'m':5,'d':21}, 90 | 'Cancer':{'m':6,'d':22}, 91 | 'Leo':{'m':7,'d':22}, 92 | 'Virgo':{'m':8,'d':23}, 93 | 'Libra':{'m':9,'d':23}, 94 | 'Scorpio':{'m':10,'d':22}, 95 | 'Sagittarius':{'m':11,'d':21}, 96 | 'Capricorn2':{'m':11,'d':31} 97 | } 98 | var astrologicalSign = '', zodiacEnd, astrologicalSign 99 | for(z in zodiac) { 100 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 101 | if (born <= zodiacEnd) { astrologicalSign = z; break } 102 | } 103 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 104 | return astrologicalSign 105 | } 106 | } 107 | 108 | canvas.add(new fabric.LabeledRect({label: zodiacExpertComponent.name, top: oTop + 300, left: oLeft, width: 200, height: 200, fill: '#b0b0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), zodiacExpertComponent) 109 | 110 | var imageSearchComponent = { 111 | name: 'imageSearchEngine', 112 | getImgUrl: function(zodiac) { 113 | return zodiac ? (zodiac + '.png') : '' 114 | } 115 | } 116 | 117 | canvas.add(new fabric.LabeledRect({label: imageSearchComponent.name, top: oTop + 50, left: oLeft + 950, width: 200, height: 250, fill: '#23f0aa', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), imageSearchComponent) 118 | 119 | var csPersonsZodiacExpertComponent = { 120 | name: 'csPersonsZodiacExpert', 121 | getCSPersonImgUrl: function(zodiac) { 122 | var zodiacCSPersons = { 123 | Capricorn: 'anita-borg', 124 | Aquarius: 'alan-turing', 125 | Pisces: 'jospeh-licklider', 126 | Aries: 'wesley-clark', 127 | Taurus: 'alan-kay', 128 | Gemini: 'alonzo-church', 129 | Cancer: 'adi-shamir', 130 | Leo: 'marvin-minsky', 131 | Virgo: 'stephen-wolfram', 132 | Libra: 'guy-steele', 133 | Scorpio: 'david-patterson', 134 | Sagittarius: 'stephen-cook' 135 | } 136 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 137 | } 138 | } 139 | 140 | canvas.add(new fabric.LabeledRect({label: csPersonsZodiacExpertComponent.name, top: oTop + 325, left: oLeft + 925, width: 300, height: 200, fill: '#4080e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), csPersonsZodiacExpertComponent) 141 | 142 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 143 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 144 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 145 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 146 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 147 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 148 | 149 | kb.addComponent(csPersonsZodiacExpertComponent) 150 | kb.addComponent(imageSearchComponent) 151 | kb.addComponent(zodiacExpertComponent) 152 | kb.addComponent(dateParserComponent) 153 | 154 | var once = true 155 | canvas.getElementByName('input').on('editing:exited', function() { if (once) { once = false; myAppComponent.run(this.text) } }) 156 | 157 | function newImageElement(name, imgSrc) { 158 | var divE = document.getElementById('dynamically-added') 159 | var imgE = document.createElement('img') 160 | var imgEId = 'element-' + name 161 | imgE.setAttribute('id', imgEId) 162 | imgE.setAttribute('src', imgSrc) 163 | divE.appendChild(imgE) 164 | return imgE 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /tests/zodiac5/virgo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/virgo.png -------------------------------------------------------------------------------- /tests/zodiac6/aquarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aquarius.png -------------------------------------------------------------------------------- /tests/zodiac6/aries.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/aries.png -------------------------------------------------------------------------------- /tests/zodiac6/blank.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/blank.png -------------------------------------------------------------------------------- /tests/zodiac6/cancer.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cancer.png -------------------------------------------------------------------------------- /tests/zodiac6/capricorn.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/capricorn.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-adi-shamir.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-adi-shamir.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-alan-kay.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-kay.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-alan-turing.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alan-turing.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-alonzo-church.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-alonzo-church.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-anita-borg.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-anita-borg.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-david-patterson.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-david-patterson.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-guy-steele.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-guy-steele.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-jospeh-licklider.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-jospeh-licklider.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-marvin-minsky.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-marvin-minsky.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-stephen-cook.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-cook.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-stephen-wolfram.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-stephen-wolfram.png -------------------------------------------------------------------------------- /tests/zodiac6/cs-wesley-clark.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/cs-wesley-clark.png -------------------------------------------------------------------------------- /tests/zodiac6/gemini.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/gemini.png -------------------------------------------------------------------------------- /tests/zodiac6/index.html: -------------------------------------------------------------------------------- 1 | ../home.html -------------------------------------------------------------------------------- /tests/zodiac6/leo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/leo.png -------------------------------------------------------------------------------- /tests/zodiac6/libra.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/libra.png -------------------------------------------------------------------------------- /tests/zodiac6/pisces.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/pisces.png -------------------------------------------------------------------------------- /tests/zodiac6/sagittarius.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/sagittarius.png -------------------------------------------------------------------------------- /tests/zodiac6/scorpio.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/scorpio.png -------------------------------------------------------------------------------- /tests/zodiac6/taurus.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/taurus.png -------------------------------------------------------------------------------- /tests/zodiac6/test.js: -------------------------------------------------------------------------------- 1 | var kb = new cbm.KB(true) 2 | var canvas = new cbm.Canvas('c') 3 | 4 | var oLeft = 150, oTop = 20, font1 = 'Lucida Handwriting' 5 | var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] 6 | 7 | var myAppComponent = { 8 | name: 'myApp', 9 | run: function(userInput) { 10 | // parse the input 11 | this.dateParser = kb.findByAPIName('getDate') 12 | this.dateParser.getDate(userInput) 13 | kb.askByMeaning( 14 | '(and (programVariableHasProperty ?THAT ?THAT-GETDATE)' 15 | + '(programVariableIsaFunctionWithOutput ?THAT-GETDATE ?DATE ?_)' 16 | + '(zodiacSignDateRange ?SIGN (DayOfYearFn ?BEGIN-MONTH ?BEGIN-DAY) (DayOfYearFn ?END-MONTH ?END-DAY))' 17 | + '(laterThanOrCooriginatingWith (DayFn ?END-DAY (MonthFn ?END-MONTH (YearFn 1776))) ?DATE)' 18 | + '(laterThanOrCooriginatingWith ?DATE (DayFn ?BEGIN-DAY (MonthFn ?BEGIN-MONTH (YearFn 1776)))))', 19 | this, this.dateParser, false, this.dateParserInfoReceived) 20 | }, 21 | dateParserInfoReceived: function(answer) { 22 | if (answer) { 23 | this.answer = answer 24 | this.userSign = answer.SIGN.replace('-TheSign', '') 25 | canvas.getElementByName('signName').text = this.userSign 26 | // get a url to img of zoadiac sign 27 | this.signImgUrl = (kb.findByAPIName('getImgUrl').getImgUrl)(this.userSign) 28 | canvas.getElementByName('signImg').acyclicSet('src', this.signImgUrl) 29 | // get a uri to img of a CS person with that sign 30 | this.csPersonImgUrl = (kb.findByAPIName('getCSPersonImgUrl').getCSPersonImgUrl)(this.userSign) 31 | canvas.getElementByName('csPersonImg').acyclicSet('src', this.csPersonImgUrl) 32 | } 33 | }, 34 | dateArrayToDate: function(dateArray) { 35 | return new Date(dateArray[0], dateArray[1], dateArray[2]) 36 | } 37 | } 38 | canvas.add(new fabric.LabeledRect({label: ' myApp', top: oTop, left: oLeft + 250, width: 650, height: 500, fill: '#e0e0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), myAppComponent) 39 | 40 | var dateParserComponent = { 41 | name: 'dateParser', 42 | input: undefined, 43 | output: undefined, 44 | getDate: function(date) { 45 | this.input = date 46 | var dateObj = undefined 47 | if (date) { 48 | date = date.match(/\//) ? date.split('/') : date.split('.') 49 | if (date.length == 3) { 50 | var y = Number(date[2]) 51 | var m = Number(date[1]) 52 | var d = Number(date[0]) 53 | if (y && m && d) { 54 | m = m - 1 55 | dateObj = [y, m, d] 56 | } 57 | } 58 | } 59 | this.output = dateObj 60 | return dateObj 61 | }, 62 | getDate_spec: function() { 63 | return this.output ? 64 | '(programVariableIsaFunctionWithOutput ?GETDATE' 65 | + ' (DayFn ' + this.output[2] 66 | + ' (MonthFn ' + monthNames[this.output[1]] 67 | + ' (YearFn ' + this.output[0] + '))) Date)' 68 | : undefined 69 | } 70 | } 71 | 72 | canvas.add(new fabric.LabeledRect({label: dateParserComponent.name, top: oTop + 50, left: oLeft - 50, width: 200, height: 200, fill: '#f0f0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), dateParserComponent) 73 | 74 | var zodiacExpertComponent = { 75 | name: 'zodiacExpert', 76 | getZodiacSign: function(born) { 77 | var zodiac = { 78 | 'Capricorn1':{'m':0,'d':20}, 79 | 'Aquarius':{'m':1,'d':19}, 80 | 'Pisces':{'m':2,'d':20}, 81 | 'Aries':{'m':3,'d':20}, 82 | 'Taurus':{'m':4,'d':21}, 83 | 'Gemini':{'m':5,'d':21}, 84 | 'Cancer':{'m':6,'d':22}, 85 | 'Leo':{'m':7,'d':22}, 86 | 'Virgo':{'m':8,'d':23}, 87 | 'Libra':{'m':9,'d':23}, 88 | 'Scorpio':{'m':10,'d':22}, 89 | 'Sagittarius':{'m':11,'d':21}, 90 | 'Capricorn2':{'m':11,'d':31} 91 | } 92 | var astrologicalSign = '', zodiacEnd, astrologicalSign 93 | for(z in zodiac) { 94 | zodiacEnd = new Date(born.getFullYear(), zodiac[z]['m'], zodiac[z]['d']) 95 | if (born <= zodiacEnd) { astrologicalSign = z; break } 96 | } 97 | if (astrologicalSign.match(/\d/)) astrologicalSign = astrologicalSign.replace(/\d/g,'') 98 | return astrologicalSign 99 | } 100 | } 101 | 102 | canvas.add(new fabric.LabeledRect({label: zodiacExpertComponent.name, top: oTop + 300, left: oLeft, width: 200, height: 200, fill: '#b0b0e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), zodiacExpertComponent) 103 | 104 | var imageSearchComponent = { 105 | name: 'imageSearchEngine', 106 | getImgUrl: function(zodiac) { 107 | return zodiac ? (zodiac + '.png') : '' 108 | } 109 | } 110 | 111 | canvas.add(new fabric.LabeledRect({label: imageSearchComponent.name, top: oTop + 50, left: oLeft + 950, width: 200, height: 250, fill: '#23f0aa', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), imageSearchComponent) 112 | 113 | var csPersonsZodiacExpertComponent = { 114 | name: 'csPersonsZodiacExpert', 115 | getCSPersonImgUrl: function(zodiac) { 116 | var zodiacCSPersons = { 117 | Capricorn: 'anita-borg', 118 | Aquarius: 'alan-turing', 119 | Pisces: 'jospeh-licklider', 120 | Aries: 'wesley-clark', 121 | Taurus: 'alan-kay', 122 | Gemini: 'alonzo-church', 123 | Cancer: 'adi-shamir', 124 | Leo: 'marvin-minsky', 125 | Virgo: 'stephen-wolfram', 126 | Libra: 'guy-steele', 127 | Scorpio: 'david-patterson', 128 | Sagittarius: 'stephen-cook' 129 | } 130 | return 'cs-' + zodiacCSPersons[zodiac] + '.png' 131 | } 132 | } 133 | 134 | canvas.add(new fabric.LabeledRect({label: csPersonsZodiacExpertComponent.name, top: oTop + 325, left: oLeft + 925, width: 300, height: 200, fill: '#4080e0', strokeWidth: 4, stroke: 'gray', opacity: 0.8}), csPersonsZodiacExpertComponent) 135 | 136 | canvas.add(new fabric.Text('Your Birthdate:', {top: oTop + 100, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 137 | canvas.add(new fabric.IText('_', {top: oTop + 100, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'input'}) 138 | canvas.add(new fabric.Text('Your Sign:', {top: oTop + 200, left: oLeft + 300, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black'})) 139 | canvas.add(new fabric.Text('?', {top: oTop + 200, left: oLeft + 600, fontFamily: font1, fontSize: 30, padding: 5, fill: 'black', textBackgroundColor: '#ffff66'}), {name: 'signName'}) 140 | canvas.add(new fabric.Image(newImageElement('img1', 'blank.png'), {top: oTop + 275, left: oLeft + 350, width: 200, height: 200}), {name: 'signImg'}) 141 | canvas.add(new fabric.Image(newImageElement('img2', 'blank.png'), {top: oTop + 275, left: oLeft + 600, width: 200, height: 200}), {name: 'csPersonImg'}) 142 | 143 | kb.addComponent(csPersonsZodiacExpertComponent) 144 | kb.addComponent(imageSearchComponent) 145 | kb.addComponent(zodiacExpertComponent) 146 | kb.addComponent(dateParserComponent) 147 | 148 | var once = true 149 | canvas.getElementByName('input').on('editing:exited', function() { if (once) { once = false; myAppComponent.run(this.text) } }) 150 | 151 | function newImageElement(name, imgSrc) { 152 | var divE = document.getElementById('dynamically-added') 153 | var imgE = document.createElement('img') 154 | var imgEId = 'element-' + name 155 | imgE.setAttribute('id', imgEId) 156 | imgE.setAttribute('src', imgSrc) 157 | divE.appendChild(imgE) 158 | return imgE 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /tests/zodiac6/virgo.png: -------------------------------------------------------------------------------- 1 | ../zodiac1/virgo.png --------------------------------------------------------------------------------