diff --git a/rules/AndEntailment.java b/rules/AndEntailment.java new file mode 100644 index 00000000..cf7b17d4 --- /dev/null +++ b/rules/AndEntailment.java @@ -0,0 +1,276 @@ +package sneps.snip.rules; + +import java.util.ArrayList; +import java.util.HashSet; + +import org.junit.Rule; + +import sneps.exceptions.DuplicatePropositionException; +import sneps.exceptions.NodeNotFoundInNetworkException; +import sneps.exceptions.NotAPropositionNodeException; +import sneps.network.Node; +import sneps.network.PropositionNode; +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.term.Term; +import sneps.snebr.Context; +import sneps.snebr.Controller; +import sneps.snebr.Support; +import sneps.snip.Report; +import sneps.snip.classes.FlagNode; +import sneps.snip.classes.RuleUseInfo; + +public class AndEntailment extends RuleNode { + private static final long serialVersionUID = -8545987005610860977L; + private NodeSet consequents;//TODO Proposition Nodes get + + public AndEntailment(Term syn) { + super(syn); + setConsequents(new NodeSet()); + } + + public ArrayList getConsequentReports(ArrayList concequents, PropositionNode Node, Context c) { + ArrayList reports = new ArrayList(); + for(Node n : consequents) { + reports.add(n.processReports()); + } + return reports; + } + + + + + + + + private void ConcludeIntroduction(boolean wrongRule, int posCount, int negCount, ArrayList consequents2) { + // TODO Auto-generated method stub + if(wrongRule) { + System.out.println("This rule is a wrong rule"); + } + } + + + public int isAndEntReportSetValid(ArrayList reports, Node RulNode, ArrayList antecedents) { + + int isValid = 0; + for(Report report : reports) { + for(Support s : report.getSupports()) { + boolean containsIntroRule = false; + boolean containsNodesReq = true; + for(Node n : s.getNodes()) { + if(n instanceof RuleNode) { + containsIntroRule = true; + } + for(Node ant : s.getAntecedents()) { + if(!((RuleNode) n).getPatternNodes().contains(ant)) { + containsNodesReq = false; + break; + } + } + if (!containsIntroRule && !containsNodesReq) { + return 3; + } + if (report.isNegative() && !containsIntroRule && containsNodesReq) { + return -1; + } + if (report.isPositive() && !containsIntroRule && containsNodesReq) { + isValid = 1; + } + + } + } + + + } + return isValid; +} + + public void applyAndRuleHandler(PropositionNode AndNode, int ContextId ) throws NotAPropositionNodeException, NodeNotFoundInNetworkException, DuplicatePropositionException { + + IntroductionProcess i = new IntroductionProcess(); + + ArrayList antecedents = new ArrayList(); + ArrayList consequents = new ArrayList(); + Context TempContext = i.getTempContext(antecedents,ContextId); + + int posCount = 0; + int negCount = 0; + boolean wrongRule = false; + + for(Node n: consequents ) { + + ArrayList reports = getConsequentReports(consequents, AndNode, TempContext); + int isAndEntReportSetValid = isAndEntReportSetValid(reports, AndNode,antecedents); + + + if (isAndEntReportSetValid > 1) { + wrongRule = true; + break; + } + + else if(isAndEntReportSetValid == -1) { + negCount += 1 ; + break; + } + else if(isAndEntReportSetValid == 1) { + posCount += 1 ; + + } + ConcludeIntroduction(wrongRule, posCount, negCount, consequents); + } + + + + + + + + + + + + + + + + + + // OLD +// String contxt = report.getContextName(); +// if (report.isPositive()) { +// FlagNodeSet fns = new FlagNodeSet(); +// fns.putIn(new FlagNode(signature, report.getSupports(), 1)); +// RuleUseInfo rui = new RuleUseInfo(report.getSubstitutions(), +// 1, 0, fns); +// addNotSentRui(rui, contxt,signature); +// } +// if (contextRuisSet.getByContext(contxt).getPositiveNodes().size() >= antNodesWithoutVars.size() + antNodesWithVars.size()) +// sendSavedRUIs(report.getContextName()); +// } +// +// @Override +// protected void applyRuleOnRui(RuleUseInfo Rui, String contextID) { +// //addNotSentRui(Rui, contextID); +// if (Rui.getPosCount() != antNodesWithVars.size() + antNodesWithoutVars.size()) +// return; +// Support originSupports = this.getBasicSupport(); +// HashSet sup = new HashSet(); +// sup.add(originSupports); +// +// //Send this V +// contextRuisSet.getByContext(contextID).getPositiveNodes().addNode(this); +// +// //contextRuisSet.getByContext((String) Controller.getContextByName(contextID)).insertRUI(Rui); +// +// Report reply = new Report(Rui.getSub(), Rui.getSupport(sup), true, contextID); +// broadcastReport(reply); + } + + + + + + + + + + + +// @Override +// public void applyRuleHandler(Report report, Node signature) { +// String contxt = report.getContextName(); +// if (report.isPositive()) { +// FlagNodeSet fns = new FlagNodeSet(); +// fns.putIn(new FlagNode(signature, report.getSupports(), 1)); +// RuleUseInfo rui = new RuleUseInfo(report.getSubstitutions(), +// 1, 0, fns); +// addNotSentRui(rui, contxt,signature); +// } +// if (contextRuisSet.getByContext(contxt).getPositiveNodes().size() >= antNodesWithoutVars.size() + antNodesWithVars.size()) +// sendSavedRUIs(report.getContextName()); +// } +// +// @Override +// protected void applyRuleOnRui(RuleUseInfo Rui, String contextID) { +// //addNotSentRui(Rui, contextID); +// if (Rui.getPosCount() != antNodesWithVars.size() + antNodesWithoutVars.size()) +// return; +// Support originSupports = this.getBasicSupport(); +// HashSet sup = new HashSet(); +// sup.add(originSupports); +// +// //Send this V +// contextRuisSet.getByContext(contextID).getPositiveNodes().addNode(this); +// +// //contextRuisSet.getByContext((String) Controller.getContextByName(contextID)).insertRUI(Rui); +// +// Report reply = new Report(Rui.getSub(), Rui.getSupport(sup), true, contextID); +// broadcastReport(reply); +// } +// +// public void addNotSentRui(RuleUseInfo rui, String contxt, Node signature){ +// PTree tree = (PTree) contextRuisSet.getByContext(contxt); +// if (tree == null) +// tree = (PTree) createRuisHandler(contxt); +// tree.insertRUI(rui); +// tree.getPositiveNodes().addNode(signature); +// contextRuisSet.addHandlerSet(contxt, tree); +// } +// private void sendSavedRUIs(String contextID) { +// RuleUseInfo addedConstant = getConstantRUI(contextID); +// if (addedConstant == null && antNodesWithoutVars.size() != 0) +// return; +// +// if (antNodesWithoutVars.size() != addedConstant.getPosCount()) +// return; +// +// RuleUseInfoSet ruis = ((PTree)contextRuisSet.getByContext(contextID)).getAllRootRuis(); +// if (ruis == null) { +// applyRuleOnRui(addedConstant, contextID); +// return; +// } +// +// RuleUseInfo combined; +// for (RuleUseInfo info : ruis) { +// combined = info.combine(addedConstant); +// if (combined != null) +// applyRuleOnRui(combined, contextID); +// } +// } +// +// @Override +// public RuisHandler createRuisHandler(String context) { +// Context contxt = (Context) Controller.getContextByName(context); +// PTree tree = new PTree(context); +// NodeSet ants = antNodesWithoutVars; +// ants.addAll(antNodesWithVars); +// tree.buildTree(ants); +// return this.addContextRUIS(contxt, tree); +// } + @Override + public NodeSet getDownAntNodeSet() { + return this.getDownNodeSet("&ant");//ants for & TODO name convention + } + + @Override + public void clear(){ + super.clear(); + consequents.clear(); + } + + + public NodeSet getConsequents() { + return consequents; + } + public void setConsequents(NodeSet consequents) { + this.consequents = consequents; + } + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/AndOrNode.java b/rules/AndOrNode.java new file mode 100644 index 00000000..2f4bef85 --- /dev/null +++ b/rules/AndOrNode.java @@ -0,0 +1,93 @@ +package sneps.snip.rules; + +import java.util.HashSet; +import java.util.Set; + +import sneps.network.Node; +import sneps.network.PropositionNode; +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.term.Term; +import sneps.snebr.Context; +import sneps.snebr.Controller; +import sneps.snebr.Support; +import sneps.snip.Report; +import sneps.snip.channels.Channel; +import sneps.snip.classes.RuleUseInfo; +import sneps.snip.classes.SIndex; +import sneps.snip.classes.FlagNode; + +public class AndOrNode extends RuleNode { + + boolean sign = false; + + private int min, max, args; + + public int getAndOrMin() { + return min; + } + + public int getAndOrMax() { + return max; + } + + public int getAndOrArgs() { + return args; + } + + public AndOrNode(Term syn) { + super(syn); + NodeSet minNode = this.getDownNodeSet("min"); + min = Integer.parseInt(minNode.getNode(0).getIdentifier()); + NodeSet maxNode = this.getDownNodeSet("max"); + max = Integer.parseInt(maxNode.getNode(0).getIdentifier()); + NodeSet antNodes = this.getDownNodeSet("arg"); + args = antNodes.size(); + +// this.processNodes(antNodes); + } + +// protected void applyRuleOnRui(RuleUseInfo tRui, String contextID) { +// +// if (tRui.getNegCount() == args - min) +// sign = true; +// else if (tRui.getPosCount() != max) +// return; +// +// Set nodesSentReports = new HashSet(); +// for (FlagNode fn : tRui.getFlagNodeSet()) { +// nodesSentReports.add(fn.getNode().getId()); +// } +// +// Support originSupports = this.getBasicSupport(); +// HashSet sup = new HashSet(); +// sup.add(originSupports); +// Report forwardReport = new Report(tRui.getSub(), tRui.getSupport(sup), sign,contextID); +// +// for (Channel outChannel : outgoingChannels) { +// if(!nodesSentReports.contains(outChannel.getRequester().getId())) +// outChannel.addReport(forwardReport); +// } +// +// } + + + public NodeSet getDownAntNodeSet() { + return this.getDownNodeSet("Xant"); + } + + +// protected RuisHandler createRuisHandler(String contextName) { +// Context contxt = (Context) Controller.getContextByName(contextName); +// SIndex index = new SIndex(contextName, getSharedVarsNodes(antNodesWithVars), (byte) 0, getDominatingRules()); +// return this.addContextRUIS(contxt, index); +// } + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/DoIfNode.java b/rules/DoIfNode.java new file mode 100644 index 00000000..068689cc --- /dev/null +++ b/rules/DoIfNode.java @@ -0,0 +1,40 @@ +package sneps.snip.rules; + +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.term.Term; +import sneps.snip.classes.RuleUseInfo; + +public class DoIfNode extends RuleNode { + private static final long serialVersionUID = -262476672166406490L; + + public DoIfNode(Term syn) { + super(syn); + } + +// @Override +// protected void applyRuleOnRui(RuleUseInfo tRui, String contextID) { +// // TODO Auto-generated method stub +// +// } + + @Override + public NodeSet getDownAntNodeSet() { + // TODO Auto-generated method stub + return null; + } + +// @Override +// protected RuisHandler createRuisHandler(String contextName) { +// // TODO Auto-generated method stub +// return null; +// } + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/IntroductionProcess.java b/rules/IntroductionProcess.java new file mode 100644 index 00000000..2a46cd08 --- /dev/null +++ b/rules/IntroductionProcess.java @@ -0,0 +1,231 @@ +package sneps.snip.rules; + +import sneps.network.RuleNode; +import sneps.network.VariableNode; + +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.setClasses.PropositionSet; + +import sneps.snebr.Context; +import sneps.snip.Report; +import sneps.snip.channels.Channel; +import sneps.snip.channels.ChannelTypes; +import sneps.snip.classes.RuleUseInfo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Set; + +import sneps.exceptions.DuplicatePropositionException; +import sneps.exceptions.NodeNotFoundInNetworkException; +import sneps.exceptions.NotAPropositionNodeException; +import sneps.network.Node; +import sneps.network.PropositionNode; + +public class IntroductionProcess extends RuleNode { + + + int contextId; + public RuleNode n1 = new RuleNode() { + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + + @Override + public NodeSet getDownAntNodeSet() { + // TODO Auto-generated method stub + return null; + } + }; + Report re ; + static Channel ch = new Channel() {}; + Context cx = new Context(0); + + + AndEntailment ae = new AndEntailment(term); +// OrNode on = new OrNode(term); + + + static String type;// for testing purpose + + public boolean CanBeIntroduced(PropositionNode node, Channel channel) throws NotAPropositionNodeException, NodeNotFoundInNetworkException { + +//// String currentContextName = channel.getContextName(); +// +//// if(channel.getReporter().equals(node)) { // if already working on this channel +//// return false; +//// } + if(!(node instanceof RuleNode)) { // if a node is not a Rule node + return false; + } +// if(cx.isAsserted(node)) { //rule is already asserted in the context +// return false; +// } + +// +// } + System.out.println("Rule Can Be Introduced"); + return true; + + + } + + public void BeginIntroduction(Channel channel) throws NotAPropositionNodeException, NodeNotFoundInNetworkException, DuplicatePropositionException { + +// int ContextID = 0; + + + if (CanBeIntroduced((PropositionNode)n1, channel)==true) { + + if(n1 instanceof RuleNode ) { +// System.out.println("Can BeIntroduced"); + +// if(n1 instanceof AndEntailment) { +// +// System.out.println("This is AndEntailment Node"); +// ae.applyRuleHandler(re, n1); +// } +// else if(n1 instanceof OrNode) { +// System.out.println("This is OrEntailment Node"); +// applyRuleHandler(re, n1); +// } +// else if(n1 instanceof AndOrNode ) { +// System.out.println("This is AndOr Node"); +// applyRuleHandler(re, n1); +// } +// else if(n1 instanceof NumericalEntailment ) { +// System.out.println("This is NumericalEntailment Node"); +// applyRuleHandler(re, n1); +// +// } +// else if(n1 instanceof ThreshNode ) { +// System.out.println("This is NumericalEntailment Node"); +// applyRuleHandler(re, n1); +// } +// else +// System.out.println("Not a rule node"); + + // for testing + if(type.equals("and")) { + System.out.println("This is AndEntailment Node"); + ae.applyAndRuleHandler(n1, contextId); + } + + if(type.equals("or")) { + System.out.println("This is an OrEntailment Node"); + ae.applyAndRuleHandler(n1, contextId); + } + } + + + + } + else + System.out.println("Rule Can't be introduced"); + } + + public Context getTempContext(ArrayList nodes, int ContextID) throws NotAPropositionNodeException, NodeNotFoundInNetworkException, DuplicatePropositionException { + Context tempContext = new Context(ContextID); +// String currentContextName = ch.getContextName(); + + + for(Node node : nodes) { +// if(!(((RuleNode) node).assertedInContext(currentContextName))) { +// // tempContext.add(node); +// } + if(!this.cx.isAsserted((PropositionNode)node)) { + cx.getHypothesisSet().add(node.getId()); + tempContext.getHypothesisSet().add(node.getId()); + } + } + return tempContext; + } + + + + + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + + @Override + public NodeSet getDownAntNodeSet() { + // TODO Auto-generated method stub + return null; + } + + public static void main(String[] args) throws NotAPropositionNodeException, NodeNotFoundInNetworkException, DuplicatePropositionException { + //Node M1 : PhD(x) ∧ Researcher (x) → Prof(x) + String testRule = "PhD(Jack) & Researcher(Jack) -> Prof(Jack)"; + String ant = testRule.split("->")[0].trim(); + String cns = testRule.split("->")[1].trim(); + + + + IntroductionProcess ii = new IntroductionProcess(); + ii.n1 = new RuleNode() { + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + + @Override + public NodeSet getDownAntNodeSet() { + // TODO Auto-generated method stub + return null; + } + }; + + if(ant.indexOf('&') != -1) { // if the index of (&) is in the rule + String node1 = ant.split("&")[0].trim(); + String node2 = ant.split("&")[1].trim(); + + String class1 = node1.split("\\(")[0].trim(); + String member1 = node1.split("\\(")[1].split("\\)")[0].trim(); + + + String class2 = node2.split("\\(")[0].trim(); + String member2 = node2.split("\\(")[1].split("\\)")[0].trim(); + System.out.println("Member " + member2 + " is in class " + class2); + ii.type = "and"; + + String class3 = cns.split("\\(")[0].trim(); + String member3 = cns.split("\\(")[1].split("\\)")[0].trim(); + System.out.println("Member " + member3 + " is in class " + class3); + + } else if(ant.indexOf('|') != -1) { + String n1 = ant.split("|")[0].trim(); + String n2 = ant.split("|")[1].trim(); + + +// +// String class1 = n1.split("\\(")[0].trim(); +// String member1 = n1.split("\\(")[1].split("\\)")[0].trim(); +// +// +// String class2 = n2.split("\\(")[0].trim(); +// String member2 = n2.split("\\(")[1].split("\\)")[0].trim(); +// System.out.println("Member " + member2 + " is in class " + class2); + ii.type = "or"; + + + } else { + + } + + ii.BeginIntroduction(ch); + System.out.println("The antecedents of the rule are"+ " " +ant); + System.out.println("The concequents of the rule are"+ " " +cns); + System.out.println("Rule is introduced"); + } + + +} diff --git a/rules/NumericalEntailment.java b/rules/NumericalEntailment.java new file mode 100644 index 00000000..c0e70e99 --- /dev/null +++ b/rules/NumericalEntailment.java @@ -0,0 +1,107 @@ +package sneps.snip.rules; + +import java.util.HashSet; +import java.util.Set; + +import sneps.network.Node; +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.term.Term; +import sneps.snebr.Context; +import sneps.snebr.Controller; +import sneps.snebr.Support; +import sneps.snip.Report; +import sneps.snip.classes.FlagNode; +import sneps.snip.classes.RuleUseInfo; +import sneps.snip.classes.SIndex; + +public class NumericalEntailment extends RuleNode { + private static final long serialVersionUID = 3546852401118194013L; + private NodeSet consequents; + private int i; + + public NumericalEntailment(Term syn) { + super(syn); + } + +// @Override +// public void applyRuleHandler(Report report, Node signature) { +// String contxt = report.getContextName(); +// if (report.isPositive()) { +// FlagNodeSet fns = new FlagNodeSet(); +// fns.putIn(new FlagNode(signature, report.getSupports(), 1)); +// RuleUseInfo rui = new RuleUseInfo(report.getSubstitutions(), +// 1, 0, fns); +// addNotSentRui(rui, contxt, signature); +// } +// int curPos = contextRuisSet.getByContext(contxt).getPositiveNodes().size(); +// int n = antNodesWithoutVars.size()+antNodesWithVars.size(); +// if ((curPos >= i) && ((curPos < n-i+1) || (curPos < n-1) ) ) +// sendSavedRUIs(report.getContextName()); +// } +// @Override +// protected void applyRuleOnRui(RuleUseInfo rui, String contextID) { +// if (rui.getPosCount() >= i){ +// Set originSupports = new HashSet(); +// originSupports.add(this.getBasicSupport()); +// Report reply = new Report(rui.getSub(),rui.getSupport(originSupports), true, contextID); +// broadcastReport(reply); +// } +// } +// +// public void addNotSentRui(RuleUseInfo rui, String contxt, Node signature){ +// SIndex set = (SIndex) contextRuisSet.getByContext(contxt); +// //if (set == null) +// //set = new SIndex(contxt, sharedVars, 0, consequents); +// set.insertRUI(rui); +// set.getPositiveNodes().addNode(signature); +// contextRuisSet.addHandlerSet(contxt, set); +// } +// private void sendSavedRUIs(String contextID) { +// RuleUseInfo addedConstant = getConstantRUI(contextID); +// if (addedConstant == null && antNodesWithoutVars.size() != 0) +// return; +// +// if (antNodesWithoutVars.size() != addedConstant.getPosCount()) +// return; +// +// RuleUseInfoSet ruis = ((PTree)contextRuisSet.getByContext(contextID)).getAllRootRuis(); +// if (ruis == null) { +// applyRuleOnRui(addedConstant, contextID); +// return; +// } +// +// RuleUseInfo combined; +// for (RuleUseInfo info : ruis) { +// combined = info.combine(addedConstant); +// if (combined != null) +// applyRuleOnRui(combined, contextID); +// } +// } +// +// @Override +// protected RuisHandler createRuisHandler(String contextName) {//TODO Check +// Context contxt = (Context) Controller.getContextByName(contextName); +// SIndex index = new SIndex(contextName, getSharedVarsNodes(antNodesWithVars), (byte) 0, getDominatingRules()); +// return this.addContextRUIS(contxt, index); +// } + + @Override + public NodeSet getDownAntNodeSet(){ + return this.getDownNodeSet("iant"); + } + + public NodeSet getConsequents() { + return consequents; + } + public int getI() { + return i; + } + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/OrNode.java b/rules/OrNode.java new file mode 100644 index 00000000..f9348808 --- /dev/null +++ b/rules/OrNode.java @@ -0,0 +1,69 @@ +package sneps.snip.rules; + +import java.util.HashSet; +import java.util.Set; + +import sneps.network.Node; +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.PropositionNode; +import sneps.network.classes.term.Term; +import sneps.snebr.Support; +import sneps.snip.Report; +import sneps.snip.channels.Channel; +import sneps.snip.classes.RuleUseInfo; + +public class OrNode extends RuleNode { + + private int ant,cq; + + + public OrNode(Term syn) { + super(syn); + ant = getDownNodeSet("ant").size(); + cq = getDownNodeSet("cq").size(); + } + + + public void applyOrRuleHandler(Report report, Node node) { + + if(report.isPositive()) { + + Support originSupports = this.getBasicSupport(); + HashSet sup = new HashSet(); + sup.add(originSupports); + Report reply = new Report(report.getSubstitutions(), sup, true, report.getContextName()); + + for (Channel outChannel : outgoingChannels) + outChannel.addReport(reply); + + } + +} + + + + @Override + public NodeSet getDownAntNodeSet() { + return this.getDownNodeSet("Vant"); + } + +// @Override +// protected void applyRuleOnRui(RuleUseInfo tRui, String contextID) { +// +// } +// +// @Override +// protected RuisHandler createRuisHandler(String contextName) { +// // TODO Auto-generated method stub +// return null; +// } + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/ThreshNode.java b/rules/ThreshNode.java new file mode 100644 index 00000000..e3b239ea --- /dev/null +++ b/rules/ThreshNode.java @@ -0,0 +1,97 @@ +package sneps.snip.rules; + +import java.util.HashSet; +import java.util.Set; + +import sneps.network.Node; +import sneps.network.PropositionNode; +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.PropositionNode; +import sneps.network.classes.term.Term; +import sneps.snebr.Context; +import sneps.snebr.Controller; +import sneps.snebr.Support; +import sneps.snip.Report; +import sneps.snip.channels.Channel; +import sneps.snip.classes.RuleUseInfo; +import sneps.snip.classes.SIndex; +import sneps.snip.classes.FlagNode; + +public class ThreshNode extends RuleNode { + + boolean sign = false; + + private int min, max, args; + + public int getThreshMin() { + return min; + } + + public int getThreshMax() { + return max; + } + + public int getThreshArgs() { + return args; + } + + + public ThreshNode(Term syn) { + super(syn); + NodeSet minNode = this.getDownNodeSet("thresh"); + min = Integer.parseInt(minNode.getNode(0).getIdentifier()); + NodeSet maxNode = this.getDownNodeSet("threshmax"); + max = Integer.parseInt(maxNode.getNode(0).getIdentifier()); + NodeSet antNodes = this.getDownNodeSet("arg"); + args = antNodes.size(); +// this.processNodes(antNodes); + } + +// protected void applyRuleOnRui(RuleUseInfo tRui, String contextID) { +// +// if (tRui.getPosCount() == min +// && tRui.getNegCount() == args - max - 1) +// sign = true; +// else if (tRui.getPosCount() != min - 1 || tRui.getNegCount() != args - max) +// sign = false; +// +// +// +// Set nodesSentReports = new HashSet(); +// for (FlagNode fn : tRui.getFlagNodeSet()) { +// nodesSentReports.add(fn.getNode().getId()); +// } +// +// Support originSupports = this.getBasicSupport(); +// HashSet sup = new HashSet(); +// sup.add(originSupports); +// Report forwardReport = new Report(tRui.getSub(), tRui.getSupport(sup), sign,contextID); +// +// for (Channel outChannel : outgoingChannels) { +// if(!nodesSentReports.contains(outChannel.getRequester().getId())) +// outChannel.addReport(forwardReport); +// } +// +// } +// +// +// protected RuisHandler createRuisHandler(String contextName) { +// Context contxt = (Context) Controller.getContextByName(contextName); +// SIndex index = new SIndex(contextName, getSharedVarsNodes(antNodesWithVars), (byte) 0, getDominatingRules()); +// return this.addContextRUIS(contxt, index); +// } + + @Override + public NodeSet getDownAntNodeSet() { + return this.getDownNodeSet("Tant"); + } + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +} diff --git a/rules/WhenDoNode.java b/rules/WhenDoNode.java new file mode 100644 index 00000000..76a8359b --- /dev/null +++ b/rules/WhenDoNode.java @@ -0,0 +1,42 @@ +package sneps.snip.rules; + +import sneps.network.RuleNode; +import sneps.network.classes.Semantic; +import sneps.network.classes.setClasses.NodeSet; +import sneps.network.classes.term.Term; +import sneps.snip.classes.RuleUseInfo; + +public class WhenDoNode extends RuleNode { + private static final long serialVersionUID = 2515697705889848498L; + + public WhenDoNode(Term syn) { + super(syn); + } + + +// @Override +// protected void applyRuleOnRui(RuleUseInfo tRui, String contextID) { +// // TODO Auto-generated method stub +// +// } + + + @Override + public NodeSet getDownAntNodeSet() { + // TODO Auto-generated method stub + return null; + } + +// @Override +// protected RuisHandler createRuisHandler(String contextName) { +// // TODO Auto-generated method stub +// return null; +// } + + @Override + protected void sendRui(RuleUseInfo tRui, String contextID) { + // TODO Auto-generated method stub + + } + +}