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


Python FeatureExtractor.get_dbp_sparql方法代码示例

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


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

示例1: load_queries

# 需要导入模块: from feature_extractor import FeatureExtractor [as 别名]
# 或者: from feature_extractor.FeatureExtractor import get_dbp_sparql [as 别名]
    def load_queries(self):
        if not os.path.exists(DIRECTORY):
            os.makedirs(DIRECTORY)

        data_split = int(TOTAL_QUERY*0.6)
        validation_split = int(TOTAL_QUERY*0.2)
        test_split = int(TOTAL_QUERY*0.2)
        print "data_split", data_split
        print "validation_split", validation_split
        print "test_split", test_split

        f = open(DBPEDIA_QUERY_LOG,'rb')
        fq = open(DIRECTORY+"x_query.txt",'w')
        ft = open(DIRECTORY+"y_time.txt",'w')
        ff = open(DIRECTORY+"x_features.txt",'w')
        x_f_csv = csv.writer(ff)
        sparql = SPARQLWrapper(DBPEDIA_ENDPOINT)
        f_extractor = FeatureExtractor()
        
        
        
        sw1 = StopWatch()
        sw2 = StopWatch()
        print_log_split = int(TOTAL_QUERY/10)
        
      

        count =0 
        for line in f:
            if count%print_log_split==0:
                print count," queries processed in ",sw2.elapsed_seconds()," seconds"
        
            if(count>=TOTAL_QUERY):
                break

            if count == data_split:
                fq.close()
                ft.close()
                ff.close()
                fq = open(DIRECTORY+"xval_query.txt",'w')
                ft = open(DIRECTORY+"yval_time.txt",'w')
                ff = open(DIRECTORY+"xval_features.txt",'w')
                x_f_csv = csv.writer(ff)
            elif count == (data_split+validation_split):
                fq.close()
                ft.close()
                ff.close()
                fq = open(DIRECTORY+"xtest_query.txt",'w')
                ft = open(DIRECTORY+"ytest_time.txt",'w')
                ff = open(DIRECTORY+"xtest_features.txt",'w')
                x_f_csv = csv.writer(ff)


            try:
                row = line.split()
                query_log = row[6][1:-1]
                #print query_log
                par = urlparse.parse_qs(urlparse.urlparse(query_log).query)
                #util.url_decode(row[6])
                sparql_query = par['query'][0]

                if sparql._parseQueryType(sparql_query) != SELECT:
                    continue

                #print sparql_query
                #print row

                sparql_query = f_extractor.get_dbp_sparql(sparql_query)

                #print sparql_query
                


                feature_vector = f_extractor.get_features(sparql_query)

                if feature_vector == None:
                    print "feature vector not found"
                    continue



                sparql.setQuery(sparql_query)
                sparql.setReturnFormat(JSON)

                sw1.reset()
                results = sparql.query().convert()
                elapsed = sw1.elapsed_milliseconds()

                result_rows = len(results["results"]["bindings"])

                # if result_rows == 0:
                #     continue

                # print "QUERY =", sparql_query
                # print "feature vector:",feature_vector
                # print elapsed, "seconds"                
                # print results
                # print "rows", result_rows
                # print "-----------------------"

#.........这里部分代码省略.........
开发者ID:rhasan,项目名称:query-performance,代码行数:103,代码来源:query_processor.py


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