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


Python SparqlQueryBuilder.build_query_on_the_fly方法代码示例

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


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

示例1: moStateOnTPS

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import build_query_on_the_fly [as 别名]
    def moStateOnTPS(self):
        '''
            check if module files state is saved on the TPS.
            if not all modules files are saved with the unchecked status !
        '''
        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        results = ql.process_query(sqb.build_query_on_the_fly({
            'select': '?uri ?module ?comment ?version ?graph ?state',
            'from'  : [self.graph_modules],
            'query': '{\n'+
                     '?uri rdfs:label ?module .\n'+
                     '?uri rdfs:comment ?comment .\n'+
                     '?uri :module_version ?version .\n'+
                     '?uri :module_state ?state .\n'+
                     'OPTIONAL { ?uri :module_graph ?graph . } \n'+
                     '}\n'
        }, True).query)

        self.log.debug(' ***** module on TPS ***** ')
        listMoOnTps = {}
        for result in results:
            result['checked'] = (result['state'] == "ok")
            result['wait'] = (result['state'] == "wait")
            listMoOnTps[result['module']] = 0
            self.log.debug('module : '+result['module'])
            #=======================*************** A ENLEVER *********=======================================
            #pour debugger
            #if result['wait'] :
            #    result['wait'] = False
            #==============================================================

        self.log.debug(' ***** check Available Modules ***** ')

        requestAgain = False

        for mo in self.moduleFiles:
            self.log.debug(" --> module "+mo);
            if mo not in listMoOnTps:
                self.log.debug(" --====== > new module < =======");
                self.importMoSate(self.moduleFiles[mo],'off')
                requestAgain = True

        if requestAgain :
            return False

        return results
开发者ID:ofilangi,项目名称:askomics,代码行数:49,代码来源:ModulesManager.py

示例2: generateAbstractAskomicsRDF

# 需要导入模块: from askomics.libaskomics.rdfdb.SparqlQueryBuilder import SparqlQueryBuilder [as 别名]
# 或者: from askomics.libaskomics.rdfdb.SparqlQueryBuilder.SparqlQueryBuilder import build_query_on_the_fly [as 别名]
    def generateAbstractAskomicsRDF(self, graph):
        '''
        '''
        sqb = SparqlQueryBuilder(self.settings, self.session)
        ql = QueryLauncher(self.settings, self.session)
        results = ql.process_query(sqb.build_query_on_the_fly({
            'select': '?entityDom ?entityDomLab ?relation ?entityRan ?entityRanLab',
            'query': '{\n'+
                     'GRAPH ?g { \n' +
                     '?relation a owl:ObjectProperty.\n'+
                     '?relation rdfs:domain ?entityDom.\n'+
                     '?entityDom a owl:Class .\n'+
                     'OPTIONAL { ?entityDom rdfs:label ?entityDomLab }.\n'+
                     '?relation rdfs:range ?entityRan .\n'+
                     '?entityRan a owl:Class .\n'+
                     'OPTIONAL { ?entityRan rdfs:label ?entityRanLab }.\n'+
                     'FILTER ( isIRI(?entityDom)).\n ' +
                     'FILTER ( isIRI(?entityRan)).\n ' +
                     '}\n'+
                     'VALUES ?g {<'+graph+'>}'
                     '}\n'
        }, True).query)

        entities = {}
        attributes = {}
        label = {}

        for r in results:
            if r['entityDom'] not in entities:
                entities[r['entityDom']] = {}

            if r['entityRan'] not in entities:
                entities[r['entityRan']] = {}

            entities[r['entityDom']][r['relation']] = r['entityRan']

            if ('entityDomLab' in r) and (r['entityDom'] not in label):
                if r['entityDomLab'] != '':
                    label[r['entityDom']] = r['entityDomLab']
            if ('entityRanLab' in r) and (r['entityRan'] not in label):
                if r['entityRan'] != '':
                    label[r['entityRan']] = r['entityRanLab']


        if len(entities)>0:
            values = ""
            for ent in entities:
                values += '<'+ent+'> '

            results = ql.process_query(sqb.build_query_on_the_fly({
                'select': '?entity ?attribute ?basetype',
                'query': '{\n'+
                         'GRAPH ?g { \n' +
                         '?attribute a owl:DatatypeProperty.\n'+
                         '?attribute rdfs:domain ?entity.\n'+
                         '?entity a owl:Class .\n'+
                         '?attribute rdfs:range ?basetype .\n'+
                         'FILTER ( isIRI(?basetype)).\n ' +
                         'VALUES ?entity {'+values+'}.\n ' +
                         '}\n'+
                         'VALUES ?g {<'+graph+'>}'
                         '}\n'
            }, True).query)

            for r in results:
                if r['entity'] not in attributes:
                    attributes[r['entity']] = {}
                attributes[r['entity']][r['attribute']] = r['basetype']

        rdftab = []

        rdftab.append("@prefix displaySetting: <"+self.ASKOMICS_prefix['displaySetting']+">.")
        rdftab.append("@prefix rdfs: <"+self.ASKOMICS_prefix['rdfs']+">.")

        for ent in entities:
            rdftab.append("<"+ent +"> displaySetting:entity \"true\"^^xsd:boolean.")
            if ent not in label:
                label = ent

                idxList = [ label.rfind('#'), label.rfind('/')]
                idx = -1
                for i in idxList:
                    if i>idx:
                        idx=i
                if idx>=0:
                    label = self.escape['text'](self.reverse_prefix(label[:idx+1])+':'+label[idx+1:])
                else:
                    label = self.escape['text'](label)
                rdftab.append("<"+ent +"> rdfs:label "+label+"^^xsd:string.")

            if len(entities[ent])>0:
                 rdftab.append("<"+ ent +"> displaySetting:startPoint \"true\"^^xsd:boolean.")
            if ent in attributes:
                for at in attributes[ent]:
                    rdftab.append("<"+ at +"> displaySetting:attribute \"true\"^^xsd:boolean.")

        return rdftab
开发者ID:ofilangi,项目名称:askomics,代码行数:99,代码来源:ModulesManager.py


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