MCPcopy Index your code
hub / github.com/clips/pattern / json

Function json

pattern/graph/commonsense.py:263–278  ·  view source on GitHub ↗

Returns a JSON-string with the data from commonsense.csv. Each relation is encoded as a [concept1, relation, concept2, context, weight] list.

()

Source from the content-addressed store, hash-verified

261 f.close()
262
263def 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())

Callers 1

jsonMethod · 0.85

Calls 4

CommonsenseClass · 0.85
fFunction · 0.85
encodeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…