From d539caf25ab64bc2ba709ccd492e3f7e0b7e166e Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Fri, 1 May 2020 10:38:15 +0100 Subject: [PATCH] Added cloverage output to archive --- docs/cloverage/coverage.css | 40 ++ docs/cloverage/index.html | 135 ++++++ docs/cloverage/wildwood/advocate.clj.html | 149 ++++++ docs/cloverage/wildwood/bialowieza.clj.html | 98 ++++ docs/cloverage/wildwood/caesar.clj.html | 440 ++++++++++++++++++ .../wildwood/dengine/engine.clj.html | 47 ++ docs/cloverage/wildwood/dengine/node.clj.html | 53 +++ .../wildwood/knowledge_accessor.clj.html | 110 +++++ docs/cloverage/wildwood/mongo_ka.clj.html | 149 ++++++ docs/cloverage/wildwood/schema.clj.html | 395 ++++++++++++++++ project.clj | 22 +- 11 files changed, 1628 insertions(+), 10 deletions(-) create mode 100644 docs/cloverage/coverage.css create mode 100644 docs/cloverage/index.html create mode 100644 docs/cloverage/wildwood/advocate.clj.html create mode 100644 docs/cloverage/wildwood/bialowieza.clj.html create mode 100644 docs/cloverage/wildwood/caesar.clj.html create mode 100644 docs/cloverage/wildwood/dengine/engine.clj.html create mode 100644 docs/cloverage/wildwood/dengine/node.clj.html create mode 100644 docs/cloverage/wildwood/knowledge_accessor.clj.html create mode 100644 docs/cloverage/wildwood/mongo_ka.clj.html create mode 100644 docs/cloverage/wildwood/schema.clj.html diff --git a/docs/cloverage/coverage.css b/docs/cloverage/coverage.css new file mode 100644 index 0000000..2be4e57 --- /dev/null +++ b/docs/cloverage/coverage.css @@ -0,0 +1,40 @@ +.covered { + font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace; + background-color: #558B55; +} + +.not-covered { + font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace; + background-color: red; +} + +.partial { + font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace; + background-color: orange; +} + +.not-tracked { + font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace; +} + +.blank { + font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace; +} + +td { + padding-right: 10px; +} + +td.with-bar { + width: 250px; + text-align: center; +} + +td.with-number { + text-align: right; +} + +td.ns-name { + min-width: 150px; + padding-right: 25px; +} diff --git a/docs/cloverage/index.html b/docs/cloverage/index.html new file mode 100644 index 0000000..060f1c5 --- /dev/null +++ b/docs/cloverage/index.html @@ -0,0 +1,135 @@ + + + + + Coverage Summary + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Namespace Forms Forms % Lines Lines %TotalBlankInstrumented
wildwood.advocate
2
100.00 %
2
100.00 %4752
wildwood.bialowieza
2
1
66.67 %
1
1
100.00 %3072
wildwood.caesar
353
100.00 %
38
100.00 %1443738
wildwood.dengine.engine
2
1
66.67 %
1
1
100.00 %1312
wildwood.dengine.node
3
2
60.00 %
1
2
100.00 %1533
wildwood.knowledge-accessor
2
100.00 %
2
100.00 %3462
wildwood.mongo-ka
2
38
5.00 %
2
9
18.18 %47411
wildwood.schema
167
4
97.66 %
48
3
1
98.08 %1291552
Totals:92.06 %91.07 %
+ + diff --git a/docs/cloverage/wildwood/advocate.clj.html b/docs/cloverage/wildwood/advocate.clj.html new file mode 100644 index 0000000..9974540 --- /dev/null +++ b/docs/cloverage/wildwood/advocate.clj.html @@ -0,0 +1,149 @@ + + + + wildwood/advocate.clj + + + + 001  (ns wildwood.advocate +
+ + 002    "An agent capable of playing the explanation game. +
+ + 003   +
+ + 004    An advocate must have its own knowledge accessor. Different advocates +
+ + 005    within a game may be accessing different knowledge bases, or different +
+ + 006    subsets of the same knowledge base with different - potentially competing +
+ + 007    - knowledge. It also needs to know the schema in which knowledge will be +
+ + 008    presented. +
+ + 009   +
+ + 010    Since the mechanism by which the application will communicate with the +
+ + 011    library must include a way for users to interact with the game, and +
+ + 012    since the role of the user in the came is just as a participant, +
+ + 013    advocate must be defined as a protocol, in order that it may be extended +
+ + 014    by code within the application which is passed in to the game when the +
+ + 015    game is started. Indeed, multiple agents - the user(s) and potentially +
+ + 016    non-player characters - may be passed in. +
+ + 017   +
+ + 018    In this conception, nothing within a default advocate has to be able to +
+ + 019    produce or consume natural language. It is sufficient for the API exposed +
+ + 020    by wildwood.advocate to receive and return wildwood.schema objects. +
+ + 021   +
+ + 022    Obviously to show a user interface anything similar to Arden's, or for +
+ + 023    what I intend for The Great Game, the advocates passed must 'at their +
+ + 024    other end' - that is, on the application side rather than the library +
+ + 025    side - be able to consume and emit natural language, but that functionality +
+ + 026    does not need to be part of the wildwood library, and certainly does +
+ + 027    not need to be part of the default advocate as specified here." +
+ + 028    (:require [wildwood.knowledge-accessor :refer [Accessor]] +
+ + 029              [wildwood.schema :refer [proposition? argument?]])) +
+ + 030   +
+ + 031  (defprotocol Advocate +
+ + 032    (record [self proposition value] +
+ + 033            "Pass a `proposition` with a determined `value` to me, in order that +
+ + 034            advocates can, if desired, record the determined value in their +
+ + 035            knowledge base. The API does not require that the advocate records +
+ + 036            the decision, only that it has the opportunity to do so. Return the +
+ + 037            value.") +
+ + 038    (id [self] "Return a value which uniquely identifies this agent.") +
+ + 039    (decide [self proposition argument] +
+ + 040            "Return `true`, `false` or `nil` as the value of this `proposition`, +
+ + 041            given this `argument`. The value of `proposition` should be a +
+ + 042            proposition as defined by `wildwood.schema/proposition?`; +
+ + 043            the value of `argument` should satisfy `wildwood.schema/argument?`.") +
+ + 044    (move [self proposition argument] +
+ + 045          "Return a new argument structure representing the result of applying my +
+ + 046          `decide` method to this `proposition` and `argument`, specifying in +
+ + 047          some way not yet determined what sort of move I have made.")) +
+ + diff --git a/docs/cloverage/wildwood/bialowieza.clj.html b/docs/cloverage/wildwood/bialowieza.clj.html new file mode 100644 index 0000000..e407033 --- /dev/null +++ b/docs/cloverage/wildwood/bialowieza.clj.html @@ -0,0 +1,98 @@ + + + + wildwood/bialowieza.clj + + + + 001  (ns wildwood.bialowieza +
+ + 002    "The second iteration of the core inference engine for Wildwood" +
+ + 003    (:require [wildwood.advocate :refer [Advocate]] +
+ + 004              [wildwood.schema :refer [proposition?]])) +
+ + 005   +
+ + 006    ;; to start a game we must have n advocates, where n > 1. Each must have +
+ + 007    ;; its own knowledge accessor, so at the level of the game engine we don't +
+ + 008    ;; need to know how to access knowledge. +
+ + 009   +
+ + 010    (defn decide +
+ + 011      "Decide the truth value of this `proposition` by convening a game between +
+ + 012      these advocate `agents`. Iterate the game until all agents PASS; then finally +
+ + 013      offer each agent's `record` method the `proposition` together with the +
+ + 014      decided truth value (`true` or `false`), before returning that value. +
+ + 015   +
+ + 016      The `proposition` is a proposition as defined in the `wildwood.schema`; +
+ + 017      that is to say, the predicate `wildwood.schema/predicate?` returns true +
+ + 018      of it. If the proposition isn't a predicate, throw an exception. +
+ + 019   +
+ + 020      Each of `agents` should be an object implementing the +
+ + 021      `wildwood.advocate/Advocate` protocol. If an agent isn't an Advocate, +
+ + 022      throw an exception. +
+ + 023   +
+ + 024      Do not throw an exception under any other circumstances. +
+ + 025   +
+ + 026      If an agent throws an exception, catch it and treat it as a PASS." +
+ + 027      [proposition & agents] +
+ + 028      ;; TODO: actually write it. +
+ + 029   +
+ + 030      false) +
+ + diff --git a/docs/cloverage/wildwood/caesar.clj.html b/docs/cloverage/wildwood/caesar.clj.html new file mode 100644 index 0000000..9197311 --- /dev/null +++ b/docs/cloverage/wildwood/caesar.clj.html @@ -0,0 +1,440 @@ + + + + wildwood/caesar.clj + + + + 001  (ns wildwood.caesar +
+ + 002    "A dummy set of advocates and knowledge accessors with knowledge about the +
+ + 003    death of Julius Caesar. +
+ + 004   +
+ + 005    # The Case Against Marcus Brutus +
+ + 006   +
+ + 007    Did Brutus conspire to kill Caesar in the forum in the Ides of March? +
+ + 008   +
+ + 009    Falco, the detective, must find out. +
+ + 010   +
+ + 011    ## The witnesses +
+ + 012   +
+ + 013    Anthony knows that Brutus is honourable, and that Caesar is buried. +
+ + 014   +
+ + 015    Brutus will admit he was in the forum on the ides of March and is a witness +
+ + 016    that Cassius was also present. +
+ + 017   +
+ + 018    Cassius and Longus each bear witness that the other killed Caesar in the +
+ + 019    Forum on the Ides of March. +
+ + 020   +
+ + 021    Drusilla believes that Brutus killed Caesar in the Forum on the Ides of +
+ + 022    March, but was not a witness. She also bears witness that Caesar was buried +
+ + 023    on the 18th March. +
+ + 024   +
+ + 025    Gaius believes that Brutus killed Caesar in the Forum in April, but was not +
+ + 026    a witness. +
+ + 027   +
+ + 028    ## The rules +
+ + 029   +
+ + 030    There is a rule which says that if you kill someone and you have accomplices +
+ + 031    then you're not honourable, and a default that has-accomplices is false. +
+ + 032   +
+ + 033    Note that has-accomplices boils down to +
+ + 034    > For a given verb, object, location and time, there is more than one subject. +
+ + 035   +
+ + 036    That's quite sophisticated to represent. +
+ + 037   +
+ + 038    There is a rule which says you can't be killed after you're dead (temporal +
+ + 039    reasoning). +
+ + 040   +
+ + 041    There is a rule which says if you've been killed or been buried then you're +
+ + 042    dead. +
+ + 043   +
+ + 044    The case against Brutus is based on Drusilla's claim and on Gaius's. +
+ + 045   +
+ + 046    Drusilla's can be doubted because +
+ + 047    1. She wasn't a witness and +
+ + 048    2. Is a woman. +
+ + 049   +
+ + 050    Gaius's can be doubted because +
+ + 051    1. he wasn't a witness, and because +
+ + 052    2. it's inconsistent with the evidence that Caesar was buried on the 18th. +
+ + 053   +
+ + 054    ## The conclusion +
+ + 055   +
+ + 056    Thus, I think, Falco must conclude that Brutus didn't kill Caesar, because if +
+ + 057    he had he must have had accomplices (Cassius and Longus, who clearly were +
+ + 058    accomplices and implicate one another), but honourable men don't kill with +
+ + 059    accomplices and Brutus is an honourable man. +
+ + 060   +
+ + 061    ## Features +
+ + 062   +
+ + 063    The `features` in DTree terms we're interested in to make these inferences are +
+ + 064   +
+ + 065    * `did-kill` - true of an entity which is in the subject position of a `kill` proposition; +
+ + 066    * `was-killed` - true of an entity which is in the object position of a `kill` proposition; +
+ + 067    * `buried` - true of an entity which is in the object position of a `bury` proposition; +
+ + 068    * `dead` - true of an entity of which either `was-killed` or `buried` is true; +
+ + 069    * `honourable` - true of an entity, provided that `did-lie` and `did-murder` are false; +
+ + 070    * `did-murder` - true of an entity x that `did-kill[x,y]` for some object y is true of, +
+ + 071    provided that there exists some other entity p of whom `did-kill[p,x]` is also true, +
+ + 072    or that `was-unarmed[y]` is true; +
+ + 073    * `did-lie` - true of an entity which has offered a proposition which for other reasons we do not believe. Tricky. False by default and I think we probably leave it at that for now. +
+ + 074    * `was-unarmed` - true of an entity at a time `t` if they were unarmed at the time. +
+ + 075   +
+ + 076    Note that ALL of this is too complex for the simple DTree logic of the Arboretum / +
+ + 077    KnacqTools generation. They could not unpack propositions as I'm proposing here. +
+ + 078    " +
+ + 079    (:require [wildwood.knowledge-accessor :refer [Accessor]] +
+ + 080              [wildwood.advocate :refer [Advocate]])) +
+ + 081   +
+ + 082   +
+ + 083  (def ides-of-march +
+ + 084    "16th March, 44BC" +
+ + 085    (+ -440000 300 16)) +
+ + 086   +
+ + 087  (def eighteenth-march +
+ + 088    "18th March, 44BC" +
+ + 089    (+ -440000 300 18)) +
+ + 090   +
+ + 091  (def march +
+ + 092    "The month of March, 44BC, as a range." +
+ + 093    (sort [(+ -440000 300 1) (+ -440000 300 30)])) +
+ + 094   +
+ + 095  (def april +
+ + 096    "The month of April, 44BC, as a range." +
+ + 097    (sort [(+ -440000 400 1) (+ -440000 400 30)])) +
+ + 098   +
+ + 099  (def anthony-kb +
+ + 100    "Mark Antony knows that Brutus is honourable, and that Caesar is buried." +
+ + 101    {:brutus [{:verb :is :subject :brutus :object :honourable}] +
+ + 102     :caesar [{:verb :bury :subject :calpurnia :object :caesar :date eighteenth-march :nth-hand 1}]}) +
+ + 103   +
+ + 104  (def brutus-kb +
+ + 105    "Brutus will admit that he and Cassius were in the forum in the Ides of March" +
+ + 106    {:brutus [{:verb :present :subject :brutus :object :forum :location :forum :date ides-of-march :nth-hand 1}] +
+ + 107     :cassius [{:verb :present :subject :cassius :object :forum :location :forum :date ides-of-march :nth-hand 1}] +
+ + 108     :forum [{:verb :present :subject :brutus :object :forum :location :forum :date ides-of-march :nth-hand 1} +
+ + 109             {:verb :present :subject :cassius :object :forum :location :forum :date ides-of-march :nth-hand 1}]}) +
+ + 110   +
+ + 111  (def cassius-kb +
+ + 112    "Cassius and Longus each bear witness that the other killed Caesar in the +
+ + 113    Forum on the Ides of March." +
+ + 114    {:caesar [{:verb :kill :subject :longus :object :caesar :location :forum :date ides-of-march :nth-hand 1}] +
+ + 115     :longus [{:verb :kill :subject :longus :object :caesar :location :forum :date ides-of-march :nth-hand 1}] +
+ + 116     :forum [{:verb :kill :subject :longus :object :caesar :location :forum :date ides-of-march :nth-hand 1}]}) +
+ + 117   +
+ + 118  (def drusila-kb +
+ + 119    "Drusila has heard that Brutus killed Caesar in the forum. She keys it on all three, for efficiency +
+ + 120    of retrieval." +
+ + 121    {:caesar [{:verb :kill :subject :brutus :object :caesar :location :forum :date ides-of-march :nth-hand 2} +
+ + 122              {:verb :bury :subject :calpurnia :object :caesar :date eighteenth-march :nth-hand 1}] +
+ + 123     :brutus [{:verb :kill :subject :brutus :object :caesar :location :forum :date ides-of-march :nth-hand 2}] +
+ + 124     :forum [{:verb :kill :subject :brutus :object :caesar :location :forum :date ides-of-march :nth-hand 2}]}) +
+ + 125   +
+ + 126  (def faldo-db +
+ + 127    "Falco believes that Caesar has been killed, but doesn't know by whom or when." +
+ + 128    {:caesar [{:verb :kill :object :caesar :location :forum}] +
+ + 129     :brutus [{:verb :kill :object :caesar :location :forum}] +
+ + 130     :forum [{:verb :kill :object :caesar :location :forum}]}) +
+ + 131   +
+ + 132  (def gaius-db +
+ + 133    "Gaius has heard that Brutus killed Caesar, but believes it happened in April." +
+ + 134    {:caesar [{:verb :kill :subject :brutus :object :caesar :location :forum :date april :nth-hand 2}] +
+ + 135     :brutus [{:verb :kill :subject :brutus :object :caesar :location :forum :date april :nth-hand 2}] +
+ + 136     :forum [{:verb :kill :subject :brutus :object :caesar :location :forum :date april :nth-hand 2}]}) +
+ + 137   +
+ + 138  (def longus-kb +
+ + 139    "Cassius and Longus each bear witness that the other killed Caesar in the +
+ + 140    Forum on the Ides of March." +
+ + 141    {:caesar [{:verb :kill :subject :cassius :object :caesar :location :forum :date ides-of-march :nth-hand 1}] +
+ + 142     :cassius [{:verb :kill :subject :cassius :object :caesar :location :forum :date ides-of-march :nth-hand 1}] +
+ + 143     :forum [{:verb :kill :subject :cassius :object :caesar :location :forum :date ides-of-march :nth-hand 1}]}) +
+ + 144   +
+ + diff --git a/docs/cloverage/wildwood/dengine/engine.clj.html b/docs/cloverage/wildwood/dengine/engine.clj.html new file mode 100644 index 0000000..fdd972c --- /dev/null +++ b/docs/cloverage/wildwood/dengine/engine.clj.html @@ -0,0 +1,47 @@ + + + + wildwood/dengine/engine.clj + + + + 001  (ns wildwood.dengine.engine +
+ + 002    "An implementation of the DTree engine adapted to `wildwood.schema` propositions." +
+ + 003    (:require [wildwood.knowledge-accessor :refer [Accessor]] +
+ + 004              [wildwood.schema :refer [proposition?]])) +
+ + 005   +
+ + 006  (defn decide +
+ + 007    "Decide the truth value of this `proposition`, using the dtree rooted at +
+ + 008    this `node` and knowledge provided by this `accessor`." +
+ + 009    ;; how is explanation returned in this schema? We need a richer return value +
+ + 010    ;; than just a truth value. +
+ + 011    [proposition node accessor] +
+ + 012    ;; TODO: implement +
+ + 013    false) +
+ + diff --git a/docs/cloverage/wildwood/dengine/node.clj.html b/docs/cloverage/wildwood/dengine/node.clj.html new file mode 100644 index 0000000..91e091c --- /dev/null +++ b/docs/cloverage/wildwood/dengine/node.clj.html @@ -0,0 +1,53 @@ + + + + wildwood/dengine/node.clj + + + + 001  (ns wildwood.dengine.node +
+ + 002    "A dtree node.") +
+ + 003   +
+ + 004  (defn node? +
+ + 005    "Return `true` if this `o` is recognisable as a dtree node, else `false`." +
+ + 006    ;; TODO: implement +
+ + 007    [o] +
+ + 008    false) +
+ + 009   +
+ + 010  (defn colour +
+ + 011    "If this `node` is a valid dtree node, return its colour." +
+ + 012    [node] +
+ + 013    ;; TODO: implement +
+ + 014    false) +
+ + 015   +
+ + diff --git a/docs/cloverage/wildwood/knowledge_accessor.clj.html b/docs/cloverage/wildwood/knowledge_accessor.clj.html new file mode 100644 index 0000000..b067d05 --- /dev/null +++ b/docs/cloverage/wildwood/knowledge_accessor.clj.html @@ -0,0 +1,110 @@ + + + + wildwood/knowledge_accessor.clj + + + + 001  (ns wildwood.knowledge-accessor +
+ + 002    "The key point of building Bialowieza as a library rather than a complete +
+ + 003    application is that it should be possible to hook it up to multiple sources +
+ + 004    of knowledge. Thus we must design a protocol through which knowledge can be +
+ + 005    accessed, and a schema in which it will be returned. Note that the +
+ + 006    accessor must be able to add knowledge to the knowledge base, as well as +
+ + 007    retrieve it." +
+ + 008    (:require [wildwood.schema :refer [proposition?]])) +
+ + 009   +
+ + 010  (defprotocol Accessor +
+ + 011    (fetch [self id] +
+ + 012           "Fetch all the knowledge I have about the object identified by +
+ + 013           this `id` value, as a map whose `:id` key has this `id` value. +
+ + 014   +
+ + 015           *NOTE THAT:* I now think knowledge should only be managed at the +
+ + 016           Wildwood level as sets of propositions, so the idea of bringing +
+ + 017           back some sort of object representation here is probably wrong.") +
+ + 018    (match [self proposition] +
+ + 019           "Return all the propositions I know which match this proposition. The +
+ + 020           intended use case here is that you will either supply a fully +
+ + 021           specified proposition to verify that that proposition is true, or else +
+ + 022           supply a partially specified proposition to query. +
+ + 023   +
+ + 024           e.g. passing the proposition +
+ + 025   +
+ + 026               {:verb :kill :object :caesar} +
+ + 027   +
+ + 028           would be a way of asking 'who killed caesar', and might return +
+ + 029   +
+ + 030               [{:verb :kill :subject :brutus :object :caesar} +
+ + 031                {:verb :kill :subject :cassius :object :caesar} +
+ + 032                {:verb :kill :subject :longus :object :caesar}]") +
+ + 033    (store [self proposition] +
+ + 034           "Add this `proposition` to the knowledge I hold.")) +
+ + diff --git a/docs/cloverage/wildwood/mongo_ka.clj.html b/docs/cloverage/wildwood/mongo_ka.clj.html new file mode 100644 index 0000000..c8b4ebd --- /dev/null +++ b/docs/cloverage/wildwood/mongo_ka.clj.html @@ -0,0 +1,149 @@ + + + + wildwood/mongo_ka.clj + + + + 001  (ns wildwood.mongo-ka +
+ + 002    "A knowledge accessor fetching from and storing to Mongo DB. +
+ + 003   +
+ + 004    Hierarchical databases seem a very natural fit for how we're storing +
+ + 005    knowledge. Mongo DB seems a particularly natural fit since its +
+ + 006    internal representation is JSON, which can be transformed to EDN +
+ + 007    extremely naturally." +
+ + 008    (:require [monger.core :as mg] +
+ + 009              [monger.collection :as mc] +
+ + 010              [wildwood.knowledge-accessor :refer [Accessor]]) +
+ + 011    (:import [com.mongodb MongoOptions ServerAddress] +
+ + 012             [com.mongodb DB WriteConcern] +
+ + 013             [org.bson.types ObjectId])) +
+ + 014   +
+ + 015  ;; MongoDB data items are identified by ObjectId objects. In the retrieved +
+ + 016  ;; record from MongoDB, key value is the value of a keyword `:_id` I don't +
+ + 017  ;; think there's any *in principle* reason why we should not use these objects +
+ + 018  ;; as key values - they're presumably designed to be globally unique. +
+ + 019  ;; +
+ + 020  ;; In which case, on the way down we have to set `:_id` to the value of `:id` +
+ + 021  ;; and vice versa on the way back up. +
+ + 022   +
+ + 023  (defrecord MongoKA +
+ + 024    ;; It's not clear to me whether we need to pass both the connection and the +
+ + 025    ;; database in - it's possible that the connected database handle is +
+ + 026    ;; sufficient. The value of `:collection` is the name of the collection +
+ + 027    ;; within the database to which this accessor writes. +
+ + 028    [connection db ^String collection] +
+ + 029    Accessor +
+ + 030    (fetch +
+ + 031      [_ id] +
+ + 032      (let [oid (cond +
+ + 033                  (instance? ObjectId id) id +
+ + 034                  (string? id) (ObjectId. id) +
+ + 035                  (keyword? id) (ObjectId. (name id))) +
+ + 036            record (mc/find-by-id db collection oid)] +
+ + 037        (when record +
+ + 038          (assoc +
+ + 039            (dissoc record :_id) +
+ + 040            :id id)))) +
+ + 041    (match [_ proposition] +
+ + 042           ;; I know I've seen how to do this in the Mongo documentation... +
+ + 043           ) +
+ + 044    (store [_ proposition] +
+ + 045           ;; don't really know how to do this and am too tired just now. +
+ + 046           )) +
+ + 047   +
+ + diff --git a/docs/cloverage/wildwood/schema.clj.html b/docs/cloverage/wildwood/schema.clj.html new file mode 100644 index 0000000..293961d --- /dev/null +++ b/docs/cloverage/wildwood/schema.clj.html @@ -0,0 +1,395 @@ + + + + wildwood/schema.clj + + + + 001  (ns wildwood.schema +
+ + 002    "The knowledge representation. This probably ends up looking a bit like a +
+ + 003    Toulmin schema, where claims are represented as propositions. There also +
+ + 004    need to be rules or predicates, things which can test whether a given +
+ + 005    proposition has a given value. There may be other stuff in here. +
+ + 006   +
+ + 007    Internal representation of most of this will be as Clojure maps." +
+ + 008    ) +
+ + 009   +
+ + 010  (def required-keys +
+ + 011    "Every proposition is expected to have values for these keys." +
+ + 012    #{:verb :subject :object}) +
+ + 013   +
+ + 014  (def consensual-keys +
+ + 015    "Every proposition which has these keys, in a given decision process, +
+ + 016    must have the same semantics and types for their values. The exact +
+ + 017    representations used for the values of these keys does not +
+ + 018    matter, it is consensual between all participating advocates in a +
+ + 019    decision process." +
+ + 020    #{:time       ;; a representation of time - which should have a canonical ordering; +
+ + 021      :location   ;; a representation of place - which may have concepts of proximity; +
+ + 022      :truth      ;; if present and value `false`, negates the proposition; +
+ + 023      :data       ;; an argument structure...! +
+ + 024      }) +
+ + 025   +
+ + 026  (def argument-keys +
+ + 027    "Every argument is a proposition, which additionally has these keys." +
+ + 028    #{:confidence ;; how sure am I? A value, perhaps, in the range -1 to 1, although conventionally if less than 1 we probably set the `:truth` value to false; +
+ + 029      :authority  ;; id of agent from whom, or rule from which, I know this. +
+ + 030      }) +
+ + 031   +
+ + 032  (def preserved-keys +
+ + 033    "Keys whose values should not be minimised during proposition minimisation" +
+ + 034    ;; TODO: actually, this may end up being just :data +
+ + 035    (set (cons :data argument-keys))) +
+ + 036   +
+ + 037  (defn proposition? +
+ + 038    "True if `o` qualifies as a proposition. A proposition is probably a map +
+ + 039    with some privileged keys, and may look something like a minimised +
+ + 040    `the-great-game.gossip.news-items` item. +
+ + 041   +
+ + 042    If `minimised` is passed and is `true`, then the proposition must +
+ + 043    be minimised - that is to say, the values of keys in a proposition map may +
+ + 044    not themselves be keys. Where the value of a key represents an object in the +
+ + 045    world, that value must be simply the `id` of the object, not a richer +
+ + 046    representation." +
+ + 047    ([o] +
+ + 048     (and +
+ + 049       (map? o) +
+ + 050       (every? #(o %) required-keys))) +
+ + 051    ([o minimised] +
+ + 052     (and +
+ + 053       (proposition? o)) +
+ + 054     (not +
+ + 055       (when +
+ + 056         (true? minimised) +
+ + 057         ;; not good enough. An argument is a proposition even if its argument-keys +
+ + 058         ;; are not minimised (indeed, they should not be). TODO: fix. +
+ + 059         (some map? (vals o)))))) +
+ + 060   +
+ + 061  (defn truth +
+ + 062    "If `p` is a proposition, return whether the value asserted by that +
+ + 063    proposition is `true`. If the `:truth` key is missing, `true` is +
+ + 064    assumed." +
+ + 065    ;; TODO: for orthogonality, this might be renamed `decide`. +
+ + 066    [p] +
+ + 067    (if +
+ + 068      (proposition? p) +
+ + 069      (if +
+ + 070        (false? (:truth p)) +
+ + 071        false +
+ + 072        true) +
+ + 073      nil)) +
+ + 074   +
+ + 075  (defn rule? +
+ + 076    "True if `o` qualifies as a rule. A rule is a structure which comprises +
+ + 077    * an id and +
+ + 078    * a function of two arguments, a proposition and a knowledge accessor, +
+ + 079    and which should (if this can simply be checked) return an argument +
+ + 080    structure." +
+ + 081    [o] +
+ + 082    ;; TODO: write this. In practice it may be simpler if we defprotocol or +
+ + 083    ;; defrecord a rule structure. +
+ + 084    false) +
+ + 085   +
+ + 086  (defn argument? +
+ + 087    "True if `o` qualifies as an argument structure. +
+ + 088   +
+ + 089    An argument structure is a (potentially rich) proposition which, in addition, should have values +
+ + 090    for `:confidence` and `:authority`. A value for `:data` may, and probably will, +
+ + 091    also be present but is not required. The value of `:confidence` must be a number +
+ + 092    in the range -1 to 1." +
+ + 093    [o] +
+ + 094    (and +
+ + 095      (proposition? o) +
+ + 096      (every? #(o %) argument-keys) +
+ + 097      (number? (:confidence o)) +
+ + 098      (<= -1 (:confidence o) 1))) +
+ + 099   +
+ + 100  (set (cons :data argument-keys)) +
+ + 101   +
+ + 102  (defn minimise +
+ + 103    "Expecting that `o` is a (potentially rich) proposition, return a map identical +
+ + 104    to `o` save that for each value `v` of key `k` in `o`, if `v` is a map and `k` +
+ + 105    is not a member of `argument-keys`, then the returned map shall substitute the +
+ + 106    value of `(:id v)`. +
+ + 107   +
+ + 108    see also `wildwood.knowledge-access/maximise`." +
+ + 109    [o] +
+ + 110    (if +
+ + 111      (map? o) +
+ + 112      (reduce +
+ + 113        merge +
+ + 114        {} +
+ + 115        (map +
+ + 116          (fn [k] +
+ + 117            {k +
+ + 118             (let [v (k o)] +
+ + 119               (if +
+ + 120                 (and (not (preserved-keys k)) (map? v)) +
+ + 121                 (:id v) +
+ + 122                 v))}) +
+ + 123          (keys o))) +
+ + 124      o)) +
+ + 125   +
+ + 126  (proposition? +
+ + 127    (minimise {:verb :kill +
+ + 128               :subject {:id :brutus :name "Marcus Brutus"} +
+ + 129               :object {:id :caesar :name "Gaius Julius Caesar" :wife :drusila}})) +
+ + diff --git a/project.clj b/project.clj index d807b91..c363398 100644 --- a/project.clj +++ b/project.clj @@ -1,19 +1,21 @@ (defproject wildwood "0.1.0-SNAPSHOT" - :description "A general inference library using a game theoretic inference mechanism." - :url "http://example.com/FIXME" - :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" - :url "https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html"} - :dependencies [[org.clojure/clojure "1.8.0"] - [org.clojure/math.numeric-tower "0.0.4"] - [com.taoensso/timbre "4.10.0"] - [com.novemberain/monger "3.1.0"] - [prismatic/schema "1.1.12"]] + :cloverage {:output "docs/cloverage"} :codox {:metadata {:doc "**TODO**: write docs" :doc/format :markdown} :output-path "docs/codox" :source-uri "https://github.com/simon-brooke/the-great-game/blob/master/{filepath}#L{line}"} + :dependencies [[org.clojure/clojure "1.8.0"] + [org.clojure/math.numeric-tower "0.0.4"] + [com.taoensso/timbre "4.10.0"] + [com.novemberain/monger "3.1.0"] ;; not yet used + [prismatic/schema "1.1.12"]] ;; not yet used + :description "A general inference library using a game theoretic inference mechanism." + :license {:name "GNU General Public License,version 2.0 or (at your option) any later version" + :url "https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html"} :plugins [[lein-cloverage "1.1.1"] [lein-codox "0.10.7"] [lein-cucumber "1.0.2"] [lein-gorilla "0.4.0"]] - :repl-options {:init-ns wildwood.core}) + :repl-options {:init-ns wildwood.core} + :url "https://simon-brooke.github.io/wildwood/" + )