| … | … | @@ -1,6 +1,8 @@ |
| 1 | 1 | ; |
| 2 | 2 | ; count.scm |
| 3 | | ; Attempt to count things. |
| 3 | ; Attempt to count things. Scratchpad. |
| 4 | ; Final clean version in atomspace/examples/flow/count-pipeline.scm |
| 5 | ; |
| 4 | 6 | (use-modules (opencog)) |
| 5 | 7 | |
| 6 | 8 | (define get-all-types |
| … | … | @@ -98,17 +100,20 @@ |
| 98 | 100 | (Lambda |
| 99 | 101 | (VariableList (Variable "left") (Variable "right")) |
| 100 | 102 | (Not |
| 101 | | (GreaterThan |
| 103 | (LessThan |
| 102 | 104 | (ElementOf (Number 2) |
| 103 | 105 | (ValueOf (Variable "left") (Predicate "cnt"))) |
| 104 | 106 | (ElementOf (Number 2) |
| 105 | 107 | (ValueOf (Variable "right") (Predicate "cnt"))))))) |
| 106 | 108 | |
| 107 | | (define x |
| 108 | | (SortedValue |
| 109 | (Pipe |
| 110 | (Name "sorted-types") |
| 111 | (LinkSignature |
| 112 | (TypeNode 'SortedValue) |
| 109 | 113 | (DefinedPredicate "count-order") |
| 110 | 114 | (Name "unique-types"))) |
| 111 | 115 | |
| 116 | (cog-execute! (Name "sorted-types")) |
| 112 | 117 | |
| 113 | 118 | ; Debug print |
| 114 | 119 | (cog-execute! |
| … | … | @@ -119,11 +124,140 @@ |
| 119 | 124 | (LinkSignature (Type 'LinkValue) |
| 120 | 125 | (Variable "$typ") |
| 121 | 126 | (ValueOf (Variable "$typ") (Predicate "cnt")))) |
| 122 | | (Name "unique-types"))) |
| 127 | (Name "sorted-types"))) |
| 123 | 128 | |
| 129 | ; -------------------- |
| 130 | (define (data-printer NAME COUNT) |
| 131 | (StringValue |
| 132 | (format #f "Usage count of type: ~A ~A" |
| 133 | (cog-value-ref COUNT 2) |
| 134 | (cog-name NAME)))) |
| 124 | 135 | |
| 136 | ; -------------------- |
| 125 | 137 | (cog-execute! |
| 126 | | (CollectionOf |
| 127 | | (TypeNode 'SortedValue) |
| 128 | | (Name "unique-types"))) |
| 138 | (Filter |
| 139 | (Rule |
| 140 | (TypedVariable (Variable "$typ") (Type 'Type)) ; vardecl |
| 141 | (Variable "$typ") ; body - accept everything |
| 142 | (ExecutionOutput |
| 143 | (GroundedSchema "scm:data-printer") |
| 144 | (LinkSignature (Type 'LinkValue) |
| 145 | (Variable "$typ") |
| 146 | (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 147 | (Name "sorted-types"))) |
| 148 | |
| 149 | (cog-execute! |
| 150 | (Filter |
| 151 | (Rule |
| 152 | (TypedVariable (Variable "$typ") (Type 'Type)) ; vardecl |
| 153 | ; Specify a body that rejects types without counts. |
| 154 | (And |
| 155 | (Present (Variable "$typ")) |
| 156 | (Equal |
| 157 | (Type 'FloatValue) |
| 158 | (TypeOf (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 159 | (ExecutionOutput |
| 160 | (GroundedSchema "scm:data-printer") |
| 161 | (LinkSignature (Type 'LinkValue) |
| 162 | (Variable "$typ") |
| 163 | (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 164 | (Name "sorted-types"))) |
| 165 | |
| 166 | (cog-execute! |
| 167 | (Filter |
| 168 | (Rule |
| 169 | (TypedVariable (Variable "$typ") (Type 'Type)) ; vardecl |
| 170 | ; Specify a body that rejects types without counts. |
| 171 | (And |
| 172 | (Present (Variable "$typ")) |
| 173 | (Equal |
| 174 | (Type 'FloatValue) |
| 175 | (TypeOf (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 176 | (LinkSignature (Type 'LinkValue) |
| 177 | (Node "Usage count of type: ") |
| 178 | (Variable "$typ") |
| 179 | (Node " is equal to ") |
| 180 | (ElementOf (Number 2) |
| 181 | (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 182 | (Name "sorted-types"))) |
| 183 | |
| 184 | (cog-execute! |
| 185 | (Filter |
| 186 | (Rule |
| 187 | (TypedVariable (Variable "$typ") (Type 'Type)) ; vardecl |
| 188 | ; Specify a body that rejects types without counts. |
| 189 | (And |
| 190 | (Present (Variable "$typ")) |
| 191 | (Equal |
| 192 | (Type 'FloatValue) |
| 193 | (TypeOf (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 194 | (LinkSignature (Type 'LinkValue) |
| 195 | (Node "Usage count of type: ") |
| 196 | (Variable "$typ") |
| 197 | (Node " is equal to ") |
| 198 | (ElementOf (Number 2) |
| 199 | (ValueOf (Variable "$typ") (Predicate "cnt"))))) |
| 200 | (Name "sorted-types"))) |
| 201 | |
| 202 | |
| 203 | (cog-execute! |
| 204 | (CollectionOf (Type 'StringValue) (Name "list of structures"))) |
| 205 | |
| 206 | (cog-execute! |
| 207 | (Concatenate (Type 'StringValue) (Name "list of structures"))) |
| 208 | |
| 209 | (cog-execute! |
| 210 | (LinkSignature |
| 211 | (Signature |
| 212 | (Type 'StringValue) |
| 213 | (Type 'StringValue) |
| 214 | (Type 'StringValue) |
| 215 | (Type 'StringValue)) |
| 216 | (Name "list of structures"))) |
| 217 | |
| 218 | |
| 219 | (cog-execute! |
| 220 | (Filter |
| 221 | (Rule |
| 222 | (VariableList |
| 223 | (Variable "$a") |
| 224 | (Variable "$b") |
| 225 | (Variable "$c") |
| 226 | (Variable "$d")) |
| 227 | (LinkSignature (Type 'LinkValue) |
| 228 | (Variable "$a") |
| 229 | (Variable "$b") |
| 230 | (Variable "$c") |
| 231 | (Variable "$d")) |
| 232 | (LinkSignature (Type 'LinkValue) |
| 233 | (LinkSignature (Type 'StringValue) (Variable "$a")) |
| 234 | (LinkSignature (Type 'StringValue) (Variable "$b")) |
| 235 | (LinkSignature (Type 'StringValue) (Variable "$c")) |
| 236 | (LinkSignature (Type 'StringValue) (Variable "$d")))) |
| 237 | (Name "list of structures"))) |
| 238 | |
| 239 | |
| 240 | (cog-execute! |
| 241 | (LinkSignature (Type 'StringValue) (Number 3))) |
| 242 | ;; --------- |
| 243 | (Rule |
| 244 | (VariableList |
| 245 | (TypedVariable (Variable "$typ") (Type 'Type)) |
| 246 | (TypedVariable (Variable "$cnt") (Type 'FloatValue)) ; vardecl |
| 247 | ; Specify a body that rejects types without counts. |
| 248 | (And |
| 249 | (Present (Variable "$typ")) |
| 250 | (Equal |
| 251 | (Variable "$cnt") |
| 252 | (ValueOf (Variable "$typ") (Predicate "cnt")))) |
| 253 | |
| 254 | GuardLink |
| 255 | |
| 256 | (cog-execute! |
| 257 | (Filter |
| 258 | (Equal |
| 259 | (Type 'FloatValue) |
| 260 | (TypeOf (ValueOf (Variable "$typ") (Predicate "cnt")))) |
| 261 | (Name "sorted-types"))) |
| 129 | 262 | |
| 263 | ; -------------------------- |