问题描述
我正在使用rdflib将文本文件转换为n3个文件,以节省公交车站的位置(GTFS)。例如,如果我们的纬度= 8.0,经度= 5.0。是:
POINT(5.0 8.0)” ^^ http://www.openlinksw.com/schemas/virtrdf#Geometry>。
现在,我的代码(对于我从文本文件中读取的每一行)看起来都是这样,我只是将纬度,经度保存为float xsd数据类型。我们在图形(g)中添加了每一行。>
data = fd.readline()
data = re.split(',',data)
row = {
"stop_id": data[0],"stop_code": data[1],"stop_name": data[2].replace('"',''),"stop_desc": data[3],"stop_lat": data[4],"stop_lon": data[5],"location_type": data[6]
}
# Create a node for our movie
stop_node = n['Stop/' + row['stop_id']] # Unique URI
class_node = n['Stop']
g.add((stop_node,n.HasstopId,Literal(row['stop_id'],datatype=XSD.int)))
g.add((stop_node,n.HasstopCode,Literal(row['stop_code'],n.HasstopName,Literal(row['stop_name'],datatype=XSD.string)))
g.add((stop_node,n.HasstopDesc,Literal(row['stop_desc'],n.HasstopLat,Literal(row['stop_lat'],datatype=XSD.float)))
g.add((stop_node,n.HasstopLon,Literal(row['stop_lon'],n.HasLocationType,Literal(row['location_type'],RDF.type,class_node))
输出示例:
@prefix ns1: <http://www.stops.org/> .//I have defined that in another file,not important
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://www.stops.org/Stop/01034> a ns1:Stop ;
ns1:HasLocationType "0"^^xsd:int ;
ns1:HasstopCode "10001"^^xsd:int ;
ns1:HasstopDesc "Outside National Hospital"^^xsd:string ;
ns1:HasstopId "01034"^^xsd:int ;
ns1:HasstopLat "8.0"^^xsd:float ;
ns1:HasstopLon "5.0"^^xsd:float ;
ns1:HasstopName "turn hospital"^^xsd:string .
我曾被告知如果我使用开放链接virtuoso将我的n3文件导入到它的数据库中,我可以找到examples的链接地理数据如何使用此表示形式来查询数据。我不确定我是否确切应该首先将其保存为两个浮点值,然后将convert it保存为开放链接技术中的几何点,或者是否将值转换为python使用rdflib生成的n3文件中的几何点。我在互联网上找不到其他任何相关内容。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)