当前位置: 首页>>代码示例>>Python>>正文


Python rdflib.Graph方法代码示例

本文整理汇总了Python中rdflib.Graph方法的典型用法代码示例。如果您正苦于以下问题:Python rdflib.Graph方法的具体用法?Python rdflib.Graph怎么用?Python rdflib.Graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib的用法示例。


在下文中一共展示了rdflib.Graph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [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: setUp

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def setUp(self):
        self.graph = Graph()

        self.curie_map = curie_map.get()
        self.ctd = CTD('rdf_graph', True)
        self.ctd.g = self.ctd.graph
        row1 = [
            '06-Paris-LA-66 protocol', 'C046983', 'foo',
            'Precursor Cell Lymphoblastic Leukemia-Lymphoma', 'MESH:D054198',
            'therapeutic', 'bar', 'baz', 'foo', '4519131']
        row2 = [
            '10,10-bis(4-pyridinylmethyl)-9(10H)-anthracenone', 'C112297',
            'foo', 'Hyperkinesis', 'MESH:D006948', 'marker/mechanism',
            'bar', 'baz', 'foo', '19098162']

        self.ctd._process_interactions(row1)
        self.ctd._process_interactions(row2) 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:19,代码来源:test_interactions.py

示例3: testDecrypt

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def testDecrypt(self):

        g = rdflib.Graph()
        g.parse(data=keybagturtle, format="turtle")
        kb = keybag.PasswordWrappedKeyBag.load(g)

        key = "password"
        kek = digest.pbkdf2_hmac("sha256", key, kb.salt, kb.iterations, kb.keySizeBytes);
        vek = aes_unwrap_key(kek, kb.wrappedKey)

        key1 = vek[0:16]
        key2 = vek[16:]
        tweak = codecs.decode('00', 'hex')

        cipher = python_AES.new((key1, key2), python_AES.MODE_XTS)
        text = cipher.decrypt(target_ciphertext, tweak)

        self.assertEqual(src[0:len(src)], text[0:len(src)]) 
开发者ID:aff4,项目名称:pyaff4,代码行数:20,代码来源:test_crypto.py

示例4: stringify_node

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def stringify_node(graph, node, ns_manager=None, recursion=0):
    if ns_manager is None:
        ns_manager = graph.namespace_manager
    if isinstance(ns_manager, rdflib.Graph):
        #json-ld loader can set namespace_manager to the conjunctive graph itself.
        ns_manager = ns_manager.namespace_manager
    ns_manager.bind("sh", SH, override=False, replace=False)
    if isinstance(node, rdflib.Literal):
        return stringify_literal(graph, node, ns_manager=ns_manager)
    if isinstance(node, rdflib.BNode):
        if isinstance(graph, (rdflib.ConjunctiveGraph, rdflib.Dataset)):
            graph = find_node_named_graph(graph, node)
        return stringify_blank_node(graph, node, ns_manager=ns_manager,
                                    recursion=recursion+1)
    if isinstance(node, rdflib.URIRef):
        return node.n3(namespace_manager=ns_manager)
    else:
        node_string = str(node)
    return node_string 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:21,代码来源:stringify.py

示例5: clone_dataset

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def clone_dataset(source_ds, target_ds=None):
    if target_ds and not isinstance(target_ds, (rdflib.Dataset, rdflib.ConjunctiveGraph)):
        raise RuntimeError("when cloning a dataset, the target_ds must be a conjunctiveGraph or rdflib Dataset.")
    default_union = source_ds.default_union
    if target_ds is None:
        target_ds = rdflib.Dataset(default_union=default_union)
    named_graphs = [
        rdflib.Graph(source_ds.store, i, namespace_manager=source_ds.namespace_manager)
        if not isinstance(i, rdflib.Graph) else i for i in source_ds.store.contexts(None)
    ]
    cloned_graphs = [
        clone_graph(ng, rdflib.Graph(target_ds.store, ng.identifier, namespace_manager=target_ds.namespace_manager))
        for ng in named_graphs
    ]
    default_context_id = target_ds.default_context.identifier
    for g in cloned_graphs:
        if g.identifier == default_context_id:
            target_ds.store.remove_graph(target_ds.default_context)
            target_ds.default_context = g
        target_ds.add_graph(g)
    return target_ds 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:23,代码来源:clone.py

示例6: clone_graph

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def clone_graph(source_graph, target_graph=None, identifier=None):
    """
    Make a clone of the source_graph by directly copying triples from source_graph to target_graph
    :param source_graph:
    :type source_graph: rdflib.Graph
    :param target_graph:
    :type target_graph: rdflib.Graph|None
    :param identifier:
    :type identifier: str | None
    :return: The cloned graph
    :rtype: rdflib.Graph
    """
    if isinstance(source_graph, (rdflib.Dataset, rdflib.ConjunctiveGraph)):
        return clone_dataset(source_graph, target_ds=target_graph)
    if target_graph is None:
        g = rdflib.Graph(identifier=identifier)
        for p, n in source_graph.namespace_manager.namespaces():
            g.namespace_manager.bind(p, n, override=True, replace=True)
    else:
        g = target_graph
        for p, n in source_graph.namespace_manager.namespaces():
            g.namespace_manager.bind(p, n, override=False, replace=False)
    for t in iter(source_graph):
        g.add(t)
    return g 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:27,代码来源:clone.py

示例7: mix_datasets

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def mix_datasets(base_ds, extra_ds, target_ds=None):
    default_union = base_ds.default_union
    base_named_graphs = base_ds.contexts()
    if target_ds is None:
        target_ds = rdflib.Dataset(default_union=default_union)
    if isinstance(extra_ds, (rdflib.Dataset, rdflib.ConjunctiveGraph)):
        mixin_graphs = list(extra_ds.contexts())
    else:
        mixin_graphs = [extra_ds]
    mixed_graphs = []
    for mg in mixin_graphs:
        mod_named_graphs = [mix_graphs(g, mg, target_graph=rdflib.Graph(store=target_ds.store, identifier=g.identifier)) for g in base_named_graphs]
        mixed_graphs.extend(mod_named_graphs)
    default_context_id = target_ds.default_context.identifier
    for m in mixed_graphs:
        if m.identifier == default_context_id:
            target_ds.store.remove_graph(target_ds.default_context)
            target_ds.default_context = m
        target_ds.add_graph(m)
    return target_ds 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:22,代码来源:clone.py

示例8: meta_validate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def meta_validate(shacl_graph, inference='rdfs', **kwargs):
    shacl_shacl_graph = meta_validate.shacl_shacl_graph
    if shacl_shacl_graph is None:
        from os import path
        import pickle
        import sys
        if getattr( sys, 'frozen', False ) :
                # runs in a pyinstaller bundle
                here_dir = sys._MEIPASS
                pickle_file = path.join(here_dir, "shacl-shacl.pickle")
        else :
                here_dir = path.dirname(__file__)
                pickle_file = path.join(here_dir, "shacl-shacl.pickle")
        with open(pickle_file, 'rb') as shacl_pickle:
            u = pickle.Unpickler(shacl_pickle, fix_imports=False)
            shacl_shacl_store = u.load()
        shacl_shacl_graph = rdflib.Graph(store=shacl_shacl_store, identifier="http://www.w3.org/ns/shacl-shacl")
        meta_validate.shacl_shacl_graph = shacl_shacl_graph
    shacl_graph = load_from_source(shacl_graph, rdf_format=kwargs.pop('shacl_graph_format', None),
                                   multigraph=True)
    _ = kwargs.pop('meta_shacl', None)
    return validate(shacl_graph, shacl_graph=shacl_shacl_graph, inference=inference, **kwargs) 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:24,代码来源:validate.py

示例9: __init__

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def __init__(self, graph, logger=None):
        """
        ShapesGraph
        :param graph:
        :type graph: rdflib.Graph
        :param logger:
        :type logger: logging.Logger|None
        """
        assert isinstance(graph, (rdflib.Dataset, rdflib.ConjunctiveGraph, rdflib.Graph))
        self.graph = graph
        if isinstance(self.graph, rdflib.Dataset):
            self.graph.default_union = True
        if logger is None:
            logger = logging.getLogger(__name__)
        self.logger = logger
        self._node_shape_cache = {}
        self._shapes = None
        self._custom_constraints = None
        self._add_system_triples() 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:21,代码来源:shapes_graph.py

示例10: evaluate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
        """

        :type focus_value_nodes: dict
        :type target_graph: rdflib.Graph
        """
        reports = []
        non_conformant = False

        for query_helper in self.sparql_constraints:
            if query_helper.deactivated:
                continue
            _nc, _r = self._evaluate_sparql_constraint(
                query_helper, target_graph, focus_value_nodes)
            non_conformant = non_conformant or _nc
            reports.extend(_r)
        return (not non_conformant), reports 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:19,代码来源:sparql_based_constraints.py

示例11: evaluate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
        """

        :type focus_value_nodes: dict
        :type target_graph: rdflib.Graph
        """
        min_count = int(self.min_count.value)
        if min_count == 0:
            # MinCount of zero always passes
            return True, []
        reports = []
        non_conformant = False

        for f, value_nodes in focus_value_nodes.items():
            flag = len(value_nodes) >= min_count
            if not flag:
                non_conformant = True
                rept = self.make_v_result(target_graph, f)
                reports.append(rept)
        return (not non_conformant), reports 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:22,代码来源:cardinality_constraints.py

示例12: evaluate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
        """

        :type focus_value_nodes: dict
        :type target_graph: rdflib.Graph
        """
        reports = []
        non_conformant = False

        for r in self.string_rules:
            _nc, _r = self._evaluate_string_rule(r, target_graph, focus_value_nodes)
            non_conformant = non_conformant or _nc
            reports.extend(_r)
            if not self.allow_multi_rules:
                break
        return (not non_conformant), reports 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:18,代码来源:string_based_constraints.py

示例13: evaluate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
        """

        :type focus_value_nodes: dict
        :type target_graph: rdflib.Graph
        """
        reports = []
        non_conformant = False

        for lt in iter(self.property_compare_set):
            if isinstance(lt, rdflib.Literal) or\
               isinstance(lt, rdflib.BNode):
                raise ReportableRuntimeError(
                    "Value of sh:lessThan MUST be a URI Identifier.")
            _nc, _r = self._evaluate_less_than(lt, target_graph, focus_value_nodes)
            non_conformant = non_conformant or _nc
            reports.extend(_r)
        return (not non_conformant), reports 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:20,代码来源:property_pair_constraints.py

示例14: evaluate

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
        """

        :type focus_value_nodes: dict
        :type target_graph: rdflib.Graph
        """
        reports = []
        non_conformant = False
        in_vals = self.in_vals
        for f, value_nodes in focus_value_nodes.items():
            for v in value_nodes:
                if v not in in_vals:
                    non_conformant = True
                    rept = self.make_v_result(target_graph, f, value_node=v)
                    reports.append(rept)
        return (not non_conformant), reports 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:18,代码来源:other_constraints.py

示例15: __init__

# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Graph [as 别名]
def __init__(self, node, sht_graph, result_node, data_graph, shapes_graph, label=None, status=None):
        """

        :param sht_graph:
        :type sht_graph: rdflib.Graph
        :param data_graph:
        :type data_graph: rdflib.Graph
        :param shapes_graph:
        :type shapes_graph: rdflib.Graph
        :param label:
        """
        self.node = node
        self.sht_graph = sht_graph
        self.sht_result = result_node
        self.data_graph = data_graph
        self.shapes_graph = shapes_graph
        self.label = label
        self.status = status 
开发者ID:RDFLib,项目名称:pySHACL,代码行数:20,代码来源:helpers.py


注:本文中的rdflib.Graph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。