Returns a JSON-string with the data from commonsense.csv. Each relation is encoded as a [concept1, relation, concept2, context, weight] list.
()
| 261 | f.close() |
| 262 | |
| 263 | def json(): |
| 264 | """ Returns a JSON-string with the data from commonsense.csv. |
| 265 | Each relation is encoded as a [concept1, relation, concept2, context, weight] list. |
| 266 | """ |
| 267 | f = lambda s: s.replace("'", "\\'").encode("utf-8") |
| 268 | s = [] |
| 269 | g = Commonsense() |
| 270 | for e in g.edges: |
| 271 | s.append("\n\t['%s', '%s', '%s', '%s', %.2f]" % ( |
| 272 | f(e.node1.id), |
| 273 | f(e.type), |
| 274 | f(e.node2.id), |
| 275 | f(e.context), |
| 276 | e.weight |
| 277 | )) |
| 278 | return "commonsense = [%s];" % ", ".join(s) |
| 279 | |
| 280 | #download("commonsense.csv", threshold=50) |
| 281 | #open("commonsense.js", "w").write(json()) |
no test coverage detected
searching dependent graphs…