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


Python Graph.value方法代码示例

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


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

示例1: handle

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
    def handle(self, *args, **options):
        from rdflib.graph import Graph
        from rdflib import RDFS, RDF, OWL
        from rdflib.term import URIRef, BNode, Literal
        import yaml

        OboDefinition = URIRef('http://purl.obolibrary.org/obo/IAO_0000115')
        part_of_some = URIRef('http://purl.obolibrary.org/obo/BFO_0000050_some')
        Synonym = URIRef(u'http://www.geneontology.org/formats/oboInOwl#hasSynonym')

        g = Graph()
        g.parse(args[1], 'xml')

        Model = MuscleOwl if args[0] == 'm' else BehaviorOwl

        # first pass, add the things
        for subject in nonblankthings(g, g.subjects()):
            slabel = g.label(subject)
            m = get_model_instance(Model, unicode(subject))
            m.uri = unicode(subject)
            m.label = unicode(slabel)

            m.rdfs_is_class = (subject, RDF.type, OWL.Class) in g
            m.obo_definition = unicode(g.value(subject, OboDefinition, None))
            m.rdfs_comment = unicode(g.value(subject, RDFS.comment, None))
            synonyms = [unicode(syn) for syn in g.objects(subject, Synonym)]
            if len(synonyms):
                m.synonyms_comma_separated = ", ".join(synonyms)
            else:
                m.synonyms_comma_separated = None

            m.save()

        # second pass, add the relationships
        for subject in nonblankthings(g, g.subjects()):
            slabel = g.label(subject)
            m = Model.objects.get(uri=unicode(subject))

            m.rdfs_subClassOf_ancestors.clear()
            # add all super-classes to m.rdfs_subClassOf_ancestors
            for obj in nonblankthings(g, g.transitive_objects(subject, RDFS.subClassOf)):
                if obj != subject:
                    a = Model.objects.get(uri=unicode(obj))
                    m.rdfs_subClassOf_ancestors.add(a)

            m.bfo_part_of_some.clear()
            # add all things that this thing is part of to m.bfo_part_of_some
            for obj in nonblankthings(g, g.objects(subject, part_of_some)):
                if obj != subject:
                    a = Model.objects.get(uri=unicode(obj))
                    m.bfo_part_of_some.add(a)

            # add only direct super-classes to m.rdfs_subClassOf
            #for obj in nonblankthings(g, g.objects(subject, RDFS.subClassOf)):
            #    if obj != subject:
            #        a = Model.objects.get(uri=unicode(obj))
            #        m.rdfs_subClassOf.add(a)

            m.save()
开发者ID:NESCent,项目名称:feedingdb,代码行数:61,代码来源:loadowl.py

示例2: test_xml_a

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_xml_a():
    """Test reading XML from a unicode object as data"""
    g = Graph()
    g.parse(data=rdfxml, format='xml')
    v = g.value(subject=URIRef("http://www.test.org/#CI"),
                predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v == Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:RDFLib,项目名称:rdflib,代码行数:9,代码来源:test_issue084.py

示例3: test_b

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_b():
    """Test reading N3 from a utf8 encoded string as data"""
    g = Graph()
    g.parse(data=rdf_utf8, format='n3')
    v = g.value(subject=URIRef("http://www.test.org/#CI"),
                predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v == Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:RDFLib,项目名称:rdflib,代码行数:9,代码来源:test_issue084.py

示例4: test_e

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_e():
    """Test reading N3 from a BytesIO over the string object"""
    g = Graph()
    g.parse(source=BytesIO(rdf_utf8), format='n3')
    v = g.value(subject=URIRef("http://www.test.org/#CI"),
                predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v == Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:RDFLib,项目名称:rdflib,代码行数:9,代码来源:test_issue084.py

示例5: test_c

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_c():
    """Test reading N3 from a codecs.StreamReader, outputting unicode"""
    g = Graph()
#    rdf_reader.seek(0)
    g.parse(source=rdf_reader, format='n3')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:drewp,项目名称:rdflib,代码行数:9,代码来源:test_issue084.py

示例6: test_xml_e

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_xml_e():
    """Test reading XML from a BytesIO created from utf8 encoded string"""
    g = Graph()
    g.parse(source=BytesIO(rdfxml_utf8), format='xml')
    v = g.value(subject=URIRef("http://www.test.org/#CI"),
                predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v == Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:RDFLib,项目名称:rdflib,代码行数:9,代码来源:test_issue084.py

示例7: test_xml_b

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_xml_b():
    """Test reading XML from a utf8 encoded string object as data"""
    import platform
    if platform.system() == 'Java':
        from nose import SkipTest
        raise SkipTest('unicode issue for Jython2.5')
    g = Graph()
    g.parse(data=rdfxml_utf8, format='xml')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==Literal(u"C\u00f4te d'Ivoire", lang='fr')
开发者ID:drewp,项目名称:rdflib,代码行数:12,代码来源:test_issue084.py

示例8: test_xml_e

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_xml_e():
    """Test reading XML from a BytesIO created from utf8 encoded string"""
    import platform
    if platform.system() == 'Java':
        from nose import SkipTest
        raise SkipTest('unicode issue for Jython2.5')
    g = Graph()
    g.parse(source=BytesIO(rdfxml_utf8), format='xml')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==u"C\u00f4te d'Ivoire"
开发者ID:SpazioDati,项目名称:rdflib,代码行数:12,代码来源:test_issue084.py

示例9: test_quoting

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
    def test_quoting(self):
        g = Graph()
        NS = Namespace("http://quoting.test/")
        for i, case in enumerate(cases):
            g.add((NS["subj"], NS["case%s" % i], Literal(case)))
        n3txt = g.serialize(format="n3")
        # print n3txt

        g2 = Graph()
        g2.parse(data=n3txt, format="n3")
        for i, case in enumerate(cases):
            l = g2.value(NS["subj"], NS["case%s" % i])
            # print repr(l), repr(case)
            self.assertEqual(l, Literal(case))
开发者ID:suzuken,项目名称:xbrlparser,代码行数:16,代码来源:test_n3.py

示例10: init_model

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def init_model(root_directory, model_file):
    """
    initialize models:
    1. check if core model exists (in CWD), create it if necessary;
    2. check core model version compatibility;
    3. generate node model file based on the content of root_directory.
    """
    if os.path.exists(DEFAULT_CORE_MODEL):
        SEED_LOG.info('load core model')

        core_model = Graph()
        core_model.load(DEFAULT_CORE_MODEL)

        version = core_model.value(URIRef(SEED_BASE), OWL.versionInfo)

        SEED_LOG.info('core model version: [%s]' % version)

        if not version == VERSION:
            SEED_LOG.error(
                'incompatible to program version [%s], need to regenerate.' \
                % VERSION)

            gen_core()

        else:
            SEED_LOG.info('version compatible')

    else:
        SEED_LOG.error('core model does not exist, need to generate.')

        gen_core()

    # generate node model by importing specified root directory

    root_directory = os.path.abspath(root_directory)

    if not os.path.exists(root_directory):
        SEED_LOG.error('directory not exist')
        return

    SEED_LOG.info('reading object list ...')

    object_list = read_tree(root_directory)

    SEED_LOG.info('creating node model ...')

    write_model(object_list, model_file)

    SEED_LOG.info('%d object individuals created in %s.' % \
        (len(object_list), model_file))
开发者ID:ShiZhan,项目名称:seed,代码行数:52,代码来源:model.py

示例11: _load_rules

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
 def _load_rules(self, rules_file_name):
     # Rules are stored in hash map
     rules = {}
     
     # Load the rule base into memory
     logger.debug('Loading {}'.format(rules_file_name))
     g = Graph().parse(rules_file_name, format="turtle")
     
     # Extract the namespaces from the rule base
     r_ns = {}
     for (ns, uri) in g.namespaces():
         r_ns[ns] = uri
     
     # Compose and prepare the SPARQL queries
     for s in g.subjects(RDF.type, INDEXER.Rule):
         # Extract the components of the rule
         r_if = g.value(s, INDEXER['if']).toPython().replace('\t', '')
         r_then = g.value(s, INDEXER['then']).toPython().replace('\t', '')
         rule = 'CONSTRUCT {' + r_then + '} WHERE {' + r_if + '}'
         
         # Pre-load the rule
         rules[s.toPython()] = prepareQuery(rule, initNs=r_ns)
 
     return rules
开发者ID:cgueret,项目名称:Indexer,代码行数:26,代码来源:process.py

示例12: test_xml_b

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_xml_b():
    """Test reading XML from a utf8 encoded string object as data"""
    g = Graph()
    g.parse(data=rdfxml_utf8, format='xml')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==u"C\u00f4te d'Ivoire"
开发者ID:alcides,项目名称:rdflib,代码行数:8,代码来源:test_issue084.py

示例13: test_d

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_d():
    """Test reading N3 from a StringIO over the unicode object"""
    g = Graph()
    g.parse(source=StringIO(rdf), format='n3')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==u"C\u00f4te d'Ivoire"
开发者ID:alcides,项目名称:rdflib,代码行数:8,代码来源:test_issue084.py

示例14: test_a

# 需要导入模块: from rdflib.graph import Graph [as 别名]
# 或者: from rdflib.graph.Graph import value [as 别名]
def test_a():
    """Test reading N3 from a unicode objects as data"""
    g = Graph()
    g.parse(data=rdf, format='n3')
    v = g.value(subject=URIRef("http://www.test.org/#CI"), predicate=URIRef("http://www.w3.org/2004/02/skos/core#prefLabel"))
    assert v==u"C\u00f4te d'Ivoire"
开发者ID:alcides,项目名称:rdflib,代码行数:8,代码来源:test_issue084.py


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