當前位置: 首頁>>代碼示例>>Python>>正文


Python rdflib.Namespace方法代碼示例

本文整理匯總了Python中rdflib.Namespace方法的典型用法代碼示例。如果您正苦於以下問題:Python rdflib.Namespace方法的具體用法?Python rdflib.Namespace怎麽用?Python rdflib.Namespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rdflib的用法示例。


在下文中一共展示了rdflib.Namespace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def __init__(self, user, repo):
        """Default constructor.

        Keyword arguments:
        user -- Github user.
        repo -- Github repo.
        """
        self.user = user
        self.repo = repo
        self.prov_g = Graph()
        prov_uri = URIRef("http://www.w3.org/ns/prov#")
        self.prov = Namespace(prov_uri)
        self.prov_g.bind('prov', self.prov)

        self.agent = URIRef("http://{}".format(static.SERVER_NAME))
        self.entity_d = URIRef("http://{}/api/{}/{}/spec".format(static.SERVER_NAME, self.user, self.repo))
        self.activity = URIRef(self.entity_d + "-activity")

        self.init_prov_graph() 
開發者ID:CLARIAH,項目名稱:grlc,代碼行數:21,代碼來源:prov.py

示例2: bind

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def bind(self, prefix, namespace):
        """
        Bind a prefix to a namespace.

        :param str prefix: Namespace prefix.
        :param rdflib.URIRef namespace: Fully qualified URI of namespace.
        """
        prefix = prefix.encode()
        namespace = namespace.encode()
        if self.is_txn_rw:
            # FIXME DB labels should be constants but there are problems
            # imprting them from the Cython module.
            self.put(prefix, namespace, b'pfx:ns_')
            self.put(namespace, prefix, b'ns:pfx_')
        else:
            #logger.debug('Opening RW transaction.')
            with self.txn_ctx(write=True) as wtxn:
                self.put(prefix, namespace, b'pfx:ns_')
                self.put(namespace, prefix, b'ns:pfx_') 
開發者ID:scossu,項目名稱:lakesuperior,代碼行數:21,代碼來源:lmdb_store.py

示例3: verify_rdf

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def verify_rdf(rdf_output):
    ids_ns = Namespace("http://foo.example.org/CSV/People-IDs/")
    ages_ns = Namespace("http://foo.example.org/CSV/People-Ages/")
    g = ConjunctiveGraph()
    g.parse(data=rdf_output, format="turtle")

    all_subjects = {x for x in g.subjects()}
    assert len(all_subjects) == 2

    bob_subj = ids_ns['1']
    joe_subj = ids_ns['2']
    assert bob_subj in all_subjects
    assert joe_subj in all_subjects

    # Bob's details
    assert len([g.triples((bob_subj, ids_ns.id, Literal(1)))]) == 1
    assert len([g.triples((bob_subj, ids_ns.name, Literal("Bob")))]) == 1
    assert len([g.triples((bob_subj, ages_ns.age, Literal(34)))]) == 1

    # Joe's details
    assert len([g.triples((joe_subj, ids_ns.id, Literal(2)))]) == 1
    assert len([g.triples((joe_subj, ids_ns.name, Literal("Joe")))]) == 1
    assert len([g.triples((joe_subj, ages_ns.age, Literal(54)))]) == 1 
開發者ID:bloomberg,項目名稱:pycsvw,代碼行數:25,代碼來源:test_multiple_tables.py

示例4: __init__

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def __init__(self, are_bnodes_skized=True, identifier=None):
        # print("in RDFGraph  with id: ", identifier)
        super().__init__('IOMemory', identifier)
        self.are_bnodes_skized = are_bnodes_skized

        # Can be removed when this is resolved
        # https://github.com/RDFLib/rdflib/issues/632
        for pfx in ('OBO',):  # , 'ORPHA'):
            self.bind(pfx, Namespace(self.curie_map[pfx]))

        # try adding them all
        # self.bind_all_namespaces()  # too much 
開發者ID:monarch-initiative,項目名稱:dipper,代碼行數:14,代碼來源:RDFGraph.py

示例5: _getnode

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def _getnode(self, curie):  # convention is lowercase names
        """
        This is a wrapper for creating a URIRef or Bnode object
        with a given a curie or iri as a string.

        If an id starts with an underscore, it assigns it to a BNode, otherwise
        it creates it with a standard URIRef.
        Alternatively, self.skolemize_blank_node is True,
        it will skolemize the blank node

        :param curie: str identifier formatted as curie or iri
        :return: node: RDFLib URIRef or BNode object
        """
        node = None
        if curie[0] == '_':
            if self.are_bnodes_skized is True:
                node = self.skolemizeBlankNode(curie)
            else:  # delete the leading underscore to make it cleaner
                node = BNode(re.sub(r'^_:|^_', '', curie, 1))

        # Check if curie string is actually an IRI
        elif curie[:4] == 'http' or curie[:3] == 'ftp' or curie[:4] == 'jdbc':
            node = URIRef(curie)
        else:
            iri = RDFGraph.curie_util.get_uri(curie)
            if iri is not None:
                node = URIRef(RDFGraph.curie_util.get_uri(curie))
                # Bind prefix map to graph
                prefix = curie.split(':')[0]
                if prefix not in self.namespace_manager.namespaces():
                    mapped_iri = self.curie_map[prefix]
                    self.bind(prefix, Namespace(mapped_iri))
            else:
                LOG.error("couldn't make URI for %s", curie)
                # get a sense of where the CURIE-ish? thing is comming from
                # magic number here is "steps up the call stack"
                for call in range(3, 0, -1):
                    LOG.warning(
                        '\t%sfrom: %s', '\t' * call, sys._getframe(call).f_code.co_name)
        return node 
開發者ID:monarch-initiative,項目名稱:dipper,代碼行數:42,代碼來源:RDFGraph.py

示例6: bind_all_namespaces

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def bind_all_namespaces(self):
        """
            Results in the RDF @prefix directives for every ingest
            being added to this ingest.
        """
        for prefix in self.curie_map.keys():
            iri = self.curie_map[prefix]
            self.bind(prefix, Namespace(iri))
        return

    # serialize() conflicts between rdflib & Graph.serialize abstractmethod
    # GraphUtils expects the former.  (too bad there is no multiple dispatch) 
開發者ID:monarch-initiative,項目名稱:dipper,代碼行數:14,代碼來源:RDFGraph.py

示例7: define_namespace

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def define_namespace(self):
        """
        Method used to set standard names (dbr stands for dbpediaresource, dbp for dbpediaproperty,
          dbo for dbpediaontology)

        :return:
        """

        if self.chapter != 'en':
            self.dbr = rdflib.Namespace("http://" + self.chapter + ".dbpedia.org/resource/")
        else:
            self.dbr = rdflib.Namespace("http://dbpedia.org/resource/")

        self.dbo = rdflib.Namespace("http://dbpedia.org/ontology/")
        self.dbp = rdflib.Namespace("http://dbpedia.org/property/") 
開發者ID:dbpedia,項目名稱:table-extractor,代碼行數:17,代碼來源:Mapper.py

示例8: namespace

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def namespace(self, prefix):
        """
        Get the namespace for a prefix.
        :param str prefix: Namespace prefix.
        """
        ns = self.get_data(prefix.encode(), b'pfx:ns_')

        return Namespace(ns.decode()) if ns is not None else None 
開發者ID:scossu,項目名稱:lakesuperior,代碼行數:10,代碼來源:lmdb_store.py

示例9: prefix

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def prefix(self, namespace):
        """
        Get the prefix associated with a namespace.

        **Note:** A namespace can be only bound to one prefix in this
        implementation.

        :param rdflib.Namespace namespace: Fully qualified namespace.

        :rtype: str or None
        """
        prefix = self.get_data(str(namespace).encode(), b'ns:pfx_')

        return prefix.decode() if prefix is not None else None 
開發者ID:scossu,項目名稱:lakesuperior,代碼行數:16,代碼來源:lmdb_store.py

示例10: namespaces

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def namespaces(self):
        """Get an iterator of all prefix: namespace bindings.

        :rtype: Iterator(tuple(str, rdflib.Namespace))
        """
        for pfx, ns in self.all_namespaces():
            yield (pfx, Namespace(ns)) 
開發者ID:scossu,項目名稱:lakesuperior,代碼行數:9,代碼來源:lmdb_store.py

示例11: bindings

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def bindings(self):
        return (
            ('ns1', Namespace('http://test.org/ns#')),
            ('ns2', Namespace('http://my_org.net/ns#')),
            ('ns3', Namespace('urn:test:')),
            ('ns4', Namespace('info:myinst/graph#')),
        ) 
開發者ID:scossu,項目名稱:lakesuperior,代碼行數:9,代碼來源:test_1_0_lmdb_store.py

示例12: __init__

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def __init__(self, builder, logger):
        self.logger = logger
        self.doap_namespace = Namespace('http://usefulinc.com/ns/doap#')
        self.spdx_namespace = Namespace("http://spdx.org/rdf/terms#")
        self.builder = builder 
開發者ID:spdx,項目名稱:tools-python,代碼行數:7,代碼來源:rdf.py

示例13: __init__

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def __init__(self, document, out):
        self.document = document
        self.out = out
        self.doap_namespace = Namespace('http://usefulinc.com/ns/doap#')
        self.spdx_namespace = Namespace("http://spdx.org/rdf/terms#")
        self.graph = Graph() 
開發者ID:spdx,項目名稱:tools-python,代碼行數:8,代碼來源:rdf.py

示例14: __init__

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def __init__(self,
                 empty=False,
                 version='1.0.2',
                 brick_file='brick/Brick_1_0_2.ttl',
                 brickframe_file='brick/BrickFrame_1_0_2.ttl',
                 triplestore_type=RDFLIB
                 ):
        self.triplestore_type = triplestore_type
        self._brick_version = version
        if self.triplestore_type == RDFLIB:
            self.base_package = rdflib_wrapper
        elif self.triplestore_type == VIRTUOSO:
            self.base_package = virtuoso_wrapper
        self.g = self.base_package.init_graph(empty, brick_file,
                                              brickframe_file)
        self.BRICK = Namespace('https://brickschema.org/schema/{0}/Brick#'
                               .format(self._brick_version))
        self.BF = Namespace('https://brickschema.org/schema/{0}/BrickFrame#'
                            .format(self._brick_version))
        self.BASE = Namespace('http://example.com#')
        self.sparql_prefix = """
        prefix brick: <{0}>
        prefix rdf: <{1}>
        prefix rdfs: <{2}>
        prefix base: <{3}>
        prefix bf: <{4}>
        prefix owl: <{5}>
        """.format(str(self.BRICK), RDF, RDFS, self.BASE, str(self.BF), OWL) 
開發者ID:plastering,項目名稱:plastering,代碼行數:30,代碼來源:__init__.py

示例15: get_prefixes

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import Namespace [as 別名]
def get_prefixes(version):
    BRICK = Namespace('https://brickschema.org/schema/{0}/Brick#'.format(version))
    BRICKFRAME = Namespace('https://brickschema.org/schema/{0}/BrickFrame#'.format(version))
    BRICKTAG = Namespace('https://brickschema.org/schema/{0}/BrickTag#'.format(version))
    return {
        'brick': BRICK,
        'bf': BRICKFRAME,
        'tag': BRICKTAG,
        'rdfs': rdflib.RDFS,
        'rdf': rdflib.RDF,
        'owl': rdflib.OWL,
    } 
開發者ID:plastering,項目名稱:plastering,代碼行數:14,代碼來源:brick_parser2.py


注:本文中的rdflib.Namespace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。