A semantic network of commonsense, using different relation types: - is-a, - is-part-of, - is-opposite-of, - is-property-of, - is-related-to, - is-same-as, - is-effect-of.
(self, data=os.path.join(MODULE, "commonsense.csv"), **kwargs)
| 91 | class Commonsense(Graph): |
| 92 | |
| 93 | def __init__(self, data=os.path.join(MODULE, "commonsense.csv"), **kwargs): |
| 94 | """ A semantic network of commonsense, using different relation types: |
| 95 | - is-a, |
| 96 | - is-part-of, |
| 97 | - is-opposite-of, |
| 98 | - is-property-of, |
| 99 | - is-related-to, |
| 100 | - is-same-as, |
| 101 | - is-effect-of. |
| 102 | """ |
| 103 | Graph.__init__(self, **kwargs) |
| 104 | self._properties = None |
| 105 | # Load data from the given path, |
| 106 | # a CSV-file of (concept1, relation, concept2, context, weight)-items. |
| 107 | if data is not None: |
| 108 | s = open(data).read() |
| 109 | s = s.strip(BOM_UTF8) |
| 110 | s = s.decode("utf-8") |
| 111 | s = ((v.strip("\"") for v in r.split(",")) for r in s.splitlines()) |
| 112 | for concept1, relation, concept2, context, weight in s: |
| 113 | self.add_edge(concept1, concept2, |
| 114 | type = relation, |
| 115 | context = context, |
| 116 | weight = min(int(weight)*0.1, 1.0)) |
| 117 | |
| 118 | @property |
| 119 | def concepts(self): |