[Python-modules-commits] [python-pyld] 197/276: Add quick examples to README.
Wolfgang Borgert
debacle at moszumanska.debian.org
Wed Oct 8 23:48:10 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to branch master
in repository python-pyld.
commit 649603a87959eb5b01e147c04881146974bf2225
Author: Dave Longley <dlongley at digitalbazaar.com>
Date: Mon Sep 16 14:05:41 2013 -0400
Add quick examples to README.
Closes #3.
---
README.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/README.rst b/README.rst
index 2b504a2..47fe8df 100644
--- a/README.rst
+++ b/README.rst
@@ -36,6 +36,68 @@ added semantics. Finally, the format is intended to be fast to parse, fast
to generate, stream-based and document-based processing compatible, and
require a very small memory footprint in order to operate.
+Quick Examples
+--------------
+
+.. code-block::
+
+ doc = {
+ "http://schema.org/name": "Manu Sporny",
+ "http://schema.org/url": {"@id": "http://manu.sporny.org/"},
+ "http://schema.org/image": {"@id": "http://manu.sporny.org/images/manu.png"}
+ }
+
+ context = {
+ "name": "http://schema.org/name",
+ "homepage": {"@id": "http://schema.org/url", "@type": "@id"},
+ "image": {"@id": "http://schema.org/image", "@type": "@id"}}
+
+ # compact a document according to a particular context
+ # see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form
+ compacted = jsonld.compact(doc, context)
+
+ print(json.dumps(compacted, indent=2))
+ # Output:
+ # {
+ # "@context": {...},
+ # "image": "http://manu.sporny.org/images/manu.png",
+ # "homepage": "http://manu.sporny.org/",
+ # "name": "Manu Sporny"
+ # }
+
+ # compact using URLs
+ jsonld.compact('http://example.org/doc', 'http://example.org/context')
+
+ # expand a document, removing its context
+ # see: http://json-ld.org/spec/latest/json-ld/#expanded-document-form
+ expanded = jsonld.expand(compacted)
+
+ print(json.dumps(compacted, indent=2))
+ # Output:
+ # {
+ # "http://schema.org/image": [{"@id": "http://manu.sporny.org/images/manu.png"}],
+ # "http://schema.org/name": [{"@value": "Manu Sporny"}],
+ # "http://schema.org/url": [{"@id": "http://manu.sporny.org/"}]
+ # }
+
+ # expand using URLs
+ jsonld.expand('http://example.org/doc')
+
+ # flatten a document
+ # see: http://json-ld.org/spec/latest/json-ld/#flattened-document-form
+ flattened = jsonld.flatten(doc)
+ # all deep-level trees flattened to the top-level
+
+ # frame a document
+ # see: http://json-ld.org/spec/latest/json-ld-framing/#introduction
+ framed = jsonld.frame(doc, frame)
+ # document transformed into a particular tree structure per the given frame
+
+ # normalize a document
+ normalized = jsonld.normalize(doc, {'format': 'application/nquads'})
+ # normalized is a string that is a canonical representation of the document
+ # that can be used for hashing
+
Commercial Support
------------------
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pyld.git
More information about the Python-modules-commits
mailing list