Skip to content

Commit ef0c705

Browse files
committed
Restructuring the inference directory alongwith further additions to proof
1 parent b1aa84e commit ef0c705

10 files changed

+192
-0
lines changed

aima-csharp/aima-csharp.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
<Compile Include="logic\fol\inference\defaultimpl\DefaultClauseSimplifier.cs" />
122122
<Compile Include="logic\fol\inference\defaultimpl\DefaultLightestClauseHeuristic.cs" />
123123
<Compile Include="logic\fol\inference\LightestClauseHeuristic.cs" />
124+
<Compile Include="logic\fol\inference\otter\ClauseFilter.cs" />
125+
<Compile Include="logic\fol\inference\otter\ClauseSimplifier.cs" />
126+
<Compile Include="logic\fol\inference\otter\defaultimpl\DefaultClauseFilter.cs" />
127+
<Compile Include="logic\fol\inference\otter\defaultimpl\DefaultClauseSimplifier.cs" />
128+
<Compile Include="logic\fol\inference\otter\defaultimpl\DefaultLightestClauseHeuristic.cs" />
129+
<Compile Include="logic\fol\inference\otter\LightestClauseHeuristic.cs" />
124130
<Compile Include="logic\fol\inference\proof\AbstractProofStep.cs" />
125131
<Compile Include="logic\fol\inference\proof\Proof.cs" />
126132
<Compile Include="logic\fol\inference\proof\ProofFinal.cs" />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Linq;
5+
using System.Collections.ObjectModel;
6+
using aima.core.logic.fol.kb.data;
7+
using aima.core.logic.fol.parsing.ast;
8+
9+
namespace aima.core.logic.fol.inference.proof
10+
{
11+
/**
12+
* @author Ciaran O'Reilly
13+
*
14+
*/
15+
public class ProofStepBwChGoal : AbstractProofStep
16+
{
17+
private List<ProofStep> predecessors = new List<ProofStep>();
18+
private Clause toProve = null;
19+
private Literal currentGoal = null;
20+
private Dictionary<Variable, Term> bindings = new Dictionary<Variable, Term>();
21+
22+
public ProofStepBwChGoal(Clause toProve, Literal currentGoal,
23+
Dictionary<Variable, Term> bindings)
24+
{
25+
this.toProve = toProve;
26+
this.currentGoal = currentGoal;
27+
foreach (Variable key in bindings.Keys)
28+
{
29+
this.bindings.Add(key, bindings[key]);
30+
}
31+
}
32+
33+
public Dictionary<Variable, Term> getBindings()
34+
{
35+
return bindings;
36+
}
37+
38+
public void setPredecessor(ProofStep predecessor)
39+
{
40+
predecessors.Clear();
41+
predecessors.Add(predecessor);
42+
}
43+
44+
// START-ProofStep
45+
46+
public override List<ProofStep> getPredecessorSteps()
47+
{
48+
return new ReadOnlyCollection<ProofStep>(predecessors).ToList<ProofStep>();
49+
}
50+
51+
public override String getProof()
52+
{
53+
StringBuilder sb = new StringBuilder();
54+
List<Literal> nLits = toProve.getNegativeLiterals();
55+
for (int i = 0; i < toProve.getNumberNegativeLiterals(); i++)
56+
{
57+
sb.Append(nLits[i].getAtomicSentence());
58+
if (i != (toProve.getNumberNegativeLiterals() - 1))
59+
{
60+
sb.Append(" AND ");
61+
}
62+
}
63+
if (toProve.getNumberNegativeLiterals() > 0)
64+
{
65+
sb.Append(" => ");
66+
}
67+
sb.Append(toProve.getPositiveLiterals()[0]);
68+
return sb.ToString();
69+
}
70+
71+
public override String getJustification()
72+
{
73+
return "Current Goal " + currentGoal.getAtomicSentence().ToString()
74+
+ ", " + bindings;
75+
}
76+
77+
// END-ProofStep
78+
}
79+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Collections.ObjectModel;
5+
using aima.core.logic.fol.kb.data;
6+
7+
namespace aima.core.logic.fol.inference.proof
8+
{
9+
/**
10+
* @author Ciaran O'Reilly
11+
*
12+
*/
13+
public class ProofStepFoChAlreadyAFact : AbstractProofStep
14+
{
15+
private readonly List<ProofStep> _noPredecessors = new List<ProofStep>();
16+
private Literal fact = null;
17+
18+
public ProofStepFoChAlreadyAFact(Literal fact)
19+
{
20+
this.fact = fact;
21+
}
22+
23+
// START-ProofStep
24+
25+
public override List<ProofStep> getPredecessorSteps()
26+
{
27+
return new ReadOnlyCollection<ProofStep>(_noPredecessors).ToList<ProofStep>();
28+
}
29+
30+
public override String getProof()
31+
{
32+
return fact.ToString();
33+
}
34+
35+
public override String getJustification()
36+
{
37+
return "Already a known fact in the KB.";
38+
}
39+
40+
// END-ProofStep
41+
}
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Linq;
5+
using System.Collections.ObjectModel;
6+
using aima.core.logic.fol.kb.data;
7+
using aima.core.logic.fol.parsing.ast;
8+
9+
namespace aima.core.logic.fol.inference.proof
10+
{
11+
/**
12+
* @author Ciaran O'Reilly
13+
*
14+
*/
15+
public class ProofStepFoChAssertFact : AbstractProofStep
16+
{
17+
private List<ProofStep> predecessors = new List<ProofStep>();
18+
private Clause implication = null;
19+
private Literal fact = null;
20+
private Dictionary<Variable, Term> bindings = null;
21+
22+
public ProofStepFoChAssertFact(Clause implication, Literal fact,
23+
Dictionary<Variable, Term> bindings, ProofStep predecessor)
24+
{
25+
this.implication = implication;
26+
this.fact = fact;
27+
this.bindings = bindings;
28+
if (null != predecessor)
29+
{
30+
predecessors.Add(predecessor);
31+
}
32+
}
33+
34+
// START-ProofStep
35+
36+
public override List<ProofStep> getPredecessorSteps()
37+
{
38+
return new ReadOnlyCollection<ProofStep>(predecessors).ToList<ProofStep>();
39+
}
40+
41+
public override String getProof()
42+
{
43+
StringBuilder sb = new StringBuilder();
44+
List<Literal> nLits = implication.getNegativeLiterals();
45+
for (int i = 0; i < implication.getNumberNegativeLiterals(); i++)
46+
{
47+
sb.Append(nLits[i].getAtomicSentence());
48+
if (i != (implication.getNumberNegativeLiterals() - 1))
49+
{
50+
sb.Append(" AND ");
51+
}
52+
}
53+
sb.Append(" => ");
54+
sb.Append(implication.getPositiveLiterals()[0]);
55+
return sb.ToString();
56+
}
57+
58+
public override String getJustification()
59+
{
60+
return "Assert fact " + fact.ToString() + ", " + bindings;
61+
}
62+
63+
// END-ProofStep
64+
}
65+
}

0 commit comments

Comments
 (0)