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


Python Graph.load方法代码示例

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


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

示例1: get_skill_dict

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

示例2: rdf_accession_search

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def rdf_accession_search(ref_prot_acc, sub_str):
    """
    Parses rdf url and returns a list of ENA accessions

    rdf_url: The url to a Uniprot's reference proteome rdf url
    sub_str: A sub string to look for in the rdf file
    """

    accessions = []
    rdf_graph = Graph()
    rdf_url = PROTEOME_URL % ref_prot_acc

    response = requests.get(rdf_url).status_code

    if response == httplib.OK:

        rdf_graph.load(rdf_url)

        for s, p, o in rdf_graph:
            if string.find(o, sub_str) != -1:
                accessions.append(os.path.split(o)[1])
    else:
        # return http status code
        # return response.status_code
        pass

    return accessions
开发者ID:Rfam,项目名称:rfam-production,代码行数:29,代码来源:genome_fetch.py

示例3: main

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def main():
    "Detect all orphan files and entries"
    g = Graph()
    for manifest in [MANIFEST_PATH, MANIFEST_SYNTAX_PATH,
                     MANIFEST_TURTLE_LDPATCH_PATH,]:
        g.load(manifest, format="turtle")
        LOG.debug("loaded %s", manifest)
    for manifest in [MANIFEST_TURTLE_PATH,]:
        if exists(manifest):
            g.load(manifest, format="turtle")
            LOG.debug("loaded %s", manifest)

    # looking for entries that are not part of an mf:entry list
    for subj, _, _ in g.triples((None, MF.action, None)):
        if not list(g.triples((None, RDF.first, subj))):
            print subj

    # looking for files that are not referenced
    FILTER = regex(r'.*\.(ttl|nt|ldpatch)$')
    for foldername in (TESTSUITE_PATH, TURTLE_PATH):
        for filename in listdir(foldername):
            if not FILTER.match(filename):
                continue
            if filename.startswith("manifest"):
                continue
            iri = p2i(join(foldername, filename))
            if not list(g.triples((None, None, iri))):
                print iri

    # checking that all entries have the correct name
    for subj, _, obj in g.triples((None, MF.name, None)):
        if subj.rsplit("#",1)[1] != unicode(obj):
            print "WRONG NAME for ", subj
开发者ID:pchampin,项目名称:ld-patch-testsuite,代码行数:35,代码来源:check.py

示例4: add_vocabulary

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def add_vocabulary(owl):
    """

    :param owl:
    :return:
    """
    vid, uri, owl_g, imports = __load_owl(owl)

    if vid in sch.contexts():
        raise DuplicateVocabulary('Vocabulary already contained')

    sch.add_context(vid, owl_g)
    vids = [vid]

    # TODO: Import referenced ontologies
    for im_uri in imports:
        print im_uri
        im_g = Graph()
        try:
            im_g.load(im_uri, format='turtle')
        except BadSyntax:
            try:
                im_g.load(im_uri)
            except BadSyntax:
                print 'bad syntax in {}'.format(im_uri)

        try:
            child_vids = add_vocabulary(im_g.serialize(format='turtle'))
            vids.extend(child_vids)
        except DuplicateVocabulary, e:
            print 'already added'
        except VocabularyNotFound, e:
            print 'uri not found for {}'.format(im_uri)
开发者ID:SmartDeveloperHub,项目名称:agora-fountain,代码行数:35,代码来源:onto.py

示例5: parse

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def parse(foaf_url):
    global gexf_graph
    global parsedFOAFS
    global queuedFOAFS

    g = Graph()

    try:
        g.load(foaf_url)
    except Exception:
        print "Can't fetch " + foaf_url
        return

    SIOC = Namespace("http://rdfs.org/sioc/ns#")

    acctID = URIRef(g.value(URIRef(foaf_url), FOAF.maker) + "#acct")
    root_accountName = str(g.value(acctID, FOAF.accountName))
    root_webfinger = root_accountName + "@" + urlparse(foaf_url).hostname

    subscriptions = prepareQuery(
        """SELECT ?accountName ?accountProfilePage
           WHERE {
              ?person sioc:follows ?b .
              ?b foaf:accountName ?accountName .
              ?b foaf:accountProfilePage ?accountProfilePage .
           }""",
        initNs = { "foaf": FOAF, "sioc": SIOC })

    subscribers = prepareQuery(
        """SELECT ?accountName ?accountProfilePage
           WHERE {
              ?b sioc:follows ?person .
              ?b foaf:accountName ?accountName .
              ?b foaf:accountProfilePage ?accountProfilePage .
           }""",
        initNs = { "foaf": FOAF, "sioc": SIOC })

    gexf_graph.addNode(root_webfinger, root_webfinger)

    for subscription in g.query(subscriptions, initBindings={'person': acctID}):
        accountProfilePage = str(subscription.accountProfilePage) + "/foaf"
        accountName = str(subscription.accountName)
        if (blacklisted(accountProfilePage) is False):
            hostname = urlparse(accountProfilePage).hostname
            webfinger = accountName + "@" + hostname
            gexf_graph.addNode(webfinger, webfinger)
            gexf_graph.addEdge(root_webfinger + webfinger, root_webfinger, webfinger)
            if accountProfilePage not in parsedFOAFS:
                queuedFOAFS.put(accountProfilePage)

    for subscriber in g.query(subscribers, initBindings={'person': acctID}):
        accountProfilePage = str(subscriber.accountProfilePage) + "/foaf"
        accountName = str(subscriber.accountName)
        if (blacklisted(accountProfilePage) is False):
            hostname = urlparse(accountProfilePage).hostname
            webfinger = accountName + "@" + hostname
            gexf_graph.addNode(webfinger, webfinger)
            gexf_graph.addEdge(webfinger + root_webfinger, root_webfinger, webfinger)
            if accountProfilePage not in parsedFOAFS:
                queuedFOAFS.put(accountProfilePage)
开发者ID:chimo,项目名称:graph-the-feds,代码行数:62,代码来源:graph.py

示例6: test_query2

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
 def test_query2(self):
     with open(join(EXAMPLES, "query2.json")) as query_file:
         q = load(query_file)
     result = apply(q, self.g)
     expected = Graph()
     expected.load(join(EXAMPLES, "query2.result.ttl"), format="turtle")
     assert isomorphic(result.graph, expected), result.graph.serialize(format="turtle")
开发者ID:pchampin,项目名称:json-ldq,代码行数:9,代码来源:test_json_ldq.py

示例7: DeepGraphStore

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
class DeepGraphStore():
    store_name = settings.DEEPGRAPHS_DEFAULT_STORAGE

    def __init__(self, create=True):
        self.create = create
        self.path = "databases/" + random_file_generating()

    def setUp(self):
        self.graph = Graph(store=self.store_name)
        self.graph.open(self.path, create=self.create)

        if self.create:
            self.graph.parse("http://njh.me/foaf.rdf", format='xml')
            self.graph.commit()

    def open(self, path):
        self.graph = Graph(self.store_name).open(path, False)
        return self.graph.__len__

    def query(self, sparql_query):
        return self.graph.query(sparql_query)

    def parse(self, path_to_file_):
        self.graph.parse(path_to_file_)

    def load(self, triples):
        self.graph.load(triples)

    def close(self):
        self.graph.close()

    def size(self):
        size = self.graph.__len__
        self.close()
        return size
开发者ID:deepgraphs,项目名称:dgraphdb,代码行数:37,代码来源:dgraphdbstore.py

示例8: main

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def main(argv):
    #TODO: This an RSS, there should be programatical ways to have an order to limit
    # duplication
    args = args_process(argv)

    soup = BeautifulSoup(open(args.inputfile),'lxml')

    currentbase = Graph()
    currentbase.load(args.current, format='turtle')

    g = Graph()
    c = 0
    for item in soup.find_all('item'):
        c += 1
        subject = URIRef("http://www.edsa-project.eu/jobs/StackOverflow/"+str(c))
        #URL
        url = Literal(item.guid.string)
        if args.verbose:
            print "Processing post " + url
        if is_duplicate(currentbase,url):
            if args.verbose:
                print url +" identified as duplicate, skipping..."
            continue
        g.add((subject,ns.schema.url,url))
        #Title
        g.add((subject,ns.schema.jobTitle,Literal(item.title.string)))
        #Description
        g.add((subject,ns.schema.description,Literal(item.description.string)))
        #PubDate
        date = dtp.parse(item.pubdate.string)
        g.add((subject,ns.schema.datePosted,
            Literal(date.isoformat(),datatype=XSD.Date)))

        for org in item.find_all('a10:name'):
            #hiringOrganization
            #TODO: Service to OpenCorporates to entity matching
            # Low priority, maybe can be done with SILK later
            g.add((subject,ns.schema.hiringOrganization,Literal(org.string)))
        for cat in item.find_all('category'):
            #skills
            skill = URIRef("http://www.edsa-project.eu/skill/"+cat.string)
            g.add((subject,ns.edsa.requiresSkill,skill))
            g.add((skill,ns.edsa.lexicalValue,Literal(cat.string)))
        if item.location is not None:
            #location
            g.add((subject,ns.schema.jobLocation,Literal(item.location.string)))
            try:
                tup = gn.find_location(item.location.string)
                g.add((subject,ns.edsa.Location,URIRef(tup[0])))
                g += tup[1]
            except gn.NotFoundException as e:
                #TODO: Redirect to an error file
                print("%s in subject %s" % (e,subject))
                print("problematic location %s" % item.location.string)


    currentbase += g
    g.serialize(destination=args.outputfile, format='turtle')
    currentbase.serialize(destination=args.current, format='turtle')
开发者ID:alanponce,项目名称:dashboard,代码行数:61,代码来源:mapping-StackOverflow.py

示例9: test_bnodes_sort

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

        graph = Graph()
        graph.load("tests/data/bnodes.ttl", format="turtle")
        ots = OrderedTurtleSerializer(graph)

        out = BytesIO()
        ots.serialize(out)
开发者ID:scriptotek,项目名称:otsrdflib,代码行数:10,代码来源:ots_test.py

示例10: main

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def main(argv):
    args = args_process(argv)
    dataset = Graph()
    dataset.load(args.dataset)

    #filter_non_exact(dataset)
    skilldict = get_skill_dict("datasets/skillNames.ttl")
    add_skills(dataset,skilldict)
    dataset.serialize(destination=args.outputfile)
开发者ID:edsa-project,项目名称:dashboard,代码行数:11,代码来源:post-process.py

示例11: __init__

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
class DOAP:

    def __init__(self, url):
        self.url = url
        self.graph = Graph()
        self.graph.load(url)

    def __len__(self):
        return len(self.graph)
开发者ID:wikier,项目名称:asf-doap,代码行数:11,代码来源:doap.py

示例12: _load_resources

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

示例13: read_or_create_graph

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def read_or_create_graph(tags=None):
    global _graph
    if _graph is not None:
        return _graph
    graph = Graph()
    try:
        graph.load(graph_filename)
    except OSError, e:
        print "starting new graph at %r" % graph_filename
开发者ID:drewp,项目名称:semfile,代码行数:11,代码来源:semfile.py

示例14: __parse

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
     def __parse(self, recipe, **kwargs) :
          gr = Graph()
          gr.load(recipe, format="n3");

          self.__graph = gr
          
          if kwargs.has_key('xinclude') and kwargs['xinclude'] == 1:
               self.merge_xinclude()

          return gr
开发者ID:imclab,项目名称:eatdrinkfeelgood,代码行数:12,代码来源:parser.py

示例15: fetch_triples

# 需要导入模块: from rdflib import Graph [as 别名]
# 或者: from rdflib.Graph import load [as 别名]
def fetch_triples(request, graph_uri, type, query_mapping):
    
    print graph_uri
    
    # Get the mapping
    #query_mapping = json.loads(open(SINDICE_CONFIG_MAPPING, 'r').read())
    
    # Create a new graph
    new_graph = Graph()
    
    # Bind namespaces to the graph
    for ns in namespaces_dict:
        new_graph.bind(ns, Namespace(namespaces_dict[ns]))
    
    if type in query_mapping:
        
        # Get the mapping for the particular type
        type_mapping = query_mapping[type]
        
        # Load the external graph
        external_graph = Graph()
        
        try:
            external_graph.load(URIRef(graph_uri))
        except:
            print "URI unreachable"
        
        for ns in namespaces_dict:
            external_graph.bind(ns, Namespace(namespaces_dict[ns    ]))
        
        # Iterate over the mappings
        for orig_uri in type_mapping:

            # Create a sparql query
            sparql_query = 'select * where { ?s ' + orig_uri +  ' ?o .}'
            
            # Convert the prefix version into a full URIRef
            new_uri_prefix = type_mapping[orig_uri].split(":")[0]
            if new_uri_prefix in namespaces_dict:
                new_uri = URIRef(type_mapping[orig_uri].replace(new_uri_prefix + ":", namespaces_dict[new_uri_prefix]))
                
            for row in external_graph.query(sparql_query):
                #print row
                new_graph.add((row.s, new_uri, row.o))
        
        # Get all triples from the new graph
        triple_list = list()
        spo_query = 'select * where {?s ?p ?o .}'
        for row in new_graph.query(spo_query):
            triple_list.append([row.s, row.p, row.o])
    
        return json.dumps({"triple_list": triple_list})
开发者ID:suchmaske,项目名称:rdfedit,代码行数:54,代码来源:ajax.py


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