我试图找到一个Python解决方案,它可以在不打开OpenRefine服务器的情况下,以JSON格式执行以下OpenRefine Python命令。 我的OpenRefineJSON包含任何格式正确的CSV文件的每个字段上的映射和自定义Python命令,因此这不是基本的JSON读取。 一个示例OpenRefine JSON代码,其中只有regex映射
[
{
"op": "core/text-transform",
"description": "Text transform on cells in column Sleep using expression jython:import re\n\nvalue = re.sub(\"h0\", \"h\",value)\n\nvalue = re.sub(\"h\",\"*60+\", value)\n\nreturn eval(value)\n\n \nreturn eval(value.replace(\"h\", \"*60+\"));",
"engineConfig": {
"mode": "row-based",
"facets": []
},
"columnName": "Sleep",
"expression": "jython:import re\n\nvalue = re.sub(\"h0\", \"h\",value)\n\nvalue = re.sub(\"h\",\"*60+\", value)\n\nreturn eval(value)\n\n \nreturn eval(value.replace(\"h\", \"*60+\"));",
"onError": "keep-original",
"repeat": false,
"repeatCount": 10
}
]
一种解决方案是使用每种类型的元素逐个处理JSON,但是有些包可能会有更简单的解决方案。在
Python:3.5.2
操作系统:Debian 9
pyrefine项目正是为了做到这一点。但这仍然是一个正在进行的工作,很少有业务得到支持。欢迎投稿!在
我找到了各种不同的选择。我试着判断他们是否有其他选择。Pyrefine是迄今为止唯一真正的Python解决方案。
备选方案
I.一个部分解决方案here在R中用Python创建一个字典来进行转换。这不实现GREPL编辑、Jython/Python编辑或闭包编辑。在
可以将输出编辑为Python格式。在
二。P3-batchrefine大部分是用Java编写的,但也有一些Python。它允许您以以下方式进行转换(除非您能够很好地调用外部Java库,否则不是真正的Python解决方案)。在
III.Pyrefine是一个真正的python解决方案,它的目标是按照以下方式工作,复制自其文档:
有关解析OpenRefine JSON的更多信息
我不知道任何现成的解决办法,我也不知道怎么做。解决方法可能是尝试将Jython脚本转换为函数,然后使用pandas将它们应用于csv。在
Json上的结果:
^{pr2}$最后,您可以在
result.py
的顶部添加这些行,启动脚本,然后祈祷。。。在相关问题 更多 >
编程相关推荐