如何在Python中的CSV上执行OpenRefine JSON? [英] How to execute OpenRefine JSON on CSV in Python?

查看:98
本文介绍了如何在Python中的CSV上执行OpenRefine JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种Python解决方案,该解决方案可以在不打开OpenRefine服务器的情况下以JSON执行以下OpenRefine Python命令. 我的 OpenRefine JSON在任何格式正确的CSV文件的每个字段上均包含映射和自定义Python命令,因此这不是基本的JSON读取. 一个示例OpenRefine JSON代码,其中仅使用正则表达式映射

I am trying to find a Python solution which can execute the following OpenRefine Python commands in JSON without OpenRefine server being on. My OpenRefine JSON contains mappings and custom Python commands on each field of any properly formatted CSV file, so this is not a basic JSON reading. One example OpenRefine JSON code where only regex mappings

[
  {
    "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,但是对于某些包,可能会有更简单的解决方案.

One solution is to process JSON one by one with each type of element but there may be easier solutions with some packages.

Python:3.5.2
操作系统:Debian 9

Python: 3.5.2
OS: Debian 9

推荐答案

pyrefine 项目旨在做到这一点.但这仍在进行中,几乎不支持任何操作.欢迎贡献者!

The pyrefine project aims to do exactly that. But it is still a work in progress, very few operations are supported. Contributors are welcome!

这篇关于如何在Python中的CSV上执行OpenRefine JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆