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


Python SPARQLWrapper.JSON属性代码示例

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


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

示例1: getResponseText

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def getResponseText(endpoint, query, requestedMimeType):
    """Returns the result and mimetype of executing the given query against 
    the given endpoint.

    Keyword arguments:
    endpoint - URL of sparql endpoint
    query    - SPARQL query to be executed
    requestedMimeType  Type of content requested. can be:
                'text/csv; q=1.0, */*; q=0.1'
                'application/json'
                etc.
    """
    retFormat = _mimeTypeToSparqlFormat(requestedMimeType)

    client = SPARQLWrapper(endpoint)
    client.setQuery(query)
    client.setReturnFormat(retFormat)
    client.setCredentials(static.DEFAULT_ENDPOINT_USER, static.DEFAULT_ENDPOINT_PASSWORD)
    result = client.queryAndConvert()

    if retFormat==JSON:
        result = jsonify(result)

    return result, MIME_FORMAT[retFormat] 
开发者ID:CLARIAH,项目名称:grlc,代码行数:26,代码来源:sparql.py

示例2: askQuery

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def askQuery(query):
    #print query
    try:
        sparql.setQuery(query)
        sparql.setReturnFormat(JSON)
        results = sparql.query().convert()
        #print str(results)
        for result in results:

            try:
                string = str(results[result])
                if "True" in string:
                    return "True"
            except:
                return "False"
    except:
        return "False"
        
    return "False" 
开发者ID:ag-sc,项目名称:QALD,代码行数:21,代码来源:XMLGenerator.py

示例3: selectQuery

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def selectQuery(query):
    array = []
    try:
        sparql.setQuery(query)
        sparql.setReturnFormat(JSON)
        results = sparql.query().convert()
        select_term = ""
        for result in results["head"]["vars"]:
            select_term = result
        for result in results["results"]["bindings"]:
            try:
                string1 = result[select_term]["value"]
                array.append(string1)
            except:
                #print "Unexpected error:", sys.exc_info()[0]
                pass
    except:
        pass
    return array 
开发者ID:ag-sc,项目名称:QALD,代码行数:21,代码来源:XMLGenerator.py

示例4: askQuery

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def askQuery(query):
    #print query
    if es: sparql = es_sparql
    else:  sparql = en_sparql
    try:
        sparql.setQuery(query)
        sparql.setReturnFormat(JSON)
        results = sparql.query().convert()
        #print str(results)
        for result in results:

            try:
                string = str(results[result])
                if "True" in string:
                    return "True"
            except:
                return "False"
    except:
        return "False"
        
    return "False" 
开发者ID:ag-sc,项目名称:QALD,代码行数:23,代码来源:XMLGeneratorWithoutQuery.py

示例5: selectQuery

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def selectQuery(query):
    if es: sparql = es_sparql
    else:  sparql = en_sparql
    array = []
    try:
        sparql.setQuery(query)
        sparql.setReturnFormat(JSON)
        results = sparql.query().convert()
        select_term = ""
        for result in results["head"]["vars"]:
            select_term = result
        for result in results["results"]["bindings"]:
            try:
                string1 = result[select_term]["value"]
                array.append(string1)
            except:
                #print "Unexpected error:", sys.exc_info()[0]
                pass
    except:
        pass
    return array 
开发者ID:ag-sc,项目名称:QALD,代码行数:23,代码来源:XMLGeneratorWithoutQuery.py

示例6: askClassProperty

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def askClassProperty(uri):
    sparql = SPARQLWrapper(endpoint)
    sparql.setQuery("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX owl: <http://www.w3.org/2002/07/owl#>  ASK WHERE {<"+uri+"> rdf:type owl:Class}")
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    #print results
    for result in results:
        try:
            string = str(results[result])
            if "False" in string:
                return False
            
            if "True" in string:
                return True
        except:
            pass
    return False 
开发者ID:ag-sc,项目名称:QALD,代码行数:19,代码来源:lexiconEvaluation.py

示例7: check_relation_range_type

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def check_relation_range_type(relation,qType):
    return True
    sparql = SPARQLWrapper(wikidataSPARQL)
    sparql.setQuery("""
               PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
               ASK {<"""+relation+"""> rdfs:range <"""+qType+"""> }
            """)
    sparql.setReturnFormat(JSON)
    results1 = sparql.query().convert()
    if results1['boolean']:
        return True
    else:
        sparql.setQuery("""
               PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
               ASK {<"""+relation+"""> rdfs:range ?range. ?range rdfs:subClassOf ?t. ?t rdfs:subClassOf <"""+qType+""">}
            """)
        sparql.setReturnFormat(JSON)
        results2 = sparql.query().convert()
        if results2['boolean']:
            return True
        else:
            return False
    return results1['boolean']

#To split the surface forms in case of possessive forms 
开发者ID:SDM-TIB,项目名称:falcon2.0,代码行数:27,代码来源:main.py

示例8: get_data

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def get_data(sparql_query):
    """ Gets data from Virtuoso """

    tries = 0
    max_tries = 5
    success = False
    while success is False and tries < max_tries:
        try:
            UNIPROT_SERVER.setQuery(sparql_query)
            UNIPROT_SERVER.setReturnFormat(JSON)
            UNIPROT_SERVER.setTimeout(60)
            result = UNIPROT_SERVER.query().convert()
            success = True
        except Exception as e:
            tries += 1
            result = e
            time.sleep(1)

    return result 
开发者ID:B-UMMI,项目名称:chewBBACA,代码行数:21,代码来源:auxiliary_functions.py

示例9: query

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def query(self, qstr, is_update=False):
        sparql = self._get_sparql()
        if is_update:
            sparql.setMethod(POST)
        else:
            sparql.setMethod(GET)
        sparql.setReturnFormat(JSON)
        qstr = sparql_prefix + qstr
        sparql.setHTTPAuth
        sparql.setQuery(qstr)
        raw_res = sparql.query().convert()
        if sparql.queryType == SELECT:
            res = self._format_select_res(raw_res)
        elif sparql.queryType == INSERT:
            res = raw_res # TODO: Error handling here
        elif sparql.queryType == 'LOAD':
            res = raw_res # TODO: Error handling here
        else:
            res = raw_res
        return res 
开发者ID:plastering,项目名称:plastering,代码行数:22,代码来源:virtuoso_wrapper.py

示例10: run_sparql

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def run_sparql(q):
    # TODO: select endpoint based on ontology
    #sparql = SPARQLWrapper("http://rdf.geneontology.org/sparql")
    logger.info("Connecting to sparql endpoint...")
    sparql = SPARQLWrapper("http://sparql.hegroup.org/sparql")
    logger.info("Made wrapper: {}".format(sparql))
    # TODO: iterate over large sets?
    full_q = q + ' LIMIT 250000'
    sparql.setQuery(q)
    sparql.setReturnFormat(JSON)
    logger.info("Query: {}".format(q))
    results = sparql.query().convert()
    bindings = results['results']['bindings']
    logger.info("Rows: {}".format(len(bindings)))
    for r in bindings:
        curiefy(r)
    return bindings 
开发者ID:biolink,项目名称:ontobio,代码行数:19,代码来源:sparql_ontol_utils.py

示例11: run_sparql_on

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def run_sparql_on(q, ontology):
    """
    Run a SPARQL query (q) on a given Ontology (Enum EOntology)
    """
    logger.info("Connecting to " + ontology.value + " SPARQL endpoint...")
    sparql = SPARQLWrapper(ontology.value)
    logger.info("Made wrapper: {}".format(sparql))
    sparql.setQuery(q)
    sparql.setReturnFormat(JSON)
    logger.info("Query: {}".format(q))
    results = sparql.query().convert()
    bindings = results['results']['bindings']
    logger.info("Rows: {}".format(len(bindings)))
    for r in bindings:
        curiefy(r)
    return bindings 
开发者ID:biolink,项目名称:ontobio,代码行数:18,代码来源:sparql_ontol_utils.py

示例12: run_sparql

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def run_sparql(q):
    # TODO: select endpoint based on ontology
    logger.info("Connecting to sparql endpoint...")
    sparql = SPARQLWrapper("http://query.wikidata.org/sparql")
    logger.info("Made wrapper: {}".format(sparql))
    # TODO: iterate over large sets?
    full_q = q + ' LIMIT ' + str(LIMIT)
    sparql.setQuery(q)
    sparql.setReturnFormat(JSON)
    logger.info("Query: {}".format(q))
    results = sparql.query().convert()
    bindings = results['results']['bindings']
    logger.info("Rows: {}".format(len(bindings)))
    for r in bindings:
        curiefy(r)
    return bindings 
开发者ID:biolink,项目名称:ontobio,代码行数:18,代码来源:wikidata.py

示例13: __init__

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def __init__(self, entities, config_file, dataset, endpoint, default_graph):

        self.entities = entities  # file containing a list of entities

        self.dataset = dataset

        self.wrapper = SPARQLWrapper(endpoint)

        self.wrapper.setReturnFormat(JSON)

        if default_graph:

            self.default_graph = default_graph

            self.wrapper.addDefaultGraph(self.default_graph)

        self.query_prop = "SELECT ?s ?o  WHERE {?s %s ?o. }"

        self.query_prop_uri = "SELECT ?s ?o  WHERE {?s %s ?o. FILTER (?s = %s)}"

        self._define_properties(config_file) 
开发者ID:D2KLab,项目名称:entity2rec,代码行数:23,代码来源:sparql.py

示例14: get_uri_from_wiki_id

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def get_uri_from_wiki_id(wiki_id):

        sparql = SPARQLWrapper("http://dbpedia.org/sparql")

        sparql.setQuery("""select ?s where {?s <http://dbpedia.org/ontology/wikiPageID> %d
           }""" % int(wiki_id))

        sparql.setReturnFormat(JSON)

        try:
            uri = sparql.query().convert()['results']['bindings'][0]['s']['value']

        except:

            uri = None

        return uri 
开发者ID:D2KLab,项目名称:entity2rec,代码行数:19,代码来源:sparql.py

示例15: fetch_data

# 需要导入模块: import SPARQLWrapper [as 别名]
# 或者: from SPARQLWrapper import JSON [as 别名]
def fetch_data(q, i):
    """
    Async call to DBpedia, making sparql queries
    to get the abstracts of entities of type 'Organisation'

    Arguments
    ---------
    q : query to be made
    i : request id
    """
    global final_pool
    print(f'INFO : sending request # {i + 1}')
    sparql.setQuery(q)
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()

    data = results['results']['bindings']
    final_pool = final_pool + data
    print(f'INFO : completed request # {i + 1}') 
开发者ID:dbpedia,项目名称:embeddings,代码行数:21,代码来源:sparql.py


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