我是python模板的新手。我需要使用python模板创建以下输出。它基本上包含一个数据库表名和它的三重形式的属性信息。
fuse: MIAMI_HOUSEHOLD_2009_1 rdf:type owl:NamedIndividual
fuse: MIAMI_HOUSEHOLD_2009_1 rdf:type fuse:OracleTable
fuse: MIAMI_HOUSEHOLD_2009_1 fuse: hasColumn fuse:SUBLOC_1
fuse: MIAMI_HOUSEHOLD_2009_1 fuse: hasColumn fuse:PURPOSE
fuse: MIAMI_HOUSEHOLD_2009_1 fuse: hasColumn fuse:DURATION
fuse: SUBLOC_1 rdf:type fuse:Column
fuse: SUBLOC_1 rdf:type owl:NamedIndividual
fuse: PURPOSE rdf:type fuse:Column
fuse: PURPOSE rdf:type owl:NamedIndividual
fuse: DURATION rdf:type fuse:Column
fuse: DURATION rdf:type owl:NamedIndividual
属性列表可能会根据表格中的列数而有所不同。我试过跟随。
def add_table(table_name=None, attribute=None):
#table_name: MIAMI_HOUSEHOLD_2009_1
#attribute=['SUBLOC_1', 'PURPOSE', 'DURATION']
add_table_ttl_template = Template(
"""fuse:${table_name} rdf:type owl:NamedIndividual, \n\t
fuse:${table_name} rdf:type fuse:OracleTable , \n\t ". """)
for att in attribute:
fuse: ${table_name} rdf:hasColumn fuse: ${att}, \n\t
fuse: ${att} rdf:type fuse:Column, \n\t
fuse: ${att} rdf:type owl:NamedIndividual
add_table_ttl_template = add_table_ttl_template.substitute(locals())
我认为这是错误的。任何人都可以帮我纠正吗?