ontoutils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:genepio 作者: GenEpiO 项目源码 文件源码
def get_ontology_imports(self, ontology_file_path='./imports/'):
        """
        Detects all the import files in a loaded OWL ontology graph and adds them to the graph.
        Currently assumes imports are sitting in a folder called "imports" in parent folder of this script. 
        """
        query = rdflib.plugins.sparql.prepareQuery("""
            SELECT distinct ?import_file
            WHERE {?s owl:imports ?import_file . }
            ORDER BY (?import_file)
        """, initNs = self.namespace)

        imports = self.graph.query(query, initNs = self.namespace)

        print("It has %s import files ..." % len(imports))

        for result_row in imports: # a rdflib.query.ResultRow
            file = result_row.import_file.rsplit('/',1)[1]
            file_path = ontology_file_path + '/' + file
            try:
                if os.path.isfile( file_path):
                    self.graph.parse(file_path) 
                else:
                    print ('WARNING:' + file_path + " could not be loaded!  Does its ontology include purl have a corresponding local file? \n")

            except rdflib.exceptions.ParserError as e:
                print (file_path + " needs to be in RDF OWL format!")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号