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


Python rdflib.BNode方法代碼示例

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


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

示例1: parse_entity

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def parse_entity(self, term):
        if isinstance(term, rdf.Literal):
            return Entity(id=str(term), cls="_Literal")
        elif isinstance(term, rdf.BNode):
            return None
        entstr = str(term)
        if entstr.startswith(self.entity_prefix):
            inst = entstr[len(self.entity_prefix):]
            if self.d_entity.match(inst):
                cls = 'd'
            elif self.bond_entity.match(inst):
                cls = 'bond'
            else:
                cls = None
            return Entity(id=inst, cls=cls)
        else:
            return None 
開發者ID:dmlc,項目名稱:dgl,代碼行數:19,代碼來源:rdf.py

示例2: stringify_node

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [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

示例3: _node_to_sparql_text

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _node_to_sparql_text(cls, node):
        if isinstance(node, rdflib.Literal):
            if isinstance(node.value, str):
                node_text = "\"{}\"".format(node.value)
            else:
                node_text = str(node.value)
            if node.language:
                node_text = "{}@{}".format(
                    node_text, str(node.language))
            elif node.datatype:
                node_text = "{}^^{}".format(
                    node_text, cls._node_to_sparql_text(node.datatype))
            return node_text
        elif isinstance(node, rdflib.URIRef):
            return "<{}>".format(str(node))
        elif isinstance(node, rdflib.BNode):
            # I think this works to convert a BNode to its internal id.
            return str(node)
        elif isinstance(node, str):
            return node
        raise NotImplementedError("Cannot turn that kind of node into text.") 
開發者ID:RDFLib,項目名稱:pySHACL,代碼行數:23,代碼來源:sparql_query_helper.py

示例4: get_nodes_from_node_expression

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def get_nodes_from_node_expression(self, expr, focus_node, data_graph):
        if expr == SH_this:
            return [focus_node]
        elif isinstance(expr, (rdflib.URIRef, rdflib.Literal)):
            return [expr]
        elif isinstance(expr, rdflib.BNode):
            path_nodes = set(self.shape.sg.objects(expr, SH_path))
            if len(path_nodes) > 0:
                path_results = []
                for p in path_nodes:
                    vals = self.shape.value_nodes_from_path(self.shape.sg, focus_node, p, data_graph)
                    path_results.extend(vals)
                return path_results
            else:
                raise NotImplementedError("Unsupported expression s, p, or o, in SHACL TripleRule")
        else:
            raise NotImplementedError("Unsupported expression s, p, or o, in SHACL TripleRule") 
開發者ID:RDFLib,項目名稱:pySHACL,代碼行數:19,代碼來源:__init__.py

示例5: _evaluate_string_rule

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _evaluate_string_rule(self, r, target_graph, f_v_dict):
        reports = []
        non_conformant = False
        assert isinstance(r, rdflib.Literal)
        min_len = int(r.value)
        if min_len < 0:
            raise ReportableRuntimeError("Minimum length cannot be less than zero!")
        for f, value_nodes in f_v_dict.items():
            for v in value_nodes:
                flag = False
                if min_len == 0:
                    flag = True  # min len zero always passes
                elif isinstance(v, rdflib.BNode):
                    # blank nodes cannot pass minLen validation
                    pass
                else:
                    v_string = self.value_node_to_string(v)
                    flag = len(v_string) >= min_len
                if not flag:
                    non_conformant = True
                    rept = self.make_v_result(target_graph, f, value_node=v)
                    reports.append(rept)
        return non_conformant, reports 
開發者ID:RDFLib,項目名稱:pySHACL,代碼行數:25,代碼來源:string_based_constraints.py

示例6: evaluate

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [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

示例7: _ExpandObservationDimensionValue

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _ExpandObservationDimensionValue(self, dim, data, row_id, row):
    node_id = rdflib.BNode()
    self.graph.add((row_id, SCHEMA.dimensionValue, node_id))
    self.graph.add((node_id, rdflib.RDF.type, SCHEMA.DimensionValue))
    self.graph.add((node_id, SCHEMA.dimension, data['id']))
    for dim_type in data['type']:
      if dim_type.endswith('CategoricalDimension'):
        for type_id in data['types']:
          self.graph.add((node_id, rdflib.RDF.type, type_id))
        self.graph.add((node_id, SCHEMA.codeValue, rdflib.Literal(row[dim])))
      else:
        if data['types']:
          self.graph.add(
              (node_id, SCHEMA.value,
               rdflib.Literal(row[dim],
                              datatype=rdflib.URIRef(data['types'][0]))))
        else:
          self.graph.add((node_id, SCHEMA.value, rdflib.Literal(row[dim]))) 
開發者ID:google,項目名稱:dspl,代碼行數:20,代碼來源:expander.py

示例8: _object_value_int

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _object_value_int(self, subject, predicate):
        '''
        Given a subject and a predicate, returns the value of the object as an
        integer

        Both subject and predicate must be rdflib URIRef or BNode objects

        If the value can not be parsed as intger, returns None
        '''
        object_value = self._object_value(subject, predicate)
        if object_value:
            try:
                return int(object_value)
            except ValueError:
                pass
        return None 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:18,代碼來源:profiles.py

示例9: _contact_details

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _contact_details(self, subject, predicate):
        '''
        Returns a dict with details about a vcard expression

        Both subject and predicate must be rdflib URIRef or BNode objects

        Returns keys for uri, name and email with the values set to
        None if they could not be found
        '''

        contact = {}

        for agent in self.g.objects(subject, predicate):

            contact['uri'] = (unicode(agent) if isinstance(agent,
                              rdflib.term.URIRef) else None)

            contact['name'] = self._object_value(agent, VCARD.fn)

            contact['email'] = self._object_value(agent, VCARD.hasEmail)

        return contact 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:24,代碼來源:profiles.py

示例10: test_dataset_license_from_distribution_by_title

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def test_dataset_license_from_distribution_by_title(self):
        # license_id retrieved from dct:title of dcat:license object
        g = Graph()

        dataset = URIRef("http://example.org/datasets/1")
        g.add((dataset, RDF.type, DCAT.Dataset))

        distribution = URIRef("http://example.org/datasets/1/ds/1")
        g.add((distribution, RDF.type, DCAT.Distribution))
        g.add((dataset, DCAT.distribution, distribution))
        license = BNode()
        g.add((distribution, DCT.license, license))
        g.add((license, DCT.title, Literal("Creative Commons Attribution")))

        p = RDFParser(profiles=['euro_dcat_ap'])

        p.g = g

        dataset = [d for d in p.datasets()][0]
        eq_(dataset['license_id'], 'cc-by') 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:22,代碼來源:test_euro_dcatap_profile_parse.py

示例11: test_contact_details_maintainer

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def test_contact_details_maintainer(self):
        dataset = {
            'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
            'name': 'test-dataset',
            'maintainer': 'Example Maintainer',
            'maintainer_email': 'dep@example.com',
            'author': 'Example Author',
            'author_email': 'ped@example.com',
        }

        s = RDFSerializer()
        g = s.g

        dataset_ref = s.graph_from_dataset(dataset)

        contact_details = self._triple(g, dataset_ref, DCAT.contactPoint, None)[2]
        assert contact_details
        assert_true(isinstance(contact_details, BNode))
        assert self._triple(g, contact_details, VCARD.fn, dataset['maintainer'])
        assert self._triple(g, contact_details, VCARD.hasEmail, dataset['maintainer_email']) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:22,代碼來源:test_euro_dcatap_profile_serialize.py

示例12: test_contact_details_author

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def test_contact_details_author(self):
        dataset = {
            'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
            'name': 'test-dataset',
            'author': 'Example Author',
            'author_email': 'ped@example.com',
        }

        s = RDFSerializer()
        g = s.g

        dataset_ref = s.graph_from_dataset(dataset)

        contact_details = self._triple(g, dataset_ref, DCAT.contactPoint, None)[2]
        assert contact_details
        assert_true(isinstance(contact_details, BNode))
        assert self._triple(g, contact_details, VCARD.fn, dataset['author'])
        assert self._triple(g, contact_details, VCARD.hasEmail, dataset['author_email']) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:20,代碼來源:test_euro_dcatap_profile_serialize.py

示例13: test_publisher_no_uri

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def test_publisher_no_uri(self):
        dataset = {
            'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
            'name': 'test-dataset',
            'extras': [
                {'key': 'publisher_name', 'value': 'Example Publisher'},
            ]
        }
        extras = self._extras(dataset)

        s = RDFSerializer()
        g = s.g

        dataset_ref = s.graph_from_dataset(dataset)

        publisher = self._triple(g, dataset_ref, DCT.publisher, None)[2]
        assert publisher
        assert_true(isinstance(publisher, BNode))

        assert self._triple(g, publisher, RDF.type, FOAF.Organization)
        assert self._triple(g, publisher, FOAF.name, extras['publisher_name']) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:23,代碼來源:test_euro_dcatap_profile_serialize.py

示例14: test_spatial_bad_json_no_wkt

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def test_spatial_bad_json_no_wkt(self):
        dataset = {
            'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
            'name': 'test-dataset',
            'extras': [
                {'key': 'spatial', 'value': 'NotJSON'},

            ]
        }
        extras = self._extras(dataset)

        s = RDFSerializer()
        g = s.g

        dataset_ref = s.graph_from_dataset(dataset)

        spatial = self._triple(g, dataset_ref, DCT.spatial, None)[2]
        assert spatial
        assert_true(isinstance(spatial, BNode))
        # Geometry in GeoJSON
        assert self._triple(g, spatial, LOCN.geometry, extras['spatial'], GEOJSON_IMT)

        # Geometry in WKT
        eq_(len([t for t in g.triples((spatial, LOCN.geometry, None))]), 1) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:26,代碼來源:test_euro_dcatap_profile_serialize.py

示例15: _add_agent

# 需要導入模塊: import rdflib [as 別名]
# 或者: from rdflib import BNode [as 別名]
def _add_agent(self, _dict, ref, basekey, _type):
        ''' Stores the Agent in this format:
                <dct:publisher rdf:resource="http://dati.gov.it/resource/Amministrazione/r_liguri"/>
                    <dcatapit:Agent rdf:about="http://dati.gov.it/resource/Amministrazione/r_liguri">
                        <rdf:type rdf:resource="&foaf;Agent"/>
                        <dct:identifier>r_liguri</dct:identifier>
                        <foaf:name>Regione Liguria</foaf:name>
                    </dcatapit:Agent>

            Returns the ref to the agent node
        '''

        agent_name = self._get_dict_value(_dict, basekey + '_name', 'N/A')
        agent_id = self._get_dict_value(_dict, basekey + '_identifier','N/A')

        agent = BNode()

        self.g.add((agent, RDF['type'], DCATAPIT.Agent))
        self.g.add((agent, RDF['type'], FOAF.Agent))
        self.g.add((ref, _type, agent))

        self.g.add((agent, FOAF.name, Literal(agent_name)))
        self.g.add((agent, DCT.identifier, Literal(agent_id)))

        return agent 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:27,代碼來源:profiles.py


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