[Python-modules-commits] [python-pyld] 28/276: Added 'triples' method based on implementation from jsonld.js

Wolfgang Borgert debacle at moszumanska.debian.org
Wed Oct 8 23:47:50 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 e283ef083f797bf587a1a76ccf55059933b369fc
Author: Josh Mandel <joshua.mandel at childrens.harvard.edu>
Date:   Mon Sep 12 12:19:51 2011 -0700

    Added 'triples' method based on implementation from jsonld.js
---
 lib/pyld/jsonld.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py
index c4a2512..eb409f0 100644
--- a/lib/pyld/jsonld.py
+++ b/lib/pyld/jsonld.py
@@ -817,6 +817,7 @@ class Processor:
 
         return rval
 
+
     def getCoerceType(self, ctx, property, usedCtx):
         """
         Gets the coerce type for the given property.
@@ -1737,6 +1738,33 @@ def _compareSerializations(s1, s2):
         rval = _compare(s1, s2[0:len(s1)])
     return rval
 
+
+def triples(input, callback=None):
+    normalized = normalize(input)
+    rval = None
+
+    # normalize input
+    if (callback == None):
+        rval = []
+        def callback(s,p,o):
+            rval.append({'s':s, 'p':p, 'o':o })
+            return True
+
+    quit = False
+    for e in normalized:
+        s = e['@subject']['@iri']
+        for p, obj in e.iteritems():
+            if p == '@subject': continue
+            if not isinstance(obj, list):
+                obj = [obj]
+            for o2 in obj:
+                quit = callback(s, p, o2)==False
+                if quit: break
+            if quit: break
+        if quit: break
+    
+    return rval
+
 def normalize(input):
     """
     Normalizes a JSON-LD object.

-- 
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