Ejemplo n.º 1
0
    def subject(self, subject, depth=1):
        store = self.store
        write = self.write
        indent = "\n" + indent_string * depth

        if not subject in self.__serialized:
            self.__serialized[subject] = 1
            type = first(store.objects(subject, RDF.type))

            try:
                self.nm.qname(type)
            except:
                type = None

            element = type or RDFS.Resource

            if isinstance(subject, BNode):  # not referenced more than once
                if more_than(store.triples((None, None, subject)), 1):
                    write("%s<div typeof=\"%s\" about=\"%s\">" %
                          (indent, self.getQName(element), fix(subject)))
                else:
                    write("%s<div typeof=\"%s\">" %
                          (indent, self.getQName(element)))
            else:
                write(
                    "%s<div typeof=\"%s\" about=\"%s\">" %
                    (indent, self.getQName(element), self.relativize(subject)))

            if (subject, None, None) in store:
                for predicate, object in store.predicate_objects(subject):
                    if not (predicate == RDF.type and object == type):
                        self.predicate(predicate, object, depth + 1)

            write("%s</div>" % indent)
Ejemplo n.º 2
0
    def subject(self, subject, depth=1):
        store = self.store
        write = self.write
        indent = "\n"+indent_string*depth
        
        if not subject in self.__serialized:
            self.__serialized[subject] = 1
            type = first(store.objects(subject, RDF.type))
            
            try:
                self.nm.qname(type)
            except:
                type = None
                
            element = type or RDFS.Resource

            if isinstance(subject, BNode):# not referenced more than once
                if more_than(store.triples((None, None, subject)), 1):
                    write("%s<div typeof=\"%s\" about=\"%s\">" % (indent, self.getQName(element), fix(subject)))
                else:
                    write("%s<div typeof=\"%s\">" % (indent, self.getQName(element)))
            else:
                write("%s<div typeof=\"%s\" about=\"%s\">" % (indent, self.getQName(element), self.relativize(subject)))
            
            if (subject, None, None) in store:
                for predicate, object in store.predicate_objects(subject):
                    if not (predicate == RDF.type and object == type):
                        self.predicate(predicate, object, depth+1)
                        
            write("%s</div>" % indent)
Ejemplo n.º 3
0
 def predicate(self, predicate, object, depth=1):
     writer = self.writer
     store = self.store
     writer.push(predicate)
     if isinstance(object, Literal):
         attributes = ""
         if object.language:
             writer.attribute(XMLLANG, object.language)
         if object.datatype:
             writer.attribute(RDF.datatype, object.datatype)
         writer.text(object)
     elif object in self.__serialized or not (object, None, None) in store:
         if isinstance(object, BNode):
             if more_than(store.triples((None, None, object)), 0):
                 writer.attribute(RDF.nodeID, fix(object))
         else:
             writer.attribute(RDF.resource, self.relativize(object))
     else:
         if first(store.objects(object,
                                RDF.first)):  # may not have type RDF.List
             collection = object
             self.__serialized[object] = 1
             # TODO: warn that any assertions on object other than
             # RDF.first and RDF.rest are ignored... including RDF.List
             writer.attribute(RDF.parseType, "Collection")
             col = Collection(store, object)
             for item in col:
                 if isinstance(item, URIRef):
                     self.forceRDFAbout.add(item)
                 self.subject(item)
                 if not isinstance(item, URIRef):
                     self.__serialized[item] = 1
         else:
             if first(store.triples_choices((object,
                                             RDF.type,
                                             [OWL_NS.Class,RDFS.Class]))) and\
                 isinstance(object, URIRef):
                 writer.attribute(RDF.resource, self.relativize(object))
             elif depth <= self.max_depth:
                 self.subject(object, depth + 1)
             elif isinstance(object, BNode):
                 if not object in self.__serialized and \
                    (object, None, None) in store and \
                    len(list(store.subjects(object=object)))==1:
                     #inline blank nodes if they haven't been serialized yet and are
                     #only referenced once (regardless of depth)
                     self.subject(object, depth + 1)
                 else:
                     writer.attribute(RDF.nodeID, fix(object))
             else:
                 writer.attribute(RDF.resource, self.relativize(object))
     writer.pop(predicate)
Ejemplo n.º 4
0
 def predicate(self, predicate, object, depth=1):
     writer = self.writer
     store = self.store
     writer.push(predicate)
     if isinstance(object, Literal):
         attributes = ""
         if object.language:
             writer.attribute(XMLLANG, object.language)
         if object.datatype:
             writer.attribute(RDF.datatype, object.datatype)
         writer.text(object)
     elif object in self.__serialized or not (object, None, None) in store:
         if isinstance(object, BNode):
             if more_than(store.triples((None, None, object)), 0):
                 writer.attribute(RDF.nodeID, fix(object))
         else:
             writer.attribute(RDF.resource, self.relativize(object))
     else:
         if first(store.objects(object, RDF.first)):  # may not have type RDF.List
             collection = object
             self.__serialized[object] = 1
             # TODO: warn that any assertions on object other than
             # RDF.first and RDF.rest are ignored... including RDF.List
             writer.attribute(RDF.parseType, "Collection")
             col = Collection(store, object)
             for item in col:
                 if isinstance(item, URIRef):
                     self.forceRDFAbout.add(item)
                 self.subject(item)
                 if not isinstance(item, URIRef):
                     self.__serialized[item] = 1
         else:
             if first(store.triples_choices((object, RDF.type, [OWL_NS.Class, RDFS.Class]))) and isinstance(
                 object, URIRef
             ):
                 writer.attribute(RDF.resource, self.relativize(object))
             elif depth <= self.max_depth:
                 self.subject(object, depth + 1)
             elif isinstance(object, BNode):
                 if (
                     not object in self.__serialized
                     and (object, None, None) in store
                     and len(list(store.subjects(object=object))) == 1
                 ):
                     # inline blank nodes if they haven't been serialized yet and are
                     # only referenced once (regardless of depth)
                     self.subject(object, depth + 1)
                 else:
                     writer.attribute(RDF.nodeID, fix(object))
             else:
                 writer.attribute(RDF.resource, self.relativize(object))
     writer.pop(predicate)
Ejemplo n.º 5
0
    def predicate(self, predicate, object, depth=1):
        writer = self.writer
        store = self.store
        writer.push(predicate)
        if isinstance(object, Literal):
            attributes = ""
            if object.language:
                writer.attribute(XMLLANG, object.language)
            if object.datatype:
                writer.attribute(RDF.datatype, object.datatype)
            writer.text(object)
        elif object in self.__serialized or not (object, None, None) in store:
            if isinstance(object, BNode):
                if more_than(store.triples((None, None, object)), 0):
                    writer.attribute(RDF.nodeID, fix(object))
            else:
                writer.attribute(RDF.resource, self.relativize(object))
        else:
            items = []
            for item in store.items(object):  # add a strict option to items?
                if isinstance(item, Literal):
                    items = None  # can not serialize list with literal values in them with rdf/xml
                else:
                    items.append(item)

            if first(store.objects(object,
                                   RDF.first)):  # may not have type RDF.List
                collection = object
                self.__serialized[object] = 1
                # TODO: warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                writer.attribute(RDF.parseType, "Collection")
                while collection:
                    item = first(store.objects(collection, RDF.first))
                    if item:
                        self.subject(item)
                    collection = first(store.objects(collection, RDF.rest))
                    self.__serialized[collection] = 1
            else:
                if depth <= self.max_depth:
                    self.subject(object, depth + 1)
                elif isinstance(object, BNode):
                    writer.attribute(RDF.nodeID, fix(object))
                else:
                    writer.attribute(RDF.resource, self.relativize(object))
        writer.pop(predicate)
    def predicate(self, predicate, object, depth=1):
        writer = self.writer
        store = self.store
        writer.push(predicate)
        if isinstance(object, Literal):
            attributes = ""
            if object.language:
                writer.attribute(XMLLANG, object.language)
            if object.datatype:
                writer.attribute(RDF.datatype, object.datatype)
            writer.text(object)
        elif object in self.__serialized or not (object, None, None) in store:
            if isinstance(object, BNode):
                if more_than(store.triples((None, None, object)), 0):
                    writer.attribute(RDF.nodeID, fix(object))
            else:
                writer.attribute(RDF.resource, self.relativize(object))
        else:
            items = []
            for item in store.items(object): # add a strict option to items?
                if isinstance(item, Literal):
                    items = None # can not serialize list with literal values in them with rdf/xml
                else:
                    items.append(item)

            if first(store.objects(object, RDF.first)): # may not have type RDF.List
                collection = object
                self.__serialized[object] = 1
                # TODO: warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                writer.attribute(RDF.parseType, "Collection")
                while collection:
                    item = first(store.objects(collection, RDF.first))
                    if item:
                        self.subject(item)
                    collection = first(store.objects(collection, RDF.rest))
                    self.__serialized[collection] = 1
            else:
                if depth<=self.max_depth:
                    self.subject(object, depth+1)
                elif isinstance(object, BNode):
                    writer.attribute(RDF.nodeID, fix(object))
                else:
                    writer.attribute(RDF.resource, self.relativize(object))
        writer.pop(predicate)
Ejemplo n.º 7
0
    def subject(self, subject, depth=1, skip_node=False):
        store = self.store
        write = self.write
        indent = "\n" + indent_string * depth
        if skip_node:
            depth = depth - 1

        if not subject in self.__serialized:
            self.__serialized[subject] = 1
            type = first(store.objects(subject, RDF.type))

            #try:
            #    self.nm.qname(type)
            #except:
            #    type = None

            element = type or RDFS.Resource

            if not skip_node:
                if isinstance(subject, BNode):  # not referenced more than once
                    if more_than(store.triples((None, None, subject)), 1):
                        write(
                            "%s<div itemtype=\"%s\" itemid=\"%s\" itemscope>" %
                            (indent, element, fix(subject)))
                    else:
                        write("%s<div itemtype=\"%s\" itemscope>" %
                              (indent, element))
                else:
                    write("%s<div itemtype=\"%s\" itemid=\"%s\" itemscope>" %
                          (indent, element, self.relativize(subject)))

            context = self.extract_base(element)

            if (subject, None, None) in store:
                for predicate, object in store.predicate_objects(subject):
                    if not (predicate == RDF.type and object == type):
                        self.predicate(predicate, object, depth + 1, context)

            if not skip_node:
                write("%s</div>" % indent)
Ejemplo n.º 8
0
    def subject(self, subject, depth=1, skip_node=False):
        store = self.store
        write = self.write
        indent = "\n"+indent_string*depth
        if skip_node:
            depth = depth-1
        
        if not subject in self.__serialized:
            self.__serialized[subject] = 1
            type = first(store.objects(subject, RDF.type))
            
            #try:
            #    self.nm.qname(type)
            #except:
            #    type = None

            element = type or RDFS.Resource

            if not skip_node:
                if isinstance(subject, BNode):# not referenced more than once
                    if more_than(store.triples((None, None, subject)), 1):
                        write("%s<div itemtype=\"%s\" itemid=\"%s\" itemscope>" % (indent, element, fix(subject)))
                    else:
                        write("%s<div itemtype=\"%s\" itemscope>" % (indent, element))
                else:
                    write("%s<div itemtype=\"%s\" itemid=\"%s\" itemscope>" % (indent, element, self.relativize(subject)))
            
            context = self.extract_base(element)
            
            if (subject, None, None) in store:
                for predicate, object in store.predicate_objects(subject):
                    if not (predicate == RDF.type and object == type):
                        self.predicate(predicate, object, depth+1, context)
            
            if not skip_node:
                write("%s</div>" % indent)
Ejemplo n.º 9
0
    def predicate(self, predicate, object, depth=1):
        writer = self.writer
        store = self.store
        writer.push(predicate)

        if isinstance(object, Literal):
            if object.language:
                writer.attribute(XMLLANG, object.language)

            if object.datatype == RDF.XMLLiteral and isinstance(
                    object.value, xml.dom.minidom.Document):
                writer.attribute(RDFVOC.parseType, "Literal")
                writer.text("")
                writer.stream.write(object)
            else:
                if object.datatype:
                    writer.attribute(RDFVOC.datatype, object.datatype)
                writer.text(object)

        elif object in self.__serialized or not (object, None, None) in store:

            if isinstance(object, BNode):
                if more_than(store.triples((None, None, object)), 0):
                    writer.attribute(RDFVOC.nodeID, fix(object))
            else:
                writer.attribute(RDFVOC.resource, self.relativize(object))

        else:
            if first(store.objects(object, RDF.first)):  # may not have type
                # RDF.List

                self.__serialized[object] = 1

                # Warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                import warnings

                warnings.warn(
                    "Assertions on %s other than RDF.first " % repr(object) +
                    "and RDF.rest are ignored ... including RDF.List",
                    UserWarning,
                    stacklevel=2,
                )
                writer.attribute(RDFVOC.parseType, "Collection")

                col = Collection(store, object)

                for item in col:

                    if isinstance(item, URIRef):
                        self.forceRDFAbout.add(item)
                    self.subject(item)

                    if not isinstance(item, URIRef):
                        self.__serialized[item] = 1
            else:
                if first(
                        store.triples_choices((object, RDF.type, [
                            OWL_NS.Class, RDFS.Class
                        ]))) and isinstance(object, URIRef):
                    writer.attribute(RDFVOC.resource, self.relativize(object))

                elif depth <= self.max_depth:
                    self.subject(object, depth + 1)

                elif isinstance(object, BNode):

                    if (object not in self.__serialized
                            and (object, None, None) in store
                            and len(list(store.subjects(object=object))) == 1):
                        # inline blank nodes if they haven't been serialized yet
                        # and are only referenced once (regardless of depth)
                        self.subject(object, depth + 1)
                    else:
                        writer.attribute(RDFVOC.nodeID, fix(object))

                else:
                    writer.attribute(RDFVOC.resource, self.relativize(object))

        writer.pop(predicate)
Ejemplo n.º 10
0
    def predicate(self, predicate, object, depth=1):
        writer = self.writer
        store = self.store
        writer.push(predicate)

        if isinstance(object, Literal):
            if object.language:
                writer.attribute(XMLLANG, object.language)

            if (object.datatype == RDF.XMLLiteral and
                    isinstance(object.value, xml.dom.minidom.Document)):
                writer.attribute(RDF.parseType, "Literal")
                writer.text("")
                writer.stream.write(object)
            else:
                if object.datatype:
                    writer.attribute(RDF.datatype, object.datatype)
                writer.text(object)

        elif object in self.__serialized or not (object, None, None) in store:

            if isinstance(object, BNode):
                if more_than(store.triples((None, None, object)), 0):
                    writer.attribute(RDF.nodeID, fix(object))
            else:
                writer.attribute(RDF.resource, self.relativize(object))

        else:
            if first(store.objects(object, RDF.first)):  # may not have type
                                                         # RDF.List

                self.__serialized[object] = 1

                # Warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                import warnings
                warnings.warn(
                    "Assertions on %s other than RDF.first " % repr(object) +
                    "and RDF.rest are ignored ... including RDF.List",
                    UserWarning, stacklevel=2)
                writer.attribute(RDF.parseType, "Collection")

                col = Collection(store, object)

                for item in col:

                    if isinstance(item, URIRef):
                        self.forceRDFAbout.add(item)
                    self.subject(item)

                    if not isinstance(item, URIRef):
                        self.__serialized[item] = 1
            else:
                if first(store.triples_choices(
                    (object, RDF.type, [OWL_NS.Class, RDFS.Class]))) \
                        and isinstance(object, URIRef):
                    writer.attribute(RDF.resource, self.relativize(object))

                elif depth <= self.max_depth:
                    self.subject(object, depth + 1)

                elif isinstance(object, BNode):

                    if not object in self.__serialized \
                            and (object, None, None) in store \
                            and len(list(store.subjects(object=object))) == 1:
                        # inline blank nodes if they haven't been serialized yet
                        # and are only referenced once (regardless of depth)
                        self.subject(object, depth + 1)
                    else:
                        writer.attribute(RDF.nodeID, fix(object))

                else:
                    writer.attribute(RDF.resource, self.relativize(object))

        writer.pop(predicate)
Ejemplo n.º 11
0
    def predicate(self, predicate, object, depth=1, context=None):
        store = self.store
        write = self.write
        indent = "\n"+indent_string*depth

        if isinstance(object, Literal):
            write("%s<meta itemprop=\"%s\"" % (indent, self.relativize(predicate, context)))
            #if object.language:
            #    write(" xml:lang=\"%s\"" % object.language)
            #elif object.datatype:
            #    write(" datatype=\"%s\"" % self.getQName(object.datatype))
            write(" content=\"%s\" />" % object)
        elif object in self.__serialized or not (object, None, None) in store:
            write("%s<link itemprop=\"%s\"" % (indent, self.relativize(predicate, context)))
            if isinstance(object, BNode) and more_than(store.triples((None, None, object)), 0):
                write(" href=\"%s\" />" % fix(object))
            else:
                write(" href=\"%s\" />" % self.relativize(object))
        else:
            if first(store.objects(object, RDF.first)): # may not have type RDF.List
                self.__serialized[object] = 1
                
                # Warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                import warnings
                warnings.warn(
                    "Assertions on %s other than RDF.first " % repr(object) + \
                    "and RDF.rest are ignored ... including RDF.List", 
                    UserWarning, stacklevel=2)
                
                col = Collection(store, object)
                for item in col:
                    if isinstance(item, BNode):
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), fix(item)))
                    elif isinstance(item, URIRef):
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), self.relativize(item)))
                    else:
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), item))
                    if not isinstance(item, URIRef):
                        self.__serialized[item] = 1
            else:
                if first(store.triples_choices((object, 
                                                RDF.type, 
                                                [OWL_NS.Class,RDFS.Class]))) \
                      and isinstance(object, URIRef):
                    write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), self.relativize(object)))
                    
                elif depth <= self.max_depth:
                    write("%s<div itemprop=\"%s\"" % (indent, self.relativize(predicate, context)))
                    if first(store.objects(object, RDF.type)):
                        write(" itemtype=\"%s\"" % first(store.objects(object, RDF.type)))
                    if isinstance(object, URIRef):
                        write(" itemid=\"%s\"" % object)
                    write(" itemscope>")
                    self.subject(object, depth+1, True) # skip node
                    write("%s</div>" % indent)
                
                elif isinstance(object, BNode):
                    if not object in self.__serialized \
                    and (object, None, None) in store \
                    and len(list(store.subjects(object=object))) == 1:
                        #inline blank nodes if they haven't been serialized yet and are
                        #only referenced once (regardless of depth)
                        #write(">")
                        self.subject(object, depth+1)
                        #write(indent)
                    else:
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), fix(object)))
                    
                else:
                    write("%s<link itemprop=\"%s\" href=\"%s\" />" % (indent, self.relativize(predicate, context), self.relativize(object)))
Ejemplo n.º 12
0
 def subj_as_obj_more_than(ceil):
     return more_than(store.triples((None, None, subject)),
                      ceil)
Ejemplo n.º 13
0
 def subj_as_obj_more_than(ceil):
     return more_than(store.triples((None, None, subject)), ceil)
Ejemplo n.º 14
0
	def predicate(self, predicate, object, depth=1):
		def defaultCase() :
			if depth <= self.max_depth:
				self.subject(object, depth+1)
			elif isinstance(object, BNode):
				writer.attribute(RDF.nodeID, fix(object))
			else:
				writer.attribute(RDF.resource, self.relativize(object))
		#####
		
		writer = self.writer
		store = self.store
		writer.push(predicate)
		
		if isinstance(object, Literal):
			attributes = ""
			to_escape = True
			if object.language:
				writer.attribute(XMLLANG, object.language)
			if object.datatype:
				if ("%s" % object.datatype) == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral" :
					writer.attribute(RDF.parseType, "Literal")
					to_escape = False
				else :
					writer.attribute(RDF.datatype, object.datatype)
			writer.text(object,to_escape)
		elif object in self.list_heads :
			items = [item for item in store.items(object)]
			if True not in [ isinstance(item,Literal) for item in items ] :
				# This is a kosher list that could be handled with the Collection parse type trick
				self.__serialized[object] = 1
				if object in self.list_really_heads :
					collection = object
					self.__serialized[object] = 1
					writer.attribute(RDF.parseType, "Collection")
					for item in items :
						if item in self.__serialized :
							# bugger; already done somewhere else... :-)
							writer.push(RDF.Description)
							if isinstance(item, BNode):
								if more_than(store.triples((None, None, item)), 0):
									writer.attribute(RDF.nodeID, fix(item))
							else:
								writer.attribute(RDF.about, self.relativize(item))
							writer.pop(RDF.Description)
						else :
							self.subject(item)
							self.__serialized[item] = 1
			else :
				defaultCase()
		elif object in self.__serialized or not (object, None, None) in store:
			if isinstance(object, BNode):
				if more_than(store.triples((None, None, object)), 0):
					writer.attribute(RDF.nodeID, fix(object))
			else:
				writer.attribute(RDF.resource, self.relativize(object))
		elif (object,RDF.type,RDF.Seq) in store or (object,RDF.type,RDF.Bag) in store or (object,RDF.type,RDF.Alt) in store :
			seq = Seq(store,object)
			self.__serialized[object] = 1
			if (object,RDF.type,RDF.Seq) in store :
				typ = RDF.Seq
			elif (object,RDF.type,RDF.Alt) in store :
				typ = RDF.Alt
			else :
				typ = RDF.Bag
			writer.push(typ)
			for item in seq :
				self.predicate(RDF.li,item,depth+1)
			writer.pop(typ)
		else :
			defaultCase()
		writer.pop(predicate)
Ejemplo n.º 15
0
    def predicate(self, predicate, object, depth=1, context=None):
        store = self.store
        write = self.write
        indent = "\n" + indent_string * depth

        if isinstance(object, Literal):
            write("%s<meta itemprop=\"%s\"" %
                  (indent, self.relativize(predicate, context)))
            #if object.language:
            #    write(" xml:lang=\"%s\"" % object.language)
            #elif object.datatype:
            #    write(" datatype=\"%s\"" % self.getQName(object.datatype))
            write(" content=\"%s\" />" % object)
        elif object in self.__serialized or not (object, None, None) in store:
            write("%s<link itemprop=\"%s\"" %
                  (indent, self.relativize(predicate, context)))
            if isinstance(object, BNode) and more_than(
                    store.triples((None, None, object)), 0):
                write(" href=\"%s\" />" % fix(object))
            else:
                write(" href=\"%s\" />" % self.relativize(object))
        else:
            if first(store.objects(object,
                                   RDF.first)):  # may not have type RDF.List
                self.__serialized[object] = 1

                # Warn that any assertions on object other than
                # RDF.first and RDF.rest are ignored... including RDF.List
                import warnings
                warnings.warn(
                    "Assertions on %s other than RDF.first " % repr(object) + \
                    "and RDF.rest are ignored ... including RDF.List",
                    UserWarning, stacklevel=2)

                col = Collection(store, object)
                for item in col:
                    if isinstance(item, BNode):
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                              (indent, self.relativize(predicate,
                                                       context), fix(item)))
                    elif isinstance(item, URIRef):
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                              (indent, self.relativize(
                                  predicate, context), self.relativize(item)))
                    else:
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                              (indent, self.relativize(predicate,
                                                       context), item))
                    if not isinstance(item, URIRef):
                        self.__serialized[item] = 1
            else:
                if first(store.triples_choices((object,
                                                RDF.type,
                                                [OWL_NS.Class,RDFS.Class]))) \
                      and isinstance(object, URIRef):
                    write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                          (indent, self.relativize(
                              predicate, context), self.relativize(object)))

                elif depth <= self.max_depth:
                    write("%s<div itemprop=\"%s\"" %
                          (indent, self.relativize(predicate, context)))
                    if first(store.objects(object, RDF.type)):
                        write(" itemtype=\"%s\"" %
                              first(store.objects(object, RDF.type)))
                    if isinstance(object, URIRef):
                        write(" itemid=\"%s\"" % object)
                    write(" itemscope>")
                    self.subject(object, depth + 1, True)  # skip node
                    write("%s</div>" % indent)

                elif isinstance(object, BNode):
                    if not object in self.__serialized \
                    and (object, None, None) in store \
                    and len(list(store.subjects(object=object))) == 1:
                        #inline blank nodes if they haven't been serialized yet and are
                        #only referenced once (regardless of depth)
                        #write(">")
                        self.subject(object, depth + 1)
                        #write(indent)
                    else:
                        write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                              (indent, self.relativize(predicate,
                                                       context), fix(object)))

                else:
                    write("%s<link itemprop=\"%s\" href=\"%s\" />" %
                          (indent, self.relativize(
                              predicate, context), self.relativize(object)))
    def predicate(self, predicate, object, depth=1):
        def defaultCase():
            if depth <= self.max_depth:
                self.subject(object, depth + 1)
            elif isinstance(object, BNode):
                writer.attribute(RDF.nodeID, fix(object))
            else:
                writer.attribute(RDF.resource, self.relativize(object))

        #####

        writer = self.writer
        store = self.store
        writer.push(predicate)

        if isinstance(object, Literal):
            attributes = ""
            if object.language:
                writer.attribute(XMLLANG, object.language)
            if object.datatype:
                if (
                        "%s" % object.datatype
                ) == "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral":
                    writer.attribute(RDF.parseType, "Literal")
                else:
                    writer.attribute(RDF.datatype, object.datatype)
            writer.text(object)
        elif object in self.__serialized or not (object, None, None) in store:
            if isinstance(object, BNode):
                if more_than(store.triples((None, None, object)), 0):
                    writer.attribute(RDF.nodeID, fix(object))
            else:
                writer.attribute(RDF.resource, self.relativize(object))
        elif (object, RDF.type,
              RDF.Seq) in store or (object, RDF.type,
                                    RDF.Bag) in store or (object, RDF.type,
                                                          RDF.Alt) in store:
            seq = Seq(store, object)
            self.__serialized[object] = 1
            if (object, RDF.type, RDF.Seq) in store:
                typ = RDF.Seq
            elif (object, RDF.type, RDF.Alt) in store:
                typ = RDF.Alt
            else:
                typ = RDF.Bag
            writer.push(typ)
            for item in seq:
                self.predicate(RDF.li, item, depth + 1)
            writer.pop(typ)
        elif object in self.listHeads:
            items = [item for item in store.items(object)]
            if True not in [isinstance(item, Literal) for item in items]:
                # This is a kosher list that could be handled with the Collection parse type trick
                collection = object
                self.__serialized[object] = 1
                writer.attribute(RDF.parseType, "Collection")
                for item in items:
                    if item in self.__serialized:
                        # bugger; already done somewhere else... :-)
                        writer.push(RDF.Description)
                        if isinstance(item, BNode):
                            if more_than(store.triples((None, None, item)), 0):
                                writer.attribute(RDF.nodeID, fix(item))
                        else:
                            writer.attribute(RDF.about, self.relativize(item))
                        writer.pop(RDF.Description)
                    else:
                        self.subject(item)
                        self.__serialized[item] = 1
            else:
                defaultCase()
        else:
            defaultCase()
        writer.pop(predicate)