├── .circleci └── config.yml ├── .gitignore ├── AUTHORS ├── CMakeLists.txt ├── LICENSE ├── README.md ├── examples ├── CMakeLists.txt └── pln │ ├── README.md │ ├── amusing-friend │ ├── Amusing_Friend_PLN_Demo.html │ ├── README.md │ ├── amusing-friend-bc.scm │ ├── amusing-friend-fc-traces.scm │ ├── amusing-friend-fc.scm │ ├── amusing-friend-pm.scm │ ├── kb.scm │ ├── pln-bc-config.scm │ └── pln-config.scm │ ├── ancestors │ ├── README.md │ ├── ancestors.scm │ └── kb.scm │ ├── chicken-feet-or-pizza │ └── chicken-feet-or-pizza.scm │ ├── conjunction │ ├── README.md │ └── conjunction-rule-base-config.scm │ ├── crazy-happy │ ├── README.md │ └── crazy-happy.scm │ ├── good-songs │ ├── README.md │ ├── good-songs.scm │ └── kb.scm │ ├── inference-control-meta-learning │ ├── README.md │ ├── and-bit-prior.scm │ ├── distributed-inference-control-learning.md │ ├── icl-parameters.scm │ ├── icl-utilities.scm │ ├── icl.scm │ ├── icr-rb.scm │ ├── kb.scm │ ├── mine-control-rules.scm │ ├── mk-control-rules.scm │ ├── mk-history.scm │ ├── pln-rb.scm │ ├── ppc-kb.scm │ ├── ppc-rb.scm │ ├── preproof-expander-is-preproof.scm │ └── proof-is-preproof.scm │ ├── moses-pln-synergy │ ├── README.md │ ├── dataset.csv │ ├── haskell │ │ ├── BackgroundKnowledge.hs │ │ ├── MosesModel.hs │ │ ├── PlnRules.hs │ │ └── example_moses.hs │ ├── moses-cmd.sh │ └── scm │ │ ├── README.md │ │ ├── background-knowledge.scm │ │ ├── moses-model.scm │ │ ├── moses-pln-synergy-bc.scm │ │ ├── moses-pln-synergy-fc.scm │ │ ├── moses-pln-synergy-pm.scm │ │ ├── pln-bc-config.scm │ │ └── pln-fc-config.scm │ ├── propositional │ ├── README.md │ └── propositional-rule-base-config.scm │ ├── socrates │ ├── README.md │ ├── john-is-a-man-r2l-output.scm │ ├── men-breathe-air-r2l-output.scm │ └── socrates-pm.scm │ ├── sumo │ ├── README.md │ ├── pln-config1.scm │ ├── pln-config2.scm │ ├── pln-config3.scm │ ├── sumo-test1-bc.scm │ ├── sumo-test1-pm.scm │ ├── sumo-test2-bc.scm │ └── sumo-test3-bc.scm │ ├── universal-instantiation │ ├── README.md │ ├── kb.scm │ └── rb.scm │ └── which-product │ └── README.md ├── lib ├── CMakeLists.txt └── PLNConfig.cmake.in ├── opencog ├── CMakeLists.txt ├── README.md ├── cython │ ├── CMakeLists.txt │ ├── README.md │ └── opencog │ │ ├── CMakeLists.txt │ │ ├── __init__.py │ │ ├── pln.pyx │ │ └── pln_types.pyx ├── pln │ ├── CMakeLists.txt │ ├── README.md │ ├── facts │ │ └── junctor-lambda-distribution.scm │ ├── meta-rules │ │ ├── CMakeLists.txt │ │ └── predicate │ │ │ ├── CMakeLists.txt │ │ │ ├── conditional-partial-instantiation.scm │ │ │ ├── conditional-total-instantiation.scm │ │ │ └── universal-total-instantiation.scm │ ├── pln-config-deprecated.scm │ ├── pln-utils.scm │ ├── pln.scm │ ├── rules │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── extensional │ │ │ ├── CMakeLists.txt │ │ │ ├── concept-direct-evaluation.scm │ │ │ ├── conjunction-direct-introduction.scm │ │ │ ├── extensional-similarity-direct-introduction.scm │ │ │ ├── extensional-utils.scm │ │ │ ├── member-deduction.scm │ │ │ └── subset-direct-introduction.scm │ │ ├── intensional │ │ │ ├── CMakeLists.txt │ │ │ ├── attraction-introduction.scm │ │ │ ├── intensional-difference-direct-introduction.scm │ │ │ ├── intensional-difference-member-introduction.scm │ │ │ ├── intensional-inheritance-direct-introduction.scm │ │ │ └── intensional-similarity-direct-introduction.scm │ │ ├── predicate │ │ │ ├── CMakeLists.txt │ │ │ └── conditional-direct-evaluation.scm │ │ ├── propositional │ │ │ ├── CMakeLists.txt │ │ │ ├── consequent-disjunction-elimination.scm │ │ │ ├── contraposition.scm │ │ │ ├── crisp-conjunction-introduction.scm │ │ │ ├── formulas.scm │ │ │ ├── fuzzy-conjunction-introduction.scm │ │ │ ├── fuzzy-disjunction-introduction.scm │ │ │ └── modus-ponens.scm │ │ ├── temporal │ │ │ ├── CMakeLists.txt │ │ │ ├── back-predictive-implication-direct-evaluation.scm │ │ │ ├── back-predictive-implication-scope-conditional-conjunction-introduction.scm │ │ │ ├── back-predictive-implication-scope-deduction-cogscm.scm │ │ │ ├── back-predictive-implication-scope-direct-evaluation.scm │ │ │ ├── back-predictive-implication-scope-direct-introduction.scm │ │ │ ├── predictive-implication-direct-evaluation.scm │ │ │ ├── predictive-implication-scope-deduction.scm │ │ │ ├── predictive-implication-scope-direct-evaluation.scm │ │ │ ├── predictive-implication-scope-direct-introduction.scm │ │ │ ├── temporal-reasoning.md │ │ │ └── utils.scm │ │ ├── term │ │ │ ├── CMakeLists.txt │ │ │ ├── condition-negation.scm │ │ │ ├── deduction.scm │ │ │ ├── formulas.scm │ │ │ ├── full-deduction.scm │ │ │ └── present-deduction.scm │ │ └── wip │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── abduction.scm │ │ │ ├── and-as-1st-arg-inside-inheritance-link.scm │ │ │ ├── and-as-2nd-arg-inside-inheritance-link.scm │ │ │ ├── and-breakdown.scm │ │ │ ├── and-elimination.scm │ │ │ ├── and-evaluation.scm │ │ │ ├── and-introduction.scm │ │ │ ├── and-lambda-distribution.scm │ │ │ ├── and-lambda-factorization-double-implication.scm │ │ │ ├── and-simplification.scm │ │ │ ├── and-to-context.scm │ │ │ ├── and-to-subset-rule1.scm │ │ │ ├── and-to-subset-rulen.scm │ │ │ ├── and-transformation.scm │ │ │ ├── attraction.scm │ │ │ ├── closed-lambda-evaluation.scm │ │ │ ├── closed-lambda-introduction.scm │ │ │ ├── compile-rules.scm │ │ │ ├── context-free-to-sensitive.scm │ │ │ ├── contextualize.scm │ │ │ ├── decontextualize.scm │ │ │ ├── equivalence-scope-distribution.scm │ │ │ ├── equivalence-to-implication.scm │ │ │ ├── evaluation-implication.scm │ │ │ ├── evaluation-to-member.scm │ │ │ ├── extensional-similarity-evaluation.scm │ │ │ ├── forall-implication-to-higher-order.scm │ │ │ ├── forall-instantiation.scm │ │ │ ├── formulas.scm │ │ │ ├── implication-and-lambda-factorization.scm │ │ │ ├── implication-and.scm │ │ │ ├── implication-direct-evaluation.scm │ │ │ ├── implication-implicant-conjunction.scm │ │ │ ├── implication-implicant-disjunction.scm │ │ │ ├── implication-implicant-distribution.scm │ │ │ ├── implication-instantiation.scm │ │ │ ├── implication-introduction.scm │ │ │ ├── implication-scope-to-implication.scm │ │ │ ├── implication-to-implication-scope.scm │ │ │ ├── induction.scm │ │ │ ├── inheritance-to-member.scm │ │ │ ├── inheritance.scm │ │ │ ├── instantiation.scm │ │ │ ├── intensional-inheritance-evaluation.scm │ │ │ ├── intensional-similarity-evaluation.scm │ │ │ ├── inversion.scm │ │ │ ├── member-to-evaluation.scm │ │ │ ├── member-to-inheritance.scm │ │ │ ├── negated-subset-evaluation.scm │ │ │ ├── negation-introduction.scm │ │ │ ├── not-elimination.scm │ │ │ ├── not-introduction.scm │ │ │ ├── not-simplification.scm │ │ │ ├── ontological-inheritance.scm │ │ │ ├── or-breakdown.scm │ │ │ ├── or-elimination.scm │ │ │ ├── or-evaluation.scm │ │ │ ├── or-introduction.scm │ │ │ ├── or-simplification.scm │ │ │ ├── or-transformation.scm │ │ │ ├── precise-modus-ponens.scm │ │ │ ├── predicate-lambda-evaluation.scm │ │ │ ├── similarity.scm │ │ │ ├── subset-evaluation.scm │ │ │ ├── symmetric-modus-ponens.scm │ │ │ ├── temp-deduction.scm │ │ │ ├── term-probability.scm │ │ │ └── transitive-similarity.scm │ └── types │ │ ├── CMakeLists.txt │ │ ├── atom_types.script │ │ └── atom_types_init.cc └── torchpln │ ├── converter.py │ └── pln │ ├── __init__.py │ ├── common.py │ └── rules │ ├── __init__.py │ └── propositional │ ├── __init__.py │ ├── consequent-disjunction-elimination.scm │ ├── contraposition.scm │ ├── formulas.scm │ ├── fuzzy-conjunction-introduction.scm │ ├── fuzzy-disjunction-introduction.scm │ └── modus-ponens.scm └── tests ├── CMakeLists.txt ├── pln ├── CMakeLists.txt ├── MOSESPLNSynergyUTest.cxxtest ├── PLNUTest.cxxtest ├── TemporalReasoningUTest.cxxtest ├── modus-ponens-contraposition.scm └── rules │ ├── CMakeLists.txt │ ├── PLNRulesUTest.cxxtest │ ├── TemporalReasoningRulesUTest.cxxtest │ ├── complex-temporal-deduction-kb.scm │ ├── full-deduction-kb.scm │ ├── implication-direct-evaluation.scm │ ├── implication-extra-variables.scm │ ├── simple-assertions.scm │ ├── simple-consequent-disjunction-elimination.scm │ ├── simple-contraposition.scm │ ├── simple-equivalence.scm │ ├── simple-forall.scm │ ├── simple-implication-implicant-conjunction.scm │ ├── simple-implication-scope.scm │ ├── simple-implication.scm │ ├── simple-lambda.scm │ ├── simple-predicates.scm │ ├── simple-temporal-deduction-kb.scm │ └── temporal-conditional-conjunction.scm └── torchpln └── test.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.log 3 | .vagrant 4 | .DS_Store 5 | *.swp 6 | # chatscript files 7 | *.top 8 | 9 | # misc binaries 10 | bin 11 | bin-debug 12 | build 13 | build-debug 14 | opencog/cogserver/server/cogserver 15 | opencog/atomspace/type-definer 16 | opencog/persist/sniff 17 | examples/extending/derivedserver 18 | examples/hopfield/hopfield 19 | examples/server/derivedserver 20 | opencog/embodiment/DestinCudaAlt/bin/destin 21 | opencog/embodiment/DestinCudaAlt/bin/kerneltest 22 | 23 | # cmake 24 | CMakeCache.txt 25 | CMakeFiles 26 | Makefile 27 | cmake_install.cmake 28 | 29 | # ctest 30 | Testing/ 31 | DartTestfile.txt 32 | *UTest.cpp 33 | *UTest 34 | 35 | # cpack 36 | install_manifest.txt 37 | CPackConfig.cmake 38 | CPackSourceConfig.cmake 39 | _CPack_Packages/ 40 | *.tgz 41 | *.tar.gz 42 | *.tar.bz2 43 | 44 | # deb packaging 45 | build-stamp 46 | debian/files 47 | debian/libatomspace/ 48 | debian/libatomspace-dev/ 49 | debian/opencog-core/ 50 | debian/opencog-core-dev/ 51 | debian/opencog-dbg/ 52 | debian/opencog-server/ 53 | debian/opencog-server-dev/ 54 | debian/tmp/ 55 | 56 | # win32 57 | *.lib 58 | *.pdb 59 | *.exe* 60 | *.ilk 61 | *.dll* 62 | *.nmake 63 | CTestTestfile.cmake 64 | 65 | # CTAGS 66 | TAGS 67 | .TAGS 68 | tags 69 | .tags 70 | 71 | # GNU GLOBAL 72 | GPATH 73 | GRTAGS 74 | GSYMS 75 | GTAGS 76 | *.gch 77 | 78 | # quilt 79 | .pc 80 | patches 81 | 82 | cscope.out 83 | # opencog/embodiment/embodiment.conf 84 | # opencog/embodiment/dev_embodiment.conf 85 | 86 | # DeSTIN SWIG generated sources 87 | opencog/embodiment/DestinCuda/JavaDestin/gen_src/javadestin/* 88 | opencog/embodiment/DestinCuda/DestinKernelJAVA_wrap.* 89 | 90 | # Python bytecode 91 | *.pyc 92 | *.pyo 93 | 94 | # ~ 95 | *.py~ 96 | 97 | # ide 98 | .idea 99 | 100 | # Haskell stuff 101 | *.so 102 | .stack-work 103 | a.out 104 | 105 | # Generated by http://gitignore.io 106 | # Qt-es 107 | CMakeLists.txt.user 108 | *.pro.user 109 | *.pro.user.* 110 | moc_*.cpp 111 | qrc_*.cpp 112 | ui_*.h 113 | Makefile 114 | *-build-* 115 | 116 | # Eclipse 117 | .cproject 118 | .project 119 | .settings/ 120 | 121 | ### Linux ### 122 | *~ 123 | *.autosave 124 | 125 | .vscode/ 126 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | @author Ben Goertzel 2 | @author Cassio Pennachin 3 | @author Murilo Saraiva de Queiroz 4 | @author Linas Vepstas 5 | @author Nil Geisweiller 6 | @author Joel Pitt 7 | @author Andre Senna 8 | @author Jared Wigmore 9 | @author Zhenhua Cai 10 | @author Troy Huang 11 | @author Shujing Ke 12 | @author Ruiting Lian 13 | @author Lake Watkins 14 | @author Alex van der Peet 15 | @author max willis 16 | @author Scott Jones 17 | @author Carlos Lopes 18 | @author Fabricio Silva 19 | @author Gustavo Gama 20 | @author Moshe Looks 21 | @author Ari Heljakka 22 | @author Rodrigo Barra 23 | @author Thiago Maia 24 | @author Tony Lofthouse 25 | @author Trent Waddington 26 | @author Welter Silva 27 | @author Samir Araujo 28 | @author Keyvan Mir Mohammad Sadeghi 29 | @author Hedra S. Yusuf 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Probabilistic Logic Network 2 | 3 | opencog | singnet 4 | ------- | ------- 5 | [![CircleCI](https://circleci.com/gh/opencog/pln.svg?style=svg)](https://circleci.com/gh/opencog/pln) | [![CircleCI](https://circleci.com/gh/singnet/pln.svg?style=svg)](https://circleci.com/gh/singnet/pln) 6 | 7 | Probabilistic Logic Network, or PLN for short, is a logic invented by 8 | Ben Goertzel et al [1] for common sense reasoning. It is particularily 9 | well suited for uncertain reasoning, especially when knowledge is 10 | based on limited observations from reality, but can also handle 11 | abstract mathematical reasoning, and the relationship between the two. 12 | 13 | To handle uncertainty PLN represents truth as a second order 14 | distribution, i.e. a probabilistic distribution over probabilistic 15 | distributions. Doing so allows to capture uncertainty while remaining 16 | in the well known and proven framework of probability theory. 17 | 18 | # This version of PLN is no longer maintained 19 | 20 | Effort has been shifted to [Hyperon PLN](https://github.com/trueagi-io/hyperon-pln). 21 | 22 | ## Building and Installing 23 | 24 | ### Prequisite 25 | 26 | * Build and install [Unified Rule Engine](https://github.com/opencog/ure) 27 | 28 | ### Building PLN 29 | 30 | ```bash 31 | # Download PLN 32 | git clone https://github.com/opencog/pln.git 33 | 34 | # Move to its project folder 35 | cd pln 36 | 37 | # Build with CMake 38 | mkdir build 39 | cd build 40 | cmake .. 41 | make -j 42 | ``` 43 | 44 | ### Installing PLN 45 | 46 | After building, you must install PLN 47 | 48 | ```bash 49 | sudo make install 50 | ``` 51 | 52 | Running `ldconfig` might required as well 53 | 54 | ```bash 55 | ldconfig /usr/local/lib/opencog 56 | ``` 57 | 58 | Usage 59 | ----- 60 | 61 | The easiest way to use PLN is via its scheme bindings. For that enter 62 | 63 | ```bash 64 | guile 65 | ``` 66 | 67 | load the PLN module 68 | 69 | ```scheme 70 | (use-modules (opencog pln)) 71 | ``` 72 | 73 | then load PLN rules with functions `pln-load`, and run the forward and 74 | backward chainers with `pln-fc` and `pln-bc`. More help can be found in 75 | guile's online help `(help pln-load)`, `(help pln-fc)` and `(help pln-bc)`. 76 | 77 | More usage information can be found in 78 | 79 | [opencog/pln/README.md](opencog/pln/README.md) 80 | 81 | Examples 82 | -------- 83 | 84 | PLN examples can be found under the [examples/pln](examples/pln) 85 | directory. In particular the following examples use the `pln` module 86 | 87 | 88 | * [examples/pln/ancestors](examples/pln/ancestors) 89 | * [examples/pln/good-songs](examples/pln/good-songs) 90 | 91 | The other examples can be informative but directly use the URE and 92 | thus are less user friendly. 93 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Empty .... 2 | -------------------------------------------------------------------------------- /examples/pln/README.md: -------------------------------------------------------------------------------- 1 | Collection of PLN examples. 2 | 3 | Only 2 examples 4 | 5 | [ancestors](ancestors) 6 | [good-songs](good-songs) 7 | 8 | use the new PLN API and thus should be looked at first. 9 | 10 | The other examples are also informative, just keep in mind that they 11 | use an old more convoluted API. 12 | -------------------------------------------------------------------------------- /examples/pln/amusing-friend/README.md: -------------------------------------------------------------------------------- 1 | Amusing honest friend 2 | ===================== 3 | 4 | **Warning:** this example does not use the new PLN API and thus is not 5 | recommanded for new users. 6 | 7 | PLN demo involving deductive and abductive reasoning. Self is looking 8 | for an amusing honest friend and infers that Bob would be one based on 9 | his actions and the fact that friends tend to be honest (that's the 10 | abductive part). 11 | 12 | Step-by-step 13 | ------------ 14 | 15 | To run the inference step by step using the pattern matcher only, load 16 | of paste each step in you guile shell from the following file 17 | 18 | ``` 19 | amusing-friend-pm.scm 20 | ``` 21 | 22 | each step is detailed here. 23 | 24 | Forward Chainer 25 | --------------- 26 | 27 | To run the inference using the forward chainer, load the following in 28 | your guile shell 29 | 30 | ```scheme 31 | (load "amusing-friend-fc.scm") 32 | ``` 33 | 34 | Once the inference is complete (a few hours) you may query each step 35 | as explained in the file 36 | 37 | ``` 38 | amusing-friend-fc-traces.scm 39 | ``` 40 | 41 | Inference Chain Documentation 42 | ----------------------------- 43 | 44 | The file Amusing_Friend_PLN_Demo.html documents the inference chain 45 | steps of the demo. The file can be opened in a web browser. Detail 46 | information about the PLN rules and Atomese involved at each step can be 47 | displayed by expanding the step panel sections. 48 | -------------------------------------------------------------------------------- /examples/pln/amusing-friend/amusing-friend-fc.scm: -------------------------------------------------------------------------------- 1 | ;; Like moses-pln-synergy-pm.scm but this version relies on the 2 | ;; forward chainer. 3 | 4 | (use-modules (opencog ure)) 5 | 6 | ;; Set logger to DEBUG 7 | ;; (ure-logger-set-sync! #t) 8 | ;; (ure-logger-set-stdout! #t) 9 | (ure-logger-set-level! "debug") 10 | 11 | ;; Load the background knowledge 12 | (load "kb.scm") 13 | 14 | ;; Load the PLN configuration for this demo 15 | (load "pln-config.scm") 16 | 17 | (pln-fc (SetLink people-telling-the-truth-are-honest 18 | friends-tend-to-be-honest 19 | human-acquainted-tend-to-become-friends 20 | people-telling-jokes-are-funny 21 | funny-is-loosely-equivalent-to-amusing)) 22 | -------------------------------------------------------------------------------- /examples/pln/ancestors/README.md: -------------------------------------------------------------------------------- 1 | # Deduction 2 | 3 | Simple PLN demo to show how to reason about the transitivity of 4 | inheritance links. 5 | 6 | ## Usage 7 | 8 | ```bash 9 | guile -l ancestors.scm 10 | ``` 11 | 12 | The ancestors should be stored in `ancestors` variable 13 | 14 | ```scheme 15 | ancestors 16 | ``` 17 | 18 | which should contain the following 19 | 20 | ```scheme 21 | (SetLink 22 | (ConceptNode "B") 23 | (ConceptNode "D") 24 | (ConceptNode "F") 25 | (ConceptNode "C") 26 | ) 27 | ``` 28 | -------------------------------------------------------------------------------- /examples/pln/ancestors/ancestors.scm: -------------------------------------------------------------------------------- 1 | ;; Load PLN (with only the rule that matters) 2 | (use-modules (opencog pln)) 3 | (pln-load-rule 'inheritance-present-deduction) 4 | 5 | ;; Load KB 6 | (load "kb.scm") 7 | 8 | ;; Build query to find all ancestors of A (according to inheritance) 9 | (define A (Concept "A")) 10 | (define X (Variable "$X")) 11 | (define vardecl (TypedVariable X (Type "ConceptNode"))) 12 | (define AX (Inheritance A X)) 13 | 14 | ;; Call forward chainer on the query 15 | (define fcresults (pln-fc AX #:vardecl vardecl)) 16 | 17 | ;; Get all ancestors 18 | (define ancestors (cog-execute! (Get vardecl AX))) 19 | -------------------------------------------------------------------------------- /examples/pln/ancestors/kb.scm: -------------------------------------------------------------------------------- 1 | ;; Simple inheritance relationships from issue 2 | ;; https://github.com/opencog/atomspace/issues/2472 3 | 4 | (Inheritance 5 | (Concept "A") 6 | (Concept "B") 7 | ) 8 | 9 | (Inheritance 10 | (Concept "B") 11 | (Concept "C") 12 | ) 13 | 14 | (Inheritance 15 | (Concept "B") 16 | (Concept "F") 17 | ) 18 | 19 | (Inheritance 20 | (Concept "C") 21 | (Concept "D") 22 | ) 23 | -------------------------------------------------------------------------------- /examples/pln/conjunction/README.md: -------------------------------------------------------------------------------- 1 | Conjunction 2 | =========== 3 | 4 | **Warning:** this example does not use the new PLN API and thus is not 5 | recommanded for new users. 6 | 7 | Simple example showing how to calculate the TV of a conjunction using 8 | the backward chainer. 9 | 10 | Usage 11 | ----- 12 | 13 | Load the conjunction rule base in the guile interpreter: 14 | 15 | ```bash 16 | $ guile -l conjunction-rule-base-config.scm 17 | ``` 18 | 19 | Optionally, set the log level to debug (can be insightful to read): 20 | 21 | ```scheme 22 | (ure-logger-set-level! "debug") 23 | ``` 24 | 25 | Define a conjunction to evaluate: 26 | 27 | ```scheme 28 | (define P (Predicate "P")) 29 | (define A (Concept "A")) 30 | (define B (Concept "B")) 31 | (define PA (Evaluation (stv 0.5 0.8) P A)) 32 | (define PB (Evaluation (stv 0.3 0.9) P B)) 33 | (define PAPB (And PA PB)) 34 | ``` 35 | 36 | As you see simple TVs have been assigned to PA and PB but not to its 37 | conjunction. By default a simple TV with null confidence (equivalent 38 | to total ignorance) is assigned. Now let's call the backward chainer 39 | on the conjunction to evaluate its TV: 40 | 41 | ```scheme 42 | (conj-bc PAPB) 43 | ``` 44 | 45 | You should get something 46 | 47 | ```scheme 48 | $2 = (SetLink 49 | (AndLink (stv 0.3 0.8) 50 | (EvaluationLink (stv 0.3 0.9) 51 | (PredicateNode "P") 52 | (ConceptNode "B") 53 | ) 54 | (EvaluationLink (stv 0.5 0.8) 55 | (PredicateNode "P") 56 | (ConceptNode "A") 57 | ) 58 | ) 59 | ) 60 | ``` 61 | -------------------------------------------------------------------------------- /examples/pln/conjunction/conjunction-rule-base-config.scm: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; URE Configuration file for a mere fuzzy conjunction rule 3 | ;; 4 | ;; Before running any PLN inference you must load that file in the 5 | ;; AtomSpace 6 | 7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 8 | ;; Load required modules and utils ;; 9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 10 | 11 | (use-modules (opencog)) 12 | (use-modules (opencog ure)) 13 | 14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 15 | ;; Define a rule-based system ;; 16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 17 | 18 | (define conjunction-rule-base (ConceptNode "conjunction-rule-base")) 19 | 20 | ;; Define conj-bc for convenience 21 | (define (conj-bc target) (cog-bc conjunction-rule-base target)) 22 | 23 | ;;;;;;;;;;;;;;;; 24 | ;; Load rules ;; 25 | ;;;;;;;;;;;;;;;; 26 | 27 | ;; Load the fuzzy conjunction rule 28 | (add-to-load-path "../../../opencog/pln/rules") 29 | (load-from-path "propositional/fuzzy-conjunction-introduction.scm") 30 | 31 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32 | ;; Associate rules to the conjunction rule base ;; 33 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 34 | 35 | ; List the rules 36 | (define rules 37 | (list 38 | fuzzy-conjunction-introduction-1ary-rule-name 39 | fuzzy-conjunction-introduction-2ary-rule-name 40 | fuzzy-conjunction-introduction-3ary-rule-name 41 | fuzzy-conjunction-introduction-4ary-rule-name 42 | fuzzy-conjunction-introduction-5ary-rule-name 43 | ) 44 | ) 45 | ;; Associate rules to the conjunction rule base 46 | (ure-add-rules conjunction-rule-base rules) 47 | 48 | ;;;;;;;;;;;;;;;;;;;;;; 49 | ;; Other parameters ;; 50 | ;;;;;;;;;;;;;;;;;;;;;; 51 | 52 | ;; Termination criteria parameters. Two iterations are needed, one for 53 | ;; initializing the BIT, the other to calculate the conjunction. 54 | (ure-set-num-parameter conjunction-rule-base "URE:maximum-iterations" 2) 55 | -------------------------------------------------------------------------------- /examples/pln/crazy-happy/README.md: -------------------------------------------------------------------------------- 1 | Status: broken, chatbot needs to be reconfigured 2 | 3 | Abduction reasoning based on NLP knowledge. Given the sentences 4 | 5 | Ben is happy 6 | Ben is crazy 7 | 8 | Perform abductive reasoning to come up with the implication 9 | 10 | Crazy people are happy. 11 | -------------------------------------------------------------------------------- /examples/pln/good-songs/README.md: -------------------------------------------------------------------------------- 1 | # Good Songs 2 | 3 | The problem is simple, infer preferences about songs given that people 4 | tend to like songs from the same authors. 5 | 6 | # Usage 7 | 8 | ```bash 9 | guile -l good-songs.scm 10 | ``` 11 | 12 | Results should be stored in 13 | 14 | ```scheme 15 | fc-results 16 | ``` 17 | 18 | which should include, among others, 19 | 20 | ```scheme 21 | (EvaluationLink (stv 0.9 0.5625) 22 | (PredicateNode "like") 23 | (ListLink 24 | (ConceptNode "Marry") 25 | (ConceptNode "Dextrose is my bitch"))) 26 | ``` 27 | 28 | Because Marry likes a song from the same author. 29 | -------------------------------------------------------------------------------- /examples/pln/good-songs/good-songs.scm: -------------------------------------------------------------------------------- 1 | ;; Load PLN 2 | (use-modules (opencog pln)) 3 | (pln-load-rule 'fuzzy-conjunction-introduction-2ary) 4 | (pln-load-rule 'conditional-total-instantiation-implication-scope-meta) 5 | 6 | (use-modules (opencog logger)) 7 | (use-modules (opencog ure)) 8 | ;; (cog-logger-set-level! "fine") 9 | (ure-logger-set-level! "debug") 10 | 11 | ;; Load KB 12 | (load "kb.scm") 13 | 14 | ;; What does Marry like? 15 | (define what (Variable "$what")) 16 | (define vardecl (TypedVariable what (Type "ConceptNode"))) 17 | (define sources (Set 18 | song-3-composed-by-author-2 19 | marry-like-song-3 20 | listener-like-song-from-same-author)) 21 | (define target (Evaluation like (List marry what))) 22 | 23 | ;; Call forward chainer 24 | ;; 25 | ;; fc-results includes, among others, 26 | ;; 27 | ;; (EvaluationLink (stv 0.9 0.5625) 28 | ;; (PredicateNode "like") 29 | ;; (ListLink 30 | ;; (ConceptNode "Marry") 31 | ;; (ConceptNode "Dextrose is my bitch"))) 32 | ;; 33 | ;; Because Marry likes a song from the same author 34 | (define fc-results 35 | (pln-fc sources #:maximum-iterations 20 #:fc-retry-exhausted-sources #t)) 36 | 37 | ;; Call backward chainer 38 | ;; 39 | ;; The following does not work due to the lack of full support of 40 | ;; meta-rule in backward chainer. 41 | ;; 42 | ;; (pln-bc target #:vardecl vardecl #:maximum-iterations 1000) 43 | -------------------------------------------------------------------------------- /examples/pln/good-songs/kb.scm: -------------------------------------------------------------------------------- 1 | ;; Authors 2 | 3 | (define author-1 (Concept "Metal Head")) 4 | (define author-2 (Concept "Electronic Kundalini")) 5 | (define author-3 (Concept "The Underground Aliens")) 6 | 7 | ;; Songs 8 | 9 | (define song-1 (Concept "Dust or bust")) 10 | (define song-2 (Concept "From harmony to noise and back")) 11 | (define song-3 (Concept "The multiverse within")) 12 | (define song-4 (Concept "Dextrose is my bitch")) 13 | (define song-5 (Concept "I cannot wait to see you with my six eyes")) 14 | (define song-6 (Concept "Symphony of a multidimensional time")) 15 | 16 | ;; Listeners 17 | 18 | (define john (Concept "John")) 19 | (define marry (Concept "Marry")) 20 | 21 | ;; Authoring 22 | 23 | (define composed-by (Predicate "composed-by")) 24 | 25 | (define song-1-composed-by-author-1 26 | (Evaluation (stv 1 1) composed-by (List song-1 author-1))) 27 | (define song-2-composed-by-author-1 28 | (Evaluation (stv 1 1) composed-by (List song-2 author-1))) 29 | (define song-3-composed-by-author-2 30 | (Evaluation (stv 1 1) composed-by (List song-3 author-2))) 31 | (define song-4-composed-by-author-2 32 | (Evaluation (stv 1 1) composed-by (List song-4 author-2))) 33 | (define song-5-composed-by-author-3 34 | (Evaluation (stv 1 1) composed-by (List song-5 author-3))) 35 | (define song-6-composed-by-author-3 36 | (Evaluation (stv 1 1) composed-by (List song-6 author-3))) 37 | 38 | ;; Listener's preferences 39 | 40 | (define like (Predicate "like")) 41 | 42 | (define john-like-song-2 43 | (Evaluation (stv 1 1) like (List john song-2))) 44 | (define marry-like-song-3 45 | (Evaluation (stv 1 1) like (List marry song-3))) 46 | (define marry-like-song-6 47 | (Evaluation (stv 1 1) like (List marry song-6))) 48 | 49 | ;; If listener L likes song S from author A, then L is likely to like 50 | ;; other songs from A 51 | 52 | (define L (Variable "$listener")) 53 | (define S (Variable "$song")) 54 | (define OS (Variable "$other-song")) 55 | (define A (Variable "$author")) 56 | (define ct (Type "ConceptNode")) 57 | 58 | (define listener-like-song-from-same-author 59 | (ImplicationScope (stv 0.9 1) 60 | (VariableList 61 | (TypedVariable L ct) 62 | (TypedVariable S ct) 63 | (TypedVariable A ct)) 64 | (And 65 | (Evaluation like (List L S)) 66 | (Evaluation composed-by (List S A))) 67 | (ImplicationScope 68 | (TypedVariable OS ct) 69 | (Evaluation composed-by (List OS A)) 70 | (Evaluation like (List L OS))))) 71 | -------------------------------------------------------------------------------- /examples/pln/inference-control-meta-learning/icl-parameters.scm: -------------------------------------------------------------------------------- 1 | ;; Set global parameters 2 | 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | ;; Problem set size (number of problems to solve per iteration) ;; 5 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6 | 7 | ;; (define pss 100) ;; That one may crash guile with "Too many root sets" 8 | (define pss 50) 9 | ;; (define pss 20) 10 | ;; (define pss 10) 11 | ;; (define pss 5) 12 | ;; (define pss 2) 13 | ;; (define pss 1) 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Number of iterations (learning + meta-learning) ;; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | (define niter 2) 20 | ;; (define niter 1) 21 | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 23 | ;; Number of iterations used to solve for each problem ;; 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 25 | 26 | (define piter 20) 27 | ;; (define piter 10) 28 | ;; (define piter 2) 29 | 30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 31 | ;; Minimum support for mining control rule patterns ;; 32 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 33 | 34 | (define minsup 3) 35 | ;; (define minsup 1) 36 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 37 | ;; Number of iterations to mine each inference rule for control rules ;; 38 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 39 | 40 | (define miter 200) 41 | ;; (define miter 1) 42 | -------------------------------------------------------------------------------- /examples/pln/inference-control-meta-learning/icr-rb.scm: -------------------------------------------------------------------------------- 1 | ;; URE Configuration file for producing Inference Control Rules 2 | 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | ;; Load required modules and utils ;; 5 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6 | 7 | (use-modules (opencog)) 8 | (use-modules (opencog ure)) 9 | 10 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 11 | ;; Define inference control rule-base system ;; 12 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 13 | 14 | ;; Define icr-bc to evaluation inference control rule implication 15 | ;; scope link based on evidence 16 | (define icr-rb (ConceptNode "icr-rb")) 17 | (define (icr-bc . args) 18 | (apply cog-bc (cons icr-rb args))) 19 | 20 | ;; Define pre-processing rule-base to produce antecedants then used by 21 | ;; icr-rb 22 | (define pp-icr-rb (ConceptNode "pp-icr-rb")) 23 | (define (pp-icr-bc . args) 24 | (apply cog-bc (cons pp-icr-rb args))) 25 | 26 | ;;;;;;;;;;;;;;;; 27 | ;; Load rules ;; 28 | ;;;;;;;;;;;;;;;; 29 | 30 | ;; Load the rules. Either w.r.t this file path 31 | (add-to-load-path "../../../opencog/pln/") 32 | 33 | (define rule-filenames 34 | (list "rules/predicate/conditional-direct-evaluation.scm" 35 | "rules/propositional/crisp-conjunction-introduction.scm")) 36 | (for-each load-from-path rule-filenames) 37 | 38 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 39 | ;; Associate rules to rule bases ;; 40 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 41 | 42 | (ure-add-rule icr-rb conditional-direct-evaluation-implication-scope-rule-name) 43 | (ure-add-rule pp-icr-rb true-conjunction-introduction-2ary-rule-name) 44 | 45 | ;;;;;;;;;;;;;;;;;;;;;; 46 | ;; Other parameters ;; 47 | ;;;;;;;;;;;;;;;;;;;;;; 48 | 49 | (ure-set-num-parameter icr-rb "URE:maximum-iterations" 2) 50 | (ure-set-num-parameter pp-icr-rb "URE:maximum-iterations" 2) 51 | -------------------------------------------------------------------------------- /examples/pln/inference-control-meta-learning/ppc-kb.scm: -------------------------------------------------------------------------------- 1 | ;; Knowledge-base about preproof and anything else we need to 2 | ;; post-process the trace atomspace before handing it to the process 3 | ;; in charge of producing inference control rules. ppc stands for 4 | ;; post-process corpus. 5 | ;; 6 | ;; Actually these are moved in there own files, namely, 7 | ;; and-bit-prior.scm, proof-is-preproof.scm and 8 | ;; preproof-expander-is-preproof to be processed individually as to 9 | ;; speed up ppc inferences. 10 | -------------------------------------------------------------------------------- /examples/pln/inference-control-meta-learning/ppc-rb.scm: -------------------------------------------------------------------------------- 1 | ;; URE Configuration file for post-processing inference traces to 2 | ;; produce an inference history corpus. 3 | 4 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 5 | ;; Load required modules and utils ;; 6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 7 | 8 | (use-modules (opencog)) 9 | (use-modules (opencog ure)) 10 | 11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 12 | ;; Define post-process corpus rule-base system ;; 13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 | 15 | (define ppc-rbs (ConceptNode "post-process-corpus-rule-base")) 16 | 17 | ;; Define ppc-bc for convenience 18 | (define (ppc-bc . args) 19 | (apply cog-bc (cons ppc-rbs args))) 20 | 21 | ;;;;;;;;;;;;;;;; 22 | ;; Load rules ;; 23 | ;;;;;;;;;;;;;;;; 24 | 25 | ;; Load the rules. Either w.r.t this file path 26 | (add-to-load-path "../../../opencog/pln/") 27 | 28 | (define rule-filenames 29 | (list "meta-rules/predicate/conditional-total-instantiation.scm" 30 | "rules/propositional/fuzzy-conjunction-introduction.scm" 31 | ) 32 | ) 33 | (for-each load-from-path rule-filenames) 34 | 35 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 36 | ;; Associate rules to PLN ;; 37 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 38 | 39 | ;; List the rules 40 | (define rules 41 | (list 42 | conditional-total-instantiation-implication-scope-meta-rule-name 43 | fuzzy-conjunction-introduction-2ary-rule-name 44 | ) 45 | ) 46 | 47 | ;; Associate rules to ppc 48 | (ure-add-rules ppc-rbs rules) 49 | 50 | ;;;;;;;;;;;;;;;;;;;;;; 51 | ;; Other parameters ;; 52 | ;;;;;;;;;;;;;;;;;;;;;; 53 | 54 | ;; Termination criteria parameters 55 | (ure-set-num-parameter ppc-rbs "URE:maximum-iterations" 100) 56 | -------------------------------------------------------------------------------- /examples/pln/inference-control-meta-learning/proof-is-preproof.scm: -------------------------------------------------------------------------------- 1 | ;; 2. If and-BIT A is a proof of target T, then it is a preproof of 2 | ;; target T as well. 3 | ;; 4 | ;; Implication <1 1> 5 | ;; Predicate "URE:BC:proof-of" 6 | ;; Predicate "URE:BC:preproof-of" 7 | (define proof-is-preproof 8 | (Implication (stv 1 1) 9 | (Predicate "URE:BC:proof-of") 10 | (Predicate "URE:BC:preproof-of"))) 11 | 12 | ;; Load conditional-total-instantiation-implication-meta-rule 13 | (add-to-load-path "../../../opencog/pln/") 14 | (load-from-path "meta-rules/predicate/conditional-total-instantiation.scm") 15 | 16 | ;; Turn proof-is-preproof into a rule 17 | (define proof-is-preproof-rule 18 | (car (apply-rule conditional-total-instantiation-implication-meta-rule 19 | proof-is-preproof))) 20 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/README.md: -------------------------------------------------------------------------------- 1 | # MOSES PLN synergy demo 2 | 3 | **Warning:** this example does not use the new PLN API and thus is not 4 | recommanded for new users. 5 | 6 | Simple demo showing how PLN reasoning can be used to overcome the 7 | uncertainties resulting from the low number of samples during 8 | learning. 9 | 10 | # Content 11 | 12 | This demo exists in 2 binding languages 13 | 1. Scheme, under the scm sub-directory, 14 | 2. Haskell, under the haskell sub-directory (unmaintained). 15 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/dataset.csv: -------------------------------------------------------------------------------- 1 | take-treatment-1,take-treatment-2,eat-lots-fruits-vegetables,recovery-speed-of-injury-alpha 2 | 0,1,1,0 3 | 0,1,1,1 4 | 1,0,0,1 5 | 0,1,1,1 6 | 1,0,0,1 7 | 1,0,1,1 8 | 0,1,0,0 9 | 1,0,1,1 10 | 0,1,0,0 11 | 1,0,1,1 12 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/haskell/MosesModel.hs: -------------------------------------------------------------------------------- 1 | -- GSoC 2015 - Haskell bindings for OpenCog. 2 | {-# LANGUAGE DataKinds #-} 3 | 4 | module MosesModel (mosesModel) where 5 | 6 | import OpenCog.AtomSpace (Atom(..),AtomType(ImplicationT),stv,noTv,(|>),(\>)) 7 | 8 | mosesModel :: Atom ImplicationT 9 | mosesModel = ImplicationLink (stv 0.875 0.44) 10 | (OrLink noTv 11 | |> PredicateNode "take-treatment-1" noTv 12 | \> PredicateNode "eat-lots-fruits-vegetables" noTv 13 | ) 14 | (PredicateNode "recovery-speed-of-injury-alpha" noTv) 15 | 16 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/haskell/example_moses.hs: -------------------------------------------------------------------------------- 1 | -- GSoC 2015 - Haskell bindings for OpenCog. 2 | 3 | -- | Simple example on using Haskell bindings and the Pattern Matcher. 4 | -- (Following this example: https://github.com/ngeiswei/moses-pln-example) 5 | import OpenCog.AtomSpace (Atom(..),AtomGen(..),AtomSpace,appGen,cogBind, 6 | runOnNewAtomSpace,get,insert,remove,debug, 7 | printAtom,AtomType(..),noTv,stv,(|>),(\>)) 8 | import Control.Monad.IO.Class (liftIO) 9 | import BackgroundKnowledge (bkn) 10 | import PlnRules (plnRuleForAllHack 11 | ,plnRuleEliminateNeutralElementHack 12 | ,plnRuleEliminateDanglingJunctorHack 13 | ,plnRuleEquivalenceHack 14 | ,plnRuleAverageHack) 15 | import MosesModel (mosesModel) 16 | 17 | main :: IO () 18 | main = let insertGen :: AtomGen -> AtomSpace () 19 | insertGen = appGen insert 20 | printGen :: AtomGen -> IO () 21 | printGen = appGen printAtom 22 | showRes :: Maybe AtomGen -> AtomSpace () 23 | showRes at = liftIO $ do 24 | putStrLn "Res:" 25 | case at of 26 | Nothing -> print at 27 | Just at -> printGen at 28 | in runOnNewAtomSpace $ do 29 | mapM_ insertGen bkn 30 | insert mosesModel 31 | insert plnRuleForAllHack 32 | insert plnRuleEliminateNeutralElementHack 33 | insert plnRuleEliminateDanglingJunctorHack 34 | insert plnRuleEquivalenceHack 35 | insert plnRuleAverageHack 36 | 37 | res1 <- cogBind plnRuleForAllHack 38 | res2 <- cogBind plnRuleEliminateNeutralElementHack 39 | res3 <- cogBind plnRuleEliminateDanglingJunctorHack 40 | res4 <- cogBind plnRuleEquivalenceHack 41 | res5 <- cogBind plnRuleAverageHack 42 | 43 | mapM_ showRes [res1,res2,res3,res4,res5] 44 | 45 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/moses-cmd.sh: -------------------------------------------------------------------------------- 1 | moses \ 2 | --input-file dataset.csv \ 3 | --target-feature recovery-speed-of-injury-alpha \ 4 | --output-with-labels 1 \ 5 | --problem pre \ 6 | -q 0.7 \ 7 | -p 0.5 \ 8 | --result-count 1 \ 9 | --output-format scheme 10 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/scm/moses-model.scm: -------------------------------------------------------------------------------- 1 | ; MOSES model gotten from 2 | ; 3 | ; moses -i dataset.csv -u recovery-speed-of-injury-alpha -W 1 -Hpre -q0.7 -p0.5 -c 1 --output-format scheme 4 | ; 5 | ; Wrapped in an ImplicationLink to relate models and target feature + 6 | ; confidence. The confidence is obtained with the formula N / (N+K) 7 | ; where N = 8, the number of entries in dataset.csv satisfying the 8 | ; model, K=800. 9 | 10 | (define moses-model 11 | (ImplicationLink (stv 0.875 0.0099) 12 | (OrLink 13 | (PredicateNode "take-treatment-1") 14 | (PredicateNode "eat-lots-fruits-vegetables") 15 | ) 16 | (PredicateNode "recovery-speed-of-injury-alpha") 17 | ) 18 | ) 19 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/scm/moses-pln-synergy-fc.scm: -------------------------------------------------------------------------------- 1 | ;; Like moses-pln-synergy-pm.scm but this version relies on the 2 | ;; forward chainer. 3 | 4 | ;; Set logger to DEBUG 5 | ;; (ure-logger-set-sync! #t) 6 | ;; (ure-logger-set-stdout! #t) 7 | ;; (ure-logger-set-level! "debug") 8 | 9 | ;; Load MOSES model 10 | (load "moses-model.scm") 11 | 12 | ;; Load the background knowledge 13 | (load "background-knowledge.scm") 14 | 15 | ;; Load the PLN configuration for this demo 16 | (load "pln-fc-config.scm") 17 | 18 | (pln-fc (SetLink if-X-takes-Y-and-Y-contains-Z-then-X-takes-Z 19 | take-treatment-1-X-is-equivalent-to-take-X-treatment-1 20 | take-compound-A-X-is-equivalent-to-take-X-compound-A 21 | being-well-hydrated-tends-to-speed-up-injury-recovery)) 22 | -------------------------------------------------------------------------------- /examples/pln/moses-pln-synergy/scm/moses-pln-synergy-pm.scm: -------------------------------------------------------------------------------- 1 | ;; PLN inference carried over the background knowledge to overwrite 2 | ;; the truth value of the MOSES model based solely on the dataset. 3 | (use-modules (opencog) (opencog exec)) 4 | 5 | ;; Load MOSES model 6 | (load "moses-model.scm") 7 | 8 | ;; Load the background knowledge 9 | (load "background-knowledge.scm") 10 | 11 | ;; Load the PLN configuration for this demo 12 | (load "pln-fc-config.scm") 13 | 14 | ;; Apply the inference rules using the pattern matcher. This only 15 | ;; contains the executions, see the README.md for the explanations and 16 | ;; the expected results. 17 | 18 | ;; (1) 19 | (for-each (lambda (i) (cog-execute! implication-partial-instantiation-rule)) 20 | (iota 2)) 21 | 22 | ;; (2) 23 | (cog-execute! implication-scope-to-implication-rule) 24 | 25 | ;; (3) 26 | (cog-execute! and-lambda-distribution-rule) 27 | 28 | ;; (4) 29 | (cog-execute! closed-lambda-evaluation-rule) 30 | 31 | ;; (5) 32 | (cog-execute! implication-introduction-rule) 33 | 34 | ;; (6) 35 | (cog-execute! implication-implicant-distribution-rule) 36 | 37 | ;; (7) 38 | (cog-execute! implication-and-lambda-factorization-rule) 39 | 40 | ;; (8) 41 | (cog-execute! deduction-implication-rule) 42 | 43 | ;; (9) 44 | (cog-execute! deduction-implication-rule) 45 | 46 | ;; (10) 47 | (cog-execute! implication-total-instantiation-rule) 48 | 49 | ;; (11) 50 | (cog-execute! equivalence-to-implication-rule) 51 | 52 | ;; (12) 53 | (cog-execute! deduction-implication-rule) 54 | 55 | ;; (13) 56 | (cog-execute! deduction-implication-rule) 57 | 58 | ;; (14) 59 | (cog-execute! deduction-implication-rule) 60 | 61 | ;; (15) 62 | ;; (cog-execute! deduction-implication-rule) 63 | 64 | ;; (16) 65 | (cog-execute! implication-implicant-disjunction-rule) 66 | -------------------------------------------------------------------------------- /examples/pln/propositional/README.md: -------------------------------------------------------------------------------- 1 | Propositional 2 | ============= 3 | 4 | **Warning:** this example does not use the new PLN API and thus is not 5 | recommanded for new users. 6 | 7 | Simple example showing how to calculate the TV of a fuzzy proposition 8 | using the backward chainer. 9 | 10 | Usage 11 | ----- 12 | 13 | Load the propositional rule base in the guile interpreter: 14 | 15 | ```bash 16 | $ guile -l propositional-rule-base-config.scm 17 | ``` 18 | 19 | Optionally, set the log level to debug (can be insightful to read): 20 | 21 | ```scheme 22 | (ure-logger-set-level! "debug") 23 | ``` 24 | 25 | Define a proposition to evaluate: 26 | 27 | ```scheme 28 | (define P (Predicate "P")) 29 | (define Q (Predicate "Q")) 30 | (define A (Concept "A")) 31 | (define B (Concept "B")) 32 | (define C (Concept "C")) 33 | (define PA (Evaluation (stv 0.5 0.8) P A)) 34 | (define PB (Evaluation (stv 0.3 0.9) P B)) 35 | (define QC (Evaluation (stv 0.9 0.7) Q C)) 36 | (define proposition (Or (And PA PB) (Not QC))) 37 | ``` 38 | 39 | As you see simple TVs have been assigned to PA, PB and QC but not to 40 | the proposition. By default a simple TV with null confidence 41 | (equivalent to total ignorance) is assigned. Now let's call the 42 | backward chainer on the proposition to evaluate its TV: 43 | 44 | ```scheme 45 | (prop-bc proposition) 46 | ``` 47 | 48 | You should get something 49 | 50 | ```scheme 51 | $2 = (SetLink 52 | (OrLink (stv 0.3 0.7) 53 | (AndLink (stv 0.3 0.8) 54 | (EvaluationLink (stv 0.3 0.9) 55 | (PredicateNode "P") 56 | (ConceptNode "B") 57 | ) 58 | (EvaluationLink (stv 0.5 0.8) 59 | (PredicateNode "P") 60 | (ConceptNode "A") 61 | ) 62 | ) 63 | (NotLink (stv 0.1 0.7) 64 | (EvaluationLink (stv 0.9 0.7) 65 | (PredicateNode "Q") 66 | (ConceptNode "C") 67 | ) 68 | ) 69 | ) 70 | ) 71 | ``` 72 | -------------------------------------------------------------------------------- /examples/pln/propositional/propositional-rule-base-config.scm: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; URE Configuration file for a mere fuzzy conjunction rule 3 | ;; 4 | ;; Before running any PLN inference you must load that file in the 5 | ;; AtomSpace 6 | 7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 8 | ;; Load required modules and utils ;; 9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 10 | 11 | (use-modules (opencog)) 12 | (use-modules (opencog ure)) 13 | 14 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 15 | ;; Define a rule-based system ;; 16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 17 | 18 | (define propositional-rule-base (ConceptNode "propositional-rule-base")) 19 | 20 | ;; Define conj-bc for convenience 21 | (define (prop-bc target) (cog-bc propositional-rule-base target)) 22 | 23 | ;;;;;;;;;;;;;;;; 24 | ;; Load rules ;; 25 | ;;;;;;;;;;;;;;;; 26 | 27 | ;; Load the rules of the propositional rule base 28 | (define pln-rules-dir "../../../opencog/pln/rules/") 29 | (define (append-rule-dir basename) (string-append pln-rules-dir basename)) 30 | (define rule-basenames 31 | (list "propositional/fuzzy-conjunction-introduction.scm" 32 | "propositional/fuzzy-disjunction-introduction.scm" 33 | "wip/negation-introduction.scm" 34 | ) 35 | ) 36 | (define rule-files (map append-rule-dir rule-basenames)) 37 | (for-each load rule-files) 38 | 39 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 40 | ;; Associate rules to the conjunction rule base ;; 41 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 42 | 43 | ;; List the rules 44 | (define rules 45 | (list 46 | fuzzy-conjunction-introduction-1ary-rule-name 47 | fuzzy-conjunction-introduction-2ary-rule-name 48 | fuzzy-conjunction-introduction-3ary-rule-name 49 | fuzzy-conjunction-introduction-4ary-rule-name 50 | fuzzy-conjunction-introduction-5ary-rule-name 51 | fuzzy-disjunction-introduction-1ary-rule-name 52 | fuzzy-disjunction-introduction-2ary-rule-name 53 | fuzzy-disjunction-introduction-3ary-rule-name 54 | fuzzy-disjunction-introduction-4ary-rule-name 55 | fuzzy-disjunction-introduction-5ary-rule-name 56 | negation-introduction-rule-name 57 | ) 58 | ) 59 | 60 | ;; Associate rules to the conjunction rule base 61 | (ure-add-rules propositional-rule-base rules) 62 | 63 | ;;;;;;;;;;;;;;;;;;;;;; 64 | ;; Other parameters ;; 65 | ;;;;;;;;;;;;;;;;;;;;;; 66 | 67 | ;; Termination criteria parameters. We set 20 iterations, propositions 68 | ;; requiring more computation steps won't be evaluated. 69 | (ure-set-num-parameter propositional-rule-base "URE:maximum-iterations" 20) 70 | -------------------------------------------------------------------------------- /examples/pln/socrates/john-is-a-man-r2l-output.scm: -------------------------------------------------------------------------------- 1 | ;; Obtained from running 2 | ;; 3 | ;; (mock-pln-input "John is a man") 4 | ;; 5 | ;; then TVs have been edited at hand so that abduction and deduction 6 | ;; work as they should. 7 | 8 | (define true-stv (stv 1 1)) 9 | (define man-stv (stv 0.01 0.1)) 10 | (define john-stv (stv 0.001 0.1)) 11 | 12 | (InheritanceLink true-stv 13 | (ConceptNode "man@5d693a26-661d-4c15-844c-c1c7c34281c4" man-stv) 14 | (ConceptNode "man" man-stv) 15 | ) 16 | (InheritanceLink 17 | (SpecificEntityNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 18 | (DefinedLinguisticConceptNode "male" (stv 0.055555556 0.0012484394)) 19 | ) 20 | (InheritanceLink 21 | (InterpretationNode "sentence@1a59ced0-01c9-4511-972d-70cf0bcb2ee9_parse_0_interpretation_$X" (stv 1 0.0012484394)) 22 | (DefinedLinguisticConceptNode "DeclarativeSpeechAct" (stv 0.09523809 0.0024937654)) 23 | ) 24 | (EvaluationLink 25 | (DefinedLinguisticPredicateNode "definite" (stv 1 0.0012484394)) 26 | (ListLink 27 | (ConceptNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 28 | ) 29 | ) 30 | (InheritanceLink true-stv 31 | (ConceptNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 32 | (ConceptNode "man@5d693a26-661d-4c15-844c-c1c7c34281c4" man-stv) 33 | ) 34 | (EvaluationLink 35 | (PredicateNode "is@6586f2ba-d712-4cb0-a22b-2abe5dcb45ec" (stv 0.66666663 0.0049751243)) 36 | (ListLink 37 | (ConceptNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 38 | ) 39 | ) 40 | (EvaluationLink 41 | (PredicateNode "is@6586f2ba-d712-4cb0-a22b-2abe5dcb45ec" (stv 0.66666663 0.0049751243)) 42 | (ListLink 43 | (ConceptNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 44 | (ConceptNode "man@5d693a26-661d-4c15-844c-c1c7c34281c4" man-stv) 45 | ) 46 | ) 47 | (InheritanceLink 48 | (PredicateNode "is@6586f2ba-d712-4cb0-a22b-2abe5dcb45ec" (stv 0.66666663 0.0049751243)) 49 | (DefinedLinguisticConceptNode "present" (stv 0.090909086 0.0024937654)) 50 | ) 51 | (InheritanceLink true-stv 52 | (ConceptNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 53 | (ConceptNode "John" john-stv) 54 | ) 55 | (InheritanceLink 56 | (SpecificEntityNode "John@326e86cc-c68a-4030-ab89-444a88a249ce" john-stv) 57 | (ConceptNode "John" john-stv) 58 | ) 59 | (ImplicationLink 60 | (PredicateNode "is@6586f2ba-d712-4cb0-a22b-2abe5dcb45ec" (stv 0.66666663 0.0049751243)) 61 | (PredicateNode "be" (stv 0.14285715 0.0012484394)) 62 | ) 63 | -------------------------------------------------------------------------------- /examples/pln/socrates/men-breathe-air-r2l-output.scm: -------------------------------------------------------------------------------- 1 | ;; Obtained from running 2 | ;; 3 | ;; (mock-pln-input "Men breathe air") 4 | ;; 5 | ;; then TVs have been edited at hand so that abduction and deduction 6 | ;; work as they should. 7 | 8 | (define true-stv (stv 1 1)) 9 | (define man-stv (stv 0.01 0.1)) 10 | 11 | (ReferenceLink 12 | (PredicateNode "breathe@33c11265-4d02-4c3b-86be-515ad87fba5c" (stv 0.36363634 0.0049751243)) 13 | (WordInstanceNode "breathe@bf2b486b-3dd5-4b50-92e4-20b54d33d226") 14 | ) 15 | 16 | (InheritanceLink 17 | (InterpretationNode "sentence@7538a7fe-68a4-44c8-a8e0-554337d90a51_parse_0_interpretation_$X" (stv 0.5 0.0012484394)) 18 | (DefinedLinguisticConceptNode "DeclarativeSpeechAct" (stv 0.09523809 0.0024937654)) 19 | ) 20 | (EvaluationLink 21 | (PredicateNode "breathe@33c11265-4d02-4c3b-86be-515ad87fba5c" (stv 0.36363634 0.0049751243)) 22 | (ListLink 23 | (ConceptNode "men@f8717726-5dde-475f-979c-222790e9fe06" man-stv) 24 | ) 25 | ) 26 | (InheritanceLink true-stv 27 | (ConceptNode "air@0e01ce55-cdd4-4d11-b6f1-9b7bf72c12c3" (stv 0.083333328 0.0024937654)) 28 | (ConceptNode "air" (stv 0.045454547 0.0012484394)) 29 | ) 30 | (InheritanceLink 31 | (PredicateNode "breathe@33c11265-4d02-4c3b-86be-515ad87fba5c" (stv 0.36363634 0.0049751243)) 32 | (DefinedLinguisticConceptNode "present" (stv 0.090909086 0.0024937654)) 33 | ) 34 | (EvaluationLink true-stv 35 | (PredicateNode "breathe@33c11265-4d02-4c3b-86be-515ad87fba5c" (stv 0.36363634 0.0049751243)) 36 | (ListLink 37 | (ConceptNode "men@f8717726-5dde-475f-979c-222790e9fe06" man-stv) 38 | (ConceptNode "air@0e01ce55-cdd4-4d11-b6f1-9b7bf72c12c3" (stv 0.083333328 0.0024937654)) 39 | ) 40 | ) 41 | (InheritanceLink true-stv 42 | (ConceptNode "men@f8717726-5dde-475f-979c-222790e9fe06" man-stv) 43 | (ConceptNode "man" man-stv) 44 | ) 45 | (ImplicationLink true-stv 46 | (PredicateNode "breathe@33c11265-4d02-4c3b-86be-515ad87fba5c" (stv 0.36363634 0.0049751243)) 47 | (PredicateNode "breathe" (stv 0.083333336 0.0012484394)) 48 | ) 49 | -------------------------------------------------------------------------------- /examples/pln/sumo/README.md: -------------------------------------------------------------------------------- 1 | # Backward Chainer Experiments over SUMO 2 | 3 | **Warning:** this example does not use the new PLN API and thus is not 4 | recommanded for new users. 5 | 6 | ## Usage 7 | 8 | ### Import SUMO 9 | 10 | First you need to import the SUMO KB to opencog. For that clone 11 | opencog's external-tools repository in the folder of your choice 12 | 13 | ```bash 14 | git clone git@github.com:opencog/external-tools.git 15 | ``` 16 | 17 | then convert the kif files into scheme (it's gonna take a while) 18 | 19 | ```bash 20 | cd external-tools/SUMO_importer 21 | ./sumo-opencog.sh 22 | ``` 23 | 24 | copy the output folder to here (where that README.md is located) 25 | 26 | ```bash 27 | cd 28 | cp /SUMO_importer/all-sumo-labeled-kb.scm . 29 | cp /SUMO_importer/sumo/output/Merge.scm . 30 | cp -r /SUMO_importer/sumo/output/tests . 31 | cd 32 | ``` 33 | 34 | You can now launch guile and load SUMO into the atomspace (for now 35 | `Merge.scm` rather than `all-sumo-labeled-kb.scm`) 36 | 37 | ```bash 38 | guile --no-auto-compile -l Merge.scm 39 | ``` 40 | 41 | ### Calling the Backward Chainer 42 | 43 | First, set the logger level 44 | 45 | ```scheme 46 | (ure-logger-set-level! "debug") 47 | ``` 48 | 49 | Load PLN 50 | 51 | ```scheme 52 | (load "pln-config.scm") 53 | ``` 54 | 55 | Then call the backward chainer on some hypothesis and target like 56 | 57 | ```scheme 58 | (MemberLink (stv 1.000000 1.000000) 59 | (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 60 | (ConceptNode "Organization" (stv 0.010000 1.000000)) 61 | ) 62 | ``` 63 | 64 | ```scheme 65 | (define target 66 | (ExistsLink 67 | (TypedVariableLink 68 | (VariableNode "?MEMBER") 69 | (TypeChoice 70 | (TypeNode "ConceptNode") 71 | (TypeNode "SchemaNode") 72 | (TypeNode "PredicateNode") 73 | ) 74 | ) 75 | (MemberLink 76 | (VariableNode "?MEMBER") 77 | (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 78 | ) 79 | ) 80 | ) 81 | ``` 82 | 83 | ```scheme 84 | (pln-bc target) 85 | ``` 86 | -------------------------------------------------------------------------------- /examples/pln/sumo/pln-config1.scm: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; URE Configuration file for PLN 3 | ;; 4 | ;; Before running any PLN inference you must load that file in the 5 | ;; AtomSpace 6 | ;; 7 | ;; In order to add new rules you need to hack this file in 2 places 8 | ;; 9 | ;; 1. In the Load rules section, to add the file name where the rule is 10 | ;; defined (see define rule-files). 11 | ;; 12 | ;; 2. In the Associate rules to PLN section, to add the name of the 13 | ;; rule and its weight (see define rules). 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Load required modules and utils ;; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | (use-modules (opencog)) 20 | (use-modules (opencog ure)) 21 | 22 | ;XXX This is bad and broken and wrong; one should not try to bypass the 23 | ; scheme module system like this, its just asking for carpet burns. 24 | (load-from-path "utilities.scm") 25 | (load-from-path "av-tv.scm") 26 | (load-from-path "opencog/ure/ure-utils.scm") 27 | 28 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 29 | ;; Define PLN rule-based system ;; 30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 31 | 32 | (define pln-rbs (ConceptNode "PLN")) 33 | 34 | ;; Define pln-fc and pln-bc for convenience 35 | (define (pln-fc source) (cog-fc pln-rbs source)) 36 | (define (pln-bc target) (cog-bc pln-rbs target)) 37 | 38 | ;;;;;;;;;;;;;;;; 39 | ;; Load rules ;; 40 | ;;;;;;;;;;;;;;;; 41 | 42 | ;; Load the rules. Either w.r.t this file path 43 | (add-to-load-path "../../../opencog/pln/rules") 44 | (add-to-load-path "../../../opencog/pln/meta-rules") 45 | 46 | (define rule-filenames 47 | (list ;; "term/deduction.scm" 48 | "predicate/conditional-total-instantiation.scm" 49 | "propositional/fuzzy-conjunction-introduction.scm" 50 | ) 51 | ) 52 | (for-each load-from-path rule-filenames) 53 | 54 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 55 | ;; Associate rules to PLN ;; 56 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 57 | 58 | ; List the rules 59 | (define rules 60 | (list ;; deduction-inheritance-rule-name 61 | conditional-total-instantiation-implication-scope-meta-rule-name 62 | conditional-total-instantiation-implication-meta-rule-name 63 | conditional-total-instantiation-inheritance-meta-rule-name 64 | fuzzy-conjunction-introduction-3ary-rule-name 65 | ) 66 | ) 67 | 68 | ;; Associate rules to PLN 69 | (ure-add-rules pln-rbs rules) 70 | 71 | ;; ;;;;;;;;;;;;;;;;;;;;;; 72 | ;; ;; Other parameters ;; 73 | ;; ;;;;;;;;;;;;;;;;;;;;;; 74 | 75 | ;; Termination criteria parameters 76 | (ure-set-num-parameter pln-rbs "URE:maximum-iterations" 50000) 77 | 78 | ;; Attention allocation (0 to disable it, 1 to enable it) 79 | (ure-set-fuzzy-bool-parameter pln-rbs "URE:attention-allocation" 0) 80 | 81 | ;; Complexity penalty 82 | (ure-set-num-parameter pln-rbs "URE:complexity-penalty" 1) 83 | 84 | ;; BIT reduction parameters 85 | (ure-set-num-parameter pln-rbs "URE:BC:maximum-bit-size" 50000) 86 | -------------------------------------------------------------------------------- /examples/pln/sumo/pln-config2.scm: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; URE Configuration file for PLN 3 | ;; 4 | ;; Before running any PLN inference you must load that file in the 5 | ;; AtomSpace 6 | ;; 7 | ;; In order to add new rules you need to hack this file in 2 places 8 | ;; 9 | ;; 1. In the Load rules section, to add the file name where the rule is 10 | ;; defined (see define rule-files). 11 | ;; 12 | ;; 2. In the Associate rules to PLN section, to add the name of the 13 | ;; rule and its weight (see define rules). 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Load required modules and utils ;; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | (use-modules (opencog)) 20 | (use-modules (opencog ure)) 21 | 22 | ;XXX This is bad and broken and wrong; one should not try to bypass the 23 | ; scheme module system like this, its just asking for carpet burns. 24 | (load-from-path "utilities.scm") 25 | (load-from-path "av-tv.scm") 26 | (load-from-path "opencog/ure/ure-utils.scm") 27 | 28 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 29 | ;; Define PLN rule-based system ;; 30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 31 | 32 | (define pln-rbs (ConceptNode "PLN")) 33 | 34 | ;; Define pln-fc and pln-bc for convenience 35 | (define (pln-fc source) (cog-fc pln-rbs source)) 36 | (define (pln-bc target) (cog-bc pln-rbs target)) 37 | 38 | ;;;;;;;;;;;;;;;; 39 | ;; Load rules ;; 40 | ;;;;;;;;;;;;;;;; 41 | 42 | ;; Load the rules. Either w.r.t this file path 43 | (add-to-load-path "../../../opencog/pln/rules") 44 | (add-to-load-path "../../../opencog/pln/meta-rules") 45 | 46 | (define rule-filenames 47 | (list ;; "term/deduction.scm" 48 | "predicate/conditional-total-instantiation.scm" 49 | "propositional/fuzzy-conjunction-introduction.scm" 50 | ) 51 | ) 52 | (for-each load-from-path rule-filenames) 53 | 54 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 55 | ;; Associate rules to PLN ;; 56 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 57 | 58 | ; List the rules 59 | (define rules 60 | (list ;; deduction-inheritance-rule-name 61 | conditional-total-instantiation-implication-scope-meta-rule-name 62 | conditional-total-instantiation-implication-meta-rule-name 63 | conditional-total-instantiation-inheritance-meta-rule-name 64 | fuzzy-conjunction-introduction-3ary-rule-name 65 | ) 66 | ) 67 | 68 | ;; Associate rules to PLN 69 | (ure-add-rules pln-rbs rules) 70 | 71 | ;; ;;;;;;;;;;;;;;;;;;;;;; 72 | ;; ;; Other parameters ;; 73 | ;; ;;;;;;;;;;;;;;;;;;;;;; 74 | 75 | ;; Termination criteria parameters 76 | (ure-set-num-parameter pln-rbs "URE:maximum-iterations" 50000) 77 | 78 | ;; Attention allocation (0 to disable it, 1 to enable it) 79 | (ure-set-fuzzy-bool-parameter pln-rbs "URE:attention-allocation" 0) 80 | 81 | ;; Complexity penalty 82 | (ure-set-num-parameter pln-rbs "URE:complexity-penalty" 1) 83 | 84 | ;; BIT reduction parameters 85 | (ure-set-num-parameter pln-rbs "URE:BC:maximum-bit-size" 50000) 86 | -------------------------------------------------------------------------------- /examples/pln/sumo/sumo-test1-bc.scm: -------------------------------------------------------------------------------- 1 | ;; Use the backward chainer to prove that a SUMO Organization has at 2 | ;; least one member. 3 | ;; 4 | ;; The reasoning goes as follows 5 | ;; 6 | ;; 1. An Organization is a Group, Org1-1 is an instance of an 7 | ;; Organization, therefore it is an instance of a Group. 8 | ;; 9 | ;; 2. A Group is a Collection, from 1. Org1-1 is an instance of a 10 | ;; Group, therefore it is an instance of a Collection. 11 | ;; 12 | ;; 3. A Collection has at least one member, since Org1-1 is a 13 | ;; Collection it has at least one member. 14 | ;; 15 | ;; Warning: if each step takes too long start guile loading only 16 | ;; Merge.scm instead all-sumo-labeled-kb.scm (don't forget to copy 17 | ;; Merge.scm from`/SUMO_importer/sumo/output` to the 18 | ;; current directory). 19 | ;; 20 | ;; guile --no-auto-compile -l Merge.scm 21 | 22 | ;; Set logger to debug level 23 | (ure-logger-set-level! "debug") 24 | 25 | ;; Load PLN rule base 26 | (load "pln-config1.scm") 27 | 28 | ;; Add axioms pertaining to the test 29 | (MemberLink (stv 1.000000 1.000000) 30 | (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 31 | (ConceptNode "Organization" (stv 0.010000 1.000000)) 32 | ) 33 | 34 | ;; Define target 35 | (define target 36 | (ExistsLink 37 | (TypedVariableLink 38 | (VariableNode "?MEMBER") 39 | (TypeChoice 40 | (TypeNode "ConceptNode") 41 | (TypeNode "SchemaNode") 42 | (TypeNode "PredicateNode") 43 | ) 44 | ) 45 | (MemberLink 46 | (VariableNode "?MEMBER") 47 | (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 48 | ) 49 | ) 50 | ) 51 | 52 | ;; Prove target 53 | (pln-bc target) 54 | -------------------------------------------------------------------------------- /examples/pln/sumo/sumo-test1-pm.scm: -------------------------------------------------------------------------------- 1 | ;; Execute step by step inference to prove that a SUMO Organization 2 | ;; has at least one member. 3 | ;; 4 | ;; The reasoning goes as follows 5 | ;; 6 | ;; 1. An Organization is a Group, Org1-1 is an instance of an 7 | ;; Organization, therefore it is an instance of a Group. 8 | ;; 9 | ;; 2. A Group is a Collection, from 1. Org1-1 is an instance of a 10 | ;; Group, therefore it is an instance of a Collection. 11 | ;; 12 | ;; 3. A Collection has at least one member, since Org1-1 is a 13 | ;; Collection it has at least one member. 14 | ;; 15 | ;; Warning: if each step takes too long start guile loading only 16 | ;; Merge.scm instead all-sumo-labeled-kb.scm (don't forget to copy 17 | ;; Merge.scm from`/SUMO_importer/sumo/output` to the 18 | ;; current directory). 19 | ;; 20 | ;; guile --no-auto-compile -l Merge.scm 21 | 22 | (ure-logger-set-level! "debug") 23 | 24 | (load "pln-config.scm") 25 | 26 | ;; Org1-1 is an Organization 27 | (MemberLink (stv 1.000000 1.000000) 28 | (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 29 | (ConceptNode "Organization" (stv 0.010000 1.000000)) 30 | ) 31 | 32 | ;; 1. Apply conditional instantiation using the MemberLink above and 33 | ;; inheritance KB-15619, to obtain 34 | ;; 35 | ;; (MemberLink (stv 1 0.99) 36 | ;; (ConceptNode "Org1-1") 37 | ;; (ConceptNode "Group")) 38 | (meta-bind conditional-total-instantiation-inheritance-meta-rule) 39 | 40 | ;; 2. Apply conditional instantiation using the MemberLink in 1. and 41 | ;; inheritance KB-16125, to obtain 42 | ;; 43 | ;; (MemberLink (stv 1 0.99) 44 | ;; (ConceptNode "Org1-1") 45 | ;; (ConceptNode "Collection")) 46 | (meta-bind conditional-total-instantiation-inheritance-meta-rule) 47 | 48 | ;; 3. Apply conditional instantiation using 2. and KB-16709 to produce 49 | ;; the target 50 | ;; 51 | ;; (ExistsLink 52 | ;; (TypedVariableLink 53 | ;; (VariableNode "?MEMBER") 54 | ;; (TypeChoice 55 | ;; (TypeNode "ConceptNode") 56 | ;; (TypeNode "SchemaNode") 57 | ;; (TypeNode "PredicateNode") 58 | ;; ) 59 | ;; ) 60 | ;; (MemberLink 61 | ;; (VariableNode "?MEMBER") 62 | ;; (ConceptNode "Org1-1" (stv 0.010000 1.000000)) 63 | ;; ) 64 | ;; ) 65 | (meta-bind conditional-total-instantiation-implication-scope-meta-rule) 66 | -------------------------------------------------------------------------------- /examples/pln/sumo/sumo-test3-bc.scm: -------------------------------------------------------------------------------- 1 | ;; Use the backward chainer to prove that a non negative real number 2 | ;; is not a negative real number. 3 | ;; 4 | ;; The informal reasoning goes as follows 5 | ;; 6 | ;; 1. The sign of a non negative real number is 0 or 1 7 | ;; 8 | ;; 2. Therefore the sign is not -1 9 | ;; 10 | ;; 3. Therefore it is not a negative real number 11 | 12 | ;; TODO need to have the backward chainer fully supports meta-rules, 13 | ;; so that conditional instantiation and contraposition can be 14 | ;; back-chained to produce the target. The other option would be to 15 | ;; implement contrapositive conditional instantiation, but we won't 16 | ;; escape full meta-rule support. 17 | 18 | ;; Set logger to debug level 19 | (ure-logger-set-level! "debug") 20 | 21 | ;; The sumo knowledge base (without compiling) 22 | (primitive-load "Merge.scm") 23 | 24 | ;; Load PLN rule base 25 | (load "pln-config3.scm") 26 | 27 | ;; Add axioms pertaining to the test 28 | ;; KB-test3-1 29 | (MemberLink (stv 1.000000 1.000000) 30 | (ConceptNode "Number3-1" (stv 0.010000 1.000000)) ; [6502352803782467190][1] 31 | (ConceptNode "NonnegativeRealNumber" (stv 0.010000 1.000000)) ; [854426703771326157][1] 32 | ) ; [12939358011030762013][1] 33 | 34 | ;; Define taget 35 | (define target 36 | (NotLink 37 | (MemberLink 38 | (ConceptNode "Number3-1" (stv 0.010000 1.000000)) ; [6502352803782467190][1] 39 | (ConceptNode "NegativeRealNumber" (stv 0.010000 1.000000)) ; [2370306305334504801][1] 40 | ) ; [14455237612593940657][1] 41 | ) ; [14475556587474805702][1] 42 | ) 43 | 44 | ;; Prove target 45 | (pln-bc target) 46 | -------------------------------------------------------------------------------- /examples/pln/universal-instantiation/README.md: -------------------------------------------------------------------------------- 1 | Universal Instantiation 2 | ======================= 3 | 4 | **Warning:** this example does not use the new PLN API and thus is not 5 | recommanded for new users. 6 | 7 | Simple example of universal instantiation, using the pattern matcher, 8 | the backward and forward chainers. 9 | 10 | Pattern Matcher 11 | --------------- 12 | 13 | Load the knowledge and rule base in guile. 14 | 15 | ```scheme 16 | (load "kb.scm") 17 | (load "rb.scm") 18 | ``` 19 | 20 | Let's call meta-bind to apply universal instantiation over the entire 21 | atomspace. 22 | 23 | ```scheme 24 | (meta-bind universal-total-instantiation-forall-1ary-meta-rule) 25 | ``` 26 | 27 | You should get the following results. 28 | 29 | ```scheme 30 | $9 = (SetLink 31 | (InheritanceLink (stv 1 1) 32 | (ConceptNode "Infinity") 33 | (ConceptNode "Abstractverse") 34 | ) 35 | (InheritanceLink (stv 1 1) 36 | (ConceptNode "Mathematics") 37 | (ConceptNode "Abstractverse") 38 | ) 39 | (InheritanceLink (stv 1 1) 40 | (ConceptNode "Space") 41 | (ConceptNode "Abstractverse") 42 | ) 43 | (InheritanceLink (stv 1 1) 44 | (ConceptNode "URE") 45 | (ConceptNode "Abstractverse") 46 | ) 47 | (InheritanceLink (stv 1 1) 48 | (ConceptNode "Time") 49 | (ConceptNode "Abstractverse") 50 | ) 51 | (InheritanceLink (stv 1 1) 52 | (ConceptNode "Abstractverse") 53 | (ConceptNode "Abstractverse") 54 | ) 55 | (InheritanceLink (stv 1 1) 56 | (ConceptNode "PLN") 57 | (ConceptNode "Abstractverse") 58 | ) 59 | (InheritanceLink (stv 1 1) 60 | (ConceptNode "Cat") 61 | (ConceptNode "Abstractverse") 62 | ) 63 | ) 64 | ``` 65 | 66 | Forward Chainer 67 | --------------- 68 | 69 | ```scheme 70 | (clear) 71 | (load "kb.scm") 72 | (load "rb.scm") 73 | ``` 74 | 75 | Let's call the forward chainer 76 | 77 | ```scheme 78 | (pln-fc forall) 79 | ``` 80 | 81 | which should return the same as `meta-bind` or a slightly smaller 82 | subset of it. 83 | 84 | Backward Chainer 85 | ---------------- 86 | 87 | Clear the atomspace and reload the knowledge base. 88 | 89 | Load the knowledge base. 90 | 91 | ```scheme 92 | (clear) 93 | (load "kb.scm") 94 | (load "rb.scm") 95 | ``` 96 | 97 | Let's call the backward chainer and ask what inherits from the 98 | abstractverse. 99 | 100 | ```scheme 101 | (pln-bc (Inheritance (Variable "$X") (Concept "Abstractverse")) 102 | (TypedVariable (Variable "$X") (Type "ConceptNode"))) 103 | ``` 104 | 105 | which should return the same as `meta-bind` or a slightly smaller 106 | subset of it. 107 | -------------------------------------------------------------------------------- /examples/pln/universal-instantiation/kb.scm: -------------------------------------------------------------------------------- 1 | ;; Knowledge-base for the universal instantiation example 2 | 3 | ;; All concepts inherits from the abstractverse 4 | (define forall 5 | (ForAll (stv 1 1) 6 | (TypedVariable 7 | (Variable "$C") 8 | (Type "ConceptNode")) 9 | (Inheritance 10 | (Variable "$C") 11 | (Concept "Abstractverse"))) 12 | ) 13 | 14 | ;; Instances of concepts 15 | (Concept "Cat") 16 | (Concept "Time") 17 | (Concept "Space") 18 | (Concept "Infinity") 19 | (Concept "Mathematics") 20 | -------------------------------------------------------------------------------- /examples/pln/universal-instantiation/rb.scm: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; URE Configuration file for PLN 3 | ;; 4 | ;; Before running any PLN inference you must load that file in the 5 | ;; AtomSpace 6 | ;; 7 | ;; In order to add new rules you need to hack this file in 2 places 8 | ;; 9 | ;; 1. In the Load rules section, to add the file name where the rule is 10 | ;; defined (see define rule-files). 11 | ;; 12 | ;; 2. In the Associate rules to PLN section, to add the name of the 13 | ;; rule and its weight (see define rules). 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Load required modules and utils ;; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | (use-modules (opencog)) 20 | (use-modules (opencog ure)) 21 | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 23 | ;; Define PLN rule-based system ;; 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 25 | 26 | (define pln-rbs (ConceptNode "PLN")) 27 | 28 | ;; Define pln-fc and pln-bc for convenience 29 | (define (pln-fc source) (cog-fc pln-rbs source)) 30 | (define (pln-bc target vardecl) (cog-bc pln-rbs target #:vardecl vardecl)) 31 | 32 | ;;;;;;;;;;;;;;;; 33 | ;; Load rules ;; 34 | ;;;;;;;;;;;;;;;; 35 | 36 | ;; Load the rules. Either w.r.t this file path 37 | (add-to-load-path "../../../opencog/pln/meta-rules/") 38 | 39 | (define rule-filenames 40 | (list "predicate/universal-total-instantiation.scm")) 41 | (for-each load-from-path rule-filenames) 42 | 43 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 44 | ;; Associate rules to PLN ;; 45 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 46 | 47 | ; List the rules 48 | (define rules 49 | (list 50 | universal-total-instantiation-forall-1ary-meta-rule-name)) 51 | 52 | ;; Associate rules to PLN 53 | (ure-add-rules pln-rbs rules) 54 | 55 | ;;;;;;;;;;;;;;;;;;;;;; 56 | ;; Other parameters ;; 57 | ;;;;;;;;;;;;;;;;;;;;;; 58 | 59 | ;; Termination criteria parameters 60 | (ure-set-num-parameter pln-rbs "URE:maximum-iterations" 10) 61 | 62 | ;; Attention allocation (0 to disable it, 1 to enable it) 63 | (ure-set-fuzzy-bool-parameter pln-rbs "URE:attention-allocation" 0) 64 | 65 | ;; Complexity penalty 66 | (ure-set-num-parameter pln-rbs "URE:complexity-penalty" 1) 67 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ConfigPackageLocation lib/cmake/PLN) 2 | 3 | include(CMakePackageConfigHelpers) 4 | 5 | configure_package_config_file(PLNConfig.cmake.in 6 | ${CMAKE_CURRENT_BINARY_DIR}/PLNConfig.cmake 7 | INSTALL_DESTINATION lib/PLN/cmake 8 | PATH_VARS CMAKE_INSTALL_PREFIX 9 | ) 10 | 11 | write_basic_package_version_file( 12 | "${CMAKE_CURRENT_BINARY_DIR}/PLNConfigVersion.cmake" 13 | VERSION ${SEMANTIC_VERSION} 14 | COMPATIBILITY SameMajorVersion 15 | ) 16 | 17 | INSTALL(FILES 18 | ${CMAKE_CURRENT_BINARY_DIR}/PLNConfigVersion.cmake 19 | ${CMAKE_CURRENT_BINARY_DIR}/PLNConfig.cmake 20 | DESTINATION ${ConfigPackageLocation} 21 | ) 22 | -------------------------------------------------------------------------------- /lib/PLNConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(PLN_DATA_DIR "@CMAKE_INSTALL_PREFIX@/share/opencog") 4 | set(PLN_VERSION "@SEMANTIC_VERSION@") 5 | set(PLN_FOUND 1) 6 | -------------------------------------------------------------------------------- /opencog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | DECLARE_GUILE_CONFIG_TARGET(SCM_CONFIG "opencog pln-config" "PLN_TEST") 2 | 3 | IF (HAVE_PLN) 4 | ADD_SUBDIRECTORY (pln) 5 | ENDIF (HAVE_PLN) 6 | 7 | IF (HAVE_CYTHON) 8 | ADD_SUBDIRECTORY (cython) 9 | ENDIF (HAVE_CYTHON) 10 | 11 | WRITE_GUILE_CONFIG( 12 | ${GUILE_BIN_DIR}/opencog/pln-config.scm 13 | SCM_CONFIG TRUE 14 | ) 15 | 16 | WRITE_GUILE_CONFIG( 17 | ${GUILE_BIN_DIR}/opencog/pln-config-installable.scm 18 | SCM_CONFIG FALSE 19 | ) 20 | 21 | INSTALL( 22 | FILES ${GUILE_BIN_DIR}/opencog/pln-config-installable.scm 23 | DESTINATION ${GUILE_SITE_DIR}/opencog RENAME pln-config.scm 24 | ) 25 | -------------------------------------------------------------------------------- /opencog/README.md: -------------------------------------------------------------------------------- 1 | See [pln/README.md](pln/README.md). 2 | -------------------------------------------------------------------------------- /opencog/cython/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | ADD_SUBDIRECTORY (opencog) 3 | 4 | # module init 5 | file(MAKE_DIRECTORY opencog) 6 | file(COPY opencog/__init__.py DESTINATION opencog) 7 | -------------------------------------------------------------------------------- /opencog/cython/README.md: -------------------------------------------------------------------------------- 1 | # Python bindings for PLN 2 | 3 | ## Requirements 4 | 5 | * Python 2.7, Python 3 recommended. 6 | * Cython 0.14 or later. http://www.cython.org/ 7 | 8 | The bindings are written mostly using Cython, which allows writing 9 | code that looks pythonic but gets compiled to C. It also makes it 10 | trivial to access both Python objects and C objects without using a 11 | bunch of extra Python library API calls. 12 | 13 | ## Package structure 14 | 15 | Currently the package structure looks like this: 16 | 17 | opencog.pln 18 | opencog.pln.types 19 | -------------------------------------------------------------------------------- /opencog/cython/opencog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Need to use -fno-strict-aliasing when compiling cython code, in order 3 | # to avoid nasty compiler warnings about aliasing. Cython explicitly 4 | # performs aliasing, in order to emulate python object inheritance. 5 | # See, for example, 6 | # https://groups.google.com/forum/#!topic/cython-users/JV1-KvIUeIg 7 | # 8 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") 9 | 10 | INCLUDE_DIRECTORIES( 11 | ${ATOMSPACE_INCLUDE_DIR} 12 | ${Python3_INCLUDE_DIRS} 13 | ${CMAKE_CURRENT_SOURCE_DIR} 14 | ${CMAKE_CURRENT_BINARY_DIR} 15 | ) 16 | 17 | SET(CYTHON_FLAGS "-3" "-f" "-Wextra" # "-Werror" 18 | "-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython" 19 | "-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython/opencog") 20 | 21 | # Use this as a guide: 22 | # https://github.com/OpenKinect/libfreenect/blob/master/wrappers/python/CMakeLists.txt 23 | 24 | ##################### PLN Types ################## 25 | 26 | CYTHON_ADD_MODULE_PYX(pln 27 | "pln_types.pyx" 28 | ) 29 | 30 | list(APPEND ADDITIONAL_MAKE_CLEAN_FILES "pln_types.cpp") 31 | 32 | # opencog.pln_types Python bindings 33 | INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) 34 | 35 | ADD_LIBRARY(pln_cython SHARED 36 | pln.cpp 37 | ) 38 | 39 | ADD_DEPENDENCIES(pln_cython pln-types) 40 | 41 | TARGET_LINK_LIBRARIES(pln_cython 42 | ${NO_AS_NEEDED} 43 | pln-types 44 | ${ATOMSPACE_LIBRARIES} 45 | ${Python3_LIBRARIES} 46 | ) 47 | 48 | SET_TARGET_PROPERTIES(pln_cython PROPERTIES 49 | PREFIX "" 50 | OUTPUT_NAME pln) 51 | 52 | INSTALL (TARGETS pln_cython 53 | DESTINATION "${PYTHON_DEST}") 54 | -------------------------------------------------------------------------------- /opencog/cython/opencog/__init__.py: -------------------------------------------------------------------------------- 1 | from pkgutil import extend_path 2 | __path__ = extend_path(__path__, __name__) 3 | -------------------------------------------------------------------------------- /opencog/cython/opencog/pln.pyx: -------------------------------------------------------------------------------- 1 | # Cython/distutils can only handle a single file as the source for 2 | # a python module. Since it is helpful to be able to split the binding 3 | # code into separate files, we just include them here. 4 | # 5 | # Note that the ordering of include statements may influence whether 6 | # things work or not 7 | 8 | include "pln_types.pyx" 9 | -------------------------------------------------------------------------------- /opencog/cython/opencog/pln_types.pyx: -------------------------------------------------------------------------------- 1 | from opencog.atomspace import get_refreshed_types 2 | from opencog.utilities import add_node, add_link 3 | 4 | cdef extern : 5 | void pln_types_init() 6 | 7 | pln_types_init() 8 | types = get_refreshed_types() 9 | 10 | include "opencog/pln/types/pln_types.pyx" 11 | -------------------------------------------------------------------------------- /opencog/pln/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ADD_SUBDIRECTORY (types) 3 | ADD_SUBDIRECTORY (rules) 4 | ADD_SUBDIRECTORY (meta-rules) 5 | 6 | ADD_GUILE_MODULE(FILES 7 | pln.scm 8 | pln-utils.scm 9 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln" 10 | ) 11 | -------------------------------------------------------------------------------- /opencog/pln/meta-rules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Predicate algebra rules 2 | ADD_SUBDIRECTORY(predicate) 3 | -------------------------------------------------------------------------------- /opencog/pln/meta-rules/predicate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Predicate logic meta-rules 2 | ADD_GUILE_MODULE(FILES 3 | conditional-total-instantiation.scm 4 | conditional-partial-instantiation.scm 5 | universal-total-instantiation.scm 6 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/meta-rules/predicate" 7 | ) 8 | -------------------------------------------------------------------------------- /opencog/pln/pln-config-deprecated.scm: -------------------------------------------------------------------------------- 1 | ; 2 | ; URE Configuration file for PLN 3 | ; 4 | ; Before running any PLN inference you must load that file in the 5 | ; AtomSpace 6 | ; 7 | ; In order to add new rules you need to hack this file in 2 places 8 | ; 9 | ; 1. In the Load rules section, to add the file name where the rule is 10 | ; defined (see define rule-files). 11 | ; 12 | ; 2. In the Associate rules to PLN section, to add the name of the 13 | ; rule and its weight (see define rules). 14 | 15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 16 | ;; Load required modules and utils ;; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | (use-modules (opencog)) 20 | (use-modules (opencog ure)) 21 | 22 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 23 | ;; Define PLN rule-based system ;; 24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 25 | 26 | (define pln-rbs (ConceptNode "PLN")) 27 | 28 | ; Define pln-fc and pln-bc for convenience 29 | (define (pln-fc source) (cog-fc pln-rbs source)) 30 | (define (pln-bc target) (cog-bc pln-rbs target)) 31 | 32 | ;;;;;;;;;;;;;;;; 33 | ;; Load rules ;; 34 | ;;;;;;;;;;;;;;;; 35 | 36 | ; Load the rules (use load for relative path w.r.t. to that file) 37 | (define config-dir (dirname (current-filename))) 38 | (define (prepend-config-dir fp) (string-append config-dir "/" fp)) 39 | (define rule-files (list "rules/term/deduction.scm" 40 | "rules/propositional/modus-ponens.scm")) 41 | (for-each (lambda (fp) (load (prepend-config-dir fp))) rule-files) 42 | 43 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 44 | ;; Associate rules to PLN ;; 45 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 46 | 47 | ; List the rules and their weights. 48 | (define rules (list deduction-inheritance-rule-name 49 | modus-ponens-implication-rule-name)) 50 | 51 | ; Associate rules to PLN 52 | (ure-add-rules pln-rbs rules) 53 | 54 | ;;;;;;;;;;;;;;;;;;;;; 55 | ;; Other paramters ;; 56 | ;;;;;;;;;;;;;;;;;;;;; 57 | 58 | ; Termination criteria parameters 59 | (ure-set-num-parameter pln-rbs "URE:maximum-iterations" 20) 60 | 61 | ; Attention allocation (0 to disable it, 1 to enable it) 62 | (ure-set-fuzzy-bool-parameter pln-rbs "URE:attention-allocation" 0) 63 | -------------------------------------------------------------------------------- /opencog/pln/pln.scm: -------------------------------------------------------------------------------- 1 | (define-module (opencog pln) 2 | #:use-module (opencog) 3 | #:use-module (opencog pln-config) 4 | ) 5 | 6 | ; Load the C library that calls the classserver to load the types. 7 | (load-extension 8 | (string-append opencog-ext-path-pln "libpln-types") 9 | "pln_types_init") 10 | 11 | (load-from-path "opencog/pln/types/pln_types.scm") 12 | (load "pln/pln-utils.scm") 13 | -------------------------------------------------------------------------------- /opencog/pln/rules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Boolean algebra rules 2 | ADD_SUBDIRECTORY(propositional) 3 | 4 | # Term logic rules 5 | ADD_SUBDIRECTORY(term) 6 | 7 | # Predicate logic rules 8 | ADD_SUBDIRECTORY(predicate) 9 | 10 | # Intensional reasoning rules 11 | ADD_SUBDIRECTORY(intensional) 12 | 13 | # Extensional reasoning rules 14 | ADD_SUBDIRECTORY(extensional) 15 | 16 | # Temporal reasoning rules 17 | ADD_SUBDIRECTORY(temporal) 18 | 19 | # Work in progress rules 20 | ADD_SUBDIRECTORY(wip) 21 | -------------------------------------------------------------------------------- /opencog/pln/rules/README.md: -------------------------------------------------------------------------------- 1 | # PLN Rule definitions for the URE 2 | 3 | Implements PLN rules according to 4 | http://wiki.opencog.org/w/URE_Configuration_Format 5 | 6 | ## Contents 7 | 8 | PLN rules are partitioned into boolean, predicate and term logic. 9 | These terms are used loosely since PLN is rather different than any of 10 | those. The folders are organized as follows 11 | 12 | - `propositional` contains rules dealing with `AndLink`, `OrLink` and 13 | `NotLink` evaluation and introduction. They are fuzzy for the most 14 | part, contrary to what the name folder seems to suggest. 15 | - `predicate` contains rules for universal and conditional 16 | instantiation and generalization. 17 | - `term` contains rules dealing with deduction, abduction, 18 | induction and inversion. 19 | - `wip` contains work-in-progress rules, incomplete or broken. Often 20 | only compatible with the forward chainer. 21 | 22 | ## PLN Examples 23 | 24 | Multiple examples can be found under 25 | 26 | ``` 27 | /examples/pln 28 | ``` 29 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Extensional rules 2 | ADD_GUILE_MODULE(FILES 3 | subset-direct-introduction.scm 4 | conjunction-direct-introduction.scm 5 | extensional-similarity-direct-introduction.scm 6 | concept-direct-evaluation.scm 7 | member-deduction.scm 8 | extensional-utils.scm 9 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/extensional" 10 | ) 11 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/concept-direct-evaluation.scm: -------------------------------------------------------------------------------- 1 | ;; Calculate the TV of a concept based on direct evidence 2 | ;; 3 | ;; Member X1 A 4 | ;; ... 5 | ;; Member Xn A 6 | ;; |- 7 | ;; A 8 | ;; 9 | ;; where TV is calculated using direct evidence obtained from member. For now we assume that TV1 to TVn are absolutely true. 10 | 11 | ;; Rule 12 | ;; 13 | ;; TODO: support n-ary 14 | (define concept-direct-evaluation-rule 15 | (let* ((X (Variable "$X")) 16 | (Y (Variable "$Y")) 17 | (A (Variable "$A")) 18 | (CptT (Type 'Concept))) 19 | (Bind 20 | (VariableSet 21 | X 22 | Y 23 | (TypedVariable A CptT)) 24 | (And 25 | (Present 26 | (Member X A) 27 | (Member Y A) 28 | A) 29 | (Evaluation 30 | (GroundedPredicate "scm: absolutely-true") 31 | (Member X A)) 32 | (Evaluation 33 | (GroundedPredicate "scm: absolutely-true") 34 | (Member Y A)) 35 | (Not (Identical X Y))) 36 | (ExecutionOutput 37 | (GroundedSchema "scm: concept-direct-evaluation") 38 | (List 39 | ;; Conclusion 40 | A 41 | ;; Premises 42 | (Set 43 | (Member X A) 44 | (Member Y A))))))) 45 | 46 | ;; Formula 47 | (define (concept-direct-evaluation conclusion . premises) 48 | ;; (cog-logger-debug "(concept-direct-evaluation conclusion=~a . premises=~a)" conclusion premises) 49 | (if (= (length premises) 1) 50 | (let* ((mbr-lnks (cog-outgoing-set (car premises))) 51 | (mbr-lnk-A (car mbr-lnks)) 52 | (mbr-lnk-B (cadr mbr-lnks)) 53 | (all-nodes (cog-get-atoms 'Node #f)) 54 | (usize (length all-nodes)) ; TODO: replace this 55 | ; horrible hack 56 | (vsize (if (not (equal? mbr-lnk-A mbr-lnk-B)) 2 1)) 57 | (tv-s (/ vsize usize)) 58 | (tv-c (count->confidence usize))) 59 | ;; Update conjunction TV 60 | (if (< 0 tv-c) 61 | (cog-merge-hi-conf-tv! conclusion (stv tv-s tv-c)))))) 62 | 63 | (define concept-direct-evaluation-rule-name 64 | (DefinedSchemaNode "concept-direct-evaluation-rule")) 65 | (DefineLink concept-direct-evaluation-rule-name 66 | concept-direct-evaluation-rule) 67 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/conjunction-direct-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; Conjunction direct introduction rule 2 | ;; 3 | ;; A 4 | ;; B 5 | ;; |- 6 | ;; And 7 | ;; A 8 | ;; B 9 | ;; 10 | ;; where TV is calculated using direct evidence obtained from member 11 | ;; or evaluation links. 12 | 13 | (load "extensional-utils.scm") 14 | 15 | ;; Rule 16 | ;; 17 | ;; TODO: support n-ary 18 | (define conjunction-direct-introduction-rule 19 | (let* ((A (Variable "$A")) 20 | (B (Variable "$B")) 21 | (CptT (Type 'Concept))) 22 | (Bind 23 | (VariableSet 24 | (TypedVariable A CptT) 25 | (TypedVariable B CptT)) 26 | (Present 27 | A 28 | B) 29 | (ExecutionOutput 30 | (GroundedSchema "scm: conjunction-direct-introduction") 31 | (List 32 | ;; Conclusion 33 | (And A B) 34 | ;; Premises 35 | (Set 36 | A 37 | B)))))) 38 | 39 | ;; Formula. Note that for now is also produces MemberLink while this 40 | ;; should probably go in a separate rule. 41 | (define (conjunction-direct-introduction conclusion . premises) 42 | ;; (cog-logger-debug "(conjunction-direct-introduction conclusion=~a . premises=~a)" conclusion premises) 43 | (if (= (length premises) 1) 44 | (let* ((operands (car premises)) 45 | (A (gar operands)) 46 | (B (gdr operands)) 47 | ;; Fetch all members of A and B 48 | (A-mbrs (get-members-of A)) 49 | (B-mbrs (get-members-of B)) 50 | (AB-mbrs (lset-intersection equal? A-mbrs B-mbrs)) 51 | (all-nodes (cog-get-atoms 'Node #f)) 52 | (usize (length all-nodes)) ; TODO: replace this 53 | ; horrible hack 54 | (tv-s (/ (length AB-mbrs) usize)) 55 | (tv-c (count->confidence usize))) 56 | ;; Create members over the conjunction 57 | ;; TODO: use min tvs instead of (stv 1 1) 58 | 59 | ;; Update conjunction TV 60 | (if (and (< 0 tv-s) (< 0 tv-c)) ; Hack 61 | (let* ((tv (stv tv-s tv-c))) 62 | (map (lambda (x) (Member (stv 1 1) x conclusion)) AB-mbrs) 63 | (cog-merge-hi-conf-tv! conclusion (stv tv-s tv-c))))))) 64 | 65 | (define conjunction-direct-introduction-rule-name 66 | (DefinedSchemaNode "conjunction-direct-introduction-rule")) 67 | (DefineLink conjunction-direct-introduction-rule-name 68 | conjunction-direct-introduction-rule) 69 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/extensional-utils.scm: -------------------------------------------------------------------------------- 1 | ;; Helpers for rules pertaining to extensional reasoning 2 | 3 | (define (variable? X) 4 | " 5 | Return #t iff X is a variable or glob 6 | " 7 | (or (equal? (cog-type X) 'VariableNode) 8 | (equal? (cog-type X) 'GlobNode))) 9 | 10 | (define (get-member-links-of C) 11 | " 12 | Given C, return all its member links, 13 | (except link with variable as member). 14 | " 15 | (let* ((mbr-lnks (cog-filter 'MemberLink (cog-incoming-set C))) 16 | (nonvar-mbr-of-C? (lambda (x) 17 | (and (equal? C (gdr x)) 18 | (< 0 (cog-confidence x)) 19 | (not (variable? (gar x))))))) 20 | (filter nonvar-mbr-of-C? mbr-lnks))) 21 | 22 | (define (get-members-of C) 23 | " 24 | Given C, return all its members (except variables) 25 | " 26 | (map gar (get-member-links-of C))) 27 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/member-deduction.scm: -------------------------------------------------------------------------------- 1 | ;; TODO: maybe this should go to the term folder 2 | 3 | ;; Member deduction rule 4 | ;; 5 | ;; Subset A B 6 | ;; Member X A 7 | ;; |- 8 | ;; Member X B 9 | ;; 10 | ;; For now assume that TV1 and TV2 are absolutly true. 11 | 12 | ;; Rule 13 | (define member-deduction-rule 14 | (let* ((X (Variable "$X")) 15 | (A (Variable "$A")) 16 | (B (Variable "$B")) 17 | (CptT (Type 'Concept))) 18 | (Bind 19 | (VariableSet 20 | X 21 | (TypedVariable A CptT) 22 | (TypedVariable B CptT)) 23 | (And 24 | (Present 25 | (Member X A) 26 | (Subset A B)) 27 | (Evaluation 28 | (GroundedPredicate "scm: absolutely-true") 29 | (Member X A)) 30 | (Evaluation 31 | (GroundedPredicate "scm: absolutely-true") 32 | (Subset A B))) 33 | (ExecutionOutput 34 | (GroundedSchema "scm: member-deduction") 35 | (List 36 | ;; Conclusion 37 | (Member X B) 38 | ;; Premises 39 | (Subset A B) 40 | (Member X A)))))) 41 | 42 | ;; Formula 43 | (define (member-deduction conclusion . premises) 44 | ;; (cog-logger-debug "(member-deduction conclusion=~a . premises=~a)" conclusion premises) 45 | (if (= (length premises) 2) 46 | (let* ((SubAB (car premises)) 47 | (MemXA (cadr premises)) 48 | (tv-s (* (cog-mean SubAB) (cog-mean MemXA))) 49 | (tv-c (min (cog-confidence SubAB) (cog-confidence MemXA)))) 50 | (if (and (= 1 tv-s) (= 1 tv-c)) ; Only add if absolutely true 51 | (cog-merge-hi-conf-tv! conclusion (stv tv-s tv-c)))))) 52 | 53 | (define member-deduction-rule-name 54 | (DefinedSchemaNode "member-deduction-rule")) 55 | (DefineLink member-deduction-rule-name 56 | member-deduction-rule) 57 | -------------------------------------------------------------------------------- /opencog/pln/rules/extensional/subset-direct-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; Subset direct introduction rule 2 | ;; 3 | ;; A 4 | ;; B 5 | ;; TODO: add existential condition of member links 6 | ;; |- 7 | ;; Subset 8 | ;; A 9 | ;; B 10 | ;; 11 | ;; where TV is calculated using direct evidence obtained from member 12 | ;; links (thus is extensional, not mixed). 13 | 14 | (load "extensional-utils.scm") 15 | 16 | ;; Rule 17 | (define subset-direct-introduction-rule 18 | (let* ((A (Variable "$A")) 19 | (B (Variable "$B")) 20 | (CptT (TypeInh 'Concept)) 21 | (AndT (Type 'And))) 22 | (Bind 23 | (VariableSet 24 | (TypedVariable A (TypeChoice CptT AndT)) 25 | (TypedVariable B (TypeChoice CptT AndT))) 26 | (Present 27 | A 28 | B) 29 | (ExecutionOutput 30 | (GroundedSchema "scm: subset-direct-introduction") 31 | (List 32 | ;; Conclusion 33 | (Subset A B) 34 | ;; Premises 35 | A 36 | B))))) 37 | 38 | ;; Given a list of members of A and B calculate the TV of 39 | ;; 40 | ;; SubsetLink 41 | ;; A 42 | ;; B 43 | (define (subset-evidence->tv A-mbrs B-mbrs) 44 | ;; (cog-logger-debug "(subset-evidence->tv A-mbrs=~a B-mbrs=~a)" A-mbrs B-mbrs) 45 | (let* ;; TODO consider TVs of the members 46 | ((A-size (length A-mbrs)) 47 | (AB-mbrs (lset-intersection equal? A-mbrs B-mbrs)) 48 | (AB-size (length AB-mbrs)) 49 | (strength (if (< 0 A-size) 50 | (exact->inexact (/ AB-size A-size)) 51 | 1)) 52 | (confidence (if (< 0 A-size) 53 | (count->confidence A-size) 54 | 0))) 55 | (stv strength confidence))) 56 | 57 | ;; Formula 58 | (define (subset-direct-introduction conclusion . premises) 59 | ;; (cog-logger-debug "(subset-direct-introduction conclusion=~a . premises=~a)" conclusion premises) 60 | (if (= (length premises) 2) 61 | (let* ((Ss conclusion) 62 | (A (car premises)) 63 | (B (cadr premises)) 64 | ;; Fetch all members of A and B 65 | (A-mbrs (get-members-of A)) 66 | (B-mbrs (get-members-of B)) 67 | ;; Calculate the TV based on the members of A and B 68 | (tv (subset-evidence->tv A-mbrs B-mbrs))) 69 | (if (and (< 0 (cog-tv-mean tv)) (< 0 (cog-tv-confidence tv))) 70 | (cog-merge-hi-conf-tv! Ss tv))))) 71 | 72 | (define subset-direct-introduction-rule-name 73 | (DefinedSchemaNode "subset-direct-introduction-rule")) 74 | (DefineLink subset-direct-introduction-rule-name 75 | subset-direct-introduction-rule) 76 | -------------------------------------------------------------------------------- /opencog/pln/rules/intensional/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Intensional rules 2 | ADD_GUILE_MODULE(FILES 3 | attraction-introduction.scm 4 | intensional-inheritance-direct-introduction.scm 5 | intensional-similarity-direct-introduction.scm 6 | intensional-difference-direct-introduction.scm 7 | intensional-difference-member-introduction.scm 8 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/intensional" 9 | ) 10 | -------------------------------------------------------------------------------- /opencog/pln/rules/intensional/attraction-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Attraction introduction rule, e.g. for Subset 3 | ;; 4 | ;; Subset 5 | ;; A 6 | ;; B 7 | ;; Subset 8 | ;; Not 9 | ;; A 10 | ;; B 11 | ;; |- 12 | ;; Attraction 13 | ;; A 14 | ;; B 15 | ;; 16 | ;; where TV is defined as follows 17 | ;; 18 | ;; TV.s = pattern-of(B,A) 19 | ;; TV.c = min(STV.c, SNTV.c) 20 | ;; 21 | ;; pattern-of(B,A) = (P(B|A)-P(B|¬A))+ 22 | ;; 23 | ;; where s(B) is the prior of B and x+ is the positive part of x. For 24 | ;; now the prior of B is 1. 25 | 26 | ;; Rule for Subset (TODO: replace by generator) 27 | (define subset-attraction-introduction-rule 28 | (let* ((A (Variable "$A")) 29 | (B (Variable "$B")) 30 | (CT (TypeInh "ConceptNode"))) 31 | (BindLink 32 | (VariableSet 33 | (TypedVariable A CT) 34 | (TypedVariable B CT)) 35 | (Present 36 | (Subset A B) 37 | (Subset (Not A) B)) 38 | (ExecutionOutputLink 39 | (GroundedSchemaNode "scm: attraction-introduction") 40 | (ListLink 41 | ;; Conclusion 42 | (Attraction A B) 43 | ;; Premises 44 | (Subset A B) 45 | (Subset (Not A) B)))))) 46 | 47 | ;; Formula 48 | (define (attraction-introduction conclusion . premises) 49 | (if (= (length premises) 2) 50 | (let* ((ATT conclusion) 51 | (SAB (car premises)) 52 | (SNAB (cadr premises)) 53 | (ATTs (max 0 (- (cog-mean SAB) (cog-mean SNAB)))) 54 | (ATTc (min (cog-confidence SAB) (cog-confidence SNAB))) 55 | (ATTtv (stv ATTs ATTc))) 56 | (if (< 0 ATTc) (cog-merge-hi-conf-tv! ATT ATTtv))))) 57 | 58 | ; Name the rule 59 | (define subset-attraction-introduction-rule-name 60 | (DefinedSchemaNode "subset-attraction-introduction-rule")) 61 | (DefineLink subset-attraction-introduction-rule-name 62 | subset-attraction-introduction-rule) 63 | -------------------------------------------------------------------------------- /opencog/pln/rules/intensional/intensional-difference-member-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; Rule for introducing 2 | ;; 3 | ;; MemberLink 4 | ;; X 5 | ;; IntensionalDifferenceLink 6 | ;; A 7 | ;; B 8 | ;; 9 | ;; based on the direct evidence of patterns of A and B, and 10 | ;; the intensional difference between them. 11 | ;; 12 | ;; IntensionalDifferenceLink 13 | ;; A 14 | ;; B 15 | ;; AttractionLink 16 | ;; A 17 | ;; X 18 | ;; AttractionLink 19 | ;; B 20 | ;; X 21 | ;; |- 22 | ;; MemberLink 23 | ;; X 24 | ;; IntensionalDifferenceLink 25 | ;; A 26 | ;; B 27 | 28 | ;; Rule 29 | (define intensional-difference-member-introduction-rule 30 | (let* ((A (Variable "$A")) 31 | (B (Variable "$B")) 32 | (X (Variable "$X")) 33 | (CT (TypeInh "ConceptNode"))) 34 | (Bind 35 | (VariableSet 36 | (TypedVariable A CT) 37 | (TypedVariable B CT) 38 | (TypedVariable X CT)) 39 | (And 40 | (Present 41 | (IntensionalDifference A B) 42 | (Attraction A X) 43 | (Attraction B X))) 44 | (ExecutionOutput 45 | (GroundedSchema "scm: intensional-difference-member-introduction") 46 | (List 47 | ;; Conclusion 48 | (Member X (IntensionalDifference A B)) 49 | ;; Premises 50 | (IntensionalDifference A B) 51 | (Attraction A X) 52 | (Attraction B X)))))) 53 | 54 | ;; Formula 55 | (define (intensional-difference-member-introduction conclusion . premises) 56 | ;; Given the attraction links of A and B, calculate the 57 | ;; strength of the TV expressed as 58 | ;; 59 | ;; min(attraction(A,X), 1 - attraction(B,X)) 60 | ;; 61 | ;; where the attraction(A,X) is the strength of the TV of 62 | ;; 63 | ;; Attraction 64 | ;; A 65 | ;; X 66 | (define (get-strength A-at B-at) 67 | (min (cog-mean A-at) (- 1 (cog-mean B-at)))) 68 | 69 | ;; Given the attraction links of A and B, calculate the 70 | ;; confidence of the TV expressed as 71 | ;; 72 | ;; min(attraction(A,X), attraction(B,X)) 73 | ;; 74 | ;; where the attraction(A,X) is the confidence of the TV of 75 | ;; 76 | ;; Attraction 77 | ;; A 78 | ;; X 79 | (define (get-confidence A-at B-at) 80 | (min (cog-confidence A-at) (cog-confidence B-at))) 81 | 82 | (let* ((MembLink conclusion) 83 | (A-at (cadr premises)) 84 | (B-at (caddr premises)) 85 | (TVs (get-strength A-at B-at)) 86 | (TVc (get-confidence A-at B-at)) 87 | (TV (stv TVs TVc))) 88 | (if (< 0 TVc) (cog-merge-hi-conf-tv! MembLink TV)))) 89 | 90 | ; Name the rule 91 | (define intensional-difference-member-introduction-rule-name 92 | (DefinedSchemaNode "intensional-difference-member-introduction-rule")) 93 | (DefineLink intensional-difference-member-introduction-rule-name 94 | intensional-difference-member-introduction-rule) 95 | -------------------------------------------------------------------------------- /opencog/pln/rules/predicate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Predicate looking logic rules 2 | ADD_GUILE_MODULE(FILES 3 | conditional-direct-evaluation.scm 4 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/predicate" 5 | ) 6 | -------------------------------------------------------------------------------- /opencog/pln/rules/propositional/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Boolean algebra rules 2 | ADD_GUILE_MODULE(FILES 3 | consequent-disjunction-elimination.scm 4 | modus-ponens.scm 5 | contraposition.scm 6 | fuzzy-conjunction-introduction.scm 7 | crisp-conjunction-introduction.scm 8 | fuzzy-disjunction-introduction.scm 9 | formulas.scm 10 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/propositional" 11 | ) 12 | -------------------------------------------------------------------------------- /opencog/pln/rules/propositional/formulas.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Negate formula 3 | ;; 4 | ;; Negates the probability 5 | ;; ----------------------------------------------------------------------------- 6 | 7 | (define (negate a) 8 | (- 1 a)) 9 | 10 | ;; ============================================================================= 11 | ;; PreciseModusPonens formula 12 | ;; 13 | ;; Returns the strength value of the precise modus ponens rule 14 | ;; ----------------------------------------------------------------------------- 15 | 16 | (define (precise-modus-ponens-strength-formula sA sAB snotAB) 17 | (+ (* sAB sA) (* snotAB (negate sA)))) 18 | 19 | -------------------------------------------------------------------------------- /opencog/pln/rules/temporal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Extensional rules 2 | ADD_GUILE_MODULE(FILES 3 | predictive-implication-scope-direct-introduction.scm 4 | predictive-implication-direct-evaluation.scm 5 | predictive-implication-scope-direct-evaluation.scm 6 | predictive-implication-scope-deduction.scm 7 | back-predictive-implication-direct-evaluation.scm 8 | back-predictive-implication-scope-direct-evaluation.scm 9 | back-predictive-implication-scope-direct-introduction.scm 10 | back-predictive-implication-scope-deduction-cogscm.scm 11 | utils.scm 12 | back-predictive-implication-scope-conditional-conjunction-introduction.scm 13 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/temporal" 14 | ) 15 | -------------------------------------------------------------------------------- /opencog/pln/rules/term/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Term logic rules 2 | ADD_GUILE_MODULE(FILES 3 | deduction.scm 4 | full-deduction.scm 5 | present-deduction.scm 6 | formulas.scm 7 | condition-negation.scm 8 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/term" 9 | ) 10 | -------------------------------------------------------------------------------- /opencog/pln/rules/term/condition-negation.scm: -------------------------------------------------------------------------------- 1 | ;; Condition Negation rule, e.g. for Subset 2 | ;; 3 | ;; Subset 4 | ;; A 5 | ;; B 6 | ;; |- 7 | ;; Subset 8 | ;; Not A 9 | ;; B 10 | ;; 11 | ;; where TV is defined as follows 12 | ;; 13 | ;; Strength: 14 | ;; 15 | ;; TV.s = (BTV.s - STV.s * ATV.s) / (1 - ATV.s) 16 | ;; 17 | ;; which derives from 18 | ;; 19 | ;; P(B|¬A) = P(B∩¬A) / P(¬A) 20 | ;; = (P(B) - P(B∩A)) / (1 - P(A)) 21 | ;; = (P(B) - P(B|A)*P(A)) / (1 - P(A)) 22 | ;; 23 | ;; Confidence: 24 | ;; 25 | ;; TV.c = min(count->confidence(confidence->count(ATV.c) * (1 - ATV.s)), STV.c) 26 | ;; 27 | ;; which is a heuristic deriving from 28 | ;; 29 | ;; 1) Estimating the positive count of (Not A), which should be the 30 | ;; count of (Subset (Not A) B). 31 | ;; 32 | ;; 2) Combine with (via min) the count of (Subset A B) in case the 33 | ;; estimation of 1) is too high. 34 | 35 | ;; Rule for Subset 36 | ;; 37 | ;; TODO: replace by generator. 38 | (define subset-condition-negation-rule 39 | (let* ((A (Variable "$A")) 40 | (B (Variable "$B")) 41 | (CT (Type "ConceptNode"))) 42 | (Bind 43 | (VariableSet 44 | (TypedVariable A CT) 45 | (TypedVariable B CT)) 46 | (Present 47 | (Subset A B)) 48 | (ExecutionOutput 49 | (GroundedSchema "scm: subset-condition-negation") 50 | (List 51 | ;; Conclusion 52 | (Subset (Not A) B) 53 | ;; Premises 54 | (Subset A B) 55 | A 56 | B))))) 57 | 58 | ;; Formula 59 | (define (subset-condition-negation conclusion . premises) 60 | (if (= (length premises) 3) 61 | (let* ((NS conclusion) 62 | (S (car premises)) 63 | (A (cadr premises)) 64 | (B (caddr premises)) 65 | (Ss (cog-mean S)) 66 | (Sc (cog-confidence S)) 67 | (As (cog-mean A)) 68 | (Ac (cog-confidence A)) 69 | (Bs (cog-mean B)) 70 | (NAs (- 1 As)) 71 | (NSs (if (< As 1) 72 | (/ (- Bs (* Ss As)) NAs) 73 | 1)) 74 | (NSc (if (< As 1) 75 | (min (count->confidence (* (confidence->count Ac) NAs)) Sc) 76 | 0)) 77 | (NStv (stv NSs NSc))) 78 | (cog-merge-hi-conf-tv! NS NStv)))) 79 | 80 | ;; Name 81 | (define subset-condition-negation-rule-name 82 | (DefinedSchemaNode "subset-condition-negation-rule")) 83 | (DefineLink subset-condition-negation-rule-name subset-condition-negation-rule) 84 | -------------------------------------------------------------------------------- /opencog/pln/rules/term/present-deduction.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Crisp deduction rules 3 | ;; 4 | ;; Inheritance 5 | ;; A 6 | ;; B 7 | ;; Inheritance 8 | ;; B 9 | ;; C 10 | ;; |- 11 | ;; Inheritance 12 | ;; A 13 | ;; C 14 | ;; 15 | ;; For now only the following rule is implemented 16 | ;; 17 | ;; present-deduction-inheritance-rule 18 | ;; 19 | ;; No precondition exists on the TV, only the mere presence of the 20 | ;; Inheritance is enough. Likewise the conclusion requires no formula, 21 | ;; it only adds the presence of the conclusion to the atomspace. 22 | ;; 23 | ;; ----------------------------------------------------------------------------- 24 | 25 | (use-modules (opencog logger)) 26 | 27 | ;; Generate the corresponding deduction rule given its link-type and 28 | ;; the type of each variable (the same for all 3). 29 | (define (gen-present-deduction-rule link-type var-type) 30 | (let* ((A (Variable "$A")) 31 | (B (Variable "$B")) 32 | (C (Variable "$C")) 33 | (AB (link-type A B)) 34 | (BC (link-type B C)) 35 | (AC (link-type A C))) 36 | (Bind 37 | (VariableList 38 | (TypedVariable A var-type) 39 | (TypedVariable B var-type) 40 | (TypedVariable C var-type)) 41 | (And 42 | (Present 43 | AB 44 | BC) 45 | (Not (Identical A C))) 46 | AC))) 47 | 48 | ;;;;;;;;;;;;;;;; 49 | ;; New naming ;; 50 | ;;;;;;;;;;;;;;;; 51 | 52 | (define inheritance-present-deduction-rule 53 | (gen-present-deduction-rule InheritanceLink (TypeNode "ConceptNode"))) 54 | 55 | ;; Name the rules 56 | (define inheritance-present-deduction-rule-name 57 | (DefinedSchemaNode "inheritance-present-deduction-rule")) 58 | (DefineLink inheritance-present-deduction-rule-name 59 | inheritance-present-deduction-rule) 60 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Work in progress rules 2 | ADD_GUILE_MODULE(FILES 3 | implication-direct-evaluation.scm 4 | instantiation.scm 5 | implication-instantiation.scm 6 | and-introduction.scm 7 | and-lambda-factorization-double-implication.scm 8 | and-simplification.scm 9 | equivalence-scope-distribution.scm 10 | equivalence-to-implication.scm 11 | implication-and-lambda-factorization.scm 12 | implication-implicant-conjunction.scm 13 | implication-implicant-disjunction.scm 14 | implication-implicant-distribution.scm 15 | implication-scope-to-implication.scm 16 | implication-to-implication-scope.scm 17 | inversion.scm 18 | closed-lambda-introduction.scm 19 | closed-lambda-evaluation.scm 20 | predicate-lambda-evaluation.scm 21 | and-lambda-distribution.scm 22 | and-to-context.scm 23 | contextualize.scm 24 | extensional-similarity-evaluation.scm 25 | intensional-inheritance-evaluation.scm 26 | member-to-evaluation.scm 27 | or-simplification.scm 28 | abduction.scm 29 | and-as-1st-arg-inside-inheritance-link.scm 30 | and-as-2nd-arg-inside-inheritance-link.scm 31 | and-breakdown.scm 32 | and-elimination.scm 33 | compile-rules.scm 34 | decontextualize.scm 35 | evaluation-to-member.scm 36 | forall-implication-to-higher-order.scm 37 | forall-instantiation.scm 38 | implication-and.scm 39 | induction.scm 40 | inheritance-to-member.scm 41 | intensional-similarity-evaluation.scm 42 | member-to-inheritance.scm 43 | not-introduction.scm 44 | not-elimination.scm 45 | not-simplification.scm 46 | ontological-inheritance.scm 47 | or-breakdown.scm 48 | or-introduction.scm 49 | or-elimination.scm 50 | or-evaluation.scm 51 | precise-modus-ponens.scm 52 | README.md 53 | subset-evaluation.scm 54 | symmetric-modus-ponens.scm 55 | term-probability.scm 56 | transitive-similarity.scm 57 | and-evaluation.scm 58 | and-to-subset-rule1.scm 59 | and-to-subset-rulen.scm 60 | and-transformation.scm 61 | attraction.scm 62 | context-free-to-sensitive.scm 63 | evaluation-implication.scm 64 | implication-introduction.scm 65 | inheritance.scm 66 | negated-subset-evaluation.scm 67 | or-transformation.scm 68 | similarity.scm 69 | negation-introduction.scm 70 | temp-deduction.scm 71 | formulas.scm 72 | MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/pln/rules/wip" 73 | ) 74 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/README.md: -------------------------------------------------------------------------------- 1 | Rules that have not been sorted yet. They might work but it's not sure. 2 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-as-1st-arg-inside-inheritance-link.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; And as 1st arg inside inheritance link rule 3 | ;; 4 | ;; InheritanceLink 5 | ;; A 6 | ;; C 7 | ;; InheritanceLink 8 | ;; B 9 | ;; C 10 | ;; |- 11 | ;; InheritanceLink 12 | ;; AndLink 13 | ;; A 14 | ;; B 15 | ;; C 16 | ;; 17 | ;; ----------------------------------------------------------------------------- 18 | (load "formulas.scm") 19 | 20 | (define and-as-1st-arg-inside-inheritance-link-rule 21 | (BindLink 22 | (VariableList 23 | (VariableNode "$A") 24 | (VariableNode "$B") 25 | (VariableNode "$C")) 26 | (AndLink 27 | (InheritanceLink 28 | (VariableNode "$A") 29 | (VariableNode "$C")) 30 | (InheritanceLink 31 | (VariableNode "$B") 32 | (VariableNode "$C")) 33 | (NotLink 34 | (IdenticalLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")))) 37 | (ExecutionOutputLink 38 | (GroundedSchemaNode "scm: and-as-1st-arg-formula") 39 | (ListLink 40 | (VariableNode "$A") 41 | (VariableNode "$B") 42 | (VariableNode "$C") 43 | (InheritanceLink 44 | (VariableNode "$A") 45 | (VariableNode "$C")) 46 | (InheritanceLink 47 | (VariableNode "$B") 48 | (VariableNode "$C")) 49 | (AndLink 50 | (VariableNode "$A") 51 | (VariableNode "$B")) 52 | (InheritanceLink 53 | (AndLink 54 | (VariableNode "$A") 55 | (VariableNode "$B")) 56 | (VariableNode "$C")))))) 57 | 58 | (define (and-as-1st-arg-formula A B C AC BC AB ABC) 59 | ( 60 | (cog-set-tv! 61 | AB 62 | (stv 63 | (* (cog-mean A) (cog-mean B)) 64 | (min (cog-confidence A) (cog-confidence B)))) 65 | (cog-set-tv! 66 | ABC 67 | (stv 68 | (/ 69 | (* 70 | (* (cog-mean AC) (cog-mean BC)) 71 | (* (cog-mean A) (cog-mean B))) 72 | (* (cog-mean C) (cog-mean AB))) 73 | (min 74 | (cog-confidence A) 75 | (cog-confidence B) 76 | (cog-confidence C) 77 | (cog-confidence AC) 78 | (cog-confidence BC)))))) 79 | 80 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-as-2nd-arg-inside-inheritance-link.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; And as 2nd arg inside inheritance link rule 3 | ;; 4 | ;; InheritanceLink 5 | ;; A 6 | ;; B 7 | ;; InheritanceLink 8 | ;; A 9 | ;; C 10 | ;; |- 11 | ;; InheritanceLink 12 | ;; A 13 | ;; AndLink 14 | ;; B 15 | ;; C 16 | ;; 17 | ;; ----------------------------------------------------------------------------- 18 | (load "formulas.scm") 19 | 20 | (define and-as-2nd-arg-inside-inheritance-link-rule 21 | (BindLink 22 | (VariableList 23 | (VariableNode "$A") 24 | (VariableNode "$B") 25 | (VariableNode "$C")) 26 | (AndLink 27 | (InheritanceLink 28 | (VariableNode "$A") 29 | (VariableNode "$B")) 30 | (InheritanceLink 31 | (VariableNode "$A") 32 | (VariableNode "$C")) 33 | (NotLink 34 | (IdenticalLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")))) 37 | (ExecutionOutputLink 38 | (GroundedSchemaNode "scm: and-as-2nd-arg-formula") 39 | (ListLink 40 | (VariableNode "$A") 41 | (VariableNode "$B") 42 | (VariableNode "$C") 43 | (InheritanceLink 44 | (VariableNode "$A") 45 | (VariableNode "$B")) 46 | (InheritanceLink 47 | (VariableNode "$A") 48 | (VariableNode "$C")) 49 | (AndLink 50 | (VariableNode "$B") 51 | (VariableNode "$C")) 52 | (InheritanceLink 53 | (VariableNode "$A") 54 | (AndLink 55 | (VariableNode "$B") 56 | (VariableNode "$C"))))))) 57 | 58 | (define (and-as-2nd-arg-formula A B C AB AC BC ABC) 59 | ( 60 | (cog-set-tv! 61 | BC 62 | (stv 63 | (* (cog-mean B) (cog-mean C)) 64 | (min (cog-confidence B) (cog-confidence C)))) 65 | (cog-set-tv! 66 | ABC 67 | (stv 68 | (/ 69 | (* 70 | (* (cog-mean AB) (cog-mean BC)) 71 | (* (cog-mean A) (cog-mean AC))) 72 | (* (cog-mean C) (cog-mean B))) 73 | (min 74 | (cog-confidence A) 75 | (cog-confidence B) 76 | (cog-confidence C) 77 | (cog-confidence AB) 78 | (cog-confidence AC)))))) 79 | 80 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-breakdown.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; AndBreakdownRule 3 | ; 4 | ; AndLink 5 | ; A 6 | ; B 7 | ; & 8 | ; A 9 | ; |- 10 | ; B 11 | ;---------------------------------------------------------------------- 12 | 13 | 14 | (define and-breakdown-rule 15 | (BindLink 16 | (VariableList 17 | (VariableNode "$A") 18 | (VariableNode "$B")) 19 | (AndLink 20 | (AndLink 21 | (VariableNode "$A") 22 | (VariableNode "$B")) 23 | (VariableNode "$A")) 24 | (ExecutionOutputLink 25 | (GroundedSchemaNode "scm: and-breakdown-formula") 26 | (ListLink 27 | (AndLink 28 | (VariableNode "$A") 29 | (VariableNode "$B")) 30 | (VariableNode "$A") 31 | (VariableNode "$B"))))) 32 | 33 | (define (and-breakdown-formula AB A B) 34 | (cog-set-tv! 35 | B 36 | (and-breakdown-side-effect-free-formula AB A B)) 37 | ) 38 | 39 | (define (and-breakdown-side-effect-free-formula AB A B) 40 | (let 41 | ((sAB (cog-mean AB)) 42 | (cAB (cog-confidence AB)) 43 | (sA (cog-mean A)) 44 | (cA (cog-confidence A))) 45 | (stv (/ sAB sA) (min cAB cA)))) 46 | 47 | ; Name the rule 48 | (define and-breakdown-rule-name (DefinedSchemaNode "and-breakdown-rule")) 49 | (DefineLink and-breakdown-rule-name and-breakdown-rule) 50 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-elimination.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; AndEliminationRule 3 | ; 4 | ; AndLink 5 | ; A 6 | ; B 7 | ; |- 8 | ; A 9 | ; B 10 | ;---------------------------------------------------------------------- 11 | ;; Given rule is binary because creating more than one link would create 12 | ;; an issue with backward chaining. 13 | ;; TODO :- Create the rule n-ary 14 | 15 | (define and-elimination-rule 16 | (BindLink 17 | (VariableList 18 | (VariableNode "$A") 19 | (VariableNode "$B")) 20 | (AndLink 21 | (AndLink 22 | (VariableNode "$A") 23 | (VariableNode "$B"))) 24 | (ExecutionOutputLink 25 | (GroundedSchemaNode "scm: and-elimination-formula") 26 | (ListLink 27 | (AndLink 28 | (VariableNode "$A") 29 | (VariableNode "$B")) 30 | (VariableNode "$A") 31 | (VariableNode "$B"))))) 32 | 33 | (define (and-elimination-formula AB A B) 34 | (cog-set-tv! 35 | A 36 | (and-elimination-side-effect-free-formula AB)) 37 | (cog-set-tv! 38 | B 39 | (and-elimination-side-effect-free-formula AB)) 40 | ) 41 | 42 | (define (and-elimination-side-effect-free-formula AB) 43 | (let 44 | ((sAB (cog-mean AB)) 45 | (cAB (cog-confidence AB))) 46 | (stv (expt sAB 0.5) (/ cAB 1.42)))) 47 | 48 | ; Name the rule 49 | (define and-elimination-rule-name (DefinedSchemaNode "and-elimination-rule")) 50 | (DefineLink and-elimination-rule-name and-elimination-rule) 51 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; AndEvaluationRule 3 | ; 4 | ; AndLink 5 | ; MemberLink 6 | ; C 7 | ; A 8 | ; MemberLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; AndLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define and-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (MemberLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (MemberLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: and-evaluation-formula") 33 | (ListLink 34 | (AndLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (MemberLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (MemberLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (and-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (and-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (and-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (and (>= sCA 0.5) (>= sCB 0.5)) 56 | (stv 1 1) 57 | (stv 0 1)))) 58 | 59 | ; Name the rule 60 | (define and-evaluation-rule-name (DefinedSchemaNode "and-evaluation-rule")) 61 | (DefineLink and-evaluation-rule-name and-evaluation-rule) 62 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-lambda-distribution.scm: -------------------------------------------------------------------------------- 1 | ;; ======================================================================= 2 | ;; AndLink Lambda Distribution Rule 3 | ;; (TODO add wiki page) 4 | ;; 5 | ;; LambdaLink 6 | ;; V 7 | ;; AndLink 8 | ;; A1 9 | ;; ... 10 | ;; An 11 | ;; |- 12 | ;; AndLink 13 | ;; LambdaLink 14 | ;; V 15 | ;; A1 16 | ;; ... 17 | ;; LambdaLink 18 | ;; V 19 | ;; An 20 | ;; 21 | ;; where V is a variable or a list of variables, A1 to An are bodies 22 | ;; using containing variable(s) V. 23 | ;; ----------------------------------------------------------------------- 24 | 25 | (define and-lambda-distribution-variables 26 | (VariableList 27 | (TypedVariableLink 28 | (VariableNode "$TyVs") 29 | (TypeChoice 30 | (TypeNode "TypedVariableLink") 31 | (TypeNode "VariableNode") 32 | (TypeNode "VariableList"))) 33 | (TypedVariableLink 34 | (VariableNode "$And") 35 | (TypeNode "AndLink")))) 36 | 37 | (define and-lambda-distribution-body 38 | (QuoteLink (LambdaLink 39 | (UnquoteLink (VariableNode "$TyVs")) 40 | (UnquoteLink (VariableNode "$And"))))) 41 | 42 | (define and-lambda-distribution-rewrite 43 | (ExecutionOutputLink 44 | (GroundedSchemaNode "scm: and-lambda-distribution-formula") 45 | (ListLink 46 | and-lambda-distribution-body))) 47 | 48 | (define and-lambda-distribution-rule 49 | (BindLink 50 | and-lambda-distribution-variables 51 | and-lambda-distribution-body 52 | and-lambda-distribution-rewrite)) 53 | 54 | (define (and-lambda-distribution-formula Lamb) 55 | (let* ( 56 | (Lamb-outgoings (cog-outgoing-set Lamb)) 57 | (SV (car Lamb-outgoings)) 58 | (conjunction (cadr Lamb-outgoings)) 59 | (junctors (cog-outgoing-set conjunction)) 60 | (wrap_with_lambda (lambda (junctor) (LambdaLink SV junctor))) 61 | (wrapped_junctors (map wrap_with_lambda junctors))) 62 | (cog-set-tv! (apply AndLink wrapped_junctors) (cog-tv Lamb)))) 63 | 64 | ;; Name the rule 65 | (define and-lambda-distribution-rule-name 66 | (DefinedSchemaNode "and-lambda-distribution-rule")) 67 | (DefineLink and-lambda-distribution-rule-name 68 | and-lambda-distribution-rule) 69 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-simplification.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; AndSimplificationRule 3 | ; 4 | ; A 5 | ; AndLink 6 | ; B 7 | ; C 8 | ; |- 9 | ; AndLink 10 | ; A 11 | ; B 12 | ; C 13 | ;---------------------------------------------------------------------- 14 | 15 | 16 | (define and-simplification-rule 17 | (BindLink 18 | (VariableList 19 | (VariableNode "$A") 20 | (VariableNode "$B") 21 | (VariableNode "$C")) 22 | (AndLink 23 | (VariableNode "$A") 24 | (AndLink 25 | (VariableNode "$B") 26 | (VariableNode "$C"))) 27 | (ExecutionOutputLink 28 | (GroundedSchemaNode "scm: and-simplification-formula") 29 | (ListLink 30 | (AndLink 31 | (VariableNode "$A") 32 | (AndLink 33 | (VariableNode "$B") 34 | (VariableNode "$C"))) 35 | (AndLink 36 | (VariableNode "$A") 37 | (VariableNode "$B") 38 | (VariableNode "$C")))))) 39 | 40 | (define (and-simplification-formula AABC ABC) 41 | (cog-set-tv! 42 | ABC 43 | (and-simplification-side-effect-free-formula AABC ABC)) 44 | ) 45 | 46 | (define (and-simplification-side-effect-free-formula AABC ABC) 47 | (let 48 | ((sAABC (cog-mean AABC)) 49 | (cAABC (cog-confidence AABC))) 50 | (stv sAABC cAABC))) 51 | 52 | ; Name the rule 53 | (define and-simplification-rule-name 54 | (DefinedSchemaNode "and-simplification-rule")) 55 | (DefineLink and-simplification-rule-name and-simplification-rule) 56 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-to-context.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; AndToContextRule 3 | ; 4 | ; SubsetLink 5 | ; AndLink 6 | ; A 7 | ; C 8 | ; AndLink 9 | ; B 10 | ; C 11 | ; |- 12 | ; ContextLink 13 | ; C 14 | ; SubsetLink 15 | ; A 16 | ; B 17 | ; 18 | ; ----------------------------------------------------------------------------- 19 | (define and-to-context-rule 20 | (BindLink 21 | (VariableList 22 | (VariableNode "$A") 23 | (VariableNode "$B") 24 | (VariableNode "$C")) 25 | (SubsetLink 26 | (AndLink 27 | (VariableNode "$A") 28 | (VariableNode "$C")) 29 | (AndLink 30 | (VariableNode "$B") 31 | (VariableNode "$C"))) 32 | (ExecutionOutputLink 33 | (GroundedSchemaNode "scm: and-to-context-formula") 34 | (ListLink 35 | (SubsetLink 36 | (AndLink 37 | (VariableNode "$A") 38 | (VariableNode "$C")) 39 | (AndLink 40 | (VariableNode "$B") 41 | (VariableNode "$C"))) 42 | (ContextLink 43 | (VariableNode "$C") 44 | (SubsetLink 45 | (VariableNode "$A") 46 | (VariableNode "$B"))))))) 47 | 48 | (define (and-to-context-formula SACBC CAB) 49 | (cog-set-tv! 50 | CAB (cog-tv SACBC))) 51 | 52 | 53 | 54 | ; Name the rule 55 | (define and-to-context-rule-name (DefinedSchemaNode "and-to-context-rule")) 56 | (DefineLink and-to-context-rule-name and-to-context-rule) 57 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-to-subset-rule1.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; And to Subset Rule1 3 | ; 4 | ; AndLink 5 | ; AndLink 6 | ; A 7 | ; B 8 | ; A 9 | ; |- 10 | ; SubsetLink 11 | ; A 12 | ; B 13 | ; 14 | ; ----------------------------------------------------------------------------- 15 | 16 | (define and-to-subset1-rule 17 | (BindLink 18 | (VariableList 19 | (VariableNode "$A") 20 | (VariableNode "$B")) 21 | (AndLink 22 | (AndLink 23 | (VariableNode "$A") 24 | (VariableNode "$B")) 25 | (VariableNode "$A")) 26 | (ExecutionOutputLink 27 | (GroundedSchemaNode "scm: and-to-subset1-formula") 28 | (ListLink 29 | (AndLink 30 | (VariableNode "$A") 31 | (VariableNode "$B")) 32 | (VariableNode "$A") 33 | (SubsetLink 34 | (VariableNode "$A") 35 | (VariableNode "$B")))))) 36 | 37 | (define (and-to-subset1-formula AAB A SAB) 38 | (cog-set-tv! 39 | SAB 40 | (if 41 | (= (cog-mean A) 0) 42 | (stv 0 0) 43 | (stv 44 | (/ (cog-mean AAB) (cog-mean A)) 45 | (min (cog-confidence AAB) (cog-confidence A)))))) 46 | 47 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/and-transformation.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; AndTransformationRule 3 | ; 4 | ; AndLink 5 | ; A 6 | ; B 7 | ; |- 8 | ; (NotLink (A => (NotLink B))) 9 | ; 10 | ;---------------------------------------------------------------------- 11 | 12 | 13 | (define and-transformation-rule 14 | (BindLink 15 | (VariableList 16 | (VariableNode "$A") 17 | (VariableNode "$B")) 18 | (AndLink 19 | (VariableNode "$A") 20 | (VariableNode "$B")) 21 | (ExecutionOutputLink 22 | (GroundedSchemaNode "scm: and-transformation-formula") 23 | (ListLink 24 | (AndLink 25 | (VariableNode "$A") 26 | (VariableNode "$B")) 27 | (NotLink 28 | (ImplicationLink 29 | (VariableNode "$A") 30 | (NotLink 31 | (VariableNode "$B")))))))) 32 | 33 | (define (and-transformation-formula AB NIAB) 34 | (cog-set-tv! 35 | NIAB 36 | (and-transformation-side-effect-free-formula AB NIAB)) 37 | ) 38 | 39 | 40 | (define (and-transformation-side-effect-free-formula AB NIAB) 41 | (let 42 | ((sAB (cog-mean AB)) 43 | (cAB (cog-confidence AB))) 44 | (stv sAB cAB))) 45 | 46 | ; Name the rule 47 | (define and-transformation-rule-name (DefinedSchemaNode "and-transformation-rule")) 48 | (DefineLink and-transformation-rule-name and-transformation-rule) 49 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/attraction.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; AttractionRule 3 | ; 4 | ; AndLink 5 | ; SubsetLink 6 | ; A 7 | ; B 8 | ; SubsetLink 9 | ; NotLink 10 | ; A 11 | ; B 12 | ; |- 13 | ; AttractionLink 14 | ; A 15 | ; B 16 | ; 17 | ; ----------------------------------------------------------------------------- 18 | 19 | (define attraction-rule 20 | (BindLink 21 | (VariableList 22 | (VariableNode "$A") 23 | (VariableNode "$B")) 24 | (AndLink 25 | (SubsetLink 26 | (VariableNode "$A") 27 | (VariableNode "$B")) 28 | (SubsetLink 29 | (NotLink 30 | (VariableNode "$A")) 31 | (VariableNode "$B"))) 32 | (ExecutionOutputLink 33 | (GroundedSchemaNode "scm: attraction-formula") 34 | (ListLink 35 | (AttractionLink 36 | (VariableNode "$A") 37 | (VariableNode "$B")) 38 | (SubsetLink 39 | (VariableNode "$A") 40 | (VariableNode "$B")) 41 | (SubsetLink 42 | (NotLink 43 | (VariableNode "$A")) 44 | (VariableNode "$B")))))) 45 | 46 | (define (attraction-formula AB SAB SnAB) 47 | (cog-set-tv! 48 | AB 49 | (attraction-side-effect-free-formula AB SAB SnAB) 50 | ) 51 | ) 52 | 53 | (define (attraction-side-effect-free-formula AB SAB SnAB) 54 | (let 55 | ( 56 | (sSAB (cog-mean SAB)) 57 | (cSAB (cog-confidence SAB)) 58 | (sSnAB (cog-mean SnAB)) 59 | (cSnAB (cog-confidence SnAB)) 60 | 61 | ) 62 | (if 63 | (<= sSAB sSnAB) 64 | (stv 0 (min cSAB cSnAB)) 65 | (stv (- sSAB sSnAB) (min cSAB cSnAB))))) 66 | 67 | ; Name the rule 68 | (define attraction-rule-name (DefinedSchemaNode "attraction-rule")) 69 | (DefineLink attraction-rule-name attraction-rule) 70 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/closed-lambda-evaluation.scm: -------------------------------------------------------------------------------- 1 | ;; ===================================================================== 2 | ;; Closed lambda evaluation rule 3 | ;; 4 | ;; LambdaLink 5 | ;; V 6 | ;; Body 7 | ;; |- 8 | ;; LambdaLink 9 | ;; V 10 | ;; Body 11 | ;; 12 | ;; Like closed-lambda-introduction-rule but merely calculate the TV of 13 | ;; an existing lambda link over a closed term instead of building 14 | ;; one. It is a strict refinement used to not pollute the atomspace 15 | ;; with extranous combinations when applied in a naive forward way. 16 | ;; ---------------------------------------------------------------------- 17 | 18 | (define closed-lambda-evaluation-vardecl 19 | (VariableList 20 | (TypedVariableLink 21 | (VariableNode "$V") 22 | (TypeChoice 23 | (TypeNode "TypedVariableLink") 24 | (TypeNode "VariableList") 25 | (TypeNode "VariableNode"))) 26 | (TypedVariableLink 27 | (VariableNode "$B") 28 | (TypeNode "EvaluationLink")))) 29 | 30 | (define closed-lambda-evaluation-pattern 31 | (AndLink 32 | (QuoteLink (LambdaLink 33 | (UnquoteLink (VariableNode "$V")) 34 | (UnquoteLink (VariableNode "$B")))) 35 | (EvaluationLink 36 | (GroundedPredicateNode "scm: closed-lambda-evaluation-precondition") 37 | (VariableNode "$B")))) 38 | 39 | (define closed-lambda-evaluation-rewrite 40 | (ExecutionOutputLink 41 | (GroundedSchemaNode "scm: closed-lambda-evaluation-formula") 42 | (ListLink 43 | (QuoteLink (LambdaLink 44 | (UnquoteLink (VariableNode "$V")) 45 | (UnquoteLink (VariableNode "$B")))) 46 | (VariableNode "$B")))) 47 | 48 | (define closed-lambda-evaluation-rule 49 | (BindLink 50 | closed-lambda-evaluation-vardecl 51 | closed-lambda-evaluation-pattern 52 | closed-lambda-evaluation-rewrite)) 53 | 54 | (define (closed-lambda-evaluation-formula lamb body) 55 | (cog-set-tv! lamb (cog-tv body))) 56 | 57 | (define (closed-lambda-evaluation-precondition atom) 58 | (bool->tv (and (cog-closed? atom) (< 0 (cog-confidence atom))))) 59 | 60 | ;; Name the rule 61 | (define closed-lambda-evaluation-rule-name 62 | (DefinedSchemaNode "closed-lambda-evaluation-rule")) 63 | (DefineLink closed-lambda-evaluation-rule-name 64 | closed-lambda-evaluation-rule) 65 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/closed-lambda-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; ===================================================================== 2 | ;; Closed lamdba introduction rule 3 | ;; 4 | ;; V 5 | ;; Body 6 | ;; |- 7 | ;; LambdaLink 8 | ;; V 9 | ;; Body 10 | ;; 11 | ;; Wrap a Lambda around a closed atom (that is an atom without free 12 | ;; variables in it) and assign to the lambda the TV of the body. So 13 | ;; basically create a constant predicate or schema. 14 | ;; ---------------------------------------------------------------------- 15 | 16 | (define closed-lambda-introduction-vardecl 17 | (VariableList 18 | (TypedVariableLink 19 | (VariableNode "$V") 20 | (TypeChoice 21 | (TypeNode "TypedVariableLink") 22 | (TypeNode "VariableList") 23 | (TypeNode "VariableNode"))) 24 | (TypedVariableLink 25 | (VariableNode "$B") 26 | (TypeNode "EvaluationLink")))) 27 | 28 | (define closed-lambda-introduction-pattern 29 | (AndLink 30 | (VariableNode "$V") 31 | (VariableNode "$B") 32 | (EvaluationLink 33 | (GroundedPredicateNode "scm: closed-lambda-introduction-precondition") 34 | (VariableNode "$B")))) 35 | 36 | (define closed-lambda-introduction-rewrite 37 | (ExecutionOutputLink 38 | (GroundedSchemaNode "scm: closed-lambda-introduction-formula") 39 | (ListLink 40 | (QuoteLink (LambdaLink 41 | (UnquoteLink (VariableNode "$V")) 42 | (UnquoteLink (VariableNode "$B")))) 43 | (VariableNode "$B")))) 44 | 45 | (define closed-lambda-introduction-rule 46 | (BindLink 47 | closed-lambda-introduction-vardecl 48 | closed-lambda-introduction-pattern 49 | closed-lambda-introduction-rewrite)) 50 | 51 | (define (closed-lambda-introduction-formula lamb body) 52 | (cog-set-tv! lamb (cog-tv body))) 53 | 54 | (define (closed-lambda-introduction-precondition atom) 55 | (bool->tv (and (cog-closed? atom) (< 0 (cog-confidence atom))))) 56 | 57 | ;; Name the rule 58 | (define closed-lambda-introduction-rule-name 59 | (DefinedSchemaNode "closed-lambda-introduction-rule")) 60 | (DefineLink closed-lambda-introduction-rule-name 61 | closed-lambda-introduction-rule) 62 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/compile-rules.scm: -------------------------------------------------------------------------------- 1 | ; ========================================================================== 2 | ; Compile the functions to improve performance 3 | ; ========================================================================== 4 | 5 | (define functions-list (list 6 | 'deduction-rule 7 | 'simple-deduction-strength-formula 8 | 'simple-deduction-side-effect-free-formula 9 | 10 | 'modus-ponens-rule 11 | 'simple-modus-ponens-formula 12 | 'simple-modus-ponens-side-effect-free-formula 13 | )) 14 | 15 | (for-each 16 | (lambda (f) (compile f #:env (current-module))) 17 | functions-list) 18 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/context-free-to-sensitive.scm: -------------------------------------------------------------------------------- 1 | ;=============================================================================== 2 | ; ContextFreeToSensitiveRule 3 | ; http://wiki.opencog.org/w/ContextFreeToSensitiveRule 4 | ; 5 | ; C 6 | ; A 7 | ; |- 8 | ; ContextLink 9 | ; C 10 | ; A 11 | ;------------------------------------------------------------------------------- 12 | 13 | (define context-free-to-sensitive-rule 14 | (BindLink 15 | (VariableList 16 | (VariableNode "$A") 17 | (VariableNode "$C")) 18 | (AndLink 19 | (VariableNode "$C") 20 | (VariableNode "$A")) 21 | (ExecutionOutputLink 22 | (GroundedSchemaNode "scm: context-free-to-sensitive-formula") 23 | (ListLink 24 | (ContextLink 25 | (VariableNode "$C") 26 | (VariableNode "$A")) 27 | (AndLink 28 | (VariableNode "$C") 29 | (VariableNode "$A")))))) 30 | 31 | (define (context-free-to-sensitive-formula Context CA) 32 | (cog-set-tv! Context 33 | (cog-new-stv (cog-mean CA) (cog-confidence CA)))) 34 | ; ; strength (now just computed as the mean of the strengths of C & A) 35 | ; (/ 36 | ; (+ 37 | ; (cog-mean C) (cog-mean A)) 38 | ; 2) 39 | ; ; confidence 40 | ; (* 41 | ; (cog-confidence C) 42 | ; (cog-confidence A) 43 | ; (- 1 (entropy (cog-mean C))) 44 | ; (- 1 (entropy (cog-mean A)))) 45 | 46 | ;(define (entropy p) 47 | ; (- 48 | ; (sum ; how should sigma be implemented here? 49 | ; ; should a uniform distribution be assumed? 50 | ; (* 51 | ; p 52 | ; (log p))))) 53 | 54 | ; Name the rule 55 | (define context-free-to-sensitive-rule-name 56 | (DefinedSchemaNode "context-free-to-sensitive-rule")) 57 | (DefineLink 58 | context-free-to-sensitive-rule-name 59 | context-free-to-sensitive-rule) 60 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/equivalence-scope-distribution.scm: -------------------------------------------------------------------------------- 1 | ;; ======================================================================= 2 | ;; Equivalence Scope Distribution Rule 3 | ;; (TODO add wiki page) 4 | ;; 5 | ;; EquivalenceLink 6 | ;; V 7 | ;; P 8 | ;; Q 9 | ;; |- 10 | ;; EquivalenceLink 11 | ;; LambdaLink 12 | ;; V 13 | ;; P 14 | ;; LambdaLink 15 | ;; V 16 | ;; Q 17 | ;; 18 | ;; where V is a variable or a list of variables, P and Q are the 19 | ;; implicant and implicand bodies. 20 | ;; ----------------------------------------------------------------------- 21 | 22 | (define equivalence-scope-distribution-variables 23 | (VariableList 24 | (TypedVariableLink 25 | (VariableNode "$TyVs") 26 | (TypeChoice 27 | (TypeNode "TypedVariableLink") 28 | (TypeNode "VariableList"))) 29 | (VariableNode "$P") 30 | (VariableNode "$Q"))) 31 | 32 | (define equivalence-scope-distribution-body 33 | (EquivalenceLink 34 | (VariableNode "$TyVs") 35 | (VariableNode "$P") 36 | (VariableNode "$Q"))) 37 | 38 | (define equivalence-scope-distribution-rewrite 39 | (ExecutionOutputLink 40 | (GroundedSchemaNode "scm: equivalence-scope-distribution-formula") 41 | (ListLink 42 | equivalence-scope-distribution-body))) 43 | 44 | (define equivalence-scope-distribution-rule 45 | (BindLink 46 | equivalence-scope-distribution-variables 47 | equivalence-scope-distribution-body 48 | equivalence-scope-distribution-rewrite)) 49 | 50 | (define (equivalence-scope-distribution-formula Impl) 51 | (let* ( 52 | (Impl-outgoings (cog-outgoing-set Impl)) 53 | (SV (car Impl-outgoings)) 54 | (P (cadr Impl-outgoings)) 55 | (Q (caddr Impl-outgoings)) 56 | (Impl-tv (cog-tv Impl))) 57 | (cog-set-tv! 58 | (EquivalenceLink 59 | (LambdaLink SV P) 60 | (LambdaLink SV Q)) 61 | Impl-tv))) 62 | 63 | ;; Name the rule 64 | (define equivalence-scope-distribution-rule-name 65 | (DefinedSchemaNode "equivalence-scope-distribution-rule")) 66 | (DefineLink equivalence-scope-distribution-rule-name 67 | equivalence-scope-distribution-rule) 68 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/equivalence-to-implication.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; EquivalenceToImplicationRule 3 | ;; 4 | ;; Equivalence 5 | ;; A 6 | ;; B 7 | ;; |- 8 | ;; Implication 9 | ;; A 10 | ;; B 11 | ;; Implication 12 | ;; B 13 | ;; A 14 | ;; 15 | ;; In practice we only need to provide the rewrite term for 16 | ;; 17 | ;; Implication 18 | ;; A 19 | ;; B 20 | ;; 21 | ;; as B->A will automatically be generated due to EquivalenceLink 22 | ;; being symmetric. 23 | ;; ----------------------------------------------------------------------------- 24 | 25 | (use-modules (opencog logger)) 26 | 27 | (define equivalence-to-implication-vardecl 28 | (VariableList 29 | (Variable "$A") 30 | (Variable "$B"))) 31 | 32 | (define equivalence-to-implication-premise 33 | (Equivalence 34 | (Variable "$A") 35 | (Variable "$B"))) 36 | 37 | (define equivalence-to-implication-precondition 38 | (EvaluationLink 39 | (GroundedPredicate "scm: gt-zero-confidence") 40 | equivalence-to-implication-premise)) 41 | 42 | (define equivalence-to-implication-pattern 43 | (And 44 | equivalence-to-implication-premise 45 | equivalence-to-implication-precondition)) 46 | 47 | (define equivalence-to-implication-conclusion 48 | (Implication 49 | (Variable "$A") 50 | (Variable "$B"))) 51 | 52 | (define equivalence-to-implication-rewrite 53 | (ExecutionOutput 54 | (GroundedSchema "scm: equivalence-to-implication-formula") 55 | (List 56 | equivalence-to-implication-conclusion 57 | equivalence-to-implication-premise))) 58 | 59 | (define equivalence-to-implication-rule 60 | (Bind 61 | equivalence-to-implication-vardecl 62 | equivalence-to-implication-pattern 63 | equivalence-to-implication-rewrite)) 64 | 65 | (define (equivalence-to-implication-formula AB EQ) 66 | (let* ((A (gar AB)) 67 | (B (gdr AB)) 68 | (sA (cog-mean A)) 69 | (sB (cog-mean B)) 70 | (sEQ (cog-mean EQ)) 71 | (cEQ (cog-confidence EQ)) 72 | (sAB (if (< 0.99 (* sEQ cEQ)) ; Hack to work around the 73 | ; lack of distributional 74 | ; TV. If sEQ is high enough, 75 | ; we just set sAB as sEQ 76 | sEQ 77 | ;; Formula based on PLN book formula for sim2inh 78 | (/ (* (+ 1 (/ sB sA)) sEQ) (+ 1 sEQ))))) 79 | (if (< 0 cEQ) ; 80 | (cog-merge-hi-conf-tv! AB (stv sAB cEQ))))) 81 | 82 | ;; Name the rule 83 | (define equivalence-to-implication-rule-name 84 | (DefinedSchema "equivalence-to-implication-rule")) 85 | (Define 86 | equivalence-to-implication-rule-name 87 | equivalence-to-implication-rule) 88 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/extensional-similarity-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; ExtensionalSimilarityEvaluationRule 3 | ; 4 | ; AndLink 5 | ; MemberLink 6 | ; C 7 | ; A 8 | ; MemberLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; ExtensionalSimilarityLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define extensional-similarity-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (MemberLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (MemberLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: extensional-similarity-evaluation-formula") 33 | (ListLink 34 | (ExtensionalSimilarityLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (MemberLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (MemberLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (extensional-similarity-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (extensional-similarity-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (extensional-similarity-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (and (< sCA 0.5) (< sCB 0.5)) 56 | (stv 0 0) 57 | (if 58 | (and (>= sCA 0.5) (>= sCB 0.5)) 59 | (stv 1 1) 60 | (stv 0 1))))) 61 | 62 | ; Name the rule 63 | (define extensional-similarity-evaluation-rule-name 64 | (DefinedSchemaNode "extensional-similarity-evaluation-rule")) 65 | (DefineLink extensional-similarity-evaluation-rule-name 66 | extensional-similarity-evaluation-rule) 67 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/forall-implication-to-higher-order.scm: -------------------------------------------------------------------------------- 1 | ;; ======================================================================= 2 | ;; ForAll Implication to higher order rule 3 | ;; (TODO add wiki page) 4 | ;; 5 | ;; ForAllLink 6 | ;; V 7 | ;; ImplicationLink 8 | ;; P[V] 9 | ;; Q[V] 10 | ;; |- 11 | ;; ImplicationLink 12 | ;; LambdaLink 13 | ;; V 14 | ;; P[V] 15 | ;; LambdaLink 16 | ;; V 17 | ;; Q[V] 18 | ;; 19 | ;; where V is a variable, and P[V] and Q[V] are predicate bodies 20 | ;; containing V. 21 | ;; ----------------------------------------------------------------------- 22 | 23 | (use-modules (srfi srfi-1)) 24 | 25 | (use-modules (opencog exec)) 26 | (use-modules (opencog logger)) 27 | 28 | (define forall-implication-to-higher-order-variables 29 | (VariableList 30 | (TypedVariableLink 31 | (VariableNode "$TyVs") 32 | (TypeChoice 33 | (TypeNode "TypedVariableLink") 34 | (TypeNode "VariableList"))) 35 | (TypedVariableLink 36 | (VariableNode "$Impl") 37 | (TypeNode "ImplicationLink")))) 38 | 39 | (define forall-implication-to-higher-order-body 40 | (QuoteLink (ForAllLink 41 | (UnquoteLink (VariableNode "$TyVs")) 42 | (UnquoteLink (VariableNode "$Impl"))))) 43 | 44 | (define forall-implication-to-higher-order-rewrite 45 | (ExecutionOutputLink 46 | (GroundedSchemaNode "scm: forall-implication-to-higher-order-formula") 47 | (ListLink 48 | (VariableNode "$TyVs") 49 | (VariableNode "$Impl")))) 50 | 51 | (define forall-implication-to-higher-order-rule 52 | (BindLink 53 | forall-implication-to-higher-order-variables 54 | forall-implication-to-higher-order-body 55 | forall-implication-to-higher-order-rewrite)) 56 | 57 | ;; TODO: only crisp for now 58 | (define (forall-implication-to-higher-order-formula TyVs Impl) 59 | (cog-set-tv! 60 | (let* ( 61 | (impl-outgoings (cog-outgoing-set Impl)) 62 | (impl-t (car impl-outgoings)) 63 | (impl-d (cadr impl-outgoings))) 64 | (ImplicationLink 65 | (LambdaLink 66 | TyVs 67 | impl-t) 68 | (LambdaLink 69 | TyVs 70 | impl-d))) 71 | (stv 1 1))) 72 | 73 | ;; Name the rule 74 | (define forall-implication-to-higher-order-rule-name 75 | (DefinedSchemaNode "forall-implication-to-higher-order-rule")) 76 | (DefineLink forall-implication-to-higher-order-rule-name 77 | forall-implication-to-higher-order-rule) 78 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/implication-and.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; ImplicationAndRule 3 | ; 4 | ; AndLink 5 | ; ImplicationLink 6 | ; A 7 | ; B 8 | ; ImplicationLink 9 | ; AndLink 10 | ; B 11 | ; C 12 | ; D 13 | ; |- 14 | ; ImplicationLink 15 | ; AndLink 16 | ; A 17 | ; C 18 | ; D 19 | ; 20 | ; ----------------------------------------------------------------------------- 21 | 22 | (define implication-and-rule 23 | (BindLink 24 | (VariableList 25 | (VariableNode "$A") 26 | (VariableNode "$B") 27 | (VariableNode "$C") 28 | (VariableNode "$D")) 29 | (AndLink 30 | (ImplicationLink 31 | (VariableNode "$A") 32 | (VariableNode "$B")) 33 | (ImplicationLink 34 | (AndLink 35 | (VariableNode "$B") 36 | (VariableNode "$C")) 37 | (VariableNode "$D"))) 38 | (ExecutionOutputLink 39 | (GroundedSchemaNode "scm: implication-and-formula") 40 | (ListLink 41 | (ImplicationLink 42 | (AndLink 43 | (VariableNode "$A") 44 | (VariableNode "$C")) 45 | (VariableNode "$D")) 46 | (ImplicationLink 47 | (VariableNode "$A") 48 | (VariableNode "$B")) 49 | (ImplicationLink 50 | (AndLink 51 | (VariableNode "$B") 52 | (VariableNode "$C")) 53 | (VariableNode "$D")))))) 54 | 55 | (define (implication-and-formula ACD AB BCD) 56 | (cog-set-tv! 57 | (implication-and-side-effect-free-formula ACD AB BCD) 58 | ) 59 | ) 60 | 61 | (define (implication-and-side-effect-free-formula ACD AB BCD) 62 | (stv 1 1)) 63 | 64 | ; Name the rule 65 | (define implication-and-rule-name (DefinedSchemaNode "implication-and-rule")) 66 | (DefineLink implication-and-rule-name implication-and-rule) 67 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/implication-implicant-distribution.scm: -------------------------------------------------------------------------------- 1 | ;; ===================================================================== 2 | ;; Implication implicant distribution rule 3 | ;; 4 | ;; ImplicationLink 5 | ;; P 6 | ;; Q 7 | ;; |- 8 | ;; ImplicationLink 9 | ;; P 10 | ;; AndLink 11 | ;; P 12 | ;; Q 13 | ;; 14 | ;;---------------------------------------------------------------------- 15 | 16 | (define implication-implicant-distribution-vardecl 17 | (VariableList 18 | (TypedVariableLink 19 | (VariableNode "$P") 20 | (TypeChoice 21 | (TypeNode "PredicateNode") 22 | (TypeNode "LambdaLink"))) 23 | (TypedVariableLink 24 | (VariableNode "$Q") 25 | (TypeChoice 26 | (TypeNode "PredicateNode") 27 | (TypeNode "LambdaLink"))))) 28 | 29 | (define implication-implicant-distribution-pattern 30 | (And 31 | (ImplicationLink 32 | (VariableNode "$P") 33 | (VariableNode "$Q")) 34 | (EvaluationLink 35 | (GroundedPredicateNode "scm: gt-zero-confidence") 36 | (ImplicationLink 37 | (VariableNode "$P") 38 | (VariableNode "$Q"))))) 39 | 40 | (define implication-implicant-distribution-rewrite 41 | (ExecutionOutputLink 42 | (GroundedSchemaNode "scm: implication-implicant-distribution-formula") 43 | (ListLink 44 | (ImplicationLink 45 | (VariableNode "$P") 46 | (And 47 | (VariableNode "$P") 48 | (VariableNode "$Q"))) 49 | (ImplicationLink 50 | (VariableNode "$P") 51 | (VariableNode "$Q"))))) 52 | 53 | (define implication-implicant-distribution-rule 54 | (BindLink 55 | implication-implicant-distribution-vardecl 56 | implication-implicant-distribution-pattern 57 | implication-implicant-distribution-rewrite)) 58 | 59 | (define (implication-implicant-distribution-formula DImpl Impl) 60 | (cog-merge-hi-conf-tv! DImpl (cog-tv Impl))) 61 | 62 | ;; Name the rule 63 | (define implication-implicant-distribution-rule-name 64 | (DefinedSchemaNode "implication-implicant-distribution-rule")) 65 | (DefineLink implication-implicant-distribution-rule-name 66 | implication-implicant-distribution-rule) 67 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/implication-scope-to-implication.scm: -------------------------------------------------------------------------------- 1 | ;; ======================================================================= 2 | ;; Implication Scope to Implication Rule 3 | ;; 4 | ;; ImplicationScopeLink 5 | ;; V 6 | ;; P 7 | ;; Q 8 | ;; |- 9 | ;; ImplicationLink 10 | ;; LambdaLink 11 | ;; V 12 | ;; P 13 | ;; LambdaLink 14 | ;; V 15 | ;; Q 16 | ;; 17 | ;; where V is a variable declaration, P and Q are the implicant and 18 | ;; implicand bodies. 19 | ;; ----------------------------------------------------------------------- 20 | 21 | (define implication-scope-to-implication-variables 22 | (VariableList 23 | (TypedVariableLink 24 | (VariableNode "$TyVs") 25 | (TypeChoice 26 | (TypeNode "TypedVariableLink") 27 | (TypeNode "VariableList"))) 28 | (VariableNode "$P") 29 | (VariableNode "$Q"))) 30 | 31 | (define implication-scope-to-implication-body 32 | (Quote (ImplicationScopeLink 33 | (Unquote (VariableNode "$TyVs")) 34 | (Unquote (VariableNode "$P")) 35 | (Unquote (VariableNode "$Q"))))) 36 | 37 | (define implication-scope-to-implication-rewrite 38 | (ExecutionOutputLink 39 | (GroundedSchemaNode "scm: implication-scope-to-implication-formula") 40 | (ListLink 41 | (Implication 42 | (Quote (Lambda 43 | (Unquote (VariableNode "$TyVs")) 44 | (Unquote (VariableNode "$P")))) 45 | (Quote (Lambda 46 | (Unquote (VariableNode "$TyVs")) 47 | (Unquote (VariableNode "$Q"))))) 48 | implication-scope-to-implication-body))) 49 | 50 | (define implication-scope-to-implication-rule 51 | (BindLink 52 | implication-scope-to-implication-variables 53 | implication-scope-to-implication-body 54 | implication-scope-to-implication-rewrite)) 55 | 56 | (define (implication-scope-to-implication-formula Impl ImplSc) 57 | (cog-merge-hi-conf-tv! Impl (cog-tv ImplSc))) 58 | 59 | ;; Name the rule 60 | (define implication-scope-to-implication-rule-name 61 | (DefinedSchemaNode "implication-scope-to-implication-rule")) 62 | (DefineLink implication-scope-to-implication-rule-name 63 | implication-scope-to-implication-rule) 64 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/implication-to-implication-scope.scm: -------------------------------------------------------------------------------- 1 | ;; ======================================================================= 2 | ;; Implication Scope to Implication Rule 3 | ;; (TODO add wiki page) 4 | ;; 5 | ;; ImplicationLink 6 | ;; LambdaLink 7 | ;; V 8 | ;; P 9 | ;; LambdaLink 10 | ;; V 11 | ;; Q 12 | ;; |- 13 | ;; ImplicationScopeLink 14 | ;; V 15 | ;; P 16 | ;; Q 17 | ;; 18 | ;; where V is a variable or a list of variables, P and Q are the 19 | ;; implicant and implicand bodies. 20 | ;; ----------------------------------------------------------------------- 21 | 22 | (define implication-to-implication-scope-variables 23 | (VariableList 24 | (TypedVariableLink 25 | (VariableNode "$TyVs") 26 | (TypeChoice 27 | (TypeNode "TypedVariableLink") 28 | (TypeNode "VariableList"))) 29 | (VariableNode "$P") 30 | (VariableNode "$Q"))) 31 | 32 | (define implication-to-implication-scope-body 33 | (ImplicationLink 34 | (QuoteLink (LambdaLink 35 | (UnquoteLink (VariableNode "$TyVs")) 36 | (UnquoteLink (VariableNode "$P")))) 37 | (QuoteLink (LambdaLink 38 | (UnquoteLink (VariableNode "$TyVs")) 39 | (UnquoteLink (VariableNode "$Q")))))) 40 | 41 | (define implication-to-implication-scope-rewrite 42 | (ExecutionOutputLink 43 | (GroundedSchemaNode "scm: implication-to-implication-scope-formula") 44 | (ListLink 45 | implication-to-implication-scope-body 46 | (QuoteLink (ImplicationScopeLink 47 | (UnquoteLink (VariableNode "$TyVs")) 48 | (UnquoteLink (VariableNode "$P")) 49 | (UnquoteLink (VariableNode "$Q"))))))) 50 | 51 | (define implication-to-implication-scope-rule 52 | (BindLink 53 | implication-to-implication-scope-variables 54 | implication-to-implication-scope-body 55 | implication-to-implication-scope-rewrite)) 56 | 57 | (define (implication-to-implication-scope-formula lamb-Impl Impl) 58 | (let* ( 59 | (Impl-outgoings (cog-outgoing-set Impl)) 60 | (SV (car Impl-outgoings)) 61 | (P (cadr Impl-outgoings)) 62 | (Q (caddr Impl-outgoings)) 63 | (lamb-Impl-tv (cog-tv lamb-Impl))) 64 | (cog-set-tv! 65 | (ImplicationScopeLink 66 | SV 67 | P 68 | Q) 69 | lamb-Impl-tv))) 70 | 71 | ;; Name the rule 72 | (define implication-to-implication-scope-rule-name 73 | (DefinedSchemaNode "implication-to-implication-scope-rule")) 74 | (DefineLink implication-to-implication-scope-rule-name 75 | implication-to-implication-scope-rule) 76 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/inheritance-to-member.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; InheritanceToMemberRule 3 | ; 4 | ; InheritanceLink 5 | ; B 6 | ; C 7 | ; |- 8 | ; MemberLink 9 | ; B 10 | ; C 11 | ; 12 | ; ----------------------------------------------------------------------------- 13 | 14 | (define inheritance-to-member-rule 15 | (BindLink 16 | (VariableList 17 | (VariableNode "$B") 18 | (VariableNode "$C")) 19 | (InheritanceLink 20 | (VariableNode "$B") 21 | (VariableNode "$C")) 22 | (ExecutionOutputLink 23 | (GroundedSchemaNode "scm: inheritance-to-member-formula") 24 | (ListLink 25 | (MemberLink 26 | (VariableNode "$B") 27 | (VariableNode "$C")) 28 | (InheritanceLink 29 | (VariableNode "$B") 30 | (VariableNode "$C")))))) 31 | 32 | ; ----------------------------------------------------------------------------- 33 | ; Inheritance To Member Formula 34 | ; ----------------------------------------------------------------------------- 35 | 36 | ; ----------------------------------------------------------------------------- 37 | ; Side-effect: TruthValue of the new link stays the same 38 | ; ----------------------------------------------------------------------------- 39 | 40 | (define (inheritance-to-member-formula MBC IBC) 41 | (cog-set-tv! 42 | MBC 43 | (inheritance-to-member-side-effect-free-formula 44 | MBC 45 | IBC))) 46 | 47 | ; ----------------------------------------------------------------------------- 48 | ; This version has no side effects and simply returns a TruthValue 49 | ; ----------------------------------------------------------------------------- 50 | 51 | (define (inheritance-to-member-side-effect-free-formula MBC IBC) 52 | (stv 53 | (cog-mean IBC) 54 | (* (cog-confidence IBC) 0.9))) 55 | 56 | ; ============================================================================= 57 | 58 | ; Name the rule 59 | (define inheritance-to-member-rule-name 60 | (DefinedSchemaNode "inheritance-to-member-rule")) 61 | (DefineLink 62 | inheritance-to-member-rule-name 63 | inheritance-to-member-rule) 64 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/inheritance.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; Inheritance Rule 3 | ; 4 | ; AndLink 5 | ; SubsetLink 6 | ; A 7 | ; B 8 | ; IntensionalInheritanceLink 9 | ; A 10 | ; B 11 | ; |- 12 | ; InheritanceLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define inheritance-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B")) 23 | (AndLink 24 | (SubsetLink 25 | (VariableNode "$A") 26 | (VariableNode "$B")) 27 | (IntensionalInheritanceLink 28 | (VariableNode "$A") 29 | (VariableNode "$B"))) 30 | (ExecutionOutputLink 31 | (GroundedSchemaNode "scm: inheritance-formula") 32 | (ListLink 33 | (SubsetLink 34 | (VariableNode "$A") 35 | (VariableNode "$B")) 36 | (IntensionalInheritanceLink 37 | (VariableNode "$A") 38 | (VariableNode "$B")) 39 | (InheritanceLink 40 | (VariableNode "$A") 41 | (VariableNode "$B")))))) 42 | 43 | (define (inheritance-formula SAB IIAB IAB) 44 | (cog-set-tv! 45 | IAB 46 | (stv 47 | (/ 48 | (+ (cog-mean SAB) (cog-mean IIAB)) 49 | 2.0) 50 | (min (cog-confidence SAB) (cog-confidence IIAB))))) 51 | 52 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/intensional-inheritance-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; IntensionalInheritanceEvaluationRule 3 | ; 4 | ; AndLink 5 | ; AttractionLink 6 | ; C 7 | ; A 8 | ; AttractionLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; IntensionalInheritanceLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define intensional-inheritance-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (AttractionLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (AttractionLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: intensional-inheritance-evaluation-formula") 33 | (ListLink 34 | (IntensionalInheritanceLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (AttractionLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (AttractionLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (intensional-inheritance-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (intensional-inheritance-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (intensional-inheritance-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (< sCA 0.5) 56 | (stv 0 0) 57 | (if 58 | (< sCB 0.5) 59 | (stv 1 0) 60 | (stv 1 1))))) 61 | 62 | ; Name the rule 63 | (define intensional-inheritance-evaluation-rule-name 64 | (DefinedSchemaNode "intensional-inheritance-evaluation-rule")) 65 | (DefineLink 66 | intensional-inheritance-evaluation-rule-name 67 | intensional-inheritance-evaluation-rule) 68 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/intensional-similarity-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; IntensionalSimilarityEvaluationRule 3 | ; 4 | ; AndLink 5 | ; AttractionLink 6 | ; C 7 | ; A 8 | ; AttractionLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; IntensionalSimilarityLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define intensional-similarity-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (AttractionLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (AttractionLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: intensional-similarity-evaluation-formula") 33 | (ListLink 34 | (IntensionalSimilarityLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (AttractionLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (AttractionLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (intensional-similarity-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (intensional-similarity-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (intensional-similarity-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (and (< sCA 0.5) (< sCB 0.5)) 56 | (stv 0 0) 57 | (if 58 | (and (>= sCA 0.5) (>= sCB 0.5)) 59 | (stv 1 1) 60 | (stv 0 1))))) 61 | 62 | ; Name the rule 63 | (define intensional-similarity-evaluation-rule-name 64 | (DefinedSchemaNode "intensional-similarity-evaluation-rule")) 65 | (DefineLink 66 | intensional-similarity-evaluation-rule-name 67 | intensional-similarity-evaluation-rule) 68 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/inversion.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; InversionRule 3 | ;; 4 | ;; 5 | ;; A 6 | ;; B 7 | ;; |- 8 | ;; 9 | ;; B 10 | ;; A 11 | ;; 12 | ;; Due to type system limitations, the rule has been divided into 3: 13 | ;; inversion-inheritance-rule 14 | ;; inversion-implication-rule 15 | ;; inversion-subset-rule 16 | ;; 17 | ;; ----------------------------------------------------------------------------- 18 | (load "formulas.scm") 19 | 20 | ;; Generate the corresponding inversion rule given its link-type. 21 | (define (gen-inversion-rule link-type) 22 | (BindLink 23 | (VariableList 24 | (VariableNode "$A") 25 | (VariableNode "$B")) 26 | (link-type 27 | (VariableNode "$A") 28 | (VariableNode "$B")) 29 | (ExecutionOutputLink 30 | (GroundedSchemaNode "scm: inversion-formula") 31 | (ListLink 32 | (link-type 33 | (VariableNode "$B") 34 | (VariableNode "$A")) 35 | (VariableNode "$A") 36 | (VariableNode "$B") 37 | (link-type 38 | (VariableNode "$A") 39 | (VariableNode "$B")))))) 40 | 41 | (define inversion-inheritance-rule 42 | (gen-inversion-rule InheritanceLink)) 43 | 44 | (define inversion-implication-rule 45 | (gen-inversion-rule ImplicationLink)) 46 | 47 | (define inversion-subset-rule 48 | (gen-inversion-rule SubsetLink)) 49 | 50 | (define (inversion-formula conclusion . premises) 51 | (if (= (length premises) 3) 52 | (let* 53 | ((BA conclusion) 54 | (A (list-ref premises 0)) 55 | (B (list-ref premises 1)) 56 | (AB (list-ref premises 2)) 57 | (sA (cog-mean A)) 58 | (cA (cog-confidence A)) 59 | (sB (cog-mean B)) 60 | (cB (cog-confidence B)) 61 | (sAB (cog-mean AB)) 62 | (cAB (cog-confidence AB)) 63 | (sBA (inversion-strength-formula sA sB sAB)) 64 | (cBA (* 0.9 (min cA cB cAB)))) 65 | (if (and (< 1e-8 sBA) (< 1e-8 cBA) ; Try to avoid constructing 66 | ; informationless knowledge 67 | (inversion-consistency sA sB sAB)) 68 | (cog-merge-hi-conf-tv! BA (stv sBA cBA)))))) 69 | 70 | ;; Name the rules 71 | (define inversion-inheritance-rule-name 72 | (DefinedSchemaNode "inversion-inheritance-rule")) 73 | (DefineLink inversion-inheritance-rule-name 74 | inversion-inheritance-rule) 75 | 76 | (define inversion-implication-rule-name 77 | (DefinedSchemaNode "inversion-implication-rule")) 78 | (DefineLink inversion-implication-rule-name 79 | inversion-implication-rule) 80 | 81 | (define inversion-subset-rule-name 82 | (DefinedSchemaNode "inversion-subset-rule")) 83 | (DefineLink inversion-subset-rule-name 84 | inversion-subset-rule) 85 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/member-to-inheritance.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; MemberToInheritanceRule 3 | ; 4 | ; MemberLink 5 | ; B 6 | ; C 7 | ; |- 8 | ; InheritanceLink 9 | ; B 10 | ; C 11 | ; 12 | ; ----------------------------------------------------------------------------- 13 | 14 | (define member-to-inheritance-rule 15 | (BindLink 16 | (VariableList 17 | (VariableNode "$B") 18 | (VariableNode "$C")) 19 | (MemberLink 20 | (VariableNode "$B") 21 | (VariableNode "$C")) 22 | (ExecutionOutputLink 23 | (GroundedSchemaNode "scm: member-to-inheritance-formula") 24 | (ListLink 25 | (InheritanceLink 26 | (VariableNode "$B") 27 | (VariableNode "$C")) 28 | (MemberLink 29 | (VariableNode "$B") 30 | (VariableNode "$C")))))) 31 | 32 | ; ----------------------------------------------------------------------------- 33 | ; Member To Inheritance Formula 34 | ; ----------------------------------------------------------------------------- 35 | 36 | ; ----------------------------------------------------------------------------- 37 | ; Side-effect: TruthValue of the new link stays the same 38 | ; ----------------------------------------------------------------------------- 39 | 40 | (define (member-to-inheritance-formula IBC MBC) 41 | (cog-set-tv! 42 | IBC 43 | (member-to-inheritance-side-effect-free-formula 44 | IBC 45 | MBC))) 46 | 47 | ; ----------------------------------------------------------------------------- 48 | ; This version has no side effects and simply returns a TruthValue 49 | ; ----------------------------------------------------------------------------- 50 | 51 | (define (member-to-inheritance-side-effect-free-formula IBC MBC) 52 | (stv 53 | (cog-mean MBC) 54 | (* (cog-confidence MBC) 0.9))) 55 | 56 | ; ============================================================================= 57 | 58 | ; Name the rule 59 | (define member-to-inheritance-rule-name 60 | (DefinedSchemaNode "member-to-inheritance-rule")) 61 | (DefineLink 62 | member-to-inheritance-rule-name 63 | member-to-inheritance-rule) 64 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/negated-subset-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; NegatedSubsetEvaluationRule 3 | ; 4 | ; AndLink 5 | ; MemberLink 6 | ; C 7 | ; A 8 | ; MemberLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; SubsetLink 13 | ; NotLink 14 | ; A 15 | ; B 16 | ; 17 | ; ----------------------------------------------------------------------------- 18 | 19 | (define negated-subset-evaluation-rule 20 | (BindLink 21 | (VariableList 22 | (VariableNode "$A") 23 | (VariableNode "$B") 24 | (VariableNode "$C")) 25 | (AndLink 26 | (MemberLink 27 | (VariableNode "$C") 28 | (VariableNode "$A")) 29 | (MemberLink 30 | (VariableNode "$C") 31 | (VariableNode "$B"))) 32 | (ExecutionOutputLink 33 | (GroundedSchemaNode "scm: negated-subset-evaluation-formula") 34 | (ListLink 35 | (SubsetLink 36 | (NotLink 37 | (VariableNode "$A")) 38 | (VariableNode "$B")) 39 | (MemberLink 40 | (VariableNode "$C") 41 | (VariableNode "$A")) 42 | (MemberLink 43 | (VariableNode "$C") 44 | (VariableNode "$B")))))) 45 | 46 | (define (negated-subset-evaluation-formula nAB CA CB) 47 | (cog-set-tv! 48 | nAB (negated-subset-evaluation-side-effect-free-formula nAB CA CB))) 49 | 50 | (define (subset-negated-evaluation-side-effect-free-formula nAB CA CB) 51 | (let 52 | ((snCA (- 1 (cog-mean CA))) 53 | (cnCA (cog-confidence CA)) 54 | (sCB (cog-mean CB)) 55 | (cCB (cog-confidence CB))) 56 | (if 57 | (< snCA 0.5) 58 | (stv 0 0) 59 | (if 60 | (< sCB 0.5) 61 | (stv 1 0) 62 | (stv 1 1))))) 63 | 64 | ; Name the rule 65 | (define negated-subset-evaluation-rule-name 66 | (DefinedSchemaNode "negated-subset-evaluation-rule")) 67 | (DefineLink 68 | negated-subset-evaluation-rule-name 69 | negated-subset-evaluation-rule) 70 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/negation-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Fuzzy negation introduction rule 3 | ;; 4 | ;; A 5 | ;; |- 6 | ;; NotLink 7 | ;; A 8 | ;; ----------------------------------------------------------------------------- 9 | 10 | (use-modules (srfi srfi-1)) 11 | 12 | ;; Negation rule 13 | (define negation-introduction-rule 14 | (let* ((X (Variable "$X")) 15 | (EvaluationT (Type "EvaluationLink")) 16 | (InheritanceT (Type "InheritanceLink")) 17 | (PredicateT (Type "PredicateNode")) 18 | (ConceptT (Type "ConceptNode")) 19 | (AndT (Type "AndLink")) 20 | (OrT (Type "OrLink")) 21 | ;; Not NotLink because we'd rather have that already flattened 22 | (type (TypeChoice EvaluationT InheritanceT PredicateT ConceptT)) 23 | (gen-typed-variable (lambda (x) (TypedVariable x type))) 24 | (vardecl (TypedVariable X type)) 25 | (pattern (And 26 | X 27 | ;; precondition 28 | (Evaluation 29 | (GroundedPredicate "scm: gt-zero-confidence") 30 | X))) 31 | (rewrite (ExecutionOutput 32 | (GroundedSchema "scm: negation-introduction-formula") 33 | ;; We wrap the variables in Set because the order 34 | ;; doesn't matter and this may speed up the URE. 35 | (List (Not X) X)))) 36 | (Bind 37 | vardecl 38 | pattern 39 | rewrite))) 40 | 41 | (define (negation-introduction-formula N A) 42 | (let* ((A-s (cog-mean A)) 43 | (A-c (cog-confidence A))) 44 | (cog-merge-hi-conf-tv! N (stv (- 1 A-s) A-c)))) 45 | 46 | ;; Name the rules 47 | (define negation-introduction-rule-name 48 | (DefinedSchema "negation-introduction-rule")) 49 | (DefineLink 50 | negation-introduction-rule-name 51 | negation-introduction-rule) 52 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/not-elimination.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; NotEliminationRule 3 | ; 4 | ; NotLink 5 | ; A 6 | ; |- 7 | ; A 8 | ;---------------------------------------------------------------------- 9 | 10 | 11 | (define not-elimination-rule 12 | (BindLink 13 | (VariableList 14 | (VariableNode "$A")) 15 | (NotLink 16 | (VariableNode "$A")) 17 | (ExecutionOutputLink 18 | (GroundedSchemaNode "scm: not-elimination-formula") 19 | (ListLink 20 | (NotLink 21 | (VariableNode "$A") 22 | (VariableNode "$A")))))) 23 | 24 | (define (not-elimination-formula NA A) 25 | (cog-set-tv! 26 | A 27 | (not-elimination-side-effect-free-formula NA A)) 28 | ) 29 | 30 | (define (not-elimination-side-effect-free-formula NA A) 31 | (let 32 | ((sNA (cog-mean NA)) 33 | (cNA (cog-confidence NA))) 34 | (stv (- 1 sNA) cAB ))) 35 | 36 | ; Name the rule 37 | (define not-elimination-rule-name (DefinedSchemaNode "not-elimination-rule")) 38 | (DefineLink not-elimination-rule-name not-elimination-rule) 39 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/not-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; To be replaced by negation-introduction-rule 2 | 3 | ; ===================================================================== 4 | ; Not introduction rule 5 | ; 6 | ; A 7 | ; |- 8 | ; NotLink 9 | ; A 10 | ;---------------------------------------------------------------------- 11 | 12 | (define not-introduction-rule 13 | (BindLink 14 | (VariableList 15 | (TypedVariableLink 16 | (VariableNode "$A") 17 | (TypeChoice 18 | (TypeNode "PredicateNode") 19 | (TypeNode "ConceptNode")))) 20 | (VariableNode "$A") 21 | (ExecutionOutputLink 22 | (GroundedSchemaNode "scm: not-introduction-formula") 23 | (ListLink 24 | (VariableNode "$A"))))) 25 | 26 | (define (not-introduction-formula A) 27 | (cog-set-tv! 28 | (NotLink A) 29 | (not-introduction-side-effect-free-formula A)) 30 | ) 31 | 32 | (define (negate x) 33 | (- 1 x)) 34 | 35 | (define (not-introduction-side-effect-free-formula A) 36 | (let ((sA (cog-mean A)) 37 | (cA (cog-confidence A))) 38 | (stv (negate sA) cA))) 39 | 40 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 41 | ;; Some test data (to be removed afterwards) ;; 42 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 43 | 44 | ; Name the rule 45 | (define not-introduction-rule-name 46 | (DefinedSchemaNode "not-introduction-rule")) 47 | (DefineLink 48 | not-introduction-rule-name 49 | not-introduction-rule) 50 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/not-simplification.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; NotSimplificationRule 3 | ; 4 | ; NotLink 5 | ; NotLink 6 | ; A 7 | ; |- 8 | ; A 9 | ;---------------------------------------------------------------------- 10 | 11 | 12 | (define not-simplification-rule 13 | (BindLink 14 | (VariableList 15 | (VariableNode "$A")) 16 | (NotLink 17 | (NotLink 18 | (VariableNode "$A"))) 19 | (ExecutionOutputLink 20 | (GroundedSchemaNode "scm: not-simplification-formula") 21 | (ListLink 22 | (NotLink 23 | (NotLink 24 | (VariableNode "$A"))) 25 | (VariableNode "$A"))))) 26 | 27 | (define (not-simplification-formula NNA A) 28 | (cog-set-tv! 29 | A 30 | (not-simplification-side-effect-free-formula NNA A)) 31 | ) 32 | 33 | (define (not-simplification-side-effect-free-formula NNA A) 34 | (let 35 | ((sNNA (cog-mean NNA)) 36 | (cNNA (cog-confidence NNA))) 37 | (stv (- 1 sNNA) cNNA))) 38 | 39 | ; Name the rule 40 | (define not-simplification-rule-name 41 | (DefinedSchemaNode "not-simplification-rule")) 42 | (DefineLink 43 | not-simplification-rule-name 44 | not-simplification-rule) 45 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/ontological-inheritance.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; OntologicalInheritanceRule 3 | ; 4 | ; AndLink 5 | ; InheritanceLink 6 | ; A 7 | ; B 8 | ; InheritanceLink 9 | ; B 10 | ; A 11 | ; |- 12 | ; OntologicalInheritanceLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define ontological-inheritance-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B")) 23 | (AndLink 24 | (InheritanceLink 25 | (VariableNode "$A") 26 | (VariableNode "$B")) 27 | (InheritanceLink 28 | (VariableNode "$B") 29 | (VariableNode "$A"))) 30 | (ExecutionOutputLink 31 | (GroundedSchemaNode "scm: ontological-inheritance-formula") 32 | (ListLink 33 | (OntologicalInheritanceLink 34 | (VariableNode "$A") 35 | (VariableNode "$B")) 36 | (InheritanceLink 37 | (VariableNode "$A") 38 | (VariableNode "$B")) 39 | (InheritanceLink 40 | (VariableNode "$B") 41 | (VariableNode "$A")))))) 42 | 43 | (define (ontological-inheritance-formula OAB AB BA) 44 | (cog-set-tv! 45 | OAB 46 | (ontological-inheritance-side-effect-free-formula OAB AB BA) 47 | ) 48 | ) 49 | 50 | (define (ontological-inheritance-side-effect-free-formula OAB AB BA) 51 | (let 52 | ((sAB (cog-mean AB)) 53 | (cAB (cog-confidence AB)) 54 | (sBA (cog-mean BA)) 55 | (cBA (cog-confidence BA)) 56 | ) 57 | (if 58 | (<= sAB sBA) 59 | (stv 0 (min cAB cBA)) 60 | (stv (- sAB sBA) (min cAB cBA))))) 61 | 62 | 63 | ; Name the rule 64 | (define ontological-inheritance-rule-name 65 | (DefinedSchemaNode "ontological-inheritance-rule")) 66 | (DefineLink 67 | ontological-inheritance-rule-name 68 | ontological-inheritance-rule) 69 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-breakdown.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; OrBreakdownRule 3 | ; 4 | ; OrLink 5 | ; A 6 | ; B 7 | ; & 8 | ; A 9 | ; |- 10 | ; B 11 | ;---------------------------------------------------------------------- 12 | 13 | 14 | (define or-breakdown-rule 15 | (BindLink 16 | (VariableList 17 | (VariableNode "$A") 18 | (VariableNode "$B")) 19 | (AndLink 20 | (OrLink 21 | (VariableNode "$A") 22 | (VariableNode "$B")) 23 | (VariableNode "$A")) 24 | (ExecutionOutputLink 25 | (GroundedSchemaNode "scm: or-breakdown-formula") 26 | (ListLink 27 | (OrLink 28 | (VariableNode "$A") 29 | (VariableNode "$B")) 30 | (VariableNode "$A") 31 | (VariableNode "$B"))))) 32 | 33 | (define (or-breakdown-formula AB A B) 34 | (cog-set-tv! 35 | B 36 | (or-breakdown-side-effect-free-formula AB A B)) 37 | ) 38 | 39 | (define (or-breakdown-side-effect-free-formula AB A B) 40 | (let 41 | ((sAB (cog-mean AB)) 42 | (cAB (cog-confidence AB)) 43 | (sA (cog-mean A)) 44 | (cA (cog-confidence A))) 45 | (stv (/ sAB (- 1 sA)) (min cAB cA)))) 46 | 47 | ; Name the rule 48 | (define or-breakdown-rule-name (DefinedSchemaNode "or-breakdown-rule")) 49 | (DefineLink or-breakdown-rule-name or-breakdown-rule) 50 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-elimination.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; OrEliminationRule 3 | ; 4 | ; OrLink 5 | ; A 6 | ; B 7 | ; |- 8 | ; A 9 | ; B 10 | ;---------------------------------------------------------------------- 11 | ;; Given rule is binary because creating more than one link would create 12 | ;; an issue with backward chaining. 13 | ;; TODO :- Create the rule n-ary 14 | 15 | 16 | (define or-elimination-rule 17 | (BindLink 18 | (VariableList 19 | (VariableNode "$A") 20 | (VariableNode "$B")) 21 | (AndLink 22 | (OrLink 23 | (VariableNode "$A") 24 | (VariableNode "$B"))) 25 | (ExecutionOutputLink 26 | (GroundedSchemaNode "scm: or-elimination-formula") 27 | (ListLink 28 | (OrLink 29 | (VariableNode "$A") 30 | (VariableNode "$B")) 31 | (VariableNode "$A") 32 | (VariableNode "$B"))))) 33 | 34 | (define (or-elimination-formula AB A B) 35 | (cog-set-tv! 36 | A 37 | (or-elimination-side-effect-free-formula AB)) 38 | (cog-set-tv! 39 | B 40 | (or-elimination-side-effect-free-formula AB)) 41 | ) 42 | 43 | (define (or-elimination-side-effect-free-formula AB) 44 | (let 45 | ((sAB (cog-mean AB)) 46 | (cAB (cog-confidence AB))) 47 | (stv (/ sAB 2) 1))) 48 | 49 | ; Name the rule 50 | (define or-elimination-rule-name (DefinedSchemaNode "or-elimination-rule")) 51 | (DefineLink or-elimination-rule-name or-elimination-rule) 52 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; OrEvaluationRule 3 | ; 4 | ; AndLink 5 | ; MemberLink 6 | ; C 7 | ; A 8 | ; MemberLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; OrLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define or-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (MemberLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (MemberLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: or-evaluation-formula") 33 | (ListLink 34 | (OrLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (MemberLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (MemberLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (or-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (or-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (or-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (and (< sCA 0.5) (< sCB 0.5)) 56 | (stv 0 1) 57 | (stv 1 1)))) 58 | 59 | ; Name the rule 60 | (define or-evaluation-rule-name (DefinedSchemaNode "or-evaluation-rule")) 61 | (DefineLink or-evaluation-rule-name or-evaluation-rule) 62 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-introduction.scm: -------------------------------------------------------------------------------- 1 | ;; To be replaced by fuzzy-disjunction-introduction-rule 2 | 3 | ; ===================================================================== 4 | ; Or introduction rule 5 | ; 6 | ; For now A and B can be predicates or concepts. Note that the rule 7 | ; will not try to prevent mixing predicates and concepts (we need a 8 | ; better type system for that). Also it assumes that A and B are 9 | ; independant. The rule should account for relationships between A and 10 | ; B (like inheritance, etc) to correct that assumption. 11 | ; 12 | ; A 13 | ; B 14 | ; |- 15 | ; OrLink 16 | ; A 17 | ; B 18 | ;---------------------------------------------------------------------- 19 | 20 | 21 | (define or-introduction-rule 22 | (BindLink 23 | (VariableList 24 | (TypedVariableLink 25 | (VariableNode "$A") 26 | (TypeChoice 27 | (TypeNode "PredicateNode") 28 | (TypeNode "ConceptNode"))) 29 | (TypedVariableLink 30 | (VariableNode "$B") 31 | (TypeChoice 32 | (TypeNode "PredicateNode") 33 | (TypeNode "ConceptNode")))) 34 | (AndLink 35 | (VariableNode "$A") 36 | (VariableNode "$B") 37 | (NotLink 38 | (IdenticalLink 39 | (VariableNode "$A") 40 | (VariableNode "$B")))) 41 | (ExecutionOutputLink 42 | (GroundedSchemaNode "scm: or-introduction-formula") 43 | (ListLink 44 | (VariableNode "$A") 45 | (VariableNode "$B"))))) 46 | 47 | (define (or-introduction-formula A B) 48 | (cog-set-tv! 49 | (OrLink A B) 50 | (or-introduction-side-effect-free-formula A B)) 51 | ) 52 | 53 | (define (or-introduction-side-effect-free-formula A B) 54 | (let 55 | ((sA (cog-mean A)) 56 | (sB (cog-mean B)) 57 | (cA (cog-confidence A)) 58 | (cB (cog-confidence B))) 59 | (stv (- (+ sA sB) (* sA sB)) (min cA cB)))) 60 | 61 | ; Name the rule 62 | (define or-introduction-rule-name 63 | (DefinedSchemaNode "or-introduction-rule")) 64 | (DefineLink 65 | or-introduction-rule-name 66 | or-introduction-rule) 67 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-simplification.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; OrSimplificationRule 3 | ; 4 | ; OrLink 5 | ; A 6 | ; OrLink 7 | ; B 8 | ; C 9 | ; |- 10 | ; OrLink 11 | ; A 12 | ; B 13 | ; C 14 | ;---------------------------------------------------------------------- 15 | 16 | 17 | (define or-simplification-rule 18 | (BindLink 19 | (VariableList 20 | (VariableNode "$A") 21 | (VariableNode "$B") 22 | (VariableNode "$C")) 23 | (OrLink 24 | (VariableNode "$A") 25 | (OrLink 26 | (VariableNode "$B") 27 | (VariableNode "$C"))) 28 | (ExecutionOutputLink 29 | (GroundedSchemaNode "scm: or-simplification-formula") 30 | (ListLink 31 | (OrLink 32 | (VariableNode "$A") 33 | (OrLink 34 | (VariableNode "$B") 35 | (VariableNode "$C"))) 36 | (OrLink 37 | (VariableNode "$A") 38 | (VariableNode "$B") 39 | (VariableNode "$C")))))) 40 | 41 | (define (or-simplification-formula AABC ABC) 42 | (cog-set-tv! 43 | ABC 44 | (or-simplification-side-effect-free-formula AABC ABC)) 45 | ) 46 | 47 | (define (or-simplification-side-effect-free-formula AABC ABC) 48 | (let 49 | ((sAABC (cog-mean AABC)) 50 | (cAABC (cog-confidence AABC))) 51 | (stv sAABC cAABC))) 52 | 53 | ; Name the rule 54 | (define or-simplification-rule-name (DefinedSchemaNode "or-simplification-rule")) 55 | (DefineLink or-simplification-rule-name or-simplification-rule) 56 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/or-transformation.scm: -------------------------------------------------------------------------------- 1 | ; ===================================================================== 2 | ; OrTransformationRule 3 | ; 4 | ; OrLink 5 | ; A 6 | ; B 7 | ; |- 8 | ; (NotLink A) => B 9 | ;---------------------------------------------------------------------- 10 | 11 | 12 | (define or-transformation-rule 13 | (BindLink 14 | (VariableList 15 | (VariableNode "$A") 16 | (VariableNode "$B")) 17 | (OrLink 18 | (VariableNode "$A") 19 | (VariableNode "$B")) 20 | (ExecutionOutputLink 21 | (GroundedSchemaNode "scm: or-transformation-formula") 22 | (ListLink 23 | (OrLink 24 | (VariableNode "$A") 25 | (VariableNode "$B")) 26 | (ImplicationLink 27 | (NotLink 28 | (VariableNode "$A")) 29 | (VariableNode "$B")))))) 30 | 31 | (define (or-transformation-formula OAB IAB) 32 | (cog-set-tv! 33 | IAB 34 | (or-transformation-side-effect-free-formula OAB IAB)) 35 | ) 36 | 37 | 38 | (define (or-transformation-side-effect-free-formula OAB IAB) 39 | (let 40 | ((sOAB (cog-mean OAB)) 41 | (cOAB (cog-confidence OAB))) 42 | (stv sOAB cOAB))) 43 | 44 | ; Name the rule 45 | (define or-transformation-rule-name (DefinedSchemaNode "or-transformation-rule")) 46 | (DefineLink or-transformation-rule-name or-transformation-rule) 47 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/precise-modus-ponens.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; PreciseModusPonensRule 3 | ;; 4 | ;; 5 | ;; A 6 | ;; B 7 | ;; 8 | ;; NotLink 9 | ;; A 10 | ;; B 11 | ;; A 12 | ;; |- 13 | ;; B 14 | ;; Due to type system limitations, the rule has been divided into 3: 15 | ;; precise-modus-ponens-inheritance-rule 16 | ;; precise-modus-ponens-implication-rule 17 | ;; precise-modus-ponens-subset-rule 18 | ;; 19 | 20 | ; ----------------------------------------------------------------------------- 21 | (load "formulas.scm") 22 | 23 | ;; Generate the corresponding precise modus ponens rule given its 24 | ;; link-type. 25 | (define (gen-precise-modus-ponens-rule link-type) 26 | (BindLink 27 | (VariableList 28 | (VariableNode "$A") 29 | (VariableNode "$B")) 30 | (AndLink 31 | (link-type 32 | (VariableNode "$A") 33 | (VariableNode "$B")) 34 | (link-type 35 | (NotLink 36 | (VariableNode "$A")) 37 | (VariableNode "$B"))) 38 | (ExecutionOutputLink 39 | (GroundedSchemaNode "scm: precise-modus-ponens-formula") 40 | (ListLink 41 | (VariableNode "$A") 42 | (link-type 43 | (VariableNode "$A") 44 | (VariableNode "$B")) 45 | (link-type 46 | (NotLink 47 | (VariableNode "$A")) 48 | (VariableNode "$B")) 49 | (VariableNode "$B"))))) 50 | 51 | (define precise-modus-ponens-inheritance-rule 52 | (gen-precise-modus-ponens-rule InheritanceLink)) 53 | 54 | (define precise-modus-ponens-implication-rule 55 | (gen-precise-modus-ponens-rule ImplicationLink)) 56 | 57 | (define precise-modus-ponens-subset-rule 58 | (gen-precise-modus-ponens-rule SubsetLink)) 59 | 60 | (define (precise-modus-ponens-formula A AB notAB B) 61 | (let 62 | ((sA (cog-mean A)) 63 | (cA (cog-confidence A)) 64 | (sAB (cog-mean AB)) 65 | (cAB (cog-confidence AB)) 66 | (snotAB (cog-mean notAB)) 67 | (cnotAB (cog-confidence notAB))) 68 | (cog-set-tv! 69 | B 70 | (stv 71 | (precise-modus-ponens-strength-formula sA sAB snotAB) 72 | (min (min cAB cnotAB) cA))))) 73 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/predicate-lambda-evaluation.scm: -------------------------------------------------------------------------------- 1 | ;; ===================================================================== 2 | ;; Predicate lambda evaluation rule 3 | ;; 4 | ;; Lambda 5 | ;; 6 | ;; Evaluation 7 | ;; Predicate 8 | ;; List 9 | ;; 10 | ;; |- 11 | ;; Lambda 12 | ;; 13 | ;; Evaluation 14 | ;; Predicate 15 | ;; List 16 | ;; 17 | ;; 18 | ;; Evaluate the TV of Lambda around an evaluation of a predicate. 19 | ;; ---------------------------------------------------------------------- 20 | 21 | (define predicate-lambda-evaluation-vardecl 22 | (VariableList 23 | (TypedVariable 24 | (Variable "$V") 25 | (TypeChoice 26 | (Type "TypedVariableLink") 27 | (Type "VariableList") 28 | (Type "VariableNode"))) 29 | (Variable "$P") 30 | (Variable "$Args"))) 31 | 32 | (define predicate-lambda-evaluation-clause 33 | (Quote (Lambda 34 | (Unquote (VariableNode "$V")) 35 | (Unquote (EvaluationLink 36 | (Variable "$P") 37 | (Variable "$Args")))))) 38 | 39 | (define predicate-lambda-evaluation-precondition 40 | (Evaluation 41 | (GroundedPredicate "scm: gt-zero-confidence") 42 | (Variable "$P"))) 43 | 44 | (define predicate-lambda-evaluation-pattern 45 | (And 46 | predicate-lambda-evaluation-clause 47 | predicate-lambda-evaluation-precondition)) 48 | 49 | (define predicate-lambda-evaluation-rewrite 50 | (ExecutionOutputLink 51 | (GroundedSchemaNode "scm: predicate-lambda-evaluation-formula") 52 | (ListLink 53 | predicate-lambda-evaluation-clause 54 | (Variable "$P")))) 55 | 56 | (define predicate-lambda-evaluation-rule 57 | (BindLink 58 | predicate-lambda-evaluation-vardecl 59 | predicate-lambda-evaluation-pattern 60 | predicate-lambda-evaluation-rewrite)) 61 | 62 | (define (predicate-lambda-evaluation-formula lamb pred) 63 | (if (< 0 (cog-confidence pred)) ; Try to avoid constructing 64 | ; informationless knowledge 65 | (cog-merge-hi-conf-tv! lamb (cog-tv pred)))) 66 | 67 | ;; Name the rule 68 | (define predicate-lambda-evaluation-rule-name 69 | (DefinedSchemaNode "predicate-lambda-evaluation-rule")) 70 | (DefineLink predicate-lambda-evaluation-rule-name 71 | predicate-lambda-evaluation-rule) 72 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/similarity.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Similarity Rule 3 | ;; 4 | ;; AndLink 5 | ;; A 6 | ;; B 7 | ;; OrLink 8 | ;; A 9 | ;; B 10 | ;; |- 11 | ;; SimilarityLink 12 | ;; A 13 | ;; B 14 | ;; 15 | ;; ----------------------------------------------------------------------------- 16 | 17 | (define similarity-rule 18 | (BindLink 19 | (VariableList 20 | (VariableNode "$A") 21 | (VariableNode "$B")) 22 | (AndLink 23 | (AndLink 24 | (VariableNode "$A") 25 | (VariableNode "$B")) 26 | (OrLink 27 | (VariableNode "$A") 28 | (VariableNode "$B"))) 29 | (ExecutionOutputLink 30 | (GroundedSchemaNode "scm: similarity-formula") 31 | (ListLink 32 | (AndLink 33 | (VariableNode "$A") 34 | (VariableNode "$B")) 35 | (OrLink 36 | (VariableNode "$A") 37 | (VariableNode "$B")) 38 | (SimilarityLink 39 | (VariableNode "$A") 40 | (VariableNode "$B")))))) 41 | 42 | (define (similarity-formula AAB OAB SAB) 43 | (cog-set-tv! 44 | SAB 45 | (if 46 | (= (* (cog-mean OAB) (cog-confidence OAB)) 0) 47 | (stv 0 0) 48 | (stv (/ 49 | (* (cog-mean AAB) (cog-confidence AAB)) 50 | (* (cog-mean OAB) (cog-confidence OAB))) 51 | (min (cog-confidence OAB) (cog-confidence AAB)))))) 52 | 53 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/subset-evaluation.scm: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; SubsetEvaluationRule 3 | ; 4 | ; AndLink 5 | ; MemberLink 6 | ; C 7 | ; A 8 | ; MemberLink 9 | ; C 10 | ; B 11 | ; |- 12 | ; SubsetLink 13 | ; A 14 | ; B 15 | ; 16 | ; ----------------------------------------------------------------------------- 17 | 18 | (define subset-evaluation-rule 19 | (BindLink 20 | (VariableList 21 | (VariableNode "$A") 22 | (VariableNode "$B") 23 | (VariableNode "$C")) 24 | (AndLink 25 | (MemberLink 26 | (VariableNode "$C") 27 | (VariableNode "$A")) 28 | (MemberLink 29 | (VariableNode "$C") 30 | (VariableNode "$B"))) 31 | (ExecutionOutputLink 32 | (GroundedSchemaNode "scm: subset-evaluation-formula") 33 | (ListLink 34 | (SubsetLink 35 | (VariableNode "$A") 36 | (VariableNode "$B")) 37 | (MemberLink 38 | (VariableNode "$C") 39 | (VariableNode "$A")) 40 | (MemberLink 41 | (VariableNode "$C") 42 | (VariableNode "$B")))))) 43 | 44 | (define (subset-evaluation-formula AB CA CB) 45 | (cog-set-tv! 46 | AB (subset-evaluation-side-effect-free-formula AB CA CB))) 47 | 48 | (define (subset-evaluation-side-effect-free-formula AB CA CB) 49 | (let 50 | ((sCA (cog-mean CA)) 51 | (cCA (cog-confidence CA)) 52 | (sCB (cog-mean CB)) 53 | (cCB (cog-confidence CB))) 54 | (if 55 | (< sCA 0.5) 56 | (stv 0 0) 57 | (if 58 | (< sCB 0.5) 59 | (stv 1 0) 60 | (stv 1 1))))) 61 | 62 | ; Name the rule 63 | (define subset-evaluation-rule-name (DefinedSchemaNode "subset-evaluation-rule")) 64 | (DefineLink subset-evaluation-rule-name subset-evaluation-rule) 65 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/symmetric-modus-ponens.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; SymmetricModusPonensRule 3 | ;; 4 | ;; 5 | ;; A 6 | ;; B 7 | ;; A 8 | ;; |- 9 | ;; B 10 | ;; 11 | ;; Due to type system limitations, the rule has been divided into 3: 12 | ;; symmetric-modus-ponens-similarity-rule 13 | ;; symmetric-modus-ponens-intensional-similarity-rule 14 | ;; summetric-modus-ponens-extensional-similarity-rule 15 | ;; 16 | ;; ----------------------------------------------------------------------------- 17 | (load "formulas.scm") 18 | 19 | ;; Generate the corresponding symmetric modus ponens rule given its 20 | ;; link-type. 21 | (define (gen-symmetric-modus-ponens-rule link-type) 22 | (BindLink 23 | (VariableList 24 | (VariableNode "$A") 25 | (VariableNode "$B")) 26 | (link-type 27 | (VariableNode "$A") 28 | (VariableNode "$B")) 29 | (ExecutionOutputLink 30 | (GroundedSchemaNode "scm: symmetric-modus-ponens-formula") 31 | (ListLink 32 | (VariableNode "$A") 33 | (link-type 34 | (VariableNode "$A") 35 | (VariableNode "$B")) 36 | (VariableNode "$B"))))) 37 | 38 | (define symmetric-modus-ponens-similarity-rule 39 | (gen-symmetric-modus-ponens-rule SimilarityLink)) 40 | 41 | (define symmetric-modus-ponens-intensional-similarity-rule 42 | (gen-symmetric-modus-ponens-rule IntensionalSimilarityLink)) 43 | 44 | (define symmetric-modus-ponens-extensional-similarity-rule 45 | (gen-symmetric-modus-ponens-rule ExtensionalSimilarityLink)) 46 | 47 | (define (symmetric-modus-ponens-formula A AB B) 48 | (let 49 | ((sA (cog-mean A)) 50 | (cA (cog-confidence A)) 51 | (sAB (cog-mean AB)) 52 | (cAB (cog-confidence AB)) 53 | (snotAB 0.2) 54 | (cnotAB 1)) 55 | (cog-set-tv! 56 | B 57 | (stv 58 | (+ (* sA sAB) (* (* snotAB (negate sA)) (+ 1 sAB))) 59 | (min (min cAB cnotAB) cA))))) 60 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/temp-deduction.scm: -------------------------------------------------------------------------------- 1 | ; TODO: Replace the following with pln's deduction-inheritance-rule when 2 | ; deduction-formula stops returning (cog-undefined-handle). 3 | (define (gen-temp-deduction-rule link-type) 4 | (BindLink 5 | (VariableList 6 | (VariableNode "$A") 7 | (VariableNode "$B") 8 | (VariableNode "$C")) 9 | (AndLink 10 | (link-type 11 | (VariableNode "$A") 12 | (VariableNode "$B")) 13 | (link-type 14 | (VariableNode "$B") 15 | (VariableNode "$C")) 16 | (NotLink 17 | (IdenticalLink 18 | (VariableNode "$A") 19 | (VariableNode "$C") 20 | ))) 21 | (link-type 22 | (VariableNode "$A") 23 | (VariableNode "$C"))) 24 | ) 25 | 26 | (define temp-deduction-inheritance-rule 27 | (gen-temp-deduction-rule InheritanceLink)) 28 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/term-probability.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Term Probability Rule 3 | ;; 4 | ;; 5 | ;; A 6 | ;; B 7 | ;; 8 | ;; B 9 | ;; A 10 | ;; A 11 | ;; |- 12 | ;; B 13 | ;; 14 | ;; Due to type system limitations, the rule has been divided into 3: 15 | ;; term-probability-inheritance-rule 16 | ;; term-probability-implication-rule 17 | ;; term-probability-subset-rule 18 | ;; 19 | ;; ----------------------------------------------------------------------------- 20 | (load "formulas.scm") 21 | 22 | ;; Generate the corresponding term probability rule given its 23 | ;; link-type. 24 | (define (gen-term-probability-rule link-type) 25 | (BindLink 26 | (VariableList 27 | (VariableNode "$A") 28 | (VariableNode "$B")) 29 | (AndLink 30 | (link-type 31 | (VariableNode "$A") 32 | (VariableNode "$B")) 33 | (link-type 34 | (VariableNode "$B") 35 | (VariableNode "$A"))) 36 | (ExecutionOutputLink 37 | (GroundedSchemaNode "scm: term-probability-formula") 38 | (ListLink 39 | (VariableNode "$A") 40 | (link-type 41 | (VariableNode "$A") 42 | (VariableNode "$B")) 43 | (link-type 44 | (VariableNode "$B") 45 | (VariableNode "$A")) 46 | (VariableNode "$B"))))) 47 | 48 | (define term-probability-inheritance-rule 49 | (gen-term-probability-rule InheritanceLink)) 50 | 51 | (define term-probability-implication-rule 52 | (gen-term-probability-rule ImplicationLink)) 53 | 54 | (define term-probability-subset-rule 55 | (gen-term-probability-rule SubsetLink)) 56 | 57 | (define (term-probability-formula A AB BA B) 58 | (let 59 | ((sA (cog-mean A)) 60 | (cA (cog-confidence A)) 61 | (sAB (cog-mean AB)) 62 | (cAB (cog-confidence AB)) 63 | (sBA (cog-mean BA)) 64 | (cBA (cog-confidence BA))) 65 | (cog-set-tv! 66 | B 67 | (stv 68 | (/ (* sA sAB) sBA) 69 | (min (min cAB cBA) cA))))) 70 | -------------------------------------------------------------------------------- /opencog/pln/rules/wip/transitive-similarity.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; TransitiveSimilarityRule 3 | ;; 4 | ;; 5 | ;; A 6 | ;; B 7 | ;; 8 | ;; B 9 | ;; C 10 | ;; |- 11 | ;; 12 | ;; A 13 | ;; C 14 | ;; 15 | ;; Due to type system limitations, the rule has been divided into 3: 16 | ;; transitive-similarity-similarity-rule 17 | ;; transitive-similarity-extensional-similarity-rule 18 | ;; transitive-similarity-intensional-similarity-rule 19 | ;; 20 | ;; ----------------------------------------------------------------------------- 21 | (load "formulas.scm") 22 | 23 | (define (gen-transitive-similarity-rule link-type) 24 | (BindLink 25 | (VariableList 26 | (VariableNode "$A") 27 | (VariableNode "$B") 28 | (VariableNode "$C")) 29 | (AndLink 30 | (link-type 31 | (VariableNode "$A") 32 | (VariableNode "$B")) 33 | (link-type 34 | (VariableNode "$B") 35 | (VariableNode "$C"))) 36 | (ExecutionOutputLink 37 | (GroundedSchemaNode "scm: transitive-similarity-formula") 38 | (ListLink 39 | (VariableNode "$A") 40 | (VariableNode "$B") 41 | (VariableNode "$C") 42 | (link-type 43 | (VariableNode "$A") 44 | (VariableNode "$B")) 45 | (link-type 46 | (VariableNode "$B") 47 | (VariableNode "$C")) 48 | (link-type 49 | (VariableNode "$A") 50 | (VariableNode "$C")))))) 51 | 52 | (define transitive-similarity-similarity-rule 53 | (gen-transitive-similarity-rule SimilarityLink)) 54 | 55 | (define transitive-similarity-extensional-similarity-rule 56 | (gen-transitive-similarity-rule ExtensionalSimilarityLink)) 57 | 58 | (define transitive-similarity-intensional-similarity-rule 59 | (gen-transitive-similarity-rule IntensionalSimilarityLink)) 60 | 61 | (define (transitive-similarity-formula A B C AB BC AC) 62 | (let 63 | ((sA (cog-mean A)) 64 | (cA (cog-confidence A)) 65 | (sB (cog-mean B)) 66 | (cB (cog-confidence B)) 67 | (sC (cog-mean C)) 68 | (cC (cog-confidence C)) 69 | (sAB (cog-mean AB)) 70 | (cAB (cog-confidence AB)) 71 | (sBC (cog-mean BC)) 72 | (cBC (cog-confidence BC))) 73 | (cog-set-tv! 74 | AC 75 | (stv 76 | (transitive-similarity-strength-formula sA sB sC sAB sBC) 77 | (min cAB cBC))))) 78 | -------------------------------------------------------------------------------- /opencog/pln/types/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | OPENCOG_ADD_ATOM_TYPES(atom_types.script 3 | atom_types.h 4 | atom_types.definitions 5 | atom_types.inheritance 6 | pln_types.scm 7 | pln_types.pyx 8 | ) 9 | ADD_CUSTOM_TARGET(pln_atom_types DEPENDS atom_types.h) 10 | 11 | # The atom_types.h file is written to the build directory 12 | INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) 13 | 14 | ADD_LIBRARY (pln-types SHARED 15 | atom_types_init.cc 16 | ) 17 | 18 | # Without this, parallel make will race and crap up the generated files. 19 | ADD_DEPENDENCIES(pln-types pln_atom_types) 20 | 21 | TARGET_LINK_LIBRARIES(pln-types 22 | ${ATOMSPACE_atomtypes_LIBRARY} 23 | ) 24 | 25 | INSTALL (TARGETS pln-types 26 | LIBRARY DESTINATION "lib${LIB_DIR_SUFFIX}/opencog" 27 | ) 28 | 29 | ADD_GUILE_EXTENSION(SCM_CONFIG pln-types "opencog-ext-path-pln") 30 | 31 | INSTALL (FILES 32 | ${CMAKE_CURRENT_BINARY_DIR}/atom_types.h 33 | ${CMAKE_CURRENT_BINARY_DIR}/atom_names.h 34 | DESTINATION "include/opencog/pln/types" 35 | ) 36 | 37 | INSTALL (FILES 38 | ${CMAKE_CURRENT_BINARY_DIR}/pln_types.scm 39 | DESTINATION "${GUILE_SITE_DIR}/opencog/pln/types" 40 | ) 41 | -------------------------------------------------------------------------------- /opencog/pln/types/atom_types_init.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * opencog/pln/types/atom_types_init.cc 3 | * 4 | * Copyright (C) 2014 Eddie Monroe 5 | * All Rights Reserved 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Affero General Public License v3 as 9 | * published by the Free Software Foundation and including the exceptions 10 | * at http://opencog.org/wiki/Licenses 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Affero General Public License 18 | * along with this program; if not, write to: 19 | * Free Software Foundation, Inc., 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | #include 23 | 24 | #include "opencog/pln/types/atom_types.definitions" 25 | 26 | #define INHERITANCE_FILE "opencog/pln/types/atom_types.inheritance" 27 | #define INITNAME pln_types_init 28 | 29 | #include 30 | -------------------------------------------------------------------------------- /opencog/torchpln/converter.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import shutil 4 | import sys 5 | 6 | 7 | rep = re.compile("\((Grounded[a-zA-Z]+)\s*?\"\s*?(scm):\s*(.*?)\"\s*?\)") 8 | 9 | def replace(path, target_path): 10 | os.makedirs(os.path.dirname(target_path), exist_ok=True) 11 | s = open(path, 'rt').read() 12 | new_s = '' 13 | prev_end = 0 14 | python_module = 'pln' 15 | 16 | pln_found = False 17 | for item in path.split('pln/opencog')[1].split('/')[1:-1]: 18 | if (not pln_found) and (item == 'pln'): 19 | pln_found = True 20 | continue 21 | if pln_found: 22 | python_module += '.' + item 23 | python_module += '.' 24 | for match in re.finditer(rep, s): 25 | formula = match.group(3) 26 | if 'GroundedPredicate' in match.group(1): 27 | res = '(GroundedPredicate "py:{0}")' 28 | else: 29 | res = '(GroundedSchema "py:{0}")' 30 | new_s += s[prev_end: match.start()] 31 | new_s += res.format(python_module + formula.replace('-', '_')) 32 | prev_end = match.end() 33 | new_s += s[prev_end:] 34 | with open(target_path, 'wt') as f: 35 | f.write(new_s) 36 | 37 | 38 | def convert_pln_rules(pln_dir): 39 | if os.path.exists('/tmp/pln'): 40 | shutil.rmtree('/tmp/pln') 41 | for root, dirs, files in os.walk(pln_dir): 42 | for file in files: 43 | if file.endswith('scm'): 44 | path = os.path.join(root, file) 45 | print(path) 46 | subpath = root.split('opencog/pln')[1] 47 | replace(path, os.path.join('/tmp/pln/' + subpath, file)) 48 | 49 | 50 | if __name__ == '__main__': 51 | convert_pln_rules(os.path.abspath(os.path.expanduser(sys.argv[1]))) 52 | -------------------------------------------------------------------------------- /opencog/torchpln/pln/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from opencog.scheme_wrapper import scheme_eval 4 | from opencog.type_constructors import get_type_ctor_atomspace 5 | 6 | 7 | import __main__ 8 | __main__.pln = sys.modules[__name__] 9 | from .common import TTruthValue, get_ttv, set_ttv 10 | -------------------------------------------------------------------------------- /opencog/torchpln/pln/common.py: -------------------------------------------------------------------------------- 1 | import weakref 2 | import torch 3 | from opencog.atomspace import types, PtrValue, Atom 4 | from opencog.scheme_wrapper import scheme_eval 5 | from opencog.type_constructors import * 6 | from opencog.atomspace import TensorTruthValue as TTruthValue 7 | 8 | 9 | def get_ttv(atom): 10 | value = atom.tv 11 | if not isinstance(value, TTruthValue): 12 | default = TTruthValue([atom.tv.mean, atom.tv.confidence]) 13 | atom.tv = default 14 | value = default 15 | return value.torch() 16 | 17 | 18 | def set_ttv(atom, value): 19 | if not isinstance(value, TTruthValue): 20 | value = TTruthValue(value) 21 | atom.tv = value 22 | return atom 23 | 24 | 25 | def gt_zero_confidence(atom): 26 | tensor_tv = get_ttv(atom) 27 | result = TruthValue(1 if 0 < tensor_tv.confidence else 0, 1) 28 | return result 29 | 30 | 31 | def cog_merge_hi_conf_tv(atom, tv): 32 | old_tv = get_ttv(atom) 33 | if old_tv.confidence < tv.confidence: 34 | set_ttv(atom, tv) 35 | 36 | 37 | def gar(atom): 38 | if atom.out: 39 | return atom.out[0] 40 | return None 41 | 42 | 43 | def gdr(atom): 44 | """ 45 | Return second element of outgoing list 46 | """ 47 | if len(atom.out) < 2: 48 | return None 49 | return atom.out[1] 50 | -------------------------------------------------------------------------------- /opencog/torchpln/pln/rules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opencog/pln/75815f9f21ad899f44eccba1921fa253a7c6216f/opencog/torchpln/pln/rules/__init__.py -------------------------------------------------------------------------------- /opencog/torchpln/pln/rules/propositional/formulas.scm: -------------------------------------------------------------------------------- 1 | ;; ============================================================================= 2 | ;; Negate formula 3 | ;; 4 | ;; Negates the probability 5 | ;; ----------------------------------------------------------------------------- 6 | 7 | (define (negate a) 8 | (- 1 a)) 9 | 10 | ;; ============================================================================= 11 | ;; PreciseModusPonens formula 12 | ;; 13 | ;; Returns the strength value of the precise modus ponens rule 14 | ;; ----------------------------------------------------------------------------- 15 | 16 | (define (precise-modus-ponens-strength-formula sA sAB snotAB) 17 | (+ (* sAB sA) (* snotAB (negate sA)))) 18 | 19 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ENABLE_TESTING() 2 | INCLUDE(AddCxxtest) 3 | 4 | ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${CMAKE_SOURCE_DIR}" 5 | -DPROJECT_BINARY_DIR="${CMAKE_BINARY_DIR}") 6 | 7 | # All tests should load the atomspace scm from the build dir, unless the scm 8 | # file is specific to the test (this variable is used by ADD_CXXTEST) 9 | SET(GUILE_LOAD_PATH "${PROJECT_BINARY_DIR}/opencog/scm") 10 | 11 | # Perform tests in component-dependency order, as much as possible. 12 | IF (CXXTEST_FOUND) 13 | 14 | IF (HAVE_PLN) 15 | ADD_SUBDIRECTORY (pln) 16 | ENDIF (HAVE_PLN) 17 | 18 | ENDIF (CXXTEST_FOUND) 19 | -------------------------------------------------------------------------------- /tests/pln/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY (rules) 2 | 3 | ADD_CXXTEST(MOSESPLNSynergyUTest) 4 | ADD_CXXTEST(PLNUTest) 5 | 6 | # Disable until it passes. It's causing issues in circle-ci 7 | # ADD_CXXTEST(TemporalReasoningUTest) 8 | 9 | TARGET_LINK_LIBRARIES(MOSESPLNSynergyUTest 10 | ure-types 11 | ${ATOMSPACE_LIBRARIES} 12 | ${COGUTIL_LIBRARY} 13 | ) 14 | 15 | TARGET_LINK_LIBRARIES(PLNUTest 16 | ${URE_LIBRARIES} 17 | ${UNIFY_LIBRARIES} 18 | ${ATOMSPACE_LIBRARIES} 19 | ${COGUTIL_LIBRARY} 20 | ) 21 | 22 | #TARGET_LINK_LIBRARIES(TemporalReasoningUTest 23 | # ${URE_LIBRARIES} 24 | # ${UNIFY_LIBRARIES} 25 | # ${ATOMSPACE_LIBRARIES} 26 | # ${COGUTIL_LIBRARY} 27 | #) 28 | -------------------------------------------------------------------------------- /tests/pln/modus-ponens-contraposition.scm: -------------------------------------------------------------------------------- 1 | ;; Knowledge base for PLNUTest::test_modus_ponens() 2 | 3 | (ConceptNode "apple" (stv 0.8 0.9)) 4 | (InheritanceLink (stv 0.8 0.4) 5 | (ConceptNode "apple") 6 | (ConceptNode "fruit")) 7 | 8 | (define target (ConceptNode "fruit")) 9 | -------------------------------------------------------------------------------- /tests/pln/rules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # PLNRulesUTest hangs in infinite loop 3 | # ADD_CXXTEST(PLNRulesUTest) 4 | ADD_CXXTEST(TemporalReasoningRulesUTest) 5 | 6 | #TARGET_LINK_LIBRARIES(PLNRulesUTest 7 | # ${URE_LIBRARIES} 8 | # ${UNIFY_LIBRARIES} 9 | # ${ATOMSPACE_LIBRARIES} 10 | # ${COGUTIL_LIBRARY} 11 | #) 12 | 13 | TARGET_LINK_LIBRARIES(TemporalReasoningRulesUTest 14 | ${URE_LIBRARIES} 15 | ${UNIFY_LIBRARIES} 16 | ${ATOMSPACE_LIBRARIES} 17 | ${COGUTIL_LIBRARY} 18 | ) 19 | -------------------------------------------------------------------------------- /tests/pln/rules/complex-temporal-deduction-kb.scm: -------------------------------------------------------------------------------- 1 | ;; Use temporal deduction (specialized for cognitive schematics) to 2 | ;; infer 3 | ;; 4 | ;; outside(house) ∧ exec(go_to_key) ↝ hold(key) 5 | ;; hold(key) ∧ exec(go_to_house) ↝ inside(house) 6 | ;; ⊢ 7 | ;; (outside(house) ∧ exec(go_to_key)) ≺ exec(go_to_house) ↝ inside(house) 8 | 9 | ;; outside(house) ∧ exec(go_to_key) ↝ hold(key) 10 | (BackPredictiveImplicationScopeLink (stv 1 0.00990099) 11 | (VariableSet) 12 | (SLink 13 | (ZLink)) 14 | (AndLink (stv 0.16 0.0588235) 15 | (EvaluationLink (stv 0.6 0.0588235) 16 | (PredicateNode "outside") 17 | (ListLink 18 | (ConceptNode "self") 19 | (ConceptNode "house"))) 20 | (ExecutionLink 21 | (SchemaNode "go_to_key"))) 22 | (EvaluationLink (stv 0.26 0.0588235) 23 | (PredicateNode "holds") 24 | (ListLink 25 | (ConceptNode "self") 26 | (ConceptNode "key")))) 27 | 28 | ;; hold(key) ∧ exec(go_to_house) ↝ inside(house) 29 | (BackPredictiveImplicationScopeLink (stv 1 0.00621118) 30 | (VariableSet) 31 | (SLink 32 | (ZLink)) 33 | (AndLink (stv 0.1 0.0588235) 34 | (ExecutionLink 35 | (SchemaNode "go_to_house")) 36 | (EvaluationLink (stv 0.26 0.0588235) 37 | (PredicateNode "holds") 38 | (ListLink 39 | (ConceptNode "self") 40 | (ConceptNode "key")))) 41 | (EvaluationLink (stv 0.28 0.0588235) 42 | (PredicateNode "inside") 43 | (ListLink 44 | (ConceptNode "self") 45 | (ConceptNode "house")))) 46 | -------------------------------------------------------------------------------- /tests/pln/rules/full-deduction-kb.scm: -------------------------------------------------------------------------------- 1 | ;; KB for testing the full deduction rule 2 | 3 | ;; Premises 4 | (define P (Predicate "P")) 5 | (define Q (Predicate "Q")) 6 | (define R (Predicate "R")) 7 | (define PQ-tv (stv 0.7 0.8)) 8 | (define PQR-tv (stv 0.8 0.6)) 9 | (define PNQR-tv (stv 0.9 0.4)) 10 | (define PQ (Implication PQ-tv P Q)) 11 | (define PQR (Implication PQR-tv (And P Q) R)) 12 | (define PNQR (Implication PNQR-tv (And P (Not Q)) R)) 13 | 14 | ;; Conclusion 15 | (define conclusion (Implication P R)) 16 | -------------------------------------------------------------------------------- /tests/pln/rules/implication-direct-evaluation.scm: -------------------------------------------------------------------------------- 1 | ;; For testing implication direct evaluation rule 2 | 3 | ;; Instances of P 4 | (Evaluation (stv 1 1) 5 | (Predicate "P") 6 | (Concept "A")) 7 | 8 | (Evaluation (stv 1 1) 9 | (Predicate "P") 10 | (Concept "B")) 11 | 12 | (Evaluation (stv 1 1) 13 | (Predicate "P") 14 | (Concept "C")) 15 | 16 | ;; Instances of Q 17 | (Evaluation (stv 1 1) 18 | (Predicate "Q") 19 | (Concept "B")) 20 | 21 | (Evaluation (stv 1 1) 22 | (Predicate "Q") 23 | (Concept "C")) 24 | 25 | (Evaluation (stv 1 1) 26 | (Predicate "Q") 27 | (Concept "D")) 28 | 29 | (Evaluation (stv 1 1) 30 | (Predicate "Q") 31 | (Concept "E")) 32 | -------------------------------------------------------------------------------- /tests/pln/rules/implication-extra-variables.scm: -------------------------------------------------------------------------------- 1 | ;; Define implication with extra variable in the implicand 2 | 3 | (ImplicationScopeLink (stv 1 1) 4 | (VariableList 5 | (TypedVariableLink 6 | (VariableNode "$X") 7 | (TypeNode "ConceptNode")) 8 | (TypedVariableLink 9 | (VariableNode "$Y") 10 | (TypeNode "ConceptNode"))) 11 | (EvaluationLink (stv 0.2 0.9) 12 | (PredicateNode "P") 13 | (VariableNode "$X")) 14 | (EvaluationLink 15 | (PredicateNode "Q") 16 | (List 17 | (VariableNode "$X") 18 | (VariableNode "$Y")))) 19 | 20 | (EvaluationLink (stv 1 1) 21 | (PredicateNode "P") 22 | (ConceptNode "A")) 23 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-assertions.scm: -------------------------------------------------------------------------------- 1 | ; Define the concepts 2 | 3 | (ConceptNode "Socrates" (stv .001 0.9)) 4 | (ConceptNode "Einstein" (stv .001 0.9)) 5 | (ConceptNode "Peirce" (stv .001 0.9)) 6 | (ConceptNode "man" (stv .01 0.9)) 7 | (ConceptNode "human" (stv .02 0.9)) 8 | 9 | ; Define the instances of man 10 | 11 | (InheritanceLink (stv 0.9 0.9) 12 | (ConceptNode "Socrates") 13 | (ConceptNode "man")) 14 | 15 | (InheritanceLink (stv 0.9 0.9) 16 | (ConceptNode "Einstein") 17 | (ConceptNode "man")) 18 | 19 | (InheritanceLink (stv 0.9 0.9) 20 | (ConceptNode "Peirce") 21 | (ConceptNode "man")) 22 | 23 | ; Define what man is part of 24 | 25 | (InheritanceLink (stv 0.9 0.9) 26 | (ConceptNode "man") 27 | (ConceptNode "human")) 28 | 29 | ; Assign some additional memberships as well 30 | 31 | (InheritanceLink (stv 0.9 0.9) 32 | (ConceptNode "Einstein") 33 | (ConceptNode "violin-players")) 34 | 35 | ; Pattern to match to check the output 36 | 37 | (define find-humans 38 | (BindLink 39 | (VariableNode "$X") 40 | (InheritanceLink 41 | (VariableNode "$X") 42 | (ConceptNode "human")) 43 | (ListLink 44 | (VariableNode "$X")))) 45 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-consequent-disjunction-elimination.scm: -------------------------------------------------------------------------------- 1 | ;; Simple KB to test consequent-disjunction-elimination-rule 2 | (define P (Predicate "P" (stv 0.02 0.6))) 3 | (define Q1 (Predicate "Q1" (stv 0.01 0.7))) 4 | (define Q2 (Predicate "Q2" (stv 0.05 0.8))) 5 | 6 | (Implication (stv 0.3 0.7) 7 | P 8 | (Or 9 | Q1 10 | Q2)) 11 | 12 | (Implication (stv 0.2 0.6) 13 | P 14 | Q2) 15 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-contraposition.scm: -------------------------------------------------------------------------------- 1 | (use-modules (opencog) (opencog exec)) 2 | (use-modules (opencog ure)) 3 | 4 | ;; Knowledge base 5 | 6 | (define P (Predicate "P" (stv 0.1 1))) 7 | (define Q (Predicate "Q" (stv 0.6 1))) 8 | (ImplicationLink (stv 1 1) P Q) 9 | 10 | ;; URE config 11 | 12 | (define rbs (ConceptNode "contraposition-rbs")) 13 | (ure-add-rule rbs contraposition-implication-rule-name) 14 | 15 | (define target 16 | (ImplicationLink 17 | (NotLink Q) 18 | (NotLink P)) 19 | ) 20 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-equivalence.scm: -------------------------------------------------------------------------------- 1 | (EquivalenceLink (stv 0.6 0.7) 2 | (PredicateNode "P" (stv 0.1 0.5)) 3 | (PredicateNode "Q" (stv 0.12 0.4))) 4 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-forall.scm: -------------------------------------------------------------------------------- 1 | ;; Define simple foralls to test universal rules 2 | 3 | ;; Simple ForAll involving concepts 4 | 5 | (ForAllLink (stv 1 1) 6 | (TypedVariableLink 7 | (VariableNode "$X") 8 | (TypeNode "ConceptNode")) 9 | (EvaluationLink 10 | (PredicateNode "is-concept") 11 | (VariableNode "$X") 12 | ) 13 | ) 14 | 15 | (ConceptNode "A") 16 | 17 | ;; Simple ForAll involving predicates 18 | 19 | (ForAllLink (stv 1 1) 20 | (TypedVariableLink 21 | (VariableNode "$X") 22 | (TypeNode "PredicateNode")) 23 | (EvaluationLink 24 | (PredicateNode "is-predicate") 25 | (VariableNode "$X") 26 | ) 27 | ) 28 | 29 | (PredicateNode "P") 30 | 31 | ;; Simple ForAll involving concepts and predicates 32 | 33 | (ForAllLink (stv 1 1) 34 | (VariableList 35 | (TypedVariableLink 36 | (VariableNode "$X") 37 | (TypeNode "ConceptNode")) 38 | (TypedVariableLink 39 | (VariableNode "$Y") 40 | (TypeNode "PredicateNode"))) 41 | (EvaluationLink 42 | (PredicateNode "are-concept-and-predicate") 43 | (ListLink 44 | (VariableNode "$X") 45 | (VariableNode "$Y")) 46 | ) 47 | ) 48 | 49 | ;; Simple ForAll involving ImplicationLink 50 | 51 | (ForAllLink (stv 1 1) 52 | (TypedVariableLink 53 | (VariableNode "$X") 54 | (TypeNode "ConceptNode")) 55 | (ImplicationLink 56 | (EvaluationLink 57 | (PredicateNode "P") 58 | (VariableNode "$X")) 59 | (EvaluationLink 60 | (PredicateNode "P") 61 | (VariableNode "$X")))) 62 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-implication-implicant-conjunction.scm: -------------------------------------------------------------------------------- 1 | ;; Simple KB to test implication-implicant-conjunction-rule 2 | (define P1 (Predicate "P1" (stv 0.02 0.6))) 3 | (define P2 (Predicate "P2" (stv 0.01 0.7))) 4 | (define Q (Predicate "Q" (stv 0.05 0.8))) 5 | 6 | (Implication (stv 0.1 0.7) 7 | P1 8 | Q) 9 | 10 | (Implication (stv 0.2 0.6) 11 | P2 12 | Q) 13 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-implication-scope.scm: -------------------------------------------------------------------------------- 1 | (ImplicationScope (stv 1 1) 2 | (TypedVariable 3 | (Variable "$X") 4 | (Type "ConceptNode")) 5 | (Evaluation 6 | (Predicate "P") 7 | (Variable "$X")) 8 | (Evaluation 9 | (Predicate "Q") 10 | (Variable "$X"))) 11 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-implication.scm: -------------------------------------------------------------------------------- 1 | ;; Define simple implications to test implication instantiation rules 2 | 3 | (ImplicationScopeLink (stv 1 1) 4 | (TypedVariableLink 5 | (VariableNode "$X") 6 | (TypeNode "ConceptNode")) 7 | (EvaluationLink (stv 0.2 0.9) 8 | (PredicateNode "P") 9 | (VariableNode "$X")) 10 | (EvaluationLink 11 | (PredicateNode "Q") 12 | (VariableNode "$X"))) 13 | 14 | (EvaluationLink (stv 1 1) 15 | (PredicateNode "P") 16 | (ConceptNode "A")) 17 | 18 | (ImplicationScopeLink (stv 1 1) 19 | (VariableList 20 | (TypedVariableLink 21 | (VariableNode "$X") 22 | (TypeNode "ConceptNode")) 23 | (TypedVariableLink 24 | (VariableNode "$Y") 25 | (TypeNode "ConceptNode"))) 26 | (EvaluationLink (stv 0.04 0.6) 27 | (PredicateNode "P") 28 | (ListLink 29 | (VariableNode "$X") 30 | (VariableNode "$Y"))) 31 | (EvaluationLink 32 | (PredicateNode "Q") 33 | (ListLink 34 | (VariableNode "$Y") 35 | (VariableNode "$X")))) 36 | 37 | (EvaluationLink (stv 1 1) 38 | (PredicateNode "P") 39 | (ListLink 40 | (ConceptNode "A") 41 | (ConceptNode "B"))) 42 | 43 | ;; This one is to test the implication instantiation rule when the 44 | ;; precondition cannot be satisfied 45 | (ImplicationScopeLink (stv 1 1) 46 | (TypedVariableLink 47 | (VariableNode "$X") 48 | (TypeNode "ConceptNode")) 49 | (EvaluationLink 50 | (PredicateNode "dummy-implicant") 51 | (VariableNode "$X")) 52 | (EvaluationLink 53 | (PredicateNode "dummy-implicand") 54 | (VariableNode "$X"))) 55 | 56 | ;; This one is to test implicant distribution 57 | 58 | (ImplicationLink (stv 1 1) 59 | (PredicateNode "P") 60 | (PredicateNode "Q")) 61 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-lambda.scm: -------------------------------------------------------------------------------- 1 | ;; Simple examples for LambdaLink for testing Lambda distribution rules 2 | 3 | (define l0 4 | (AndLink 5 | (LambdaLink 6 | (VariableNode "$X") 7 | (EvaluationLink 8 | (PredicateNode "P") 9 | (VariableNode "$X"))) 10 | (LambdaLink 11 | (VariableNode "$X") 12 | (EvaluationLink 13 | (PredicateNode "Q") 14 | (VariableNode "$X"))))) 15 | 16 | (define l1 17 | (LambdaLink (stv 0.6 0.3) 18 | (VariableNode "$X") 19 | (AndLink 20 | (EvaluationLink 21 | (PredicateNode "P") 22 | (VariableNode "$X")) 23 | (EvaluationLink 24 | (PredicateNode "Q") 25 | (VariableNode "$X"))))) 26 | 27 | (define l2 28 | (LambdaLink 29 | (VariableNode "$X") 30 | (EvaluationLink (stv 0.4 0.7) 31 | (PredicateNode "P") 32 | (ConceptNode "A")))) 33 | 34 | (AndLink l1 l2) 35 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-predicates.scm: -------------------------------------------------------------------------------- 1 | ;; Define 2 dummy predicates 2 | 3 | (PredicateNode "P" (stv 0.2 1)) 4 | (PredicateNode "Q" (stv 0.6 1)) 5 | 6 | ;; ;; Define a more complex predicate with Lambda 7 | 8 | ;; (LambdaLink (stv 0.2 1) 9 | ;; (VariableNode "$X") 10 | ;; (EvaluationLink 11 | ;; (PredicateNode "P") 12 | ;; (VariableNode "$X"))) 13 | 14 | ;; (LambdaLink (stv 0.6 1) 15 | ;; (VariableNode "$X") 16 | ;; (EvaluationLink 17 | ;; (PredicateNode "Q") 18 | ;; (VariableNode "$X"))) 19 | -------------------------------------------------------------------------------- /tests/pln/rules/simple-temporal-deduction-kb.scm: -------------------------------------------------------------------------------- 1 | ;; Test temporal deduction 2 | (BackPredictiveImplicationScopeLink (stv 0.345 0.91941) 3 | (VariableNode "$X") 4 | (SLink (ZLink)) 5 | (EvaluationLink 6 | (PredicateNode "P") 7 | (VariableNode "$X")) 8 | (EvaluationLink 9 | (PredicateNode "Q") 10 | (VariableNode "$X"))) 11 | 12 | (BackPredictiveImplicationScopeLink (stv 0.5 0.91941) 13 | (VariableNode "$X") 14 | (SLink (SLink 15 | (ZLink))) 16 | (And 17 | (EvaluationLink 18 | (PredicateNode "Q") 19 | (VariableNode "$X")) 20 | (ExecutionLink 21 | (SchemaNode "A2"))) 22 | (EvaluationLink 23 | (PredicateNode "R") 24 | (VariableNode "$X"))) 25 | 26 | (BackPredictiveImplicationScopeLink (stv 0.345 0.91941) 27 | (VariableNode "$X") 28 | (SLink (ZLink)) 29 | (And 30 | (EvaluationLink 31 | (PredicateNode "C") 32 | (VariableNode "$X")) 33 | (ExecutionLink 34 | (SchemaNode "A1"))) 35 | (EvaluationLink 36 | (PredicateNode "Q") 37 | (VariableNode "$X"))) 38 | 39 | (define target 40 | (Quote (BackPredictiveImplicationScopeLink 41 | (Unquote (Variable "$v")) 42 | (Unquote (Variable "$l")) 43 | (Unquote (Variable "$a")) 44 | (EvaluationLink 45 | (PredicateNode "R") 46 | (Unquote (VariableNode "$X")))))) 47 | -------------------------------------------------------------------------------- /tests/pln/rules/temporal-conditional-conjunction.scm: -------------------------------------------------------------------------------- 1 | ; Temporal conditional conjunction 2 | (BackPredictiveImplicationScopeLink (stv 1 0.0255786) 3 | (VariableSet 4 | ) 5 | (SLink 6 | (ZLink 7 | ) 8 | ) 9 | (AndLink 10 | (EvaluationLink 11 | (PredicateNode "Pellet Position") 12 | (ConceptNode "Right Square") 13 | ) 14 | (EvaluationLink 15 | (PredicateNode "Agent Position") 16 | (ConceptNode "Left Square") 17 | ) 18 | (ExecutionLink 19 | (SchemaNode "Go Right") 20 | ) 21 | ) 22 | (EvaluationLink 23 | (PredicateNode "Pellet Position") 24 | (ConceptNode "Right Square") 25 | ) 26 | ) 27 | (BackPredictiveImplicationScopeLink (stv 1 0.0255786) 28 | (VariableSet 29 | ) 30 | (SLink 31 | (ZLink 32 | ) 33 | ) 34 | (AndLink 35 | (EvaluationLink 36 | (PredicateNode "Pellet Position") 37 | (ConceptNode "Right Square") 38 | ) 39 | (EvaluationLink 40 | (PredicateNode "Agent Position") 41 | (ConceptNode "Left Square") 42 | ) 43 | (ExecutionLink 44 | (SchemaNode "Go Right") 45 | ) 46 | ) 47 | (EvaluationLink 48 | (PredicateNode "Agent Position") 49 | (ConceptNode "Right Square") 50 | ) 51 | ) 52 | (BackPredictiveImplicationScopeLink (stv 1 0.0135635) 53 | (VariableSet 54 | ) 55 | (SLink 56 | (SLink 57 | (ZLink) 58 | ) 59 | ) 60 | (AndLink 61 | (EvaluationLink 62 | (PredicateNode "Pellet Position") 63 | (ConceptNode "Right Square") 64 | ) 65 | (ExecutionLink 66 | (SchemaNode "Eat") 67 | ) 68 | (EvaluationLink 69 | (PredicateNode "Agent Position") 70 | (ConceptNode "Right Square") 71 | ) 72 | ) 73 | (EvaluationLink 74 | (PredicateNode "Reward") 75 | (NumberNode "1") 76 | ) 77 | ) 78 | 79 | (define target 80 | (Quote (BackPredictiveImplicationScopeLink 81 | (Unquote (Variable "$v")) 82 | (Unquote (Variable "$l")) 83 | (Unquote (Variable "$a")) 84 | (Unquote (Variable "$b"))))) 85 | --------------------------------------------------------------------------------