Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the rule handling methods for the five connectives, and the needed structures #194

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
799d946
remove unneeded constructors
SarahAyman Apr 1, 2019
7608a34
initial revision of previously implemented SNIP classes
SarahAyman Apr 5, 2019
f174d6a
change structure of supports in Report and FlagNode to be a set of Su…
SarahAyman Apr 10, 2019
b2db718
change supports in Report and FlagNode back to a PropSet
SarahAyman Apr 18, 2019
4a7590c
Initial revision
SarahAyman Apr 28, 2019
de1c2f2
Modify SIndex structure
SarahAyman Apr 28, 2019
670f5a9
Implement insertRUI() in RUISet class
SarahAyman Apr 28, 2019
f486a83
Add hasSameFreeVariablesAs() in Node class
SarahAyman Apr 29, 2019
fc3d5a9
SIndex Tests
SarahAyman May 2, 2019
052be6a
Implementation of rule firing for NumericalEntailment
SarahAyman May 10, 2019
7a22146
Basic implementation of OrEntailment
SarahAyman May 11, 2019
3d0145b
Change support in Report, and create outgoingChannels for sending rep…
SarahAyman May 14, 2019
58e327e
Remove SIndex errors
SarahAyman May 14, 2019
ad3ceab
Implementation of AndOr, along with some of its tests
SarahAyman May 17, 2019
27fe49e
AndOr tests
SarahAyman May 17, 2019
b76161e
Thresh and some tests for it
SarahAyman May 18, 2019
1048245
Reimplement getSharedVarsNodes() in RuleNode
SarahAyman May 18, 2019
4fb22fa
Revision of PTree
SarahAyman May 21, 2019
a65f2a5
AndEntailment and its tests
SarahAyman May 22, 2019
1be9fc5
Some modifications to the tests
SarahAyman May 22, 2019
894fd9c
Combine a reply report with knownInstances of a RuleNode
SarahAyman May 31, 2019
4166267
Update .project
youssefwalid7 Jun 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
<classpathentry kind="lib" path="lib/java-cup-11b-runtime.jar"/>
<classpathentry kind="lib" path="lib/java-cup-11b.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
</classpath>
6 changes: 0 additions & 6 deletions out/production/Java-SNePS-3.0/.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 8 additions & 4 deletions src/sneps/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -1088,14 +1088,16 @@ private static boolean isToBePattern(Object[][] array) {
* the case frame implemented by the new pattern or proposition node.
*
* @return the newly created pattern node or proposition node.
* @throws NodeNotFoundInNetworkException
* @throws NotAPropositionNodeException
*
* @throws Exception
* if the semantic class specified by the case frame was not
* successfully created and thus the node was not built.
*/

@SuppressWarnings("rawtypes")
private static Node createPatNode(Object[][] relNodeSet, CaseFrame caseFrame) {
private static Node createPatNode(Object[][] relNodeSet, CaseFrame caseFrame) throws NotAPropositionNodeException, NodeNotFoundInNetworkException {

LinkedList<DownCable> dCables = new LinkedList<DownCable>();
for (int i = 0; i < relNodeSet.length; i++) {
Expand Down Expand Up @@ -1136,7 +1138,7 @@ else if (caseFrame == RelationsRestrictedCaseFrame.whenDo)

}

private static Node createPatNode(Object[][] relNodeSet, RelationsRestrictedCaseFrame caseFrame) {
private static Node createPatNode(Object[][] relNodeSet, RelationsRestrictedCaseFrame caseFrame) throws NotAPropositionNodeException, NodeNotFoundInNetworkException {
LinkedList<DownCable> dCables = new LinkedList<DownCable>();
for (int i = 0; i < relNodeSet.length; i++) {
dCables.add(new DownCable((Relation) relNodeSet[i][0], (NodeSet) relNodeSet[i][1]));
Expand Down Expand Up @@ -1188,14 +1190,16 @@ else if (caseFrame == RelationsRestrictedCaseFrame.whenDo)
* the case frame implemented by the new closed or proposition node.
*
* @return the newly created closed or proposition node.
* @throws NodeNotFoundInNetworkException
* @throws NotAPropositionNodeException
*
* @throws Exception
* if the semantic class specified by the case frame was not
* successfully created and thus the node was not built.
*/

@SuppressWarnings("rawtypes")
private static Node createClosedNode(Object[][] relNodeSet, CaseFrame caseFrame) {
private static Node createClosedNode(Object[][] relNodeSet, CaseFrame caseFrame) throws NotAPropositionNodeException, NodeNotFoundInNetworkException {
LinkedList<DownCable> dCables = new LinkedList<DownCable>();
for (int i = 0; i < relNodeSet.length; i++) {
dCables.add(new DownCable((Relation) relNodeSet[i][0], (NodeSet) relNodeSet[i][1]));
Expand Down Expand Up @@ -1231,7 +1235,7 @@ private static Node createClosedNode(Object[][] relNodeSet, CaseFrame caseFrame)
}

@SuppressWarnings("rawtypes")
private static Node createClosedNode(Object[][] relNodeSet, RelationsRestrictedCaseFrame caseFrame) {
private static Node createClosedNode(Object[][] relNodeSet, RelationsRestrictedCaseFrame caseFrame) throws NotAPropositionNodeException, NodeNotFoundInNetworkException {
LinkedList<DownCable> dCables = new LinkedList<DownCable>();
for (int i = 0; i < relNodeSet.length; i++) {
dCables.add(new DownCable((Relation) relNodeSet[i][0], (NodeSet) relNodeSet[i][1]));
Expand Down
58 changes: 56 additions & 2 deletions src/sneps/network/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import sneps.network.cables.UpCableSet;
import sneps.network.classes.Semantic;
import sneps.network.classes.setClasses.NodeSet;
import sneps.network.classes.setClasses.VarNodeSet;
import sneps.network.classes.term.Molecular;
import sneps.network.classes.term.Open;
import sneps.network.classes.term.Term;
import sneps.snebr.Context;
import sneps.snip.channels.Channel;
Expand Down Expand Up @@ -94,7 +96,10 @@ public String getSemanticSuperClass() {
* @return the name or the label of the current node.
*/
public String getIdentifier() {
return this.term.getIdentifier();
if(this.term != null)
return this.term.getIdentifier();
else
return "";
}

/**
Expand All @@ -120,7 +125,9 @@ public NodeSet getParentNodes() {
*/
@Override
public String toString() {
return this.term.toString();
if(this.term != null)
return this.term.toString();
return null;
}

/**
Expand Down Expand Up @@ -266,5 +273,52 @@ public void setTemp(boolean temp) {
public void updateUpCables() {
((Molecular) this.getTerm()).updateUpCables(this);
}

public boolean hasSameFreeVariablesAs(Node n) {
//this Node is a VariableNode
if(this instanceof VariableNode) {
//Node to be compared with is also a VariableNode
if(n instanceof VariableNode) {
if(this.equals(((VariableNode) n)))
return true;
}

//Node to be compared with is an Open node
if(n.getTerm() instanceof Open) {
VarNodeSet freeVars = ((Open) n.getTerm()).getFreeVariables();
if((freeVars.size() == 1) && (this.equals(freeVars.getVarNode(0))))
return true;
}
}

//this Node is an Open node
if(this.getTerm() instanceof Open) {
VarNodeSet n1freeVars = ((Open) this.getTerm()).getFreeVariables();

//Node to be compared with is a VariableNode
if(n instanceof VariableNode) {
if((n1freeVars.size() == 1) &&
(n1freeVars.getVarNode(0).equals(((VariableNode) n))))
return true;
}

//Node to be compared with is an Open node
if(n.getTerm() instanceof Open) {
VarNodeSet n2freeVars = ((Open) n.getTerm()).getFreeVariables();
if(n1freeVars.size() != n2freeVars.size())
return false;

for(int i = 0; i < n1freeVars.size(); i++) {
if(!(n2freeVars.contains(n1freeVars.getVarNode(i)))) {
return false;
}
}

return true;
}
}

return false;
}

}
104 changes: 67 additions & 37 deletions src/sneps/network/PropositionNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
import sneps.exceptions.NotAPropositionNodeException;

import java.util.Hashtable;
import java.util.Set;

import sneps.snebr.Context;
import sneps.snebr.Support;
import sneps.snip.InferenceTypes;
import sneps.snip.Pair;
import sneps.snip.Report;
import sneps.snip.ReportInstances;
import sneps.snip.Runner;
import sneps.snip.channels.AntecedentToRuleChannel;
import sneps.snip.channels.Channel;
Expand All @@ -28,54 +32,35 @@
import sneps.snip.matching.LinearSubstitutions;
import sneps.snip.matching.Substitutions;

public class PropositionNode extends Node implements Serializable{
private Support basicSupport;

public class PropositionNode extends Node implements Serializable {
private static final long serialVersionUID = 1L;

protected Support basicSupport;
protected ChannelSet outgoingChannels;
protected ChannelSet incomingChannels;
protected ReportSet knownInstances;
protected ReportInstances knownInstances;
protected ReportSet newInstances;

public PropositionNode() {
outgoingChannels = new ChannelSet();
incomingChannels = new ChannelSet();
knownInstances = new ReportSet();
knownInstances = new ReportInstances();
newInstances = new ReportSet();
}

public PropositionNode(Term trm) {
super(Semantic.proposition, trm);
outgoingChannels = new ChannelSet();
incomingChannels = new ChannelSet();
knownInstances = new ReportSet();
newInstances = new ReportSet();
setTerm(trm);
}
public PropositionNode(Term trm, Semantic sem) {
this();
setTerm(trm);
setSemanticType(sem);
}
public PropositionNode(Semantic sym, Term trm){
super(sym, trm);
outgoingChannels = new ChannelSet();
incomingChannels = new ChannelSet();
knownInstances = new ReportSet();
newInstances = new ReportSet();
}
public PropositionNode(Semantic sym){
super(sym);
outgoingChannels = new ChannelSet();
incomingChannels = new ChannelSet();
knownInstances = new ReportSet();
knownInstances = new ReportInstances();
newInstances = new ReportSet();
}

public void processSingleChannelReports(Channel currentChannel) {
/*public void processSingleChannelReports(Channel currentChannel) {
ReportSet reports = currentChannel.getReportsBuffer();
for (Report currentReport : reports) {
Report alteredReport = new Report(currentReport.getSubstitutions(), currentReport.getSupports(),
currentReport.getSign(), currentReport.getContextName());
Report alteredReport = new Report(currentReport.getSubstitutions(), currentReport.getSupport(),
currentReport.getSign(), InferenceTypes.BACKWARD);
if (knownInstances.contains(alteredReport)) {
continue;
}else{
Expand All @@ -87,12 +72,12 @@ public void processSingleChannelReports(Channel currentChannel) {
currentChannel.clearReportsBuffer();
}
currentChannel.clearReportsBuffer();
}
}*/

public void processReports() {
/*public void processReports() {
for (Channel inChannel : incomingChannels)
processSingleChannelReports(inChannel);
}
}*/

public void broadcastReport(Report report) {
newInstances.addReport(report);
Expand Down Expand Up @@ -222,43 +207,88 @@ public boolean alreadyWorking(Channel channel) {
public Support getBasicSupport() {
return basicSupport;
}

public void setBasicSupport() throws NotAPropositionNodeException, NodeNotFoundInNetworkException {
this.basicSupport = new Support(this.getId());
}

public ChannelSet getOutgoingChannels() {
return outgoingChannels;
}

public void setOutgoingChannels(ChannelSet outgoingChannels) {
this.outgoingChannels = outgoingChannels;
}

public ChannelSet getIncomingChannels() {
return incomingChannels;
}

public void setIncomingChannels(ChannelSet incomingChannels) {
this.incomingChannels = incomingChannels;
}
public ReportSet getKnownInstances() {

public ReportInstances getKnownInstances() {
return knownInstances;
}
public void setKnownInstances(ReportSet knownInstances) {

public void setKnownInstances(ReportInstances knownInstances) {
this.knownInstances = knownInstances;
}

public Hashtable<String, PropositionSet> getAssumptionBasedSupport() {
return basicSupport.getAssumptionBasedSupport();
}

public Hashtable<String, PropositionSet> getJustificationSupport() {
return basicSupport.getJustificationSupport();
}

public void addJustificationBasedSupport(PropositionSet propSet) throws NodeNotFoundInPropSetException, NotAPropositionNodeException, NodeNotFoundInNetworkException{
basicSupport.addJustificationBasedSupport(propSet);
}

public boolean removeNodeFromSupports(PropositionNode propNode) {
return basicSupport.removeNodeFromSupports(propNode);

return basicSupport.removeNodeFromSupports(propNode);
}

public ReportSet getNewInstances() {
return newInstances;
}

protected Set<Channel> getOutgoingAntecedentRuleChannels() {
return outgoingChannels.getAntRuleChannels();
}

protected Set<Channel> getOutgoingRuleConsequentChannels() {
return outgoingChannels.getRuleConsChannels();
}

protected Set<Channel> getOutgoingMatchChannels() {
return outgoingChannels.getMatchChannels();
}

protected Set<Channel> getIncomingAntecedentRuleChannels() {
return incomingChannels.getAntRuleChannels();
}

protected Set<Channel> getIncomingRuleConsequentChannels() {
return incomingChannels.getRuleConsChannels();
}

protected Set<Channel> getIncomingMatchChannels() {
return incomingChannels.getMatchChannels();
}

public boolean assertedInContext(Context reportContext) {
// TODO Auto-generated method stub
return false;
}

public Channel establishChannel(ChannelTypes rulecons, Node n, LinearSubstitutions linearSubstitutions,
LinearSubstitutions linearSubstitutions2, Context currentContext, int j) {
// TODO Auto-generated method stub
return null;
}

}
Loading