1. Gabriel Farrell
  2. papers

Commits

Gabriel Farrell  committed b3c7b6f

Better formatting for JSON and JS examples

  • Participants
  • Parent commits 0ac93f9
  • Branches default

Comments (0)

Files changed (1)

File code4lib13/isis2couchdb.txt

View file
  • Ignore whitespace
 #2 are shown; some contents shortened for clarity):
 
 <pre>[sourcecode language='javascript']
-  {"10":
-      [
-          {   "_": "Kanda, Paulo Afonso",
-              "1": "University of São Paulo",
-              "2": "School of Medicine",
-              "3": "Cognitive Disorders of … Reference Center",
-              "c": "São Paulo",
-              "p": "Brasil",
-              "r": "org"
-          },
-          {   "_": "Smidth, Magali Taino",
-              "1": "University of São Paulo",
-              "2": "School of Medicine",
-              "3": "Cognitive Disorders of … Reference Center",
-              "c": "São Paulo",
-              "p": "Brasil",
-              "r": "org"
-          }
-      ],
-   "2":
-      [
-          {   "_": "538886"
-          }
-      ]
- }
+{
+    "10": [
+        {   
+            "_": "Kanda, Paulo Afonso",
+            "1": "University of São Paulo",
+            "2": "School of Medicine",
+            "3": "Cognitive Disorders of … Reference Center",
+            "c": "São Paulo",
+            "p": "Brasil",
+            "r": "org"
+        },
+        {   
+            "_": "Smidth, Magali Taino",
+            "1": "University of São Paulo",
+            "2": "School of Medicine",
+            "3": "Cognitive Disorders of … Reference Center",
+            "c": "São Paulo",
+            "p": "Brasil",
+            "r": "org"
+        }
+    ],
+    "2": [
+        {   
+            "_": "538886"
+        }
+    ]
+}
 [/sourcecode]</pre>
 
 In the representation above, the record is a JSON mapping between tags (eg.
 within long strings for clarity):
 
 <pre>[sourcecode language='javascript']
-  {"10":
-      ["Kanda, Paulo Afonso de Medeiros^1University of São Paulo
-        ^2School of Medicine^3Cognitive Disorders of Clinicas
-        Hospital Reference Center^pBrasil ^cSão Paulo^rorg",
-
-       "Smidth, Magali Taino^1University of São Paulo ^2School
-        of Medicine^3Cognitive Disorders of Clinicas Hospital
-        Reference Center^pBrasil ^cSão Paulo^rorg"
-      ],
-   "2":
-      ["538886"]
-  }
+{
+    "10": [
+        "Kanda, Paulo Afonso de Medeiros^1University of São Paulo
+          ^2School of Medicine^3Cognitive Disorders of Clinicas
+          Hospital Reference Center^pBrasil ^cSão Paulo^rorg",
+        "Smidth, Magali Taino^1University of São Paulo ^2School
+          of Medicine^3Cognitive Disorders of Clinicas Hospital
+          Reference Center^pBrasil ^cSão Paulo^rorg"
+    ],
+    "2": ["538886"]
+}
 [/sourcecode]</pre>
 
 In this format, each field occurrence is a single string, with the subfield
 approach. Another possibility is ISIS-JSON type 2:
 
 <pre>[sourcecode language='javascript']
-  {"10":
-      [
-          [
-              ["_", "Kanda, Paulo Afonso"],
-              ["1", "University of São Paulo"],
-              ["2", "School of Medicine"],
-              ["3", "Cognitive Disorders of … Reference Center"],
-              ["p", "Brasil"],
-              ["c", "São Paulo"],
-              ["r", "org"]
-          ],
-          [
-              ["_", "Smidth, Magali Taino"],
-              ["1", "University of São Paulo"],
-              ["2", "School of Medicine"],
-              ["3", "Cognitive Disorders of … Reference Center"],
-              ["p", "Brasil"],
-              ["c", "São Paulo"],
-              ["r", "org"]
-          ]
-      ],
-   "2":
-      [
-          [
-              ["_", "538886"]
-          ]
-      ]
-  }
+{
+    "10": [
+        [
+            ["_", "Kanda, Paulo Afonso"],
+            ["1", "University of São Paulo"],
+            ["2", "School of Medicine"],
+            ["3", "Cognitive Disorders of … Reference Center"],
+            ["p", "Brasil"],
+            ["c", "São Paulo"],
+            ["r", "org"]
+        ],
+        [
+            ["_", "Smidth, Magali Taino"],
+            ["1", "University of São Paulo"],
+            ["2", "School of Medicine"],
+            ["3", "Cognitive Disorders of … Reference Center"],
+            ["p", "Brasil"],
+            ["c", "São Paulo"],
+            ["r", "org"]
+        ]
+    ],
+    "2": [
+        [
+            ["_", "538886"]
+        ]
+    ]
+}
 [/sourcecode]</pre>
 
 Here each field occurrence is an association list [140], that is, a mapping
 Can be converted into this JSON document record, ready to import into CouchDB:
 
 <pre>[sourcecode language='javascript']
-{"_id": "538886",
-   "1":
-      [
-          [
-              ["_", "BR1.1"]
-          ]
-      ]
-   "2":
-      [
-          [
-              ["_", "538886"]
-          ]
-      ]
-   "4":
-      [
-          [
-              ["_", "LILACS"]
-          ],
-          [
-              ["_", "LLXPEDT"]
-          ]
-      ]
-  }
+{
+    "_id": "538886",
+   "1": [
+       [
+           ["_", "BR1.1"]
+       ]
+   ],
+   "2": [
+       [
+           ["_", "538886"]
+       ]
+   ],
+   "4": [
+       [
+           ["_", "LILACS"]
+       ],
+       [
+           ["_", "LLXPEDT"]
+       ]
+   ]
+}
 [/sourcecode]</pre>
 
 Note how the content of the first occurrence of the #2 tag was used as _id.
 
 <pre>[sourcecode language='javascript']
 function(doc) {
-    emit(doc["1"][0][0][1], doc["12"][0][0][1]);
+  emit(doc["1"][0][0][1], doc["12"][0][0][1]);
 }
 [/sourcecode]</pre>
 
 could be represented like this:
 
 <pre>[sourcecode language='javascript']
-{ "1" : "UY6.1",
-  ...
+{ 
+    "1" : "UY6.1",
+    ...
 }
 [/sourcecode]</pre>
 
 that is, <pre>doc.v1</pre> to access tag v1 in:
 
 <pre>[sourcecode language='javascript']
-{ "v1" : "UY6.1",
-  ...
+{ 
+    "v1" : "UY6.1",
+    ...
 }
 [/sourcecode]</pre>
 
 subfields every time when indexing. Therefore field #1 is represented as:
 
 <pre>[sourcecode language='javascript']
-{  "1": [
-       [
-           [
-               "_",
-               "UY6.1"
-           ]
-       ]
-   ],
-   ...
+{  
+    "1": [
+        [
+            [
+                "_",
+                "UY6.1"
+            ]
+        ]
+    ],
+    ...
 }
 [/sourcecode]</pre>
 
 
 <pre>[sourcecode language='javascript']
 function(doc) {
-    emit(doc["1"][0][0][1], doc["12"][0][0][1]);
+  emit(doc["1"][0][0][1], doc["12"][0][0][1]);
 }
 [/sourcecode]</pre>
 
 
 <pre>[sourcecode language='javascript']
 function(doc) {
-    var occur, subf;
-    if (doc.hasOwnProperty('10')) {
-        for (occur=0; occur<doc['10'].length; occur++) {
-            for (subf=0; subf<doc['10'][occur].length; subf++) {
-                if (doc['10'][occur][subf][0] === 'p') {
-                    emit(doc['10'][occur][subf][1], 1);
-                    break;
-                }
-            }
+  var occur, subf;
+  if (doc.hasOwnProperty('10')) {
+    for (occur=0; occur<doc['10'].length; occur++) {
+      for (subf=0; subf<doc['10'][occur].length; subf++) {
+        if (doc['10'][occur][subf][0] === 'p') {
+          emit(doc['10'][occur][subf][1], 1);
+          break;
         }
-    } else {
-        emit(null, 1);
+      }
     }
+  } else {
+    emit(null, 1);
+  }
 }
 [/sourcecode]</pre>
 
 
 <pre>[sourcecode language='javascript']
 function(doc) {
-    // !code vendor/isisdm_t2/_attachments/isisdm.js
-    var i, occurs = ISIS.getallsub(doc, 10, "p");
-    for (i=0; i<occurs.length; i++) {
-        if (occurs[i] !== undefined) {
-            emit(occurs[i], 1);
-        }
+  // !code vendor/isisdm_t2/_attachments/isisdm.js
+  var i, occurs = ISIS.getallsub(doc, 10, "p");
+  for (i=0; i<occurs.length; i++) {
+    if (occurs[i] !== undefined) {
+      emit(occurs[i], 1);
     }
+  }
 }
 [/sourcecode]</pre>