Changeset - f1c062f3b227
[Not reviewed]
default
0 2 0
Drew Perttula - 8 years ago 2017-03-30 05:22:48
drewp@bigasterisk.com
rdflib upgrade
Ignore-this: 299dba7405bf435dcd432fd49081a0f8
2 files changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
light9/rdfdb/rdflibpatch.py
Show inline comments
 
@@ -4,13 +4,13 @@ this is a proposal for a ConjunctiveGrap
 
import sys
 
if sys.path[0] == '/usr/lib/python2.7/dist-packages':
 
    # nosetests puts this in
 
    sys.path = sys.path[1:]
 

	
 
import unittest
 
from rdflib import ConjunctiveGraph, Graph, URIRef as U
 
from rdflib import ConjunctiveGraph, Graph, URIRef as U, Literal
 

	
 
def patchQuads(graph, deleteQuads, addQuads, perfect=False):
 
    """
 
    Delete the sequence of given quads. Then add the given quads just
 
    like addN would. If perfect is True, we'll error before the
 
    deletes or before the adds (not a real transaction) if any of the
 
@@ -70,26 +70,33 @@ def graphFromQuads(q):
 

	
 
def graphFromNQuad(text):
 
    g1 = ConjunctiveGraph()
 
    g1.parse(data=text, format='nquads')
 
    return g1
 

	
 
from rdflib.plugins.serializers.nt import _xmlcharref_encode
 
from rdflib.plugins.serializers.nt import _quoteLiteral
 
def serializeQuad(g):
 
    """replacement for graph.serialize(format='nquads')"""
 
    """
 
    replacement for graph.serialize(format='nquads')
 

	
 
    Still broken in rdflib 4.2.2: graph.serialize(format='nquads')
 
    returns empty string for my graph in
 
    TestGraphFromQuads.testSerializes.
 
    """
 
    out = []
 
    for s,p,o,c in g.quads((None,None,None)):
 
        if isinstance(c, Graph):
 
            # still not sure why this is Graph sometimes,
 
            # already URIRef other times
 
            c = c.identifier
 
        if '[' in c.n3():
 
            import ipdb;ipdb.set_trace()
 
        ntObject = _quoteLiteral(o) if isinstance(o, Literal) else o.n3()
 
        out.append(u"%s %s %s %s .\n" % (s.n3(),
 
                                     p.n3(),
 
                                     _xmlcharref_encode(o.n3()),
 
                                     ntObject,
 
                                     c.n3()))
 
    return ''.join(out)
 

	
 
def inContext(graph, newContext):
 
    """
 
    make a ConjunctiveGraph where all the triples in the given graph
requirements.txt
Show inline comments
 
rdflib==4.1.2
 
rdflib==4.2.2
 
Twisted==17.1.0
 
webcolors==1.7
 
Louie==1.1
 
cyclone==1.1
 

	
 
web.py==0.38
0 comments (0 inline, 0 general)