-
Notifications
You must be signed in to change notification settings - Fork 6
/
atomwrappers.py
174 lines (123 loc) · 4.11 KB
/
atomwrappers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""
Classes to generate atomese without working with atomspace
"""
__author__ = "Anatoly Belikov"
__email__ = "[email protected]"
from current_symbols import *
class CAtom:
def __hash__(self):
return hash(str(self))
class CNode(CAtom):
atom_type = None
def __init__(self, name):
self.name = name
def __str__(self):
return '({0} "{1}")'.format(self.atom_type, self.name.replace('"', '\\"'))
def recursive_print(self, result='', indent=''):
return result + indent + str(self)
class CLink(CAtom):
def __init__(self, *atoms, stv=None):
self.outgoing = atoms
for atom in atoms:
assert isinstance(atom, CAtom)
self.stv = stv
def __str__(self):
outgoing = '\n'.join([str(x) for x in self.outgoing])
if self.stv is not None:
return '({0} {1} {2})'.format(self.atom_type, self.stv , outgoing)
return '({0} {1})'.format(self.atom_type, outgoing)
def recursive_print(self, result='', indent=''):
if self.stv is not None:
result += indent + '({0} {1}'.format(self.atom_type, self.stv)
indent = indent + ' '
for x in self.outgoing:
result = x.recursive_print(result + '\n', indent)
result += ')'
return result
else:
result += indent + '({0}'.format(self.atom_type)
indent = indent + ' '
for x in self.outgoing:
result = x.recursive_print(result + '\n', indent)
result += ')'
return result
class CEvaluationLink(CLink):
atom_type = 'EvaluationLink'
class CExecutionLink(CLink):
atom_type = 'ExecutionLink'
class CLazyExecutionOutputLink(CLink):
atom_type = 'LazyExecutionOutputLink'
class CQuantitativePredicateLink(CLink):
atom_type = 'QuantitativePredicateLink'
class CPredicateNode(CNode):
atom_type = 'PredicateNode'
class CSchemaNode(CNode):
atom_type = 'SchemaNode'
class CQuantitativeSchemaNode(CNode):
atom_type = 'QuantitativeSchemaNode'
class CQuantitativePredicateNode(CNode):
atom_type = 'QuantitativePredicateNode'
class CConceptNode(CNode):
atom_type = 'ConceptNode'
class CNumberNode(CNode):
atom_type = 'NumberNode'
class CMoleculeNode(CNode):
atom_type = 'MoleculeNode'
class CMemberLink(CLink):
atom_type = 'MemberLink'
class CListLink(CLink):
atom_type = 'ListLink'
class CGeneNode(CNode):
def __init__(self, name):
self.name = get_current_symbol(name)
self.atom_type = 'GeneNode'
class CContextLink(CLink):
atom_type = 'ContextLink'
class CInheritanceLink(CLink):
atom_type = 'InheritanceLink'
class CRNANode(CNode):
atom_type = 'EnstNode'
class NcRNANode(CNode):
atom_type = 'RefseqNode'
class ChebiNode(CNode):
atom_type = 'ChebiNode'
class ProteinNode(CNode):
atom_type = 'UniprotNode'
class PubchemNode(CNode):
atom_type = 'PubchemNode'
class ReactomeNode(CNode):
atom_type = 'ReactomeNode'
class SMPNode(CNode):
atom_type = 'SmpNode'
class PharmGkbNode(CNode):
atom_type = 'PharmGkbNode'
class CelltypeNode(CNode):
atom_type = 'CellNode'
class UberonNode(CNode):
atom_type = 'UberonNode'
class GoCCNode(CNode):
atom_type = 'CellularComponentNode'
class GoMFNode(CNode):
atom_type = 'MolecularFunctionNode'
class GoBPNode(CNode):
atom_type = 'BiologicalProcessNode'
class ChebiOntology(CNode):
atom_type = 'ChebiOntology'
class NcbiTaxonomy(CNode):
atom_type = 'NcbiTaxonomyNode'
class CPatientNode(CNode):
atom_type = 'PatientNode'
class Entrez(CNode):
atom_type = 'EntrezNode'
class CSetLink(CLink):
atom_type = 'SetLink'
def __str__(self):
# str is used for hash computation, so need to sort outgoing set for all unordered links
outgoing = '\n'.join(sorted([str(x) for x in self.outgoing]))
return '({0} {1})'.format(self.atom_type, outgoing)
class CStv:
def __init__(self, tv, confidence):
self.tv = tv
self.confidence = confidence
def __str__(self):
return '(stv {0} {1})'.format(self.tv, self.confidence)