microdata.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:Meiji 作者: GiovanniBalestrieri 项目源码 文件源码
def __init__( self, document, graph, base = None, vocab_expansion = False, vocab_cache = True  ) :
        """
        @param graph: an RDF graph; an RDFLib Graph
        @type graph: RDFLib Graph
        @param document: top of the DOM tree, as returned by the HTML5 parser
        @keyword base: the base of the Dom tree, either set from the outside or via a @base element
        @keyword vocab_expansion: whether vocab expansion should be performed or not
        @type vocab_expansion: Boolean
        @keyword vocab_cache: if vocabulary expansion is done, then perform caching of the vocabulary data
        @type vocab_cache: Boolean
        """
        Microdata.__init__(self, document, base)
        self.vocab_expansion   = vocab_expansion
        self.vocab_cache       = vocab_cache
        self.graph             = graph
        self.ns_md             = Namespace( MD_VOCAB )
        self.graph.bind( "md",MD_VOCAB )
        self.vocabularies_used = False

        # Get the vocabularies defined in the registry bound to proper names, if any...

        def _use_rdfa_context () :
            try :
                from ..pyRdfa.initialcontext import initial_context
            except :
                from pyRdfa.initialcontext import initial_context
            retval = {}
            vocabs = initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns
            for prefix in list(vocabs.keys()) :
                uri = vocabs[prefix]
                if uri not in vocab_names and uri not in registry : retval[uri] = prefix
            return retval

        for vocab in registry :
            if vocab in vocab_names :
                self.graph.bind( vocab_names[vocab],vocab )
            else :
                hvocab = vocab + '#'
                if hvocab in vocab_names :
                    self.graph.bind( vocab_names[hvocab],hvocab )

        # Add the prefixes defined in the RDFa initial context to improve the outlook of the output
        # I put this into a try: except: in case the pyRdfa package is not available...
        try :
            try :
                from ..pyRdfa.initialcontext import initial_context
            except :
                from pyRdfa.initialcontext import initial_context
            vocabs = initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns
            for prefix in list(vocabs.keys()) :
                uri = vocabs[prefix]
                if uri not in registry :
                    # if it is in the registry, then it may have needed some special microdata massage...
                    self.graph.bind( prefix,uri )
        except :
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号