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


Python SparqlQueryBuilder.get_statistics_number_of_graphs方法代碼示例

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


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

示例1: statistics

# 需要導入模塊: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 別名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import get_statistics_number_of_graphs [as 別名]
    def statistics(self):
        """ Get information about triplet store """
        self.log.debug("== STATS ==")
        data = {}
        pm = ParamManager(self.settings, self.request.session)

        sqb = SparqlQueryBuilder(self.settings, self.request.session)
        ql = QueryLauncher(self.settings, self.request.session)
        tse = TripleStoreExplorer(self.settings, self.request.session)

        results = ql.process_query(sqb.get_statistics_number_of_triples().query)
        resultsGraphs = ql.process_query(sqb.get_statistics_number_of_triples_AskOmics_graphs().query)
        data["ntriples"] = int(results[0]["no"]) + int(resultsGraphs[0]["no"])

        results = ql.process_query(sqb.get_statistics_number_of_entities().query)
        data["nentities"] = results[0]["no"]

        results = ql.process_query(sqb.get_statistics_distinct_classes().query)
        data["nclasses"] = results[0]["no"]

        # Get the number of graphs
        results = ql.process_query(sqb.get_statistics_number_of_graphs().query)
        data["ngraphs"] = results[0]["no"]

        self.log.debug("=== LIST OF METADATAS ")

        # Get the list of named graphs
        namedGraphsResults = ql.execute_query(sqb.get_list_named_graphs().query)

        namedGraphsMetadatas = {}

        # Get a dictionnary containing the metadatas for each graph
        for indexResult in range(len(namedGraphsResults['results']['bindings'])):
            metadatasResults = ql.execute_query(sqb.get_metadatas(namedGraphsResults['results']['bindings'][indexResult]['g']['value']).query)
            metadatas = {}
            for indexMetadatasResults in range(len(metadatasResults['results']['bindings'])):
                if metadatasResults['results']['bindings'][indexMetadatasResults]['p']['value'] == "http://www.w3.org/ns/prov#generatedAtTime":
                    metadatas['loadDate'] = metadatasResults['results']['bindings'][indexMetadatasResults]['o']['value']
                if metadatasResults['results']['bindings'][indexMetadatasResults]['p']['value'] == "http://purl.org/dc/elements/1.1/creator":
                    metadatas['username'] = metadatasResults['results']['bindings'][indexMetadatasResults]['o']['value']
                if metadatasResults['results']['bindings'][indexMetadatasResults]['p']['value'] == "http://purl.org/dc/elements/1.1/hasVersion":
                    metadatas['version'] = metadatasResults['results']['bindings'][indexMetadatasResults]['o']['value']
                if metadatasResults['results']['bindings'][indexMetadatasResults]['p']['value'] == "http://www.w3.org/ns/prov#describesService":
                    metadatas['server'] = metadatasResults['results']['bindings'][indexMetadatasResults]['o']['value']
                if metadatasResults['results']['bindings'][indexMetadatasResults]['p']['value'] == "http://www.w3.org/ns/prov#wasDerivedFrom":
                    metadatas['filename'] = metadatasResults['results']['bindings'][indexMetadatasResults]['o']['value']
            namedGraphsMetadatas[namedGraphsResults['results']['bindings'][indexResult]['g']['value']] = metadatas

        data['metadata'] = namedGraphsMetadatas

        # Get the list of classes
        res_list_classes = ql.process_query(sqb.get_statistics_list_classes().query)

        data["class"] = {}
        for obj in res_list_classes:
            print(obj['class'])
            class_name = pm.remove_prefix(obj['class'])
            print(class_name)
            data["class"][class_name] = {}

        # Get the number of instances by class
        res_nb_instances = ql.process_query(sqb.get_statistics_nb_instances_by_classe().query)

        for obj in res_nb_instances:
            if 'class' in obj:
                print(data['class'])
                class_name = pm.remove_prefix(obj['class'])
                data["class"][class_name]["count"] = obj['count']

        return data
開發者ID:cbettemb,項目名稱:askomics,代碼行數:72,代碼來源:ask_view.py


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