<s> """<STR_LIT>""" <EOL> from rdflib . graph import Graph <EOL> from rdflib . namespace import Namespace , OWL <EOL> from rdflib . plugins . serializers . turtle import ( <EOL> TurtleSerializer , SUBJECT , OBJECT ) <EOL> __all__ = [ '<STR_LIT>' ] <EOL> SWAP_LOG = Namespace ( "<STR_LIT>" ) <EOL> class N3Serializer ( TurtleSerializer ) : <EOL> short_name = "<STR_LIT>" <EOL> def __init__ ( self , store , parent = None ) : <EOL> super ( N3Serializer , self ) . __init__ ( store ) <EOL> self . keywords . update ( { <EOL> OWL . sameAs : '<STR_LIT:=>' , <EOL> SWAP_LOG . implies : '<STR_LIT>' <EOL> } ) <EOL> self . parent = parent <EOL> def reset ( self ) : <EOL> super ( N3Serializer , self ) . reset ( ) <EOL> self . _stores = { } <EOL> def subjectDone ( self , subject ) : <EOL> super ( N3Serializer , self ) . subjectDone ( subject ) <EOL> if self . parent : <EOL> self . parent . subjectDone ( subject ) <EOL> def isDone ( self , subject ) : <EOL> return ( super ( N3Serializer , self ) . isDone ( subject ) <EOL> and ( not self . parent or self . parent . isDone ( subject ) ) ) <EOL> def startDocument ( self ) : <EOL> super ( N3Serializer , self ) . startDocument ( ) <EOL> def endDocument ( self ) : <EOL> if not self . parent : <EOL> super ( N3Serializer , self ) . endDocument ( ) <EOL> def indent ( self , modifier = <NUM_LIT:0> ) : <EOL> indent = super ( N3Serializer , self ) . indent ( modifier ) <EOL> if self . parent is not None : <EOL> indent += self . parent . indent ( ) <EOL> return indent <EOL> def preprocessTriple ( self , triple ) : <EOL> super ( N3Serializer , self ) . preprocessTriple ( triple ) <EOL> if isinstance ( triple [ <NUM_LIT:0> ] , Graph ) : <EOL> for t in triple [ <NUM_LIT:0> ] : <EOL> self . preprocessTriple ( t ) <EOL> if isinstance ( triple [ <NUM_LIT:2> ] , Graph ) : <EOL> for t in triple [ <NUM_LIT:2> ] : <EOL> self . preprocessTriple ( t ) <EOL> def getQName ( self , uri , gen_prefix = True ) : <EOL> qname = None <EOL> if self . parent is not None : <EOL> qname = self . parent . getQName ( uri , gen_prefix ) <EOL> if qname is None : <EOL> qname = super ( N3Serializer , self ) . getQName ( uri , gen_prefix ) <EOL> return qname <EOL> def statement ( self , subject ) : <EOL> self . subjectDone ( subject ) <EOL> properties = self . buildPredicateHash ( subject ) <EOL> if len ( properties ) == <NUM_LIT:0> : <EOL> return False <EOL> return ( self . s_clause ( subject ) <EOL> or super ( N3Serializer , self ) . statement ( subject ) ) <EOL> def path ( self , node , position , newline = False ) : <EOL> if not self . p_clause ( node , position ) : <EOL> super ( N3Serializer , self ) . path ( node , position , newline ) <EOL> def s_clause ( self , subject ) : <EOL> if isinstance ( subject , Graph ) : <EOL> self . write ( '<STR_LIT:\n>' + self . indent ( ) ) <EOL> self . p_clause ( subject , SUBJECT ) <EOL> self . predicateList ( subject ) <EOL> self . write ( '<STR_LIT>' ) <EOL> return True <EOL> else : <EOL> return False <EOL> def p_clause ( self , node , position ) : <EOL> if isinstance ( node , Graph ) : <EOL> self . subjectDone ( node ) <EOL> if position is OBJECT : <EOL> self . write ( '<STR_LIT:U+0020>' ) <EOL> self . write ( '<STR_LIT:{>' ) <EOL> self . depth += <NUM_LIT:1> <EOL> serializer = N3Serializer ( node , parent = self ) <EOL> serializer . serialize ( self . stream ) <EOL> self . depth -= <NUM_LIT:1> <EOL> self . write ( self . indent ( ) + '<STR_LIT:}>' ) <EOL> return True <EOL> else : <EOL> return False </s>
