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


Python Graph.subject_objects方法代码示例

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


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

示例1: _license_desc

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
    def _license_desc( self, url):
        permits_uri = URIRef("http://creativecommons.org/ns#permits")
        requires_uri = URIRef("http://creativecommons.org/ns#requires")
        prohibits_uri = URIRef("http://creativecommons.org/ns#prohibits")
        comment_uri = URIRef(u'http://www.w3.org/2000/01/rdf-schema#comment')
        ns_url = 'http://creativecommons.org/ns'


        license_graph = Graph()
        license_graph.parse(url)

        ns_graph = Graph()
        ns_graph.parse(ns_url)

        lines = []

        title = License.objects.get(url=url).title

        desc = 'This is an Open Access article distributed under the terms of the Creative Commons %s License \
        ( %s),' % (title, url)

        # get permits terms
        for t in license_graph.subject_objects(permits_uri):
            lines.append(ns_graph.value(subject=URIRef(t[1].replace('http:', 'https:')), predicate=comment_uri, object=None))

        if lines:
            lines = filter(None, lines)
            desc += ' which permits %s, provided the original work is properly cited.' % (', '.join(lines))

        # get requires terms
        lines = []
        for t in license_graph.subject_objects(requires_uri):
            lines.append(ns_graph.value(subject=URIRef(t[1].replace('http:', 'https:')), predicate=comment_uri, object=None))
        if lines:
            lines = filter(None, lines)
            desc += ' This license requires %s.' % (', '.join(lines))

        # get prohibits terms
        lines = []
        for t in license_graph.subject_objects(prohibits_uri):
            lines.append(ns_graph.value(subject=URIRef(t[1].replace('http:', 'https:')), predicate=comment_uri, object=None))
        if lines:
            lines = filter(None, lines)
            desc += ' This license prohibits %s.' % (', '.join(lines))

        #remove tabs, newlines and extra spaces
        desc = re.sub('\t+|\n+', ' ', desc)
        desc = re.sub(' +', ' ', desc)

        logger.debug('LICENSE DESC: %s' % desc)
        return desc
开发者ID:alexBLR,项目名称:OpenEmory,代码行数:53,代码来源:forms.py

示例2: register

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def register():
    """
    Entry point del agente que recibe los mensajes de registro

    :return:
    """
    global dsgraph
    global mss_cnt
    #cola1.put('zzz')
    message= request.args['content']
    gm = Graph()
    gr = Graph()
    gr.bind('acl',ACL)
    gm.parse(data=message)
    print gm.serialize(format='turtle')
    perf = gm.triples( (None,  RDF.type, sa)) # Obtenemos la performativa
    if perf is None:
        gr.add((ACL['not-understood'], RDF.type, sa))
    else:
        aresp= gm.subject_objects(FOAF.name)
        a,n = aresp.next()
        print a, n
        ms = ACL['message{:{fill}4d}'.format(mss_cnt, fill='0')]
        mss_cnt += 1
        gr.add((ms, RDF.type, sa))
        gr.add((ms, ACL.performative, ACL.confirm))
        gm.add((agn.juan, FOAF.name, Literal('RegisterAgent')))
        gm.add((ms, ACL.sender, agn.RegisterAgent))
        #dsgraph.open('./myRDFLibStore')
        dsgraph += gm
    return gr.serialize(format='xml')
开发者ID:wailingtam,项目名称:trip-planner,代码行数:33,代码来源:RegisterAgent.py

示例3: get_skill_dict

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def get_skill_dict(skilldataset):
    skd = Graph()
    skd.load(skilldataset,format="turtle")
    skilldict = {}
    for skillIRI, skillName in skd.subject_objects(ns.edsa.lexicalValue):
        skilldict[str(skillName.replace('-',' '))] = skillIRI
    return skilldict
开发者ID:edsa-project,项目名称:dashboard,代码行数:9,代码来源:post-process.py

示例4: thumbnail

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def thumbnail(term):
	th = []
	g = Graph()
	g.parse("http://dbpedia.org/resource/" + term)
	for thumb in g.subject_objects(URIRef("http://dbpedia.org/ontology/thumbnail")):
		th = thumb[1]
	return th
开发者ID:muratarslan,项目名称:searchengine,代码行数:9,代码来源:src.py

示例5: _load_resources

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
 def _load_resources(self, resource_path):
     # returns a mapping [resource label] => [resource uri]
     # resource_path is given relative to cwd
     graph = Graph()
     graph.load(resource_path, format='n3')
     d = {}
     for uri, label in graph.subject_objects(RDFS.label):
         d[str(label)] = str(uri)
     return d
开发者ID:h4ck3rm1k3,项目名称:ferenda,代码行数:11,代码来源:swedishlegalsource.py

示例6: get_genre_instruments

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def get_genre_instruments(genre):
    g = Graph()
    g.parse(_get_genre_url(genre))
    instruments = set()
    for prop in ("dbpedia-owl", "dbprop"):
        for stmt in g.subject_objects(dbpedia_ontology[prop]):
            instrument = _get_instrument_name_from_url(stmt[1])
            instruments.add(instrument)
    return instruments
开发者ID:neomoha,项目名称:autovj,代码行数:11,代码来源:get_genre_instruments.py

示例7: process_dbpedia

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def process_dbpedia(dbpedia, orgref_ids):
    with open(dbpedia) as infile:
        print>>sys.stderr, "DBP graph read."
        #skip first line
        infile.next()
        for count, row in enumerate(infile):
            if (count > 0) and (count % 1000000 == 0):
                print>>sys.stderr, count, "read."
            g = Graph().parse(data=row, format='nt')
            for sub, obj in g.subject_objects(predicate=DBP.wikiPageID):
                wikid = unicode(obj.toPython())
                if wikid in orgref_ids:
                    yield (wikid, sub.toPython())
开发者ID:akhanna-mdsol,项目名称:vivo-sample-data,代码行数:15,代码来源:orgref_to_dbpedia.py

示例8: update_graph_with_proxy_field

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
    def update_graph_with_proxy_field(self, graph: Graph, proxy_field_uri: str):
        """# return graph, tuple_list with coined_uris, label, lang."""
        property_uri = URIRef(proxy_field_uri)
        fields = graph.subject_objects(predicate=property_uri)
        converted_literals = []
        for subject, obj in fields:
            if isinstance(obj, Literal):
                graph.remove((subject, property_uri, obj))
                new_uri = self.generate_proxyfield_uri(obj.value, obj.language)
                graph.add((subject, property_uri, URIRef(new_uri)))
                converted_literals.append((new_uri, obj))

        return graph, converted_literals
开发者ID:delving,项目名称:nave,代码行数:15,代码来源:models.py

示例9: load_sources

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
 def load_sources(self):
   self.logger.debug("parsing dataset file %s", self.datasetfile)
   sources = {}
   vocgraph = Graph()
   try:
     vocgraph.parse(self.datasetfile, format='turtle')
   except Exception as e:
     self.logger.critical("parsing dataset file %s failed: %s", self.datasetfile, e)
     return sources
   for ds,srcurl in vocgraph.subject_objects(VOID.dataDump):
     graphuri = vocgraph.value(ds, SKOSMOS.sparqlGraph, None)
     if srcurl.endswith('.ttl'): # quick fix for problems with multiple dumps
       sources[srcurl] = graphuri
   self.logger.debug("found %d sources", len(sources))
   return sources
开发者ID:NatLibFi,项目名称:Finto-data,代码行数:17,代码来源:graphsync.py

示例10: stats

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
 def stats(self):
     """Stats of amount of triples and things (RDF classes) within each parsed document."""
     stuff = []
     for basefile in self.store.list_basefiles_for("generate"):
         g = Graph()
         g = g.parse(self.store.distilled_path(basefile))
         uri = self.canonical_uri(basefile)
         stuff.append((basefile,
                       g.value(URIRef(uri), self.ns['dcterms'].issued),
                       len(g),
                       len(list(g.subject_objects(RDF.type)))
                       ))
     print("\t".join(("identifier", "issued", "triples", "things")))
     for docstat in sorted(stuff, key=itemgetter(3)):
         print("\t".join([str(x) for x in docstat]))
开发者ID:staffanm,项目名称:ferenda,代码行数:17,代码来源:w3c.py

示例11: canonical_uri

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
    def canonical_uri(self, basefile):
        # The canonical URI for these documents cannot always be
        # computed from the basefile. Find the primary subject of the
        # distilled RDF graph instead.
        if not os.path.exists(self.store.distilled_path(basefile)):
            return None

        g = Graph()
        g.parse(self.store.distilled_path(basefile))
        subjects = list(g.subject_objects(self.ns["rdf"]["type"]))

        if subjects:
            return str(subjects[0][0])
        else:
            self.log.warning("No canonical uri in %s" % (self.distilled_path(basefile)))
            # fall back
            return super(MyndFskr, self).canonical_uri(basefile)
开发者ID:h4ck3rm1k3,项目名称:ferenda,代码行数:19,代码来源:myndfskr.py

示例12: agent1

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def agent1():
    message = request.args["content"]
    gm = Graph()
    gr = Graph()
    gr.bind("acl", ACL)
    gm.parse(data=message)
    print gm.serialize(format="turtle")
    perf = gm.triples((None, RDF.type, sa))  # Obtenemos la performativa
    if perf == None:
        gr.add((ACL["not-understood"], RDF.type, sa))
    else:
        aresp = gm.subject_objects(FOAF.name)
        a, n = aresp.next()
        print a, n
        ms = ACL["message0001"]
        gr.add((ms, RDF.type, sa))
        gr.add((ms, ACL.performative, ACL.confirm))
        gm.add((agn.juan, FOAF.name, Literal("Juan")))
        gm.add((ms, ACL.sender, agn.juan))

    return gr.serialize(format="xml")
开发者ID:wailingtam,项目名称:trip-planner,代码行数:23,代码来源:AgentRespond.py

示例13: test_create_and_read_rdf

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
    def test_create_and_read_rdf(self):
        '''
        Create and read a dataset through API and check that RDF generation doesn't break.
        '''
        data = copy.deepcopy(self.public_dataset)
        data = self.get_unique_pids(data)
        output = self.api_user_sysadmin.action.package_create(**data)

        offset = url_for("/dataset/{0}.rdf".format(output['id']))
        res = self.app.get(offset)
        assert res.status == 200, 'Wrong HTTP status code: {0}'.format(res.status)

        g = Graph()
        g.parse(data=res.body)

        assert len(list(g.subjects(RDF.type, URIRef("http://www.w3.org/ns/dcat#Dataset")))) == 1
        assert len(list(g.subject_objects(URIRef("http://purl.org/dc/terms/contributor")))) == 2

        # Test also turtle format
        offset = url_for("/dataset/{0}.ttl".format(output['id']))
        res = self.app.get(offset)
        assert res.status == 200, 'Wrong HTTP status code: {0}'.format(res.status)
开发者ID:,项目名称:,代码行数:24,代码来源:

示例14: main

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
def main(args):
    """ Rewrite an OWL file adding a prefixes to the SNOMED and ICD Labels
    """

    optparser = argparse.ArgumentParser(description="Add a tag prefix to the labels in the supplied owl file")
    optparser.add_argument('owlfile', help="Input OWL file")
    optparser.add_argument('-f', '--format', help="File format", default="n3")

    opts = optparser.parse_args(args)

    g = Graph()
    g.parse(opts.owlfile, format=opts.format)

    # Iterate over the labels
    for subj, desc in list(g.subject_objects(RDFS.label)):
        for p, t in labelmaps:
            if str(subj).startswith(p):
                g.remove([subj, RDFS.label, desc])
                g.add([subj, RDFS.label, Literal(t + '  ' + str(desc))])
                break
    output = g.serialize(format=opts.format).decode('utf-8')
    sys.stdout.write(output)
开发者ID:hsolbrig,项目名称:ICD11OWLConverter,代码行数:24,代码来源:tagadder.py

示例15: handle

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import subject_objects [as 别名]
    def handle(self, *args, **options):
    
        # Holder for our data
        g = Graph()
        
        # Find the DBpedia resource equivalent to a wikipedia page
        # http://fr.wikipedia.org/wiki/Elvis_Presley
        urls = [
            "http://dbpedia.org/resource/Elvis_Presley",
            "http://dbpedia.org/resource/Tim_Berners-Lee",
            "http://dbpedia.org/resource/Albert_Einstein",
            "http://dbpedia.org/resource/Margaret_Thatcher"
        ];
        for url in urls:
            print url
            g.parse(data=curlRDF(url), format="application/rdf+xml")

        # Display the number of vertices that were added to the Graph
        print len(g)
        # You can see a list of this data typing directly in your browser
        # http://dbpedia.org/page/Elvis_Presley
        
        for stmt in g.subject_objects(URIRef("http://dbpedia.org/ontology/birthDate")):
            print "the person represented by", str(stmt[0]), "was born on", str(stmt[1])
开发者ID:adlenafane,项目名称:Datackaton,代码行数:26,代码来源:RdflibCommand.py


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