Developing Metaweb-Enabled Web Applications
Total Page:16
File Type:pdf, Size:1020Kb
Developing Metaweb-Enabled Web Applications Metaweb Technologies, Inc. Developing Metaweb-Enabled Web Applications Metaweb Technologies, Inc. Published 2007-03-08 Copyright © 2007 Metaweb Technologies, Inc. Table of Contents 1. Introduction .................................................................................................................. 1 1.1. The Metaweb Query API ..................................................................................... 1 1.2. About this Manual .............................................................................................. 3 2. Metaweb Architecture .................................................................................................... 5 2.1. The Metaweb Object Model ................................................................................ 5 2.1.1. Common Object Properties ....................................................................... 7 2.1.2. Names, Keys, and Ids ............................................................................... 8 2.1.3. Topics ..................................................................................................... 8 2.2. Values ................................................................................................................ 9 2.2.1. /type/int .................................................................................................. 9 2.2.2. /type/float ................................................................................................ 9 2.2.3. /type/boolean ......................................................................................... 10 2.2.4. /type/id .................................................................................................. 10 2.2.5. /type/text ............................................................................................... 10 2.2.6. /type/key ............................................................................................... 10 2.2.7. /type/rawstring ....................................................................................... 11 2.2.8. /type/uri ................................................................................................ 11 2.2.9. /type/datetime ........................................................................................ 11 2.3. Types ............................................................................................................... 13 2.3.1. Core Types ............................................................................................ 14 2.3.2. Content Types ........................................................................................ 15 2.3.3. Access Control Types ............................................................................. 16 2.4. Domains .......................................................................................................... 17 2.5. Namespaces ..................................................................................................... 17 2.6. Access Control ................................................................................................. 18 3. The Metaweb Query Language ..................................................................................... 19 3.1. JavaScript Object Notation ................................................................................ 19 3.1.1. JSON Literals: null, true, false ................................................................ 20 3.1.2. JSON Numbers ...................................................................................... 20 3.1.3. JSON Strings ......................................................................................... 20 3.1.4. JSON Arrays ......................................................................................... 21 3.1.5. JSON Objects ........................................................................................ 22 3.2. MQL Tutorial ................................................................................................... 23 3.2.1. Our First Query ..................................................................................... 25 3.2.2. Query/Response Symmetry .................................................................... 26 3.2.3. Metaweb Object IDs .............................................................................. 26 3.2.4. Multiple Results and Uniqueness Errors .................................................. 27 3.2.5. Nested Queries ...................................................................................... 30 3.2.6. Asking Metaweb For Objects .................................................................. 31 3.2.7. Expanded Values and Default Properties .................................................. 34 3.2.8. Review: Asking for Values ...................................................................... 35 3.2.9. Too Much Information ........................................................................... 36 3.2.10. The id and name Properties ................................................................... 37 3.2.11. Numeric Constraints ............................................................................. 39 3.2.12. Textual Constraints: Pattern Matching in Queries ................................... 41 3.2.13. Limiting Queries .................................................................................. 43 iii 3.2.14. The Sort Directive ................................................................................ 44 3.2.15. Ordered Collections ............................................................................. 46 3.2.16. Optional Queries .................................................................................. 48 3.2.17. Using Fully-Qualified Property Names .................................................. 49 3.2.18. Wildcards ............................................................................................ 51 3.2.19. Expressing AND in Queries .................................................................. 53 3.2.20. Expressing OR in Queries ..................................................................... 55 3.2.21. Expressing NOT in Queries .................................................................. 57 3.2.22. Reflective Queries ................................................................................ 58 3.3. The MQL Grammar .......................................................................................... 60 4. Metaweb Read Services ............................................................................................... 63 4.1. Basic mqlread Queries with Perl ........................................................................ 63 4.1.1. A Better Perl Album Lister ..................................................................... 64 4.2. The mqlread Service ......................................................................................... 67 4.2.1. mqlread Input ........................................................................................ 67 4.2.2. mqlread Output ...................................................................................... 68 4.2.3. Query and Response Envelopes .............................................................. 68 4.3. A Python Album Lister ...................................................................................... 70 4.4. A Metaweb-enabled PHP Web Application ......................................................... 72 4.5. Metaweb Queries with JavaScript ...................................................................... 74 4.5.1. Listing Albums and Tracks with JavaScript .............................................. 75 4.5.2. Client-side MQL Queries with <script> ................................................... 80 4.6. mqlread Errors ................................................................................................. 81 4.7. mqlread Cursors ............................................................................................... 82 4.8. Fetching Content with trans ............................................................................... 85 4.8.1. Browsing Recent Content on freebase.com .............................................. 86 4.9. Example: A Metaweb Type Browser .................................................................. 89 5. The MQL Write Grammar ............................................................................................ 95 5.1. MQL Write Tutorial .......................................................................................... 95 5.1.1. Creating a Type to Work With ................................................................. 95 5.1.2. Creating Objects .................................................................................... 97 5.1.3. Connecting Objects ................................................................................ 99 5.1.4. Disconnecting Objects .......................................................................... 102 5.1.5. Writes and Default Properties ............................................................... 104 5.1.6. Creating and Connecting More Objects ................................................. 106 5.1.7. Review: Write Directives ...................................................................... 111 5.1.8. Working with Sets ................................................................................ 112 5.1.9. Bidirectional Links and Reciprocal Properties .......................................