OLD | NEW |
(Empty) | |
| 1 library googleapis.freebase.v1; |
| 2 |
| 3 import "dart:core" as core; |
| 4 import "dart:collection" as collection; |
| 5 import "dart:async" as async; |
| 6 import "dart:convert" as convert; |
| 7 |
| 8 import "package:crypto/crypto.dart" as crypto; |
| 9 import 'package:http/http.dart' as http; |
| 10 import '../src/common_internal.dart' as common_internal; |
| 11 import '../common/common.dart' as common; |
| 12 |
| 13 export '../common/common.dart' show ApiRequestError; |
| 14 export '../common/common.dart' show DetailedApiRequestError; |
| 15 |
| 16 /** Find Freebase entities using textual queries and other constraints. */ |
| 17 class FreebaseApi { |
| 18 |
| 19 final common_internal.ApiRequester _requester; |
| 20 |
| 21 FreebaseApi(http.Client client) : |
| 22 _requester = new common_internal.ApiRequester(client, "https://www.googlea
pis.com/", "/freebase/v1/"); |
| 23 |
| 24 /** |
| 25 * Reconcile entities to Freebase open data. |
| 26 * |
| 27 * Request parameters: |
| 28 * |
| 29 * [confidence] - Required confidence for a candidate to match. Must be |
| 30 * between .5 and 1.0 |
| 31 * Value must be between "0.0" and "1.0". |
| 32 * |
| 33 * [kind] - Classifications of entity e.g. type, category, title. |
| 34 * |
| 35 * [lang] - Languages for names and values. First language is used for |
| 36 * display. Default is 'en'. |
| 37 * |
| 38 * [limit] - Maximum number of candidates to return. |
| 39 * Value must be between "0" and "25". |
| 40 * |
| 41 * [name] - Name of entity. |
| 42 * |
| 43 * [prop] - Property values for entity formatted as |
| 44 * : |
| 45 * |
| 46 * Completes with a [ReconcileGet]. |
| 47 * |
| 48 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 49 * error. |
| 50 * |
| 51 * If the used [http.Client] completes with an error when making a REST call, |
| 52 * this method will complete with the same error. |
| 53 */ |
| 54 async.Future<ReconcileGet> reconcile({core.double confidence, core.List<core.S
tring> kind, core.List<core.String> lang, core.int limit, core.String name, core
.List<core.String> prop}) { |
| 55 var _url = null; |
| 56 var _queryParams = new core.Map(); |
| 57 var _uploadMedia = null; |
| 58 var _uploadOptions = null; |
| 59 var _downloadOptions = common.DownloadOptions.Metadata; |
| 60 var _body = null; |
| 61 |
| 62 if (confidence != null) { |
| 63 _queryParams["confidence"] = ["${confidence}"]; |
| 64 } |
| 65 if (kind != null) { |
| 66 _queryParams["kind"] = kind; |
| 67 } |
| 68 if (lang != null) { |
| 69 _queryParams["lang"] = lang; |
| 70 } |
| 71 if (limit != null) { |
| 72 _queryParams["limit"] = ["${limit}"]; |
| 73 } |
| 74 if (name != null) { |
| 75 _queryParams["name"] = [name]; |
| 76 } |
| 77 if (prop != null) { |
| 78 _queryParams["prop"] = prop; |
| 79 } |
| 80 |
| 81 |
| 82 _url = 'reconcile'; |
| 83 |
| 84 var _response = _requester.request(_url, |
| 85 "GET", |
| 86 body: _body, |
| 87 queryParams: _queryParams, |
| 88 uploadOptions: _uploadOptions, |
| 89 uploadMedia: _uploadMedia, |
| 90 downloadOptions: _downloadOptions); |
| 91 return _response.then((data) => new ReconcileGet.fromJson(data)); |
| 92 } |
| 93 |
| 94 /** |
| 95 * Search Freebase open data. |
| 96 * |
| 97 * Request parameters: |
| 98 * |
| 99 * [asOfTime] - A mql as_of_time value to use with mql_output queries. |
| 100 * |
| 101 * [callback] - JS method name for JSONP callbacks. |
| 102 * Value must have pattern "([A-Za-z0-9_$.]|\[|\])+". |
| 103 * |
| 104 * [cursor] - The cursor value to use for the next page of results. |
| 105 * |
| 106 * [domain] - Restrict to topics with this Freebase domain id. |
| 107 * |
| 108 * [encode] - The encoding of the response. You can use this parameter to |
| 109 * enable html encoding. |
| 110 * Possible string values are: |
| 111 * - "html" : Encode certain characters in the response (such as tags and |
| 112 * ambersands) using html encoding. |
| 113 * - "off" : No encoding of the response. You should not print the results |
| 114 * directly on an web page without html-escaping the content first. |
| 115 * |
| 116 * [exact] - Query on exact name and keys only. |
| 117 * |
| 118 * [filter] - A filter to apply to the query. |
| 119 * Value must have pattern "^\(.*\)$". |
| 120 * |
| 121 * [format] - Structural format of the json response. |
| 122 * Possible string values are: |
| 123 * - "ac" : Compact format useful for autocomplete/suggest UIs. |
| 124 * - "classic" : [DEPRECATED] Same format as was returned by api.freebase.com. |
| 125 * - "entity" : Basic information about the entities. |
| 126 * - "guids" : [DEPRECATED] Ordered list of a freebase guids. |
| 127 * - "ids" : Ordered list of freebase ids. |
| 128 * - "mids" : Ordered list of freebase mids. |
| 129 * |
| 130 * [help] - The keyword to request help on. |
| 131 * Possible string values are: |
| 132 * - "langs" : The language codes served by the service. |
| 133 * - "mappings" : The property/path mappings supported by the filter and |
| 134 * output request parameters. |
| 135 * - "predicates" : The predicates and path-terminating properties supported |
| 136 * by the filter and output request parameters. |
| 137 * |
| 138 * [indent] - Whether to indent the json results or not. |
| 139 * |
| 140 * [lang] - The code of the language to run the query with. Default is 'en'. |
| 141 * |
| 142 * [limit] - Maximum number of results to return. |
| 143 * |
| 144 * [mid] - A mid to use instead of a query. |
| 145 * Value must have pattern "^/[mgtx]/[0-2][0-9bcdfghjklmnpqrstvwxyz_]{1,24}$". |
| 146 * |
| 147 * [mqlOutput] - The MQL query to run againist the results to extract more |
| 148 * data. |
| 149 * |
| 150 * [output] - An output expression to request data from matches. |
| 151 * Value must have pattern "^\(.*\)$". |
| 152 * |
| 153 * [prefixed] - Prefix match against names and aliases. |
| 154 * |
| 155 * [query] - Query term to search for. |
| 156 * |
| 157 * [scoring] - Relevance scoring algorithm to use. |
| 158 * Possible string values are: |
| 159 * - "entity" : Use freebase and popularity entity ranking. |
| 160 * - "freebase" : Use freebase entity ranking. |
| 161 * - "schema" : Use schema ranking for properties and types. |
| 162 * |
| 163 * [spell] - Request 'did you mean' suggestions |
| 164 * Possible string values are: |
| 165 * - "always" : Request spelling suggestions for any query at least three |
| 166 * characters long. |
| 167 * - "no_results" : Request spelling suggestions if no results were found. |
| 168 * - "no_spelling" : Don't request spelling suggestions. |
| 169 * |
| 170 * [stemmed] - Query on stemmed names and aliases. May not be used with |
| 171 * prefixed. |
| 172 * |
| 173 * [type] - Restrict to topics with this Freebase type id. |
| 174 * |
| 175 * [with_] - A rule to match against. |
| 176 * |
| 177 * [without] - A rule to not match against. |
| 178 * |
| 179 * [downloadOptions] - Options for downloading. A download can be either a |
| 180 * Metadata (default) or Media download. Partial Media downloads are possible |
| 181 * as well. |
| 182 * |
| 183 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 184 * error. |
| 185 * |
| 186 * If the used [http.Client] completes with an error when making a REST call, |
| 187 * this method will complete with the same error. |
| 188 */ |
| 189 async.Future search({core.String asOfTime, core.String callback, core.int curs
or, core.List<core.String> domain, core.String encode, core.bool exact, core.Lis
t<core.String> filter, core.String format, core.String help, core.bool indent, c
ore.List<core.String> lang, core.int limit, core.List<core.String> mid, core.Str
ing mqlOutput, core.String output, core.bool prefixed, core.String query, core.S
tring scoring, core.String spell, core.bool stemmed, core.List<core.String> type
, core.List<core.String> with_, core.List<core.String> without, common.DownloadO
ptions downloadOptions: common.DownloadOptions.Metadata}) { |
| 190 var _url = null; |
| 191 var _queryParams = new core.Map(); |
| 192 var _uploadMedia = null; |
| 193 var _uploadOptions = null; |
| 194 var _downloadOptions = common.DownloadOptions.Metadata; |
| 195 var _body = null; |
| 196 |
| 197 if (asOfTime != null) { |
| 198 _queryParams["as_of_time"] = [asOfTime]; |
| 199 } |
| 200 if (callback != null) { |
| 201 _queryParams["callback"] = [callback]; |
| 202 } |
| 203 if (cursor != null) { |
| 204 _queryParams["cursor"] = ["${cursor}"]; |
| 205 } |
| 206 if (domain != null) { |
| 207 _queryParams["domain"] = domain; |
| 208 } |
| 209 if (encode != null) { |
| 210 _queryParams["encode"] = [encode]; |
| 211 } |
| 212 if (exact != null) { |
| 213 _queryParams["exact"] = ["${exact}"]; |
| 214 } |
| 215 if (filter != null) { |
| 216 _queryParams["filter"] = filter; |
| 217 } |
| 218 if (format != null) { |
| 219 _queryParams["format"] = [format]; |
| 220 } |
| 221 if (help != null) { |
| 222 _queryParams["help"] = [help]; |
| 223 } |
| 224 if (indent != null) { |
| 225 _queryParams["indent"] = ["${indent}"]; |
| 226 } |
| 227 if (lang != null) { |
| 228 _queryParams["lang"] = lang; |
| 229 } |
| 230 if (limit != null) { |
| 231 _queryParams["limit"] = ["${limit}"]; |
| 232 } |
| 233 if (mid != null) { |
| 234 _queryParams["mid"] = mid; |
| 235 } |
| 236 if (mqlOutput != null) { |
| 237 _queryParams["mql_output"] = [mqlOutput]; |
| 238 } |
| 239 if (output != null) { |
| 240 _queryParams["output"] = [output]; |
| 241 } |
| 242 if (prefixed != null) { |
| 243 _queryParams["prefixed"] = ["${prefixed}"]; |
| 244 } |
| 245 if (query != null) { |
| 246 _queryParams["query"] = [query]; |
| 247 } |
| 248 if (scoring != null) { |
| 249 _queryParams["scoring"] = [scoring]; |
| 250 } |
| 251 if (spell != null) { |
| 252 _queryParams["spell"] = [spell]; |
| 253 } |
| 254 if (stemmed != null) { |
| 255 _queryParams["stemmed"] = ["${stemmed}"]; |
| 256 } |
| 257 if (type != null) { |
| 258 _queryParams["type"] = type; |
| 259 } |
| 260 if (with_ != null) { |
| 261 _queryParams["with"] = with_; |
| 262 } |
| 263 if (without != null) { |
| 264 _queryParams["without"] = without; |
| 265 } |
| 266 |
| 267 _downloadOptions = downloadOptions; |
| 268 |
| 269 _url = 'search'; |
| 270 |
| 271 var _response = _requester.request(_url, |
| 272 "GET", |
| 273 body: _body, |
| 274 queryParams: _queryParams, |
| 275 uploadOptions: _uploadOptions, |
| 276 uploadMedia: _uploadMedia, |
| 277 downloadOptions: _downloadOptions); |
| 278 if (_downloadOptions == null || |
| 279 _downloadOptions == common.DownloadOptions.Metadata) { |
| 280 return _response.then((data) => null); |
| 281 } else { |
| 282 return _response; |
| 283 } |
| 284 } |
| 285 |
| 286 } |
| 287 |
| 288 |
| 289 |
| 290 /** Type or profession the candidate is notable for. */ |
| 291 class ReconcileCandidateNotable { |
| 292 /** MID of notable category. */ |
| 293 core.String id; |
| 294 |
| 295 /** Name of notable category in specified language. */ |
| 296 core.String name; |
| 297 |
| 298 |
| 299 ReconcileCandidateNotable(); |
| 300 |
| 301 ReconcileCandidateNotable.fromJson(core.Map _json) { |
| 302 if (_json.containsKey("id")) { |
| 303 id = _json["id"]; |
| 304 } |
| 305 if (_json.containsKey("name")) { |
| 306 name = _json["name"]; |
| 307 } |
| 308 } |
| 309 |
| 310 core.Map toJson() { |
| 311 var _json = new core.Map(); |
| 312 if (id != null) { |
| 313 _json["id"] = id; |
| 314 } |
| 315 if (name != null) { |
| 316 _json["name"] = name; |
| 317 } |
| 318 return _json; |
| 319 } |
| 320 } |
| 321 |
| 322 |
| 323 /** Not documented yet. */ |
| 324 class ReconcileCandidate { |
| 325 /** |
| 326 * Percentage likelihood that this candidate is the unique matching entity. |
| 327 * Value will be between 0.0 and 1.0 |
| 328 */ |
| 329 core.double confidence; |
| 330 |
| 331 /** Language code that candidate and notable names are displayed in. */ |
| 332 core.String lang; |
| 333 |
| 334 /** Freebase MID of candidate entity. */ |
| 335 core.String mid; |
| 336 |
| 337 /** Freebase name of matching entity in specified language. */ |
| 338 core.String name; |
| 339 |
| 340 /** Type or profession the candidate is notable for. */ |
| 341 ReconcileCandidateNotable notable; |
| 342 |
| 343 |
| 344 ReconcileCandidate(); |
| 345 |
| 346 ReconcileCandidate.fromJson(core.Map _json) { |
| 347 if (_json.containsKey("confidence")) { |
| 348 confidence = _json["confidence"]; |
| 349 } |
| 350 if (_json.containsKey("lang")) { |
| 351 lang = _json["lang"]; |
| 352 } |
| 353 if (_json.containsKey("mid")) { |
| 354 mid = _json["mid"]; |
| 355 } |
| 356 if (_json.containsKey("name")) { |
| 357 name = _json["name"]; |
| 358 } |
| 359 if (_json.containsKey("notable")) { |
| 360 notable = new ReconcileCandidateNotable.fromJson(_json["notable"]); |
| 361 } |
| 362 } |
| 363 |
| 364 core.Map toJson() { |
| 365 var _json = new core.Map(); |
| 366 if (confidence != null) { |
| 367 _json["confidence"] = confidence; |
| 368 } |
| 369 if (lang != null) { |
| 370 _json["lang"] = lang; |
| 371 } |
| 372 if (mid != null) { |
| 373 _json["mid"] = mid; |
| 374 } |
| 375 if (name != null) { |
| 376 _json["name"] = name; |
| 377 } |
| 378 if (notable != null) { |
| 379 _json["notable"] = (notable).toJson(); |
| 380 } |
| 381 return _json; |
| 382 } |
| 383 } |
| 384 |
| 385 |
| 386 /** Server costs for reconciling. */ |
| 387 class ReconcileGetCosts { |
| 388 /** Total number of hits found. */ |
| 389 core.int hits; |
| 390 |
| 391 /** Total milliseconds spent. */ |
| 392 core.int ms; |
| 393 |
| 394 |
| 395 ReconcileGetCosts(); |
| 396 |
| 397 ReconcileGetCosts.fromJson(core.Map _json) { |
| 398 if (_json.containsKey("hits")) { |
| 399 hits = _json["hits"]; |
| 400 } |
| 401 if (_json.containsKey("ms")) { |
| 402 ms = _json["ms"]; |
| 403 } |
| 404 } |
| 405 |
| 406 core.Map toJson() { |
| 407 var _json = new core.Map(); |
| 408 if (hits != null) { |
| 409 _json["hits"] = hits; |
| 410 } |
| 411 if (ms != null) { |
| 412 _json["ms"] = ms; |
| 413 } |
| 414 return _json; |
| 415 } |
| 416 } |
| 417 |
| 418 |
| 419 /** Not documented yet. */ |
| 420 class ReconcileGetWarning { |
| 421 /** Location of warning in the request e.g. invalid predicate. */ |
| 422 core.String location; |
| 423 |
| 424 /** Warning message to display to the user. */ |
| 425 core.String message; |
| 426 |
| 427 /** Code for identifying classes of warnings. */ |
| 428 core.String reason; |
| 429 |
| 430 |
| 431 ReconcileGetWarning(); |
| 432 |
| 433 ReconcileGetWarning.fromJson(core.Map _json) { |
| 434 if (_json.containsKey("location")) { |
| 435 location = _json["location"]; |
| 436 } |
| 437 if (_json.containsKey("message")) { |
| 438 message = _json["message"]; |
| 439 } |
| 440 if (_json.containsKey("reason")) { |
| 441 reason = _json["reason"]; |
| 442 } |
| 443 } |
| 444 |
| 445 core.Map toJson() { |
| 446 var _json = new core.Map(); |
| 447 if (location != null) { |
| 448 _json["location"] = location; |
| 449 } |
| 450 if (message != null) { |
| 451 _json["message"] = message; |
| 452 } |
| 453 if (reason != null) { |
| 454 _json["reason"] = reason; |
| 455 } |
| 456 return _json; |
| 457 } |
| 458 } |
| 459 |
| 460 |
| 461 /** Not documented yet. */ |
| 462 class ReconcileGet { |
| 463 /** |
| 464 * If filled, then the listed candidates are potential matches, and such |
| 465 * should be evaluated by a more discerning algorithm or human. The matches |
| 466 * are ordered by confidence. |
| 467 */ |
| 468 core.List<ReconcileCandidate> candidate; |
| 469 |
| 470 /** Server costs for reconciling. */ |
| 471 ReconcileGetCosts costs; |
| 472 |
| 473 /** |
| 474 * If filled, this entity is guaranteed to match at requested confidence |
| 475 * probability (default 99%). |
| 476 */ |
| 477 ReconcileCandidate match; |
| 478 |
| 479 /** |
| 480 * If filled, then there were recoverable problems that affected the request. |
| 481 * For example, some of the properties were ignored because they either are |
| 482 * not valid Freebase predicates or are not indexed for reconciliation. The |
| 483 * candidates returned should be considered valid results, with the caveat |
| 484 * that sections of the request were ignored as specified by the warning text. |
| 485 */ |
| 486 core.List<ReconcileGetWarning> warning; |
| 487 |
| 488 |
| 489 ReconcileGet(); |
| 490 |
| 491 ReconcileGet.fromJson(core.Map _json) { |
| 492 if (_json.containsKey("candidate")) { |
| 493 candidate = _json["candidate"].map((value) => new ReconcileCandidate.fromJ
son(value)).toList(); |
| 494 } |
| 495 if (_json.containsKey("costs")) { |
| 496 costs = new ReconcileGetCosts.fromJson(_json["costs"]); |
| 497 } |
| 498 if (_json.containsKey("match")) { |
| 499 match = new ReconcileCandidate.fromJson(_json["match"]); |
| 500 } |
| 501 if (_json.containsKey("warning")) { |
| 502 warning = _json["warning"].map((value) => new ReconcileGetWarning.fromJson
(value)).toList(); |
| 503 } |
| 504 } |
| 505 |
| 506 core.Map toJson() { |
| 507 var _json = new core.Map(); |
| 508 if (candidate != null) { |
| 509 _json["candidate"] = candidate.map((value) => (value).toJson()).toList(); |
| 510 } |
| 511 if (costs != null) { |
| 512 _json["costs"] = (costs).toJson(); |
| 513 } |
| 514 if (match != null) { |
| 515 _json["match"] = (match).toJson(); |
| 516 } |
| 517 if (warning != null) { |
| 518 _json["warning"] = warning.map((value) => (value).toJson()).toList(); |
| 519 } |
| 520 return _json; |
| 521 } |
| 522 } |
| 523 |
| 524 |
OLD | NEW |