1 Components.utils.import("resource://stmodules/STRequests.jsm"); 2 Components.utils.import("resource://stmodules/Logger.jsm"); 3 4 Components.utils.import("resource://stmodules/Context.jsm"); 5 6 EXPORTED_SYMBOLS = [ "SemTurkeyHTTPLegacy", "STRequests" ]; 7 8 var service = STRequests.Metadata; 9 var serviceName = service.serviceName; 10 11 12 /** 13 * returns the description of resource representing the current ontology 14 * 15 * @member STRequests.Metadata 16 * @return 17 */ 18 function getOntologyDescription() { 19 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 20 return SemTurkeyHTTPLegacy.GET(serviceName, service.getOntologyDescriptionRequest, contextAsArray); 21 } 22 23 /** 24 * returns the baseuri of the current ontology 25 * 26 * @member STRequests.Metadata 27 * @return 28 */ 29 function getBaseuri() { 30 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 31 return SemTurkeyHTTPLegacy.GET(serviceName, service.getBaseuriRequest, contextAsArray); 32 } 33 34 /** 35 * returns the default namespace of the current ontology 36 * 37 * @member STRequests.Metadata 38 * @return 39 */ 40 function getDefaultNamespace() { 41 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 42 return SemTurkeyHTTPLegacy.GET(serviceName, service.getDefaultNamespaceRequest, contextAsArray); 43 } 44 45 /** 46 * returns a tree forest representing current ontology imports. The roots of this forest list ontologies 47 * directly imported from the current ontology, while subsequent nodes represent recursive imports 48 * 49 * @member STRequests.Metadata 50 * @return 51 */ 52 function getImports() { 53 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 54 return SemTurkeyHTTPLegacy.GET(serviceName, service.getImportsRequest, contextAsArray); 55 } 56 57 /** 58 * returns a list of mappings between prefixes and namespaces. Also, for each entry it is told whether this 59 * mapping has been provided by the system (because it has been automatically guessed from the namespace name, 60 * or because it is a mapping specified in one of the imported ontologies) or if has been explictly setup by 61 * the user 62 * 63 * @member STRequests.Metadata 64 * @return 65 */ 66 function getNSPrefixMappings() { 67 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 68 return SemTurkeyHTTPLegacy.GET(serviceName, service.getNSPrefixMappingsRequest, contextAsArray); 69 } 70 71 /** 72 * returns the list of named graphs for the current ontology. By default, Semantic Turkey associates named 73 * graphs to triples of imported ontologies, as well as to <code>application</code> and <code>support</code> 74 * ontologies 75 * 76 * @member STRequests.Metadata 77 * @return 78 */ 79 function getNamedGraphs() { 80 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 81 return SemTurkeyHTTPLegacy.GET(serviceName, service.getNamedGraphsRequest, contextAsArray); 82 } 83 84 /** 85 * sets both baseuri and default namespace for the ontology of the current project 86 * 87 * @member STRequests.Metadata 88 * @param baseuri 89 * @param namespace 90 * @return 91 */ 92 function setBaseuriDefNamespace(baseuri, namespace) { 93 var baseuri = "baseuri=" + baseuri; 94 var namespace = "namespace=" + namespace; 95 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 96 return SemTurkeyHTTPLegacy.GET(serviceName, service.setBaseuriDefNamespaceRequest, baseuri, namespace, contextAsArray); 97 } 98 99 /** 100 * sets the default namespace for the ontology of the current project 101 * 102 * @member STRequests.Metadata 103 * @param namespace 104 * @return 105 */ 106 function setDefaultNamespace(namespace) { 107 var namespace = "namespace=" + namespace; 108 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 109 return SemTurkeyHTTPLegacy.GET(serviceName, service.setDefaultNamespaceRequest, namespace, contextAsArray); 110 } 111 112 /** 113 * sets the baseuri for the ontology of the current project 114 * 115 * @member STRequests.Metadata 116 * @param uri 117 * @return 118 */ 119 function setBaseuri(uri) { 120 var uri = "baseuri=" + uri; 121 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 122 return SemTurkeyHTTPLegacy.GET(serviceName, service.setBaseuriRequest, uri, contextAsArray); 123 } 124 125 /** 126 * adds a mapping between a namespace and a chosen prefix 127 * 128 * @member STRequests.Metadata 129 * @param prefix 130 * @param namespace 131 * @return 132 */ 133 function setNSPrefixMapping(prefix, namespace) { 134 var prefix = "prefix=" + prefix; 135 var namespace = "namespace=" + namespace; 136 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 137 return SemTurkeyHTTPLegacy.GET(serviceName, service.setNSPrefixMappingRequest, prefix, namespace, contextAsArray); 138 } 139 140 /** 141 * deletes a mapping from the prefix-namespace mapping table 142 * 143 * @member STRequests.Metadata 144 * @param namespace 145 * @return 146 */ 147 function removeNSPrefixMapping(namespace) { 148 var namespace = "namespace=" + namespace; 149 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 150 return SemTurkeyHTTPLegacy.GET(serviceName, service.removeNSPrefixMappingRequest, namespace, contextAsArray); 151 } 152 153 /** 154 * overwrites an entry in the prefix-namespace mapping table 155 * 156 * @member STRequests.Metadata 157 * @param prefix 158 * @param namespace 159 * @return 160 */ 161 function changeNSPrefixMapping(prefix, namespace) { 162 var prefix = "prefix=" + prefix; 163 var namespace = "namespace=" + namespace; 164 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 165 return SemTurkeyHTTPLegacy.GET(serviceName, service.changeNSPrefixMappingRequest, prefix, namespace, contextAsArray); 166 } 167 168 /** 169 * removes an import from the ontology of the current project. This operation deletes the named graph 170 * associated to this import and the triples associated to the named graph 171 * 172 * @member STRequests.Metadata 173 * @param baseuri 174 * @return 175 */ 176 function removeImport(baseuri) { 177 var baseuri = "baseuri=" + baseuri; 178 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 179 return SemTurkeyHTTPLegacy.GET(serviceName, service.removeImportRequest, baseuri, contextAsArray); 180 } 181 182 /** 183 * imports an ontology from the Web. The imported ontology is considered to be always available from the Web, 184 * so it is always rrefreshed each time the working ontology is being reloaded 185 * 186 * @member STRequests.Metadata 187 * @param baseuri 188 * @param alturl 189 * if the baseuri is different from the phisical location of the ontology, then alturl specifies 190 * where to look for the file to be downloaded 191 * @return 192 */ 193 function addFromWeb(baseuri, alturl) { 194 var baseuri = "baseuri=" + baseuri; 195 if (typeof alturl != "undefined") { 196 var alturl = "alturl=" + alturl; 197 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 198 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromWebRequest, baseuri, alturl, contextAsArray); 199 } else { 200 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 201 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromWebRequest, baseuri, contextAsArray); 202 } 203 } 204 205 /** 206 * imports an ontology from the Web to a local cache. The imported ontology is cached in a local file in 207 * Semantic Turkey's ontologies mirror location 208 * 209 * @member STRequests.Metadata 210 * @param baseuri 211 * @param mirrorFile 212 * the name of the cache file which is saved locally in the ontologies mirror of Semantic Turkey 213 * @param alturl 214 * if the baseuri is different from the phisical location of the ontology, then alturl specifies 215 * where to look for the file to be downloaded 216 * @return 217 */ 218 function addFromWebToMirror(baseuri, mirrorFile, alturl) { 219 var baseuri = "baseuri=" + baseuri; 220 var mirrorFile = "mirrorFile=" + mirrorFile; 221 if (typeof alturl != "undefined") { 222 var alturl = "alturl=" + alturl; 223 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 224 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromWebToMirrorRequest, baseuri, mirrorFile, alturl, contextAsArray); 225 } else { 226 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 227 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromWebToMirrorRequest, baseuri, mirrorFile, contextAsArray); 228 } 229 } 230 231 /** 232 * imports an ontology from a file in the local file system. The imported ontology is cached in a local file 233 * in Semantic Turkey's ontologies mirror location 234 * 235 * @member STRequests.Metadata 236 * @param baseuri 237 * @param localFilePath 238 * the path to the source file which is imported in the current ontology 239 * @param mirrorFile 240 * the name of the cache file which is saved locally in the ontologies mirror of Semantic Turkey 241 * @return 242 */ 243 function addFromLocalFile(baseuri, localFilePath, mirrorFile) { 244 var baseuri = "baseuri=" + baseuri; 245 var localFilePath = "localFilePath=" + localFilePath; 246 var mirrorFile = "mirrorFile=" + mirrorFile; 247 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 248 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromLocalFileRequest, baseuri, localFilePath, mirrorFile, contextAsArray); 249 } 250 251 /** 252 * imports an ontology by taking its content directly from the ontologies mirror of Semantic Turkey 253 * 254 * @member STRequests.Metadata 255 * @param baseuri 256 * @param mirrorFile 257 * the name of the cache file which is imported into current ontology 258 * @return 259 */ 260 function addFromOntologyMirror(baseuri, mirrorFile) { 261 baseuri = "baseuri=" + baseuri; 262 mirrorFile = "mirrorFile=" + mirrorFile; 263 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 264 return SemTurkeyHTTPLegacy.GET(serviceName, service.addFromOntologyMirrorRequest, baseuri, mirrorFile, contextAsArray); 265 } 266 267 /** 268 * as for addFromWebToMirror, excepts that this does not add an owl:imports statement to the current ontology. 269 * It is mainly used to recover failed downloads of the content of ontologies which have already been declared 270 * to be imported 271 * 272 * @member STRequests.Metadata 273 * @param baseuri 274 * @param mirrorFile 275 * @param alturl 276 * @return 277 */ 278 function downloadFromWebToMirror(baseuri, mirrorFile, alturl) { 279 var baseuri = "baseuri=" + baseuri; 280 var mirrorFile = "mirrorFile=" + mirrorFile; 281 if (typeof alturl != "undefined") { 282 var alturl = "alturl=" + alturl; 283 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 284 return SemTurkeyHTTPLegacy.GET(serviceName, service.downloadFromWebToMirrorRequest, baseuri, mirrorFile, alturl, contextAsArray); 285 } else { 286 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 287 return SemTurkeyHTTPLegacy.GET(serviceName, service.downloadFromWebToMirrorRequest, baseuri, mirrorFile, contextAsArray); 288 } 289 } 290 291 /** 292 * as for addFromWeb, excepts that this does not add an owl:imports statement to the current ontology. It is 293 * mainly used to recover failed downloads of the content of ontologies which have already been declared to be 294 * imported 295 * 296 * @member STRequests.Metadata 297 * @param baseuri 298 * @param alturl 299 * @return 300 */ 301 function downloadFromWeb(baseuri, alturl) { 302 var baseuri = "baseuri=" + baseuri; 303 if (typeof alturl != "undefined") { 304 var alturl = "alturl=" + alturl; 305 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 306 return SemTurkeyHTTPLegacy.GET(serviceName, service.downloadFromWebRequest, baseuri, alturl, contextAsArray); 307 } else { 308 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 309 return SemTurkeyHTTPLegacy.GET(serviceName, service.downloadFromWebRequest, baseuri, contextAsArray); 310 } 311 } 312 313 /** 314 * as for addFromLocalFile, excepts that this does not add an owl:imports statement to the current ontology. 315 * It is mainly used to recover failed downloads of the content of ontologies which have already been declared 316 * to be imported 317 * 318 * @member STRequests.Metadata 319 * @param baseuri 320 * @param localFilePath 321 * @param mirrorFile 322 * @param alturl 323 * @return 324 */ 325 function getFromLocalFile(baseuri, localFilePath, mirrorFile, alturl) { 326 var baseuri = "baseuri=" + baseuri; 327 var localFilePath = "localFilePath=" + localFilePath; 328 var mirrorFile = "mirrorFile=" + mirrorFile; 329 if (typeof alturl != "undefined") { 330 var alturl = "alturl=" + alturl; 331 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 332 return SemTurkeyHTTPLegacy.GET(serviceName, service.getFromLocalFileRequest, baseuri, localFilePath, mirrorFile, 333 alturl, contextAsArray); 334 } else { 335 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 336 return SemTurkeyHTTPLegacy.GET(serviceName, service.getFromLocalFileRequest, baseuri, localFilePath, mirrorFile, 337 contextAsArray); 338 } 339 } 340 341 /** 342 * mirrors an ontology which has already been imported 343 * 344 * @member STRequests.Metadata 345 * @param baseuri 346 * @param mirrorFile 347 * @return 348 */ 349 function mirrorOntology(baseuri, mirrorFile) { 350 baseuri = "baseuri=" + baseuri; 351 mirrorFile = "mirrorFile=" + mirrorFile; 352 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 353 return SemTurkeyHTTPLegacy.GET(serviceName, service.mirrorOntologyRequest, baseuri, mirrorFile, contextAsArray); 354 } 355 356 357 // Annotation SERVICE INITIALIZATION 358 //this return an implementation for Project with a specified context 359 service.prototype.getAPI = function(specifiedContext){ 360 var newObj = new service(); 361 newObj.context = specifiedContext; 362 return newObj; 363 } 364 service.prototype.getOntologyDescription = getOntologyDescription; 365 service.prototype.getBaseuri = getBaseuri; 366 service.prototype.getDefaultNamespace = getDefaultNamespace; 367 service.prototype.getImports = getImports; 368 service.prototype.getNSPrefixMappings = getNSPrefixMappings; 369 service.prototype.setBaseuriDefNamespace = setBaseuriDefNamespace; 370 service.prototype.setDefaultNamespace = setDefaultNamespace; 371 service.prototype.setBaseuri = setBaseuri; 372 service.prototype.setNSPrefixMapping = setNSPrefixMapping; 373 service.prototype.removeNSPrefixMapping = removeNSPrefixMapping; 374 service.prototype.changeNSPrefixMapping = changeNSPrefixMapping; 375 service.prototype.removeImport = removeImport; 376 service.prototype.addFromWeb = addFromWeb; 377 service.prototype.addFromWebToMirror = addFromWebToMirror; 378 service.prototype.addFromLocalFile = addFromLocalFile; 379 service.prototype.addFromOntologyMirror = addFromOntologyMirror; 380 service.prototype.downloadFromWebToMirror = downloadFromWebToMirror; 381 service.prototype.downloadFromWeb = downloadFromWeb; 382 service.prototype.getFromLocalFile = getFromLocalFile; 383 service.prototype.mirrorOntology = mirrorOntology; 384 service.prototype.getNamedGraphs = getNamedGraphs; 385 service.prototype.context = new Context(); // set the default context 386 service.constructor = service; 387 service.__proto__ = service.prototype;