From d69ad40a5c0d7d2af335b2726eda6d1ef6c5ebb1 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 7 Apr 2022 12:06:54 +0200 Subject: [PATCH 01/25] Create ReasoningController --- code/core/modules/ReasoningController | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/ReasoningController diff --git a/code/core/modules/ReasoningController b/code/core/modules/ReasoningController new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/code/core/modules/ReasoningController @@ -0,0 +1 @@ + From 1863a735b3498bb9dc2cdcc34eccc4771ead9568 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 7 Apr 2022 12:07:23 +0200 Subject: [PATCH 02/25] Delete ReasoningController --- code/core/modules/ReasoningController | 1 - 1 file changed, 1 deletion(-) delete mode 100644 code/core/modules/ReasoningController diff --git a/code/core/modules/ReasoningController b/code/core/modules/ReasoningController deleted file mode 100644 index 8b13789..0000000 --- a/code/core/modules/ReasoningController +++ /dev/null @@ -1 +0,0 @@ - From a90c441b96191d1c5152558b7d5d10f3bea05d69 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 7 Apr 2022 12:09:09 +0200 Subject: [PATCH 03/25] Create reasoning_controller --- code/core/modules/ReasoningController/reasoning_controller | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/ReasoningController/reasoning_controller diff --git a/code/core/modules/ReasoningController/reasoning_controller b/code/core/modules/ReasoningController/reasoning_controller new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/code/core/modules/ReasoningController/reasoning_controller @@ -0,0 +1 @@ + From f297669325b0b2dc3df2751d283e8926da93a174 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 7 Apr 2022 12:09:41 +0200 Subject: [PATCH 04/25] Update reasoning_controller --- .../ReasoningController/reasoning_controller | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/code/core/modules/ReasoningController/reasoning_controller b/code/core/modules/ReasoningController/reasoning_controller index 8b13789..ee594c4 100644 --- a/code/core/modules/ReasoningController/reasoning_controller +++ b/code/core/modules/ReasoningController/reasoning_controller @@ -1 +1,17 @@ - +class ReasoningController: + def ApplySubstitution (): + pass + def CheckCompatiableSubstitution (): + pass + def Request (source, destination): + pass + def SendReport(report,channel): + pass + def AddToKnownInstances(report, channel): + pass + def ForwardChain(report): + pass + def BackwardChain(report): + pass + def ProcessReportChannel(channel): + pass From be79bcc72ce227dbc5964e8f2057541214ab454a Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 28 Apr 2022 07:36:27 +0200 Subject: [PATCH 05/25] Add files via upload --- .../modules/ReasoningController/Channel.py | 46 +++++++++++++++++++ .../modules/ReasoningController/ChannelSet.py | 42 +++++++++++++++++ .../ReasoningController/ChannelType.py | 5 ++ .../modules/ReasoningController/Filter.py | 13 ++++++ 4 files changed, 106 insertions(+) create mode 100644 code/core/modules/ReasoningController/Channel.py create mode 100644 code/core/modules/ReasoningController/ChannelSet.py create mode 100644 code/core/modules/ReasoningController/ChannelType.py create mode 100644 code/core/modules/ReasoningController/Filter.py diff --git a/code/core/modules/ReasoningController/Channel.py b/code/core/modules/ReasoningController/Channel.py new file mode 100644 index 0000000..3ecdd7a --- /dev/null +++ b/code/core/modules/ReasoningController/Channel.py @@ -0,0 +1,46 @@ +import Filter +import Switch +import ChannelType + +class Channel: + global count + count = 0 + + def __init__ (channel,id,filter,switch,source,destination,status,type): + channel.id = count + channel.filter = filter + channel.switch = switch + channel.source = source + channel.destination = destination + channel.status = status + channel.type = type + + count +1 + + + def getId(channel): + return channel.id + + def setSubstitution(channel,substitution): + channel.substitution = substitution + + def getSupport(channel): + return channel.support + + def getFilter(channel): + return channel.filter + + def setFilter(channel,filter): + channel.filter = filter + + def getDestination(channel): + return channel.destination + + def setDestination(channel,destination): + channel.destination = destination + + def getSource(channel): + return channel.source + + def setSource(channel,source): + channel.source = source diff --git a/code/core/modules/ReasoningController/ChannelSet.py b/code/core/modules/ReasoningController/ChannelSet.py new file mode 100644 index 0000000..94160f1 --- /dev/null +++ b/code/core/modules/ReasoningController/ChannelSet.py @@ -0,0 +1,42 @@ +from Channel import Channel +import ChannelType +class ChannelSet(Channel): + + def __init__(channel,id,filter,switch,source,destination,status,type): + global channels + super().__init__(id,filter,switch,source,destination,status,type) + MatchedChannels = { + 'Matched' : channel + } + AntToRuleChannels = { + 'AntToRule' : channel + } + RuletoConsChannels = { + 'RuleToCons' : channel + } + + def addChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def removeChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def getChannelType(channel): + channeltype ='' + if (ChannelType.RULEANT): + channeltype = 'AntecedentToRule Channel' + if (ChannelType.RULECONS): + channeltype = 'RuleToConsequent Channel' + else: + channeltype = 'Matched Channel' + return channeltype +#x=ChannelSet(0,0,0,0,0,0,0) +#print(x.getChannelType()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ChannelType.py b/code/core/modules/ReasoningController/ChannelType.py new file mode 100644 index 0000000..6a55ff0 --- /dev/null +++ b/code/core/modules/ReasoningController/ChannelType.py @@ -0,0 +1,5 @@ +from enum import Enum +class ChannelType(Enum): + MATCHED = 1 + RULEANT = 2 + RULECONS = 3 \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Filter.py b/code/core/modules/ReasoningController/Filter.py new file mode 100644 index 0000000..c2c1f35 --- /dev/null +++ b/code/core/modules/ReasoningController/Filter.py @@ -0,0 +1,13 @@ +class Filter: + + def __init__(filter,report): + filter.report = report + + def canPass(report): + if True: + return True + else: + return False +#x = Filter(1) +#print(x.canPass()) + From 5e9a88c5fa72759a192c631382cb6176c24e772d Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 28 Apr 2022 07:38:16 +0200 Subject: [PATCH 06/25] Add files via upload --- .../ReasoningController/KnownInstance.py | 12 ++++++ .../ReasoningController/Proposition.py | 6 +++ .../modules/ReasoningController/Report.py | 37 +++++++++++++++++++ .../modules/ReasoningController/ReportSet.py | 3 ++ .../modules/ReasoningController/Switch.py | 8 ++++ 5 files changed, 66 insertions(+) create mode 100644 code/core/modules/ReasoningController/KnownInstance.py create mode 100644 code/core/modules/ReasoningController/Proposition.py create mode 100644 code/core/modules/ReasoningController/Report.py create mode 100644 code/core/modules/ReasoningController/ReportSet.py create mode 100644 code/core/modules/ReasoningController/Switch.py diff --git a/code/core/modules/ReasoningController/KnownInstance.py b/code/core/modules/ReasoningController/KnownInstance.py new file mode 100644 index 0000000..79e1f6e --- /dev/null +++ b/code/core/modules/ReasoningController/KnownInstance.py @@ -0,0 +1,12 @@ +from Report import report +from ReportSet import reportSet + +class KnownInstances(report): + def __init__(knowninstances,substitution, support,source,destination): + super.__init__(substitution, support,source,destination) + knowninstances = { + 'Substitutions' : reportSet + } + + def AddToKnownInstances(report): + reportSubs = report.getSubstitution() \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Proposition.py b/code/core/modules/ReasoningController/Proposition.py new file mode 100644 index 0000000..545cbdb --- /dev/null +++ b/code/core/modules/ReasoningController/Proposition.py @@ -0,0 +1,6 @@ +class Proposition(): + def __init__(self) -> None: + pass + + + #Attributes class (supportSet, channelSet) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Report.py b/code/core/modules/ReasoningController/Report.py new file mode 100644 index 0000000..d5a8ced --- /dev/null +++ b/code/core/modules/ReasoningController/Report.py @@ -0,0 +1,37 @@ +class Report: + def __init__(report,substitution, support,inference,source,destination): + report.substitution = substitution + report.support = support + report.inference = inference + report.destination = destination + report.source = source + + def getSubstitution(report): + return report.substitution + + def setSubstitution(report,substitution): + report.substitution = substitution + + def getSupport(report): + return report.support + + def getInference(report): + return report.inference + + def setInference(report,inference): + report.inference = inference + + def getDestination(report): + return report.destination + + def setDestination(report,destination): + report.destination = destination + + def getSource(report): + return report.source + + def setSource(report,source): + report.source = source + +#report = Report(15,5,5,5,5) +#print(report.getSubstitution()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ReportSet.py b/code/core/modules/ReasoningController/ReportSet.py new file mode 100644 index 0000000..43e6508 --- /dev/null +++ b/code/core/modules/ReasoningController/ReportSet.py @@ -0,0 +1,3 @@ +class ReportSet: + def __innit__(self): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Switch.py b/code/core/modules/ReasoningController/Switch.py new file mode 100644 index 0000000..a7ae599 --- /dev/null +++ b/code/core/modules/ReasoningController/Switch.py @@ -0,0 +1,8 @@ +class Switch(): + def __init__(switch,report): + switch.report = report + + def switchReport(report): + pass +#x=Switch(1) +#print(x.switchReport()) \ No newline at end of file From 188dd521c460fe99d77a4f4a9a3d627a57b4f1a2 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:25:14 +0200 Subject: [PATCH 07/25] Add files via upload --- .../modules/ReasoningController/Matcher.py | 7 +++ .../ReasoningController/MindGRAFController.py | 5 +++ .../modules/ReasoningController/NodeSet.py | 5 +++ .../ReasoningController/PropositionSet.py | 9 ++++ .../modules/ReasoningController/RuleNode.py | 3 ++ .../modules/ReasoningController/Runner.py | 45 +++++++++++++++++++ .../ReasoningController/Substitutions.py | 5 +++ .../modules/ReasoningController/supportSet.py | 5 +++ 8 files changed, 84 insertions(+) create mode 100644 code/core/modules/ReasoningController/Matcher.py create mode 100644 code/core/modules/ReasoningController/MindGRAFController.py create mode 100644 code/core/modules/ReasoningController/NodeSet.py create mode 100644 code/core/modules/ReasoningController/PropositionSet.py create mode 100644 code/core/modules/ReasoningController/RuleNode.py create mode 100644 code/core/modules/ReasoningController/Runner.py create mode 100644 code/core/modules/ReasoningController/Substitutions.py create mode 100644 code/core/modules/ReasoningController/supportSet.py diff --git a/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/Matcher.py new file mode 100644 index 0000000..c80e07f --- /dev/null +++ b/code/core/modules/ReasoningController/Matcher.py @@ -0,0 +1,7 @@ +class Matcher(): + def __init__(self) -> None: + pass + def Match(): + pass + def getMatchType(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/MindGRAFController.py new file mode 100644 index 0000000..2621658 --- /dev/null +++ b/code/core/modules/ReasoningController/MindGRAFController.py @@ -0,0 +1,5 @@ +class MindGRAFController(): + def __init__(self) -> None: + pass + def getContextName(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/NodeSet.py new file mode 100644 index 0000000..a31ff68 --- /dev/null +++ b/code/core/modules/ReasoningController/NodeSet.py @@ -0,0 +1,5 @@ +class NodeSet(): + def __init__(self) -> None: + pass + def getDownAnt(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/PropositionSet.py new file mode 100644 index 0000000..59fd62a --- /dev/null +++ b/code/core/modules/ReasoningController/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node): + PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/RuleNode.py b/code/core/modules/ReasoningController/RuleNode.py new file mode 100644 index 0000000..7c836a4 --- /dev/null +++ b/code/core/modules/ReasoningController/RuleNode.py @@ -0,0 +1,3 @@ +class RuleNode(): + def __init__(self) -> None: + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/Runner.py new file mode 100644 index 0000000..a64c19e --- /dev/null +++ b/code/core/modules/ReasoningController/Runner.py @@ -0,0 +1,45 @@ +from itertools import count +from lib2to3.pytree import Node +from queue import Empty +from Channel import Channel +from Proposition import Proposition + + +class Runner(): + + global highQ + highQ = [] + global lowQ + lowQ = [] + global actQ + actQ = [] + + def run(): + while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): + while(highQ.count != 0): + print("In HighQ") + runNext = highQ.pop(0) + print(runNext) + Proposition.processReports(runNext) + + while(lowQ.count != 0): + print("In LowQ") + runNext = lowQ.pop(0) + print(runNext) + runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") + if highQ: + Runner.run() + + while(actQ.count != 0): + print("In ActQ") + runNext = actQ.pop() + print(runNext) + if highQ and lowQ: + Runner.run() + + def addToHighQ(node): + highQ.append(node) + def addToLowQ(node): + lowQ.append(node) + def addToActQ(node): + actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/Substitutions.py new file mode 100644 index 0000000..09af52d --- /dev/null +++ b/code/core/modules/ReasoningController/Substitutions.py @@ -0,0 +1,5 @@ +class Substitutions(): + def __init__(self) -> None: + pass + def getSubs(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/supportSet.py new file mode 100644 index 0000000..1209bdf --- /dev/null +++ b/code/core/modules/ReasoningController/supportSet.py @@ -0,0 +1,5 @@ +class supportSet(): + def __init__(self,support): + support = [] + def getId(node): + pass \ No newline at end of file From 37940fbb601f0d480a1052e41a56af420d4cd54b Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:27:33 +0200 Subject: [PATCH 08/25] Add files via upload From 716f194c4112a173d671c58ec4347ae2293f889e Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:31:46 +0200 Subject: [PATCH 09/25] Delete code/core/modules/ReasoningController directory --- .../modules/ReasoningController/Channel.py | 46 ------------------- .../modules/ReasoningController/ChannelSet.py | 42 ----------------- .../ReasoningController/ChannelType.py | 5 -- .../modules/ReasoningController/Filter.py | 13 ------ .../ReasoningController/KnownInstance.py | 12 ----- .../modules/ReasoningController/Matcher.py | 7 --- .../ReasoningController/MindGRAFController.py | 5 -- .../modules/ReasoningController/NodeSet.py | 5 -- .../ReasoningController/Proposition.py | 6 --- .../ReasoningController/PropositionSet.py | 9 ---- .../modules/ReasoningController/Report.py | 37 --------------- .../modules/ReasoningController/ReportSet.py | 3 -- .../modules/ReasoningController/RuleNode.py | 3 -- .../modules/ReasoningController/Runner.py | 45 ------------------ .../ReasoningController/Substitutions.py | 5 -- .../modules/ReasoningController/Switch.py | 8 ---- .../ReasoningController/reasoning_controller | 17 ------- .../modules/ReasoningController/supportSet.py | 5 -- 18 files changed, 273 deletions(-) delete mode 100644 code/core/modules/ReasoningController/Channel.py delete mode 100644 code/core/modules/ReasoningController/ChannelSet.py delete mode 100644 code/core/modules/ReasoningController/ChannelType.py delete mode 100644 code/core/modules/ReasoningController/Filter.py delete mode 100644 code/core/modules/ReasoningController/KnownInstance.py delete mode 100644 code/core/modules/ReasoningController/Matcher.py delete mode 100644 code/core/modules/ReasoningController/MindGRAFController.py delete mode 100644 code/core/modules/ReasoningController/NodeSet.py delete mode 100644 code/core/modules/ReasoningController/Proposition.py delete mode 100644 code/core/modules/ReasoningController/PropositionSet.py delete mode 100644 code/core/modules/ReasoningController/Report.py delete mode 100644 code/core/modules/ReasoningController/ReportSet.py delete mode 100644 code/core/modules/ReasoningController/RuleNode.py delete mode 100644 code/core/modules/ReasoningController/Runner.py delete mode 100644 code/core/modules/ReasoningController/Substitutions.py delete mode 100644 code/core/modules/ReasoningController/Switch.py delete mode 100644 code/core/modules/ReasoningController/reasoning_controller delete mode 100644 code/core/modules/ReasoningController/supportSet.py diff --git a/code/core/modules/ReasoningController/Channel.py b/code/core/modules/ReasoningController/Channel.py deleted file mode 100644 index 3ecdd7a..0000000 --- a/code/core/modules/ReasoningController/Channel.py +++ /dev/null @@ -1,46 +0,0 @@ -import Filter -import Switch -import ChannelType - -class Channel: - global count - count = 0 - - def __init__ (channel,id,filter,switch,source,destination,status,type): - channel.id = count - channel.filter = filter - channel.switch = switch - channel.source = source - channel.destination = destination - channel.status = status - channel.type = type - - count +1 - - - def getId(channel): - return channel.id - - def setSubstitution(channel,substitution): - channel.substitution = substitution - - def getSupport(channel): - return channel.support - - def getFilter(channel): - return channel.filter - - def setFilter(channel,filter): - channel.filter = filter - - def getDestination(channel): - return channel.destination - - def setDestination(channel,destination): - channel.destination = destination - - def getSource(channel): - return channel.source - - def setSource(channel,source): - channel.source = source diff --git a/code/core/modules/ReasoningController/ChannelSet.py b/code/core/modules/ReasoningController/ChannelSet.py deleted file mode 100644 index 94160f1..0000000 --- a/code/core/modules/ReasoningController/ChannelSet.py +++ /dev/null @@ -1,42 +0,0 @@ -from Channel import Channel -import ChannelType -class ChannelSet(Channel): - - def __init__(channel,id,filter,switch,source,destination,status,type): - global channels - super().__init__(id,filter,switch,source,destination,status,type) - MatchedChannels = { - 'Matched' : channel - } - AntToRuleChannels = { - 'AntToRule' : channel - } - RuletoConsChannels = { - 'RuleToCons' : channel - } - - def addChannel(channel): - channelSourceId = channel.source.id - channelDestinationId= channel.destination.id - filtersubs = channel.filter.substitutions - switchsubs = channel.channel.substitutions - channelType = channel.getChannelType(channel) - - def removeChannel(channel): - channelSourceId = channel.source.id - channelDestinationId= channel.destination.id - filtersubs = channel.filter.substitutions - switchsubs = channel.channel.substitutions - channelType = channel.getChannelType(channel) - - def getChannelType(channel): - channeltype ='' - if (ChannelType.RULEANT): - channeltype = 'AntecedentToRule Channel' - if (ChannelType.RULECONS): - channeltype = 'RuleToConsequent Channel' - else: - channeltype = 'Matched Channel' - return channeltype -#x=ChannelSet(0,0,0,0,0,0,0) -#print(x.getChannelType()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ChannelType.py b/code/core/modules/ReasoningController/ChannelType.py deleted file mode 100644 index 6a55ff0..0000000 --- a/code/core/modules/ReasoningController/ChannelType.py +++ /dev/null @@ -1,5 +0,0 @@ -from enum import Enum -class ChannelType(Enum): - MATCHED = 1 - RULEANT = 2 - RULECONS = 3 \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Filter.py b/code/core/modules/ReasoningController/Filter.py deleted file mode 100644 index c2c1f35..0000000 --- a/code/core/modules/ReasoningController/Filter.py +++ /dev/null @@ -1,13 +0,0 @@ -class Filter: - - def __init__(filter,report): - filter.report = report - - def canPass(report): - if True: - return True - else: - return False -#x = Filter(1) -#print(x.canPass()) - diff --git a/code/core/modules/ReasoningController/KnownInstance.py b/code/core/modules/ReasoningController/KnownInstance.py deleted file mode 100644 index 79e1f6e..0000000 --- a/code/core/modules/ReasoningController/KnownInstance.py +++ /dev/null @@ -1,12 +0,0 @@ -from Report import report -from ReportSet import reportSet - -class KnownInstances(report): - def __init__(knowninstances,substitution, support,source,destination): - super.__init__(substitution, support,source,destination) - knowninstances = { - 'Substitutions' : reportSet - } - - def AddToKnownInstances(report): - reportSubs = report.getSubstitution() \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/Matcher.py deleted file mode 100644 index c80e07f..0000000 --- a/code/core/modules/ReasoningController/Matcher.py +++ /dev/null @@ -1,7 +0,0 @@ -class Matcher(): - def __init__(self) -> None: - pass - def Match(): - pass - def getMatchType(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/MindGRAFController.py deleted file mode 100644 index 2621658..0000000 --- a/code/core/modules/ReasoningController/MindGRAFController.py +++ /dev/null @@ -1,5 +0,0 @@ -class MindGRAFController(): - def __init__(self) -> None: - pass - def getContextName(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/NodeSet.py deleted file mode 100644 index a31ff68..0000000 --- a/code/core/modules/ReasoningController/NodeSet.py +++ /dev/null @@ -1,5 +0,0 @@ -class NodeSet(): - def __init__(self) -> None: - pass - def getDownAnt(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Proposition.py b/code/core/modules/ReasoningController/Proposition.py deleted file mode 100644 index 545cbdb..0000000 --- a/code/core/modules/ReasoningController/Proposition.py +++ /dev/null @@ -1,6 +0,0 @@ -class Proposition(): - def __init__(self) -> None: - pass - - - #Attributes class (supportSet, channelSet) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/PropositionSet.py deleted file mode 100644 index 59fd62a..0000000 --- a/code/core/modules/ReasoningController/PropositionSet.py +++ /dev/null @@ -1,9 +0,0 @@ -class PropositionSet(): - - propositions = {} - - def __init__(self) -> None: - pass - - def addProp(node): - PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Report.py b/code/core/modules/ReasoningController/Report.py deleted file mode 100644 index d5a8ced..0000000 --- a/code/core/modules/ReasoningController/Report.py +++ /dev/null @@ -1,37 +0,0 @@ -class Report: - def __init__(report,substitution, support,inference,source,destination): - report.substitution = substitution - report.support = support - report.inference = inference - report.destination = destination - report.source = source - - def getSubstitution(report): - return report.substitution - - def setSubstitution(report,substitution): - report.substitution = substitution - - def getSupport(report): - return report.support - - def getInference(report): - return report.inference - - def setInference(report,inference): - report.inference = inference - - def getDestination(report): - return report.destination - - def setDestination(report,destination): - report.destination = destination - - def getSource(report): - return report.source - - def setSource(report,source): - report.source = source - -#report = Report(15,5,5,5,5) -#print(report.getSubstitution()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ReportSet.py b/code/core/modules/ReasoningController/ReportSet.py deleted file mode 100644 index 43e6508..0000000 --- a/code/core/modules/ReasoningController/ReportSet.py +++ /dev/null @@ -1,3 +0,0 @@ -class ReportSet: - def __innit__(self): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/RuleNode.py b/code/core/modules/ReasoningController/RuleNode.py deleted file mode 100644 index 7c836a4..0000000 --- a/code/core/modules/ReasoningController/RuleNode.py +++ /dev/null @@ -1,3 +0,0 @@ -class RuleNode(): - def __init__(self) -> None: - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/Runner.py deleted file mode 100644 index a64c19e..0000000 --- a/code/core/modules/ReasoningController/Runner.py +++ /dev/null @@ -1,45 +0,0 @@ -from itertools import count -from lib2to3.pytree import Node -from queue import Empty -from Channel import Channel -from Proposition import Proposition - - -class Runner(): - - global highQ - highQ = [] - global lowQ - lowQ = [] - global actQ - actQ = [] - - def run(): - while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): - while(highQ.count != 0): - print("In HighQ") - runNext = highQ.pop(0) - print(runNext) - Proposition.processReports(runNext) - - while(lowQ.count != 0): - print("In LowQ") - runNext = lowQ.pop(0) - print(runNext) - runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") - if highQ: - Runner.run() - - while(actQ.count != 0): - print("In ActQ") - runNext = actQ.pop() - print(runNext) - if highQ and lowQ: - Runner.run() - - def addToHighQ(node): - highQ.append(node) - def addToLowQ(node): - lowQ.append(node) - def addToActQ(node): - actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/Substitutions.py deleted file mode 100644 index 09af52d..0000000 --- a/code/core/modules/ReasoningController/Substitutions.py +++ /dev/null @@ -1,5 +0,0 @@ -class Substitutions(): - def __init__(self) -> None: - pass - def getSubs(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Switch.py b/code/core/modules/ReasoningController/Switch.py deleted file mode 100644 index a7ae599..0000000 --- a/code/core/modules/ReasoningController/Switch.py +++ /dev/null @@ -1,8 +0,0 @@ -class Switch(): - def __init__(switch,report): - switch.report = report - - def switchReport(report): - pass -#x=Switch(1) -#print(x.switchReport()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/reasoning_controller b/code/core/modules/ReasoningController/reasoning_controller deleted file mode 100644 index ee594c4..0000000 --- a/code/core/modules/ReasoningController/reasoning_controller +++ /dev/null @@ -1,17 +0,0 @@ -class ReasoningController: - def ApplySubstitution (): - pass - def CheckCompatiableSubstitution (): - pass - def Request (source, destination): - pass - def SendReport(report,channel): - pass - def AddToKnownInstances(report, channel): - pass - def ForwardChain(report): - pass - def BackwardChain(report): - pass - def ProcessReportChannel(channel): - pass diff --git a/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/supportSet.py deleted file mode 100644 index 1209bdf..0000000 --- a/code/core/modules/ReasoningController/supportSet.py +++ /dev/null @@ -1,5 +0,0 @@ -class supportSet(): - def __init__(self,support): - support = [] - def getId(node): - pass \ No newline at end of file From 4b80cf2088cce1eeb853b004107034e322bdf5f8 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:32:21 +0200 Subject: [PATCH 10/25] Create As --- code/core/modules/ReasoningController/As | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/ReasoningController/As diff --git a/code/core/modules/ReasoningController/As b/code/core/modules/ReasoningController/As new file mode 100644 index 0000000..e539a95 --- /dev/null +++ b/code/core/modules/ReasoningController/As @@ -0,0 +1 @@ +as From a6d7a844f18fa79124181547699f5ce2b4894f26 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:33:12 +0200 Subject: [PATCH 11/25] Add files via upload --- .../modules/ReasoningController/Matcher.py | 7 +++ .../ReasoningController/MindGRAFController.py | 5 +++ .../modules/ReasoningController/NodeSet.py | 5 +++ .../ReasoningController/PropositionSet.py | 9 ++++ .../modules/ReasoningController/RuleNode.py | 3 ++ .../modules/ReasoningController/Runner.py | 45 +++++++++++++++++++ .../ReasoningController/Substitutions.py | 5 +++ .../modules/ReasoningController/supportSet.py | 5 +++ 8 files changed, 84 insertions(+) create mode 100644 code/core/modules/ReasoningController/Matcher.py create mode 100644 code/core/modules/ReasoningController/MindGRAFController.py create mode 100644 code/core/modules/ReasoningController/NodeSet.py create mode 100644 code/core/modules/ReasoningController/PropositionSet.py create mode 100644 code/core/modules/ReasoningController/RuleNode.py create mode 100644 code/core/modules/ReasoningController/Runner.py create mode 100644 code/core/modules/ReasoningController/Substitutions.py create mode 100644 code/core/modules/ReasoningController/supportSet.py diff --git a/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/Matcher.py new file mode 100644 index 0000000..c80e07f --- /dev/null +++ b/code/core/modules/ReasoningController/Matcher.py @@ -0,0 +1,7 @@ +class Matcher(): + def __init__(self) -> None: + pass + def Match(): + pass + def getMatchType(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/MindGRAFController.py new file mode 100644 index 0000000..2621658 --- /dev/null +++ b/code/core/modules/ReasoningController/MindGRAFController.py @@ -0,0 +1,5 @@ +class MindGRAFController(): + def __init__(self) -> None: + pass + def getContextName(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/NodeSet.py new file mode 100644 index 0000000..a31ff68 --- /dev/null +++ b/code/core/modules/ReasoningController/NodeSet.py @@ -0,0 +1,5 @@ +class NodeSet(): + def __init__(self) -> None: + pass + def getDownAnt(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/PropositionSet.py new file mode 100644 index 0000000..59fd62a --- /dev/null +++ b/code/core/modules/ReasoningController/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node): + PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/RuleNode.py b/code/core/modules/ReasoningController/RuleNode.py new file mode 100644 index 0000000..7c836a4 --- /dev/null +++ b/code/core/modules/ReasoningController/RuleNode.py @@ -0,0 +1,3 @@ +class RuleNode(): + def __init__(self) -> None: + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/Runner.py new file mode 100644 index 0000000..a64c19e --- /dev/null +++ b/code/core/modules/ReasoningController/Runner.py @@ -0,0 +1,45 @@ +from itertools import count +from lib2to3.pytree import Node +from queue import Empty +from Channel import Channel +from Proposition import Proposition + + +class Runner(): + + global highQ + highQ = [] + global lowQ + lowQ = [] + global actQ + actQ = [] + + def run(): + while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): + while(highQ.count != 0): + print("In HighQ") + runNext = highQ.pop(0) + print(runNext) + Proposition.processReports(runNext) + + while(lowQ.count != 0): + print("In LowQ") + runNext = lowQ.pop(0) + print(runNext) + runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") + if highQ: + Runner.run() + + while(actQ.count != 0): + print("In ActQ") + runNext = actQ.pop() + print(runNext) + if highQ and lowQ: + Runner.run() + + def addToHighQ(node): + highQ.append(node) + def addToLowQ(node): + lowQ.append(node) + def addToActQ(node): + actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/Substitutions.py new file mode 100644 index 0000000..09af52d --- /dev/null +++ b/code/core/modules/ReasoningController/Substitutions.py @@ -0,0 +1,5 @@ +class Substitutions(): + def __init__(self) -> None: + pass + def getSubs(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/supportSet.py new file mode 100644 index 0000000..1209bdf --- /dev/null +++ b/code/core/modules/ReasoningController/supportSet.py @@ -0,0 +1,5 @@ +class supportSet(): + def __init__(self,support): + support = [] + def getId(node): + pass \ No newline at end of file From 43bf1dbf7223316cd0e2d60d32322a3384df001e Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:36:01 +0200 Subject: [PATCH 12/25] Delete As --- code/core/modules/ReasoningController/As | 1 - 1 file changed, 1 deletion(-) delete mode 100644 code/core/modules/ReasoningController/As diff --git a/code/core/modules/ReasoningController/As b/code/core/modules/ReasoningController/As deleted file mode 100644 index e539a95..0000000 --- a/code/core/modules/ReasoningController/As +++ /dev/null @@ -1 +0,0 @@ -as From a0e491dbfc12bb0482511fb6e54d2989049b80e4 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 02:36:38 +0200 Subject: [PATCH 13/25] Add files via upload From a19a5c039678cedddc238eea2b3337dca8a8a8f9 Mon Sep 17 00:00:00 2001 From: AmrLamei Date: Thu, 12 May 2022 02:39:33 +0200 Subject: [PATCH 14/25] Second Commit --- Channel.py | 77 ++++++++++++++++++ Channel.pyc | Bin 0 -> 2284 bytes ChannelSet.py | 42 ++++++++++ ChannelType.py | 5 ++ ChannelType.pyc | Bin 0 -> 446 bytes Filter.py | 13 +++ Filter.pyc | Bin 0 -> 719 bytes Instance.py | 0 KnownInstances.py | 30 +++++++ Matcher.py | 7 ++ MindGRAFController.py | 5 ++ NodeSet.py | 5 ++ Proposition.py | 30 +++++++ PropositionSet.py | 9 +++ ReasoningController.py | 106 +++++++++++++++++++++++++ Report.py | 37 +++++++++ Report.pyc | Bin 0 -> 2144 bytes ReportSet.py | 21 +++++ RuleNode.py | 3 + Runner.py | 45 +++++++++++ Substitutions.py | 5 ++ Switch.py | 8 ++ Switch.pyc | Bin 0 -> 687 bytes __pycache__/Channel.cpython-39.pyc | Bin 0 -> 1843 bytes __pycache__/ChannelType.cpython-39.pyc | Bin 0 -> 392 bytes __pycache__/Filter.cpython-39.pyc | Bin 0 -> 577 bytes __pycache__/Switch.cpython-39.pyc | Bin 0 -> 586 bytes supportSet.py | 5 ++ 28 files changed, 453 insertions(+) create mode 100644 Channel.py create mode 100644 Channel.pyc create mode 100644 ChannelSet.py create mode 100644 ChannelType.py create mode 100644 ChannelType.pyc create mode 100644 Filter.py create mode 100644 Filter.pyc create mode 100644 Instance.py create mode 100644 KnownInstances.py create mode 100644 Matcher.py create mode 100644 MindGRAFController.py create mode 100644 NodeSet.py create mode 100644 Proposition.py create mode 100644 PropositionSet.py create mode 100644 ReasoningController.py create mode 100644 Report.py create mode 100644 Report.pyc create mode 100644 ReportSet.py create mode 100644 RuleNode.py create mode 100644 Runner.py create mode 100644 Substitutions.py create mode 100644 Switch.py create mode 100644 Switch.pyc create mode 100644 __pycache__/Channel.cpython-39.pyc create mode 100644 __pycache__/ChannelType.cpython-39.pyc create mode 100644 __pycache__/Filter.cpython-39.pyc create mode 100644 __pycache__/Switch.cpython-39.pyc create mode 100644 supportSet.py diff --git a/Channel.py b/Channel.py new file mode 100644 index 0000000..d3c0816 --- /dev/null +++ b/Channel.py @@ -0,0 +1,77 @@ +from multiprocessing import context +import re +from urllib import request +from Filter import Filter +from Proposition import Proposition +from ReportSet import ReportSet +from Switch import Switch +import ChannelType + +class Channel: + global count + count = 0 + global filter + filter = Filter() + global switch + switch = Switch() + global reportBuffer + reportBuffer = ReportSet() + + def __init__ (channel,id,source,destination,status,type,context): + channel.id = count + channel.source = source + channel.destination = destination + channel.status = status + channel.type = type + channel.context = context + count +1 + + def reportToSend(self,report): + canPass = filter.canPass(report) + if canPass: # and isAsserted(report) + Switch.switchReport(report) + requester = self.getSource() + Proposition.recieveReport(self) + self.getReportsBuffer().addReport(report) + + def getId(channel): + return channel.id + + def setSubstitution(channel,substitution): + channel.substitution = substitution + + def getSupport(channel): + return channel.support + + def getFilter(channel): + return channel.filter + + def getType(channel): + return channel.type + + def setFilter(channel,filter): + channel.filter = filter + + def getDestination(channel): + return channel.destination + + def setDestination(channel,destination): + channel.destination = destination + + def getSource(channel): + return channel.source + + def setSource(channel,source): + channel.source = source + + def setReportsBuffer(self,reportsBuffer): + self.reportsBuffer = reportBuffer + + def getReportsBuffer(): + return reportBuffer + + def clearReportsBuffer(self,reportsBuffer): + self.getReportsBuffer().clearReports() + + def getContext(channel): + return channel.context \ No newline at end of file diff --git a/Channel.pyc b/Channel.pyc new file mode 100644 index 0000000000000000000000000000000000000000..498502345ee3c3e5c142b87942714d3f77574689 GIT binary patch literal 2284 zcmb_d+iuf95FO|4GzD=j2nh)Zi3kbu0U!izL8^rMuz?5iVx_jBt`a-Su7xV)4gQ!9 zfOE!nWAOlOlQ=tjytZf0o|&C({@U#a58t1JQvRCg-=f)9FcJQq%tR&^*prD@jW=Y{ zkO=>lL{0fA@MH0-)KlO~hpFSx_nB}R1 zQ_LQ@4!RG?%*9KEU)ON_J#pcwj@lZ`@?{vi9eftW)+OoGC0Sa$<)$vTV2F9n7x9oQ zQrW{ocEc$R9~;hU7!kvlj88*;L$t!!7eJ%WHeTA%yZQ3tbRH+8!z|3_aq8@7e;S^~ zvurskL;7-Y?&vBAk~DDvRt^0YOy+wnTBRk9OLD!%(6#FWxgp7G+@5iS zq_7z;D;8_Tmc%OaX{;snd5z1}bW%p^e9~L4Nt5atb+pWkgDbbMSsjRXo>TwV_ zZqFc?XHh=Gt)Yg7b;|Hn!>VF#(cGrFLvxpgMbO-**@Iap|1}vKI1yG@%c9k3bQ-?j sYx;j(#WZ^SH1V3@2YQZ`N606fS?XzHKC02{LX|hv#PYo3DKu#O0h*DhX8-^I literal 0 HcmV?d00001 diff --git a/ChannelSet.py b/ChannelSet.py new file mode 100644 index 0000000..94160f1 --- /dev/null +++ b/ChannelSet.py @@ -0,0 +1,42 @@ +from Channel import Channel +import ChannelType +class ChannelSet(Channel): + + def __init__(channel,id,filter,switch,source,destination,status,type): + global channels + super().__init__(id,filter,switch,source,destination,status,type) + MatchedChannels = { + 'Matched' : channel + } + AntToRuleChannels = { + 'AntToRule' : channel + } + RuletoConsChannels = { + 'RuleToCons' : channel + } + + def addChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def removeChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def getChannelType(channel): + channeltype ='' + if (ChannelType.RULEANT): + channeltype = 'AntecedentToRule Channel' + if (ChannelType.RULECONS): + channeltype = 'RuleToConsequent Channel' + else: + channeltype = 'Matched Channel' + return channeltype +#x=ChannelSet(0,0,0,0,0,0,0) +#print(x.getChannelType()) \ No newline at end of file diff --git a/ChannelType.py b/ChannelType.py new file mode 100644 index 0000000..6a55ff0 --- /dev/null +++ b/ChannelType.py @@ -0,0 +1,5 @@ +from enum import Enum +class ChannelType(Enum): + MATCHED = 1 + RULEANT = 2 + RULECONS = 3 \ No newline at end of file diff --git a/ChannelType.pyc b/ChannelType.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a8247a38c1a9420ca5ad6939b720ca8362b71fd GIT binary patch literal 446 zcmbVI!A^uQ6nuqs*R1*h`UUL8#*-IgWLXjqD<;4m?+O8TKmNUo)KMn4~mF4kf9r{sf&oB=jqr`)U4q&bz<;JMqNWbmZ$gSn7E5}yp z!N_G%ZdKFu@=q_9yM4?dT$q^xrh=y}dEh5ddTcETL9F#~pJo5M)V6W+-Rvztjo}JT F#TWDAS?2%% literal 0 HcmV?d00001 diff --git a/Filter.py b/Filter.py new file mode 100644 index 0000000..c2c1f35 --- /dev/null +++ b/Filter.py @@ -0,0 +1,13 @@ +class Filter: + + def __init__(filter,report): + filter.report = report + + def canPass(report): + if True: + return True + else: + return False +#x = Filter(1) +#print(x.canPass()) + diff --git a/Filter.pyc b/Filter.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a745c42fbc380c95f68ae53cddb2f148e3607cf3 GIT binary patch literal 719 zcmb_ZOHPD95UmCrl{g#Sc>)$@xPUP_PDU5T7|?}mItXpV@R@Y?B$~`_JbJ|$`7;dQ|<#5p&O0V_c(BIz8Z z5%XO;bZS~HI&EFIJ3l)0gujXqJ(we8@tslH#Al7Z${SV1v#wY+sm&)>n=6P+DbN^?H z+n_7*_9i!m*Y1GCNCaNQlA94)%qpb~QIWFg%4LmX!XqWz^|K?F{d!ReINU-EYmU5K gzv_Pw*CQvx8TLZ-@-K>RuH$}^6Q*^_2jQOh0&!D@3IG5A literal 0 HcmV?d00001 diff --git a/Instance.py b/Instance.py new file mode 100644 index 0000000..e69de29 diff --git a/KnownInstances.py b/KnownInstances.py new file mode 100644 index 0000000..62cb465 --- /dev/null +++ b/KnownInstances.py @@ -0,0 +1,30 @@ +from Report import report +from ReportSet import reportSet +from Substitutions import Substitutions +from Substitutions import Substitutions +class KnownInstances(report): + global knowninstances + knowninstances = { + 'Substitutions' : reportSet + } + + def __init__(knowninstances,substitution, support,source,destination): + super.__init__(substitution, support,source,destination) + + + def addReport(report): + reportSubs = Substitutions + reportSubs = report + report.getSubstitution() + reportSet = knowninstances.pop(reportSubs) + if reportSet == None: + reportSet = [] + reportSet.append(report) + knowninstances.update(reportSubs,reportSet) + + + def getReportBySubs(Subs): + return knowninstances.get('Substitutions') + + def getSubstitution(report): + pass diff --git a/Matcher.py b/Matcher.py new file mode 100644 index 0000000..c80e07f --- /dev/null +++ b/Matcher.py @@ -0,0 +1,7 @@ +class Matcher(): + def __init__(self) -> None: + pass + def Match(): + pass + def getMatchType(): + pass \ No newline at end of file diff --git a/MindGRAFController.py b/MindGRAFController.py new file mode 100644 index 0000000..2621658 --- /dev/null +++ b/MindGRAFController.py @@ -0,0 +1,5 @@ +class MindGRAFController(): + def __init__(self) -> None: + pass + def getContextName(): + pass \ No newline at end of file diff --git a/NodeSet.py b/NodeSet.py new file mode 100644 index 0000000..a31ff68 --- /dev/null +++ b/NodeSet.py @@ -0,0 +1,5 @@ +class NodeSet(): + def __init__(self) -> None: + pass + def getDownAnt(): + pass \ No newline at end of file diff --git a/Proposition.py b/Proposition.py new file mode 100644 index 0000000..bf68222 --- /dev/null +++ b/Proposition.py @@ -0,0 +1,30 @@ +from concurrent.futures import process +from Channel import Channel +from ChannelSet import ChannelSet +from ReasoningController import ReasoningController +from Runner import Runner + + +import ChannelSet +import supportSet +class Proposition(): + global outgoingChannels + outgoingChannels = ChannelSet + global incomingChannels + incomingChannels = ChannelSet + global supports + supports = supportSet + + + def __init__(self): + pass + + def processReports(): + for x in incomingChannels: + ReasoningController.ProcessReportChannel(x) + + def recieveReport(channel): + Runner.addToHighQ(channel) + + + #Attributes class (supportSet, channelSet) \ No newline at end of file diff --git a/PropositionSet.py b/PropositionSet.py new file mode 100644 index 0000000..59fd62a --- /dev/null +++ b/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node): + PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/ReasoningController.py b/ReasoningController.py new file mode 100644 index 0000000..8ac5e97 --- /dev/null +++ b/ReasoningController.py @@ -0,0 +1,106 @@ +from typing_extensions import Self +from Channel import Channel +from KnownInstances import KnownInstances +from Report import Report +from Channel import Channel +from ChannelSet import ChannelSet +from ReportSet import ReportSet +from Substitutions import Substitutions +from Proposition import Proposition +from PropositionSet import PropositionSet +from supportSet import supportSet +from Matcher import Matcher +from ChannelType import ChannelType +from RuleNode import RuleNode +from NodeSet import NodeSet +from Runner import Runner +from MindGRAFController import MindGRAFController +class ReasoningController: + def ApplySubstitution (): + pass + def CheckCompatiableSubstitution (): + pass + + """ + Receiving a request opens a new channel + + Parameters: + source: node with the request + destination: node to be sent the report to + status: status of the channel open or closed + type: inference type BackwardChain or ForwardChain + + """ + def Request (source,destination,status,type,context): + request = Channel(source,destination,status,type,context) + def SendReport(report,channel): + channel = Channel + if channel.reportToSend(report): + print("Report:", report , "was sent from" , channel.getSource(), "to", channel.getDestination ) + else: + print("Report:", report , "could not be sent from" , channel.getSource(), "to", channel.getDestination ) + channel.clearReportsBuffer() + + def AddToKnownInstances(report): + instances = KnownInstances + instances.addReport(report) + + def ForwardChain(report): + Runner.run() + report = Report + contextName = MindGRAFController.get + ReasoningController.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "FORWARD" ,report.getSource,report.getDestination) + ReasoningController.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "FORWARD" ,report.getSource,report.getDestination) + def BackwardChain(report): + pass + def ProcessReportChannel(channel): + channel = Channel + reports = Report + reports = [channel.getReportsBuffer] + currReport = Report + for currReport in reports: + report = Report(currReport.getSubstitution,currReport.getSupport,currReport.getInference,currReport.getSource,currReport.getDestination) + knownInstances = KnownInstances + if report in knownInstances: + continue + outgoingChannels = KnownInstances + for outChannel in outgoingChannels: + outChannel = KnownInstances + outChannel.addReport(report) + channel.clearReportsBuffer + channel.clearReportsBuffer + + + def getNodesToSendReport(self,type, context, substitutions, inferenceType,source,destination): + suppSet = supportSet() + suppSet.add(suppSet.getId()) + report = Report(substitutions,suppSet,inferenceType,source,destination) + match type: + case 'MATCHED': + matches = [Matcher.Match] + if matches: + ReasoningController.sendReportToMatches(matches,report,context) + case 'RULEANT': + if isinstance(self,RuleNode): + antNodes = NodeSet.getDownAnt() + ReasoningController.sendReportToNodeSet(antNodes,report,context,type) + + + def sendReportToMatches(matched,report,context): + for currentMatch in matched: + reportSubs= Substitutions + reportSubs.getSubs() + currentMatch = Matcher + #matchType = currentMatch.getMatchType() + newChannel = Channel(currentMatch,"destinaion","status",ChannelType.MATCHED,context) + ReasoningController.sendReport(report,newChannel) + + def sendReportToNodeSet(nodeSet, report, context, type,source, destination): + for sent in nodeSet: + report = Report + reportSubs = report.getSubstitution() + newChannel = Channel(source,destination,type,"status",type,context) + ReasoningController.SendReport(report,newChannel) + + def isAsserted(context): + pass diff --git a/Report.py b/Report.py new file mode 100644 index 0000000..2de0d4c --- /dev/null +++ b/Report.py @@ -0,0 +1,37 @@ +class Report: + def __init__(report,substitution,support,inference,source,destination): + report.substitution = substitution + report.support = support + report.inference = inference + report.destination = destination + report.source = source + + def getSubstitution(report): + return report.substitution + + def setSubstitution(report,substitution): + report.substitution = substitution + + def getSupport(report): + return report.support + + def getInference(report): + return report.inference + + def setInference(report,inference): + report.inference = inference + + def getDestination(report): + return report.destination + + def setDestination(report,destination): + report.destination = destination + + def getSource(report): + return report.source + + def setSource(report,source): + report.source = source + +#report = Report(15,5,5,5,5) +#print(report.getSubstitution()) \ No newline at end of file diff --git a/Report.pyc b/Report.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a77175f1d12e8e21719bee171f3d8ed1bb13ec90 GIT binary patch literal 2144 zcmb_cO>fgc5FO{+DFwubR0#rBLA zswGLg{$F-w7Kjbxti?qiJ|-QRj_Aiz8N130f8{^G)Ct5bpx_K!5e5Ed@T!4k@ZHjx z4ukL$Fm%-D5f5kjlJwLVNYYm$lw_dBP?AuM12NOl5Mg5CptKT1)+7~5l3@Ttkfu$=NTvfdf|Sa=fHnT&Y~jZ5mc{4!(x&4{9#4X3R>I8=eHjoYf~*SX9b@;Q@9*bPxN# zTR&~kN5&k{Nf7f@i2^#r#8t8yiKt<5xx!Kgcg5zeW7AY`uvJ9y{V%e(d_QC{TS}Ie z7OAUvx+xZx(tfaz31InDmG*-Mnkr*_|37PriA&3@=@6sa*0`pq0qikcZA+8hGcBoI z>-#REgQiJ+=Z_kAwj)YW)kN*u3lsDMJXxP(XxKXqJFcM*!>@+@-*Bg4BQs2a z;XO9@q3T|x*4FLaz=yVP_XtKW2>W6C`jawNN=i=4V7zR)t-O0gyDJLi None: + pass \ No newline at end of file diff --git a/Runner.py b/Runner.py new file mode 100644 index 0000000..a64c19e --- /dev/null +++ b/Runner.py @@ -0,0 +1,45 @@ +from itertools import count +from lib2to3.pytree import Node +from queue import Empty +from Channel import Channel +from Proposition import Proposition + + +class Runner(): + + global highQ + highQ = [] + global lowQ + lowQ = [] + global actQ + actQ = [] + + def run(): + while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): + while(highQ.count != 0): + print("In HighQ") + runNext = highQ.pop(0) + print(runNext) + Proposition.processReports(runNext) + + while(lowQ.count != 0): + print("In LowQ") + runNext = lowQ.pop(0) + print(runNext) + runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") + if highQ: + Runner.run() + + while(actQ.count != 0): + print("In ActQ") + runNext = actQ.pop() + print(runNext) + if highQ and lowQ: + Runner.run() + + def addToHighQ(node): + highQ.append(node) + def addToLowQ(node): + lowQ.append(node) + def addToActQ(node): + actQ.append(node) \ No newline at end of file diff --git a/Substitutions.py b/Substitutions.py new file mode 100644 index 0000000..09af52d --- /dev/null +++ b/Substitutions.py @@ -0,0 +1,5 @@ +class Substitutions(): + def __init__(self) -> None: + pass + def getSubs(): + pass \ No newline at end of file diff --git a/Switch.py b/Switch.py new file mode 100644 index 0000000..a7ae599 --- /dev/null +++ b/Switch.py @@ -0,0 +1,8 @@ +class Switch(): + def __init__(switch,report): + switch.report = report + + def switchReport(report): + pass +#x=Switch(1) +#print(x.switchReport()) \ No newline at end of file diff --git a/Switch.pyc b/Switch.pyc new file mode 100644 index 0000000000000000000000000000000000000000..19d3f0acbe77560b6979953f7434a16107a4e28f GIT binary patch literal 687 zcmb_Z!AiqG5S`7|prt)|5d4B1r1=36tpz=ZhXfDiveaauktQkGEh_X@|HM!92YfS0 z^eh@OFSC=KH}CE0&*}K&WAT(z|7d(K5pD)3@Q$cZ^iH%Vdd!F{N&)Q^Ws0n#XXHdT zw}qxOIzWpL0qINW^VK(}LTQe0rvMP370lqwf}T9nl%!FB-#Nn&*W5G(>=f;Yj3`PY z=DQb^X|3Hft(R_DJDHyFt_abAJ3|&fINQ4Ts%r0+l`Z2%lW!|qdl%1_`O2=FHtwX) zHgEnA4aSsp>5XAQj)7FpyhDh<5eo1#=;B=>?#~J)VCv0?MLyqNMZ`mUi8Z_!PVN}1#mr*F`RiWzW&QZ@paxgxnNqEd>l^H E7bZ1;`2YX_ literal 0 HcmV?d00001 diff --git a/__pycache__/Channel.cpython-39.pyc b/__pycache__/Channel.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..22265168742a3ffd95c30875003c33bea5151668 GIT binary patch literal 1843 zcmb7F&2G~`5MKYpc7FTclwS!62?eRm3m{Zz0U@DY0vBH_*JFrLVu#(eP%Gc)%k%|! z7+*Q{6*w`ouG1y*p;^n{?0P2q&CJeD!hXNQaQuG!?tEY~_J04k-*vP&?dv+EP>chmvF}`Ao5Hs4tH^B(4Y6stz7T7~( zFld2u#rzhy;GuM&4IPv&bfJgRgFXyUwqXM{QFdSpwo!Ir2X;~RU=Q|D_F;(L9F*?K zG)&WY#tr0+JcN4CoV+^0R~#WoR+v4Yci8DFCFnSkOpgQRjSCzf_=vna4M3K!O8b)gZEG<7b_sD zvh^*NA7Kxtf^yA_%YIF#G?DsB8XPoVo(RQV7?^FWx+PWF6Ztu2Q|6S-ky&x>py?{{ zhKS`vvpqnY+J#~5!ir6F|CoJO)c2;u{Hp3`qHE)R z?^W?V)!4Q)wo1EJviUylRcBaHQ}t;_+s5ow`#x)8U24|}QB{0Xhyx7q^zI%#*BJM; zI5m^?f_O+0+NRg`tkp+Zjcnhk%F}lyRY&gLR?27Wy~?JE TqV!%>VZ5epAgJ;^10VArjV4{+ literal 0 HcmV?d00001 diff --git a/__pycache__/ChannelType.cpython-39.pyc b/__pycache__/ChannelType.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..eaf5e81afaca01d3dfdc3fdf974bfc801d14d101 GIT binary patch literal 392 zcmYjMJx{|h5Vd2sjry^}#+rqQ9ifIaf}sr(O&2d#h%FTyL`2p6R_{gZ^DDq z)`gL=TbTJ8Zt9{jx_WoveO?@OS=(@==K6HDC*M|BnW5 R0g2YX9W>wJW)5qY^bgsdQn~;D literal 0 HcmV?d00001 diff --git a/__pycache__/Filter.cpython-39.pyc b/__pycache__/Filter.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d2360e00b5b1aa7e3614e84a5ffc0c439edf135e GIT binary patch literal 577 zcmZ`zOG*Pl5bf&uWC$i+z_kz%=K>;8gKlIH)Xi*~ak|BU`NZxCXvi)ez$55J$d!8I z!j)HWWmQjty0GBYr>kGRmkkDehVlG1xp~L>LBsFxa2O-ZE~YaknS>|AlBY~D$(N9V z;tF28SGELT(z|3MKgYj+g5xwsm>o=tr65_#B}o3nQcrr)$Lh-fxuFeDi?UTZC(b6Q zC!8P*8D7AG33P)DNLFA&t)`7`N8E!ohln0cdGl-M;i%I)I}=#&lTko!YV<6G?F&&ga#m8mCB*$KE4z*EAzeq5oWM__ p>w4qP$wWNz+{-6DCnMht79MOc)kWR@d&Wiwo%$gW-K}9if^X9$Z~OoN literal 0 HcmV?d00001 diff --git a/__pycache__/Switch.cpython-39.pyc b/__pycache__/Switch.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fda51f1edf75132e9f38741d48c7902b23f2eb2f GIT binary patch literal 586 zcmZ`#J5Iwu5Z&<)6D3ek&`={;Lihp*1&Bn0ToBQ?SsCw2u@u{3*AXA3OAZ2pCRf^) ziYrhtvyMe580pP-XWr9hgF%m>9lnq5KQMk$v289ELxes?cg+M7utF@Ilu0I>C8Qu7 z39s%OTLLiQj#=d8`1X%ESPc>S2%Tgp2$nhmgtKC)D_r4W^n{PQfeFTsMUzi*+UbmP z!WBZ3-~}ugM>S)%hGY#UP;yqQCUQ)m?Yi>t)tadQ!}m#ir=`;IMX7GGQWo*3&gZ49 z8XaF|`9w}@6}POXvu6`>UQ|WHIWcN0177ww^KO;{4m+cqVC4}p2~)Ib`4xR)n~@x~ zgU<9@owruEkDZR`V8gUMPa>aWRVbcw)8o9X#e7P6pYw-#Hf<*=r1QJvEYYtcO4Z5K lBr$~0wVf|&Cy{3h15d`EsiJEBJ!8VNmi?R-?XA5agdgUobUgq7 literal 0 HcmV?d00001 diff --git a/supportSet.py b/supportSet.py new file mode 100644 index 0000000..1209bdf --- /dev/null +++ b/supportSet.py @@ -0,0 +1,5 @@ +class supportSet(): + def __init__(self,support): + support = [] + def getId(node): + pass \ No newline at end of file From ae0eb3e443d6a21129ccc1cc9e23442fec2fa8c7 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 03:07:33 +0200 Subject: [PATCH 15/25] Create test --- code/core/modules/ReasoningController/test | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/ReasoningController/test diff --git a/code/core/modules/ReasoningController/test b/code/core/modules/ReasoningController/test new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/code/core/modules/ReasoningController/test @@ -0,0 +1 @@ + From 675ed8ff24d30920ba8c36c84427f063519bbe8c Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 03:07:44 +0200 Subject: [PATCH 16/25] Delete test --- code/core/modules/ReasoningController/test | 1 - 1 file changed, 1 deletion(-) delete mode 100644 code/core/modules/ReasoningController/test diff --git a/code/core/modules/ReasoningController/test b/code/core/modules/ReasoningController/test deleted file mode 100644 index 8b13789..0000000 --- a/code/core/modules/ReasoningController/test +++ /dev/null @@ -1 +0,0 @@ - From 7bd64e4af043be4281b4e3c3bcd954eb8cfc6f76 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 12 May 2022 03:07:55 +0200 Subject: [PATCH 17/25] Create test --- code/core/modules/ReasoningController/test | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/core/modules/ReasoningController/test diff --git a/code/core/modules/ReasoningController/test b/code/core/modules/ReasoningController/test new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/code/core/modules/ReasoningController/test @@ -0,0 +1 @@ + From 6d09f64a973db82bcd0330fcc3aa8891c5df4488 Mon Sep 17 00:00:00 2001 From: AmrLamei Date: Thu, 12 May 2022 03:27:09 +0200 Subject: [PATCH 18/25] commit-v2 --- .../modules/ReasoningController/.DS_Store | Bin 0 -> 6148 bytes .../modules/ReasoningController/Channel.py | 77 +++++++++++++ .../modules/ReasoningController/Channel.pyc | Bin 0 -> 2284 bytes .../modules/ReasoningController/ChannelSet.py | 42 +++++++ .../ReasoningController/ChannelType.py | 5 + .../ReasoningController/ChannelType.pyc | Bin 0 -> 446 bytes .../modules/ReasoningController/Filter.py | 13 +++ .../modules/ReasoningController/Filter.pyc | Bin 0 -> 719 bytes .../modules/ReasoningController/Instance.py | 0 .../ReasoningController/KnownInstances.py | 30 +++++ .../modules/ReasoningController/Matcher.py | 7 ++ .../ReasoningController/MindGRAFController.py | 5 + .../modules/ReasoningController/NodeSet.py | 5 + .../ReasoningController/Proposition.py | 30 +++++ .../ReasoningController/PropositionSet.py | 9 ++ .../modules/ReasoningController/README.md | 1 + .../ReasoningController.py | 106 ++++++++++++++++++ .../modules/ReasoningController/Report.py | 37 ++++++ .../modules/ReasoningController/Report.pyc | Bin 0 -> 2144 bytes .../modules/ReasoningController/ReportSet.py | 21 ++++ .../modules/ReasoningController/RuleNode.py | 3 + .../modules/ReasoningController/Runner.py | 45 ++++++++ .../ReasoningController/Substitutions.py | 5 + .../modules/ReasoningController/Switch.py | 8 ++ .../modules/ReasoningController/Switch.pyc | Bin 0 -> 687 bytes .../__pycache__/Channel.cpython-39.pyc | Bin 0 -> 1843 bytes .../__pycache__/ChannelType.cpython-39.pyc | Bin 0 -> 392 bytes .../__pycache__/Filter.cpython-39.pyc | Bin 0 -> 577 bytes .../__pycache__/Switch.cpython-39.pyc | Bin 0 -> 586 bytes .../modules/ReasoningController/Matcher.py | 7 ++ .../ReasoningController/MindGRAFController.py | 5 + .../modules/ReasoningController/NodeSet.py | 5 + .../ReasoningController/PropositionSet.py | 9 ++ .../modules/ReasoningController/RuleNode.py | 3 + .../modules/ReasoningController/Runner.py | 45 ++++++++ .../ReasoningController/Substitutions.py | 5 + .../modules/ReasoningController/supportSet.py | 5 + .../core/modules/network/mind_controller.py | 0 .../ReasoningController/requirements.txt | 1 + .../modules/ReasoningController/supportSet.py | 5 + code/core/modules/ReasoningController/test | 1 - .../test_unittest.cpython-37-pytest-7.0.1.pyc | Bin 0 -> 709 bytes .../tests/test_unittest.py | 5 + 43 files changed, 544 insertions(+), 1 deletion(-) create mode 100644 code/core/modules/ReasoningController/.DS_Store create mode 100644 code/core/modules/ReasoningController/Channel.py create mode 100644 code/core/modules/ReasoningController/Channel.pyc create mode 100644 code/core/modules/ReasoningController/ChannelSet.py create mode 100644 code/core/modules/ReasoningController/ChannelType.py create mode 100644 code/core/modules/ReasoningController/ChannelType.pyc create mode 100644 code/core/modules/ReasoningController/Filter.py create mode 100644 code/core/modules/ReasoningController/Filter.pyc create mode 100644 code/core/modules/ReasoningController/Instance.py create mode 100644 code/core/modules/ReasoningController/KnownInstances.py create mode 100644 code/core/modules/ReasoningController/Matcher.py create mode 100644 code/core/modules/ReasoningController/MindGRAFController.py create mode 100644 code/core/modules/ReasoningController/NodeSet.py create mode 100644 code/core/modules/ReasoningController/Proposition.py create mode 100644 code/core/modules/ReasoningController/PropositionSet.py create mode 100644 code/core/modules/ReasoningController/README.md create mode 100644 code/core/modules/ReasoningController/ReasoningController.py create mode 100644 code/core/modules/ReasoningController/Report.py create mode 100644 code/core/modules/ReasoningController/Report.pyc create mode 100644 code/core/modules/ReasoningController/ReportSet.py create mode 100644 code/core/modules/ReasoningController/RuleNode.py create mode 100644 code/core/modules/ReasoningController/Runner.py create mode 100644 code/core/modules/ReasoningController/Substitutions.py create mode 100644 code/core/modules/ReasoningController/Switch.py create mode 100644 code/core/modules/ReasoningController/Switch.pyc create mode 100644 code/core/modules/ReasoningController/__pycache__/Channel.cpython-39.pyc create mode 100644 code/core/modules/ReasoningController/__pycache__/ChannelType.cpython-39.pyc create mode 100644 code/core/modules/ReasoningController/__pycache__/Filter.cpython-39.pyc create mode 100644 code/core/modules/ReasoningController/__pycache__/Switch.cpython-39.pyc create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py create mode 100644 code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py create mode 100644 code/core/modules/ReasoningController/requirements.txt create mode 100644 code/core/modules/ReasoningController/supportSet.py delete mode 100644 code/core/modules/ReasoningController/test create mode 100644 code/core/modules/ReasoningController/tests/__pycache__/test_unittest.cpython-37-pytest-7.0.1.pyc create mode 100644 code/core/modules/ReasoningController/tests/test_unittest.py diff --git a/code/core/modules/ReasoningController/.DS_Store b/code/core/modules/ReasoningController/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0lL{0fA@MH0-)KlO~hpFSx_nB}R1 zQ_LQ@4!RG?%*9KEU)ON_J#pcwj@lZ`@?{vi9eftW)+OoGC0Sa$<)$vTV2F9n7x9oQ zQrW{ocEc$R9~;hU7!kvlj88*;L$t!!7eJ%WHeTA%yZQ3tbRH+8!z|3_aq8@7e;S^~ zvurskL;7-Y?&vBAk~DDvRt^0YOy+wnTBRk9OLD!%(6#FWxgp7G+@5iS zq_7z;D;8_Tmc%OaX{;snd5z1}bW%p^e9~L4Nt5atb+pWkgDbbMSsjRXo>TwV_ zZqFc?XHh=Gt)Yg7b;|Hn!>VF#(cGrFLvxpgMbO-**@Iap|1}vKI1yG@%c9k3bQ-?j sYx;j(#WZ^SH1V3@2YQZ`N606fS?XzHKC02{LX|hv#PYo3DKu#O0h*DhX8-^I literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/ChannelSet.py b/code/core/modules/ReasoningController/ChannelSet.py new file mode 100644 index 0000000..94160f1 --- /dev/null +++ b/code/core/modules/ReasoningController/ChannelSet.py @@ -0,0 +1,42 @@ +from Channel import Channel +import ChannelType +class ChannelSet(Channel): + + def __init__(channel,id,filter,switch,source,destination,status,type): + global channels + super().__init__(id,filter,switch,source,destination,status,type) + MatchedChannels = { + 'Matched' : channel + } + AntToRuleChannels = { + 'AntToRule' : channel + } + RuletoConsChannels = { + 'RuleToCons' : channel + } + + def addChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def removeChannel(channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def getChannelType(channel): + channeltype ='' + if (ChannelType.RULEANT): + channeltype = 'AntecedentToRule Channel' + if (ChannelType.RULECONS): + channeltype = 'RuleToConsequent Channel' + else: + channeltype = 'Matched Channel' + return channeltype +#x=ChannelSet(0,0,0,0,0,0,0) +#print(x.getChannelType()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ChannelType.py b/code/core/modules/ReasoningController/ChannelType.py new file mode 100644 index 0000000..6a55ff0 --- /dev/null +++ b/code/core/modules/ReasoningController/ChannelType.py @@ -0,0 +1,5 @@ +from enum import Enum +class ChannelType(Enum): + MATCHED = 1 + RULEANT = 2 + RULECONS = 3 \ No newline at end of file diff --git a/code/core/modules/ReasoningController/ChannelType.pyc b/code/core/modules/ReasoningController/ChannelType.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a8247a38c1a9420ca5ad6939b720ca8362b71fd GIT binary patch literal 446 zcmbVI!A^uQ6nuqs*R1*h`UUL8#*-IgWLXjqD<;4m?+O8TKmNUo)KMn4~mF4kf9r{sf&oB=jqr`)U4q&bz<;JMqNWbmZ$gSn7E5}yp z!N_G%ZdKFu@=q_9yM4?dT$q^xrh=y}dEh5ddTcETL9F#~pJo5M)V6W+-Rvztjo}JT F#TWDAS?2%% literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/Filter.py b/code/core/modules/ReasoningController/Filter.py new file mode 100644 index 0000000..c2c1f35 --- /dev/null +++ b/code/core/modules/ReasoningController/Filter.py @@ -0,0 +1,13 @@ +class Filter: + + def __init__(filter,report): + filter.report = report + + def canPass(report): + if True: + return True + else: + return False +#x = Filter(1) +#print(x.canPass()) + diff --git a/code/core/modules/ReasoningController/Filter.pyc b/code/core/modules/ReasoningController/Filter.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a745c42fbc380c95f68ae53cddb2f148e3607cf3 GIT binary patch literal 719 zcmb_ZOHPD95UmCrl{g#Sc>)$@xPUP_PDU5T7|?}mItXpV@R@Y?B$~`_JbJ|$`7;dQ|<#5p&O0V_c(BIz8Z z5%XO;bZS~HI&EFIJ3l)0gujXqJ(we8@tslH#Al7Z${SV1v#wY+sm&)>n=6P+DbN^?H z+n_7*_9i!m*Y1GCNCaNQlA94)%qpb~QIWFg%4LmX!XqWz^|K?F{d!ReINU-EYmU5K gzv_Pw*CQvx8TLZ-@-K>RuH$}^6Q*^_2jQOh0&!D@3IG5A literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/Instance.py b/code/core/modules/ReasoningController/Instance.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core/modules/ReasoningController/KnownInstances.py b/code/core/modules/ReasoningController/KnownInstances.py new file mode 100644 index 0000000..62cb465 --- /dev/null +++ b/code/core/modules/ReasoningController/KnownInstances.py @@ -0,0 +1,30 @@ +from Report import report +from ReportSet import reportSet +from Substitutions import Substitutions +from Substitutions import Substitutions +class KnownInstances(report): + global knowninstances + knowninstances = { + 'Substitutions' : reportSet + } + + def __init__(knowninstances,substitution, support,source,destination): + super.__init__(substitution, support,source,destination) + + + def addReport(report): + reportSubs = Substitutions + reportSubs = report + report.getSubstitution() + reportSet = knowninstances.pop(reportSubs) + if reportSet == None: + reportSet = [] + reportSet.append(report) + knowninstances.update(reportSubs,reportSet) + + + def getReportBySubs(Subs): + return knowninstances.get('Substitutions') + + def getSubstitution(report): + pass diff --git a/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/Matcher.py new file mode 100644 index 0000000..c80e07f --- /dev/null +++ b/code/core/modules/ReasoningController/Matcher.py @@ -0,0 +1,7 @@ +class Matcher(): + def __init__(self) -> None: + pass + def Match(): + pass + def getMatchType(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/MindGRAFController.py new file mode 100644 index 0000000..2621658 --- /dev/null +++ b/code/core/modules/ReasoningController/MindGRAFController.py @@ -0,0 +1,5 @@ +class MindGRAFController(): + def __init__(self) -> None: + pass + def getContextName(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/NodeSet.py new file mode 100644 index 0000000..a31ff68 --- /dev/null +++ b/code/core/modules/ReasoningController/NodeSet.py @@ -0,0 +1,5 @@ +class NodeSet(): + def __init__(self) -> None: + pass + def getDownAnt(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Proposition.py b/code/core/modules/ReasoningController/Proposition.py new file mode 100644 index 0000000..bf68222 --- /dev/null +++ b/code/core/modules/ReasoningController/Proposition.py @@ -0,0 +1,30 @@ +from concurrent.futures import process +from Channel import Channel +from ChannelSet import ChannelSet +from ReasoningController import ReasoningController +from Runner import Runner + + +import ChannelSet +import supportSet +class Proposition(): + global outgoingChannels + outgoingChannels = ChannelSet + global incomingChannels + incomingChannels = ChannelSet + global supports + supports = supportSet + + + def __init__(self): + pass + + def processReports(): + for x in incomingChannels: + ReasoningController.ProcessReportChannel(x) + + def recieveReport(channel): + Runner.addToHighQ(channel) + + + #Attributes class (supportSet, channelSet) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/PropositionSet.py new file mode 100644 index 0000000..59fd62a --- /dev/null +++ b/code/core/modules/ReasoningController/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node): + PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/README.md b/code/core/modules/ReasoningController/README.md new file mode 100644 index 0000000..f9c1d08 --- /dev/null +++ b/code/core/modules/ReasoningController/README.md @@ -0,0 +1 @@ +# MindGRAF1.0 diff --git a/code/core/modules/ReasoningController/ReasoningController.py b/code/core/modules/ReasoningController/ReasoningController.py new file mode 100644 index 0000000..8ac5e97 --- /dev/null +++ b/code/core/modules/ReasoningController/ReasoningController.py @@ -0,0 +1,106 @@ +from typing_extensions import Self +from Channel import Channel +from KnownInstances import KnownInstances +from Report import Report +from Channel import Channel +from ChannelSet import ChannelSet +from ReportSet import ReportSet +from Substitutions import Substitutions +from Proposition import Proposition +from PropositionSet import PropositionSet +from supportSet import supportSet +from Matcher import Matcher +from ChannelType import ChannelType +from RuleNode import RuleNode +from NodeSet import NodeSet +from Runner import Runner +from MindGRAFController import MindGRAFController +class ReasoningController: + def ApplySubstitution (): + pass + def CheckCompatiableSubstitution (): + pass + + """ + Receiving a request opens a new channel + + Parameters: + source: node with the request + destination: node to be sent the report to + status: status of the channel open or closed + type: inference type BackwardChain or ForwardChain + + """ + def Request (source,destination,status,type,context): + request = Channel(source,destination,status,type,context) + def SendReport(report,channel): + channel = Channel + if channel.reportToSend(report): + print("Report:", report , "was sent from" , channel.getSource(), "to", channel.getDestination ) + else: + print("Report:", report , "could not be sent from" , channel.getSource(), "to", channel.getDestination ) + channel.clearReportsBuffer() + + def AddToKnownInstances(report): + instances = KnownInstances + instances.addReport(report) + + def ForwardChain(report): + Runner.run() + report = Report + contextName = MindGRAFController.get + ReasoningController.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "FORWARD" ,report.getSource,report.getDestination) + ReasoningController.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "FORWARD" ,report.getSource,report.getDestination) + def BackwardChain(report): + pass + def ProcessReportChannel(channel): + channel = Channel + reports = Report + reports = [channel.getReportsBuffer] + currReport = Report + for currReport in reports: + report = Report(currReport.getSubstitution,currReport.getSupport,currReport.getInference,currReport.getSource,currReport.getDestination) + knownInstances = KnownInstances + if report in knownInstances: + continue + outgoingChannels = KnownInstances + for outChannel in outgoingChannels: + outChannel = KnownInstances + outChannel.addReport(report) + channel.clearReportsBuffer + channel.clearReportsBuffer + + + def getNodesToSendReport(self,type, context, substitutions, inferenceType,source,destination): + suppSet = supportSet() + suppSet.add(suppSet.getId()) + report = Report(substitutions,suppSet,inferenceType,source,destination) + match type: + case 'MATCHED': + matches = [Matcher.Match] + if matches: + ReasoningController.sendReportToMatches(matches,report,context) + case 'RULEANT': + if isinstance(self,RuleNode): + antNodes = NodeSet.getDownAnt() + ReasoningController.sendReportToNodeSet(antNodes,report,context,type) + + + def sendReportToMatches(matched,report,context): + for currentMatch in matched: + reportSubs= Substitutions + reportSubs.getSubs() + currentMatch = Matcher + #matchType = currentMatch.getMatchType() + newChannel = Channel(currentMatch,"destinaion","status",ChannelType.MATCHED,context) + ReasoningController.sendReport(report,newChannel) + + def sendReportToNodeSet(nodeSet, report, context, type,source, destination): + for sent in nodeSet: + report = Report + reportSubs = report.getSubstitution() + newChannel = Channel(source,destination,type,"status",type,context) + ReasoningController.SendReport(report,newChannel) + + def isAsserted(context): + pass diff --git a/code/core/modules/ReasoningController/Report.py b/code/core/modules/ReasoningController/Report.py new file mode 100644 index 0000000..2de0d4c --- /dev/null +++ b/code/core/modules/ReasoningController/Report.py @@ -0,0 +1,37 @@ +class Report: + def __init__(report,substitution,support,inference,source,destination): + report.substitution = substitution + report.support = support + report.inference = inference + report.destination = destination + report.source = source + + def getSubstitution(report): + return report.substitution + + def setSubstitution(report,substitution): + report.substitution = substitution + + def getSupport(report): + return report.support + + def getInference(report): + return report.inference + + def setInference(report,inference): + report.inference = inference + + def getDestination(report): + return report.destination + + def setDestination(report,destination): + report.destination = destination + + def getSource(report): + return report.source + + def setSource(report,source): + report.source = source + +#report = Report(15,5,5,5,5) +#print(report.getSubstitution()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Report.pyc b/code/core/modules/ReasoningController/Report.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a77175f1d12e8e21719bee171f3d8ed1bb13ec90 GIT binary patch literal 2144 zcmb_cO>fgc5FO{+DFwubR0#rBLA zswGLg{$F-w7Kjbxti?qiJ|-QRj_Aiz8N130f8{^G)Ct5bpx_K!5e5Ed@T!4k@ZHjx z4ukL$Fm%-D5f5kjlJwLVNYYm$lw_dBP?AuM12NOl5Mg5CptKT1)+7~5l3@Ttkfu$=NTvfdf|Sa=fHnT&Y~jZ5mc{4!(x&4{9#4X3R>I8=eHjoYf~*SX9b@;Q@9*bPxN# zTR&~kN5&k{Nf7f@i2^#r#8t8yiKt<5xx!Kgcg5zeW7AY`uvJ9y{V%e(d_QC{TS}Ie z7OAUvx+xZx(tfaz31InDmG*-Mnkr*_|37PriA&3@=@6sa*0`pq0qikcZA+8hGcBoI z>-#REgQiJ+=Z_kAwj)YW)kN*u3lsDMJXxP(XxKXqJFcM*!>@+@-*Bg4BQs2a z;XO9@q3T|x*4FLaz=yVP_XtKW2>W6C`jawNN=i=4V7zR)t-O0gyDJLi None: + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/Runner.py new file mode 100644 index 0000000..a64c19e --- /dev/null +++ b/code/core/modules/ReasoningController/Runner.py @@ -0,0 +1,45 @@ +from itertools import count +from lib2to3.pytree import Node +from queue import Empty +from Channel import Channel +from Proposition import Proposition + + +class Runner(): + + global highQ + highQ = [] + global lowQ + lowQ = [] + global actQ + actQ = [] + + def run(): + while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): + while(highQ.count != 0): + print("In HighQ") + runNext = highQ.pop(0) + print(runNext) + Proposition.processReports(runNext) + + while(lowQ.count != 0): + print("In LowQ") + runNext = lowQ.pop(0) + print(runNext) + runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") + if highQ: + Runner.run() + + while(actQ.count != 0): + print("In ActQ") + runNext = actQ.pop() + print(runNext) + if highQ and lowQ: + Runner.run() + + def addToHighQ(node): + highQ.append(node) + def addToLowQ(node): + lowQ.append(node) + def addToActQ(node): + actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/Substitutions.py new file mode 100644 index 0000000..09af52d --- /dev/null +++ b/code/core/modules/ReasoningController/Substitutions.py @@ -0,0 +1,5 @@ +class Substitutions(): + def __init__(self) -> None: + pass + def getSubs(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Switch.py b/code/core/modules/ReasoningController/Switch.py new file mode 100644 index 0000000..a7ae599 --- /dev/null +++ b/code/core/modules/ReasoningController/Switch.py @@ -0,0 +1,8 @@ +class Switch(): + def __init__(switch,report): + switch.report = report + + def switchReport(report): + pass +#x=Switch(1) +#print(x.switchReport()) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/Switch.pyc b/code/core/modules/ReasoningController/Switch.pyc new file mode 100644 index 0000000000000000000000000000000000000000..19d3f0acbe77560b6979953f7434a16107a4e28f GIT binary patch literal 687 zcmb_Z!AiqG5S`7|prt)|5d4B1r1=36tpz=ZhXfDiveaauktQkGEh_X@|HM!92YfS0 z^eh@OFSC=KH}CE0&*}K&WAT(z|7d(K5pD)3@Q$cZ^iH%Vdd!F{N&)Q^Ws0n#XXHdT zw}qxOIzWpL0qINW^VK(}LTQe0rvMP370lqwf}T9nl%!FB-#Nn&*W5G(>=f;Yj3`PY z=DQb^X|3Hft(R_DJDHyFt_abAJ3|&fINQ4Ts%r0+l`Z2%lW!|qdl%1_`O2=FHtwX) zHgEnA4aSsp>5XAQj)7FpyhDh<5eo1#=;B=>?#~J)VCv0?MLyqNMZ`mUi8Z_!PVN}1#mr*F`RiWzW&QZ@paxgxnNqEd>l^H E7bZ1;`2YX_ literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/__pycache__/Channel.cpython-39.pyc b/code/core/modules/ReasoningController/__pycache__/Channel.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..22265168742a3ffd95c30875003c33bea5151668 GIT binary patch literal 1843 zcmb7F&2G~`5MKYpc7FTclwS!62?eRm3m{Zz0U@DY0vBH_*JFrLVu#(eP%Gc)%k%|! z7+*Q{6*w`ouG1y*p;^n{?0P2q&CJeD!hXNQaQuG!?tEY~_J04k-*vP&?dv+EP>chmvF}`Ao5Hs4tH^B(4Y6stz7T7~( zFld2u#rzhy;GuM&4IPv&bfJgRgFXyUwqXM{QFdSpwo!Ir2X;~RU=Q|D_F;(L9F*?K zG)&WY#tr0+JcN4CoV+^0R~#WoR+v4Yci8DFCFnSkOpgQRjSCzf_=vna4M3K!O8b)gZEG<7b_sD zvh^*NA7Kxtf^yA_%YIF#G?DsB8XPoVo(RQV7?^FWx+PWF6Ztu2Q|6S-ky&x>py?{{ zhKS`vvpqnY+J#~5!ir6F|CoJO)c2;u{Hp3`qHE)R z?^W?V)!4Q)wo1EJviUylRcBaHQ}t;_+s5ow`#x)8U24|}QB{0Xhyx7q^zI%#*BJM; zI5m^?f_O+0+NRg`tkp+Zjcnhk%F}lyRY&gLR?27Wy~?JE TqV!%>VZ5epAgJ;^10VArjV4{+ literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/__pycache__/ChannelType.cpython-39.pyc b/code/core/modules/ReasoningController/__pycache__/ChannelType.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..eaf5e81afaca01d3dfdc3fdf974bfc801d14d101 GIT binary patch literal 392 zcmYjMJx{|h5Vd2sjry^}#+rqQ9ifIaf}sr(O&2d#h%FTyL`2p6R_{gZ^DDq z)`gL=TbTJ8Zt9{jx_WoveO?@OS=(@==K6HDC*M|BnW5 R0g2YX9W>wJW)5qY^bgsdQn~;D literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/__pycache__/Filter.cpython-39.pyc b/code/core/modules/ReasoningController/__pycache__/Filter.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d2360e00b5b1aa7e3614e84a5ffc0c439edf135e GIT binary patch literal 577 zcmZ`zOG*Pl5bf&uWC$i+z_kz%=K>;8gKlIH)Xi*~ak|BU`NZxCXvi)ez$55J$d!8I z!j)HWWmQjty0GBYr>kGRmkkDehVlG1xp~L>LBsFxa2O-ZE~YaknS>|AlBY~D$(N9V z;tF28SGELT(z|3MKgYj+g5xwsm>o=tr65_#B}o3nQcrr)$Lh-fxuFeDi?UTZC(b6Q zC!8P*8D7AG33P)DNLFA&t)`7`N8E!ohln0cdGl-M;i%I)I}=#&lTko!YV<6G?F&&ga#m8mCB*$KE4z*EAzeq5oWM__ p>w4qP$wWNz+{-6DCnMht79MOc)kWR@d&Wiwo%$gW-K}9if^X9$Z~OoN literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/__pycache__/Switch.cpython-39.pyc b/code/core/modules/ReasoningController/__pycache__/Switch.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fda51f1edf75132e9f38741d48c7902b23f2eb2f GIT binary patch literal 586 zcmZ`#J5Iwu5Z&<)6D3ek&`={;Lihp*1&Bn0ToBQ?SsCw2u@u{3*AXA3OAZ2pCRf^) ziYrhtvyMe580pP-XWr9hgF%m>9lnq5KQMk$v289ELxes?cg+M7utF@Ilu0I>C8Qu7 z39s%OTLLiQj#=d8`1X%ESPc>S2%Tgp2$nhmgtKC)D_r4W^n{PQfeFTsMUzi*+UbmP z!WBZ3-~}ugM>S)%hGY#UP;yqQCUQ)m?Yi>t)tadQ!}m#ir=`;IMX7GGQWo*3&gZ49 z8XaF|`9w}@6}POXvu6`>UQ|WHIWcN0177ww^KO;{4m+cqVC4}p2~)Ib`4xR)n~@x~ zgU<9@owruEkDZR`V8gUMPa>aWRVbcw)8o9X#e7P6pYw-#Hf<*=r1QJvEYYtcO4Z5K lBr$~0wVf|&Cy{3h15d`EsiJEBJ!8VNmi?R-?XA5agdgUobUgq7 literal 0 HcmV?d00001 diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py new file mode 100644 index 0000000..c80e07f --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py @@ -0,0 +1,7 @@ +class Matcher(): + def __init__(self) -> None: + pass + def Match(): + pass + def getMatchType(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py new file mode 100644 index 0000000..2621658 --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py @@ -0,0 +1,5 @@ +class MindGRAFController(): + def __init__(self) -> None: + pass + def getContextName(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py new file mode 100644 index 0000000..a31ff68 --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py @@ -0,0 +1,5 @@ +class NodeSet(): + def __init__(self) -> None: + pass + def getDownAnt(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py new file mode 100644 index 0000000..59fd62a --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node): + PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py new file mode 100644 index 0000000..7c836a4 --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py @@ -0,0 +1,3 @@ +class RuleNode(): + def __init__(self) -> None: + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py new file mode 100644 index 0000000..a64c19e --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py @@ -0,0 +1,45 @@ +from itertools import count +from lib2to3.pytree import Node +from queue import Empty +from Channel import Channel +from Proposition import Proposition + + +class Runner(): + + global highQ + highQ = [] + global lowQ + lowQ = [] + global actQ + actQ = [] + + def run(): + while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): + while(highQ.count != 0): + print("In HighQ") + runNext = highQ.pop(0) + print(runNext) + Proposition.processReports(runNext) + + while(lowQ.count != 0): + print("In LowQ") + runNext = lowQ.pop(0) + print(runNext) + runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") + if highQ: + Runner.run() + + while(actQ.count != 0): + print("In ActQ") + runNext = actQ.pop() + print(runNext) + if highQ and lowQ: + Runner.run() + + def addToHighQ(node): + highQ.append(node) + def addToLowQ(node): + lowQ.append(node) + def addToActQ(node): + actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py new file mode 100644 index 0000000..09af52d --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py @@ -0,0 +1,5 @@ +class Substitutions(): + def __init__(self) -> None: + pass + def getSubs(): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py new file mode 100644 index 0000000..1209bdf --- /dev/null +++ b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py @@ -0,0 +1,5 @@ +class supportSet(): + def __init__(self,support): + support = [] + def getId(node): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py b/code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core/modules/ReasoningController/requirements.txt b/code/core/modules/ReasoningController/requirements.txt new file mode 100644 index 0000000..72ba8c1 --- /dev/null +++ b/code/core/modules/ReasoningController/requirements.txt @@ -0,0 +1 @@ +pytest == 7.0.1 \ No newline at end of file diff --git a/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/supportSet.py new file mode 100644 index 0000000..1209bdf --- /dev/null +++ b/code/core/modules/ReasoningController/supportSet.py @@ -0,0 +1,5 @@ +class supportSet(): + def __init__(self,support): + support = [] + def getId(node): + pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/test b/code/core/modules/ReasoningController/test deleted file mode 100644 index 8b13789..0000000 --- a/code/core/modules/ReasoningController/test +++ /dev/null @@ -1 +0,0 @@ - diff --git a/code/core/modules/ReasoningController/tests/__pycache__/test_unittest.cpython-37-pytest-7.0.1.pyc b/code/core/modules/ReasoningController/tests/__pycache__/test_unittest.cpython-37-pytest-7.0.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d60566565382996c70dd98f908497eaf9a6c0c68 GIT binary patch literal 709 zcmb_ZJ8#=C5I#z>EhmnL1_;otO95-K(vC$@#Cak^GxRaki=db^AXG0LDWneUCCQS1 zk&O9A1=mdd3!QpLxj~V+1nxWDk$3m;Mn`Ja4kx zWTmzP7V;^2nY5oWZlxuy$EYqaGs^a#Qnt6wwd`07 Date: Thu, 12 May 2022 03:36:24 +0200 Subject: [PATCH 19/25] Delete code/core/modules/ReasoningController/code/core/modules directory --- .../modules/ReasoningController/Matcher.py | 7 --- .../ReasoningController/MindGRAFController.py | 5 --- .../modules/ReasoningController/NodeSet.py | 5 --- .../ReasoningController/PropositionSet.py | 9 ---- .../modules/ReasoningController/RuleNode.py | 3 -- .../modules/ReasoningController/Runner.py | 45 ------------------- .../ReasoningController/Substitutions.py | 5 --- .../modules/ReasoningController/supportSet.py | 5 --- .../core/modules/network/mind_controller.py | 0 9 files changed, 84 deletions(-) delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py delete mode 100644 code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py deleted file mode 100644 index c80e07f..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Matcher.py +++ /dev/null @@ -1,7 +0,0 @@ -class Matcher(): - def __init__(self) -> None: - pass - def Match(): - pass - def getMatchType(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py deleted file mode 100644 index 2621658..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/MindGRAFController.py +++ /dev/null @@ -1,5 +0,0 @@ -class MindGRAFController(): - def __init__(self) -> None: - pass - def getContextName(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py deleted file mode 100644 index a31ff68..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/NodeSet.py +++ /dev/null @@ -1,5 +0,0 @@ -class NodeSet(): - def __init__(self) -> None: - pass - def getDownAnt(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py deleted file mode 100644 index 59fd62a..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/PropositionSet.py +++ /dev/null @@ -1,9 +0,0 @@ -class PropositionSet(): - - propositions = {} - - def __init__(self) -> None: - pass - - def addProp(node): - PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py deleted file mode 100644 index 7c836a4..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/RuleNode.py +++ /dev/null @@ -1,3 +0,0 @@ -class RuleNode(): - def __init__(self) -> None: - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py deleted file mode 100644 index a64c19e..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Runner.py +++ /dev/null @@ -1,45 +0,0 @@ -from itertools import count -from lib2to3.pytree import Node -from queue import Empty -from Channel import Channel -from Proposition import Proposition - - -class Runner(): - - global highQ - highQ = [] - global lowQ - lowQ = [] - global actQ - actQ = [] - - def run(): - while(highQ.count != 0 or lowQ.count != 0 or actQ.count != 0): - while(highQ.count != 0): - print("In HighQ") - runNext = highQ.pop(0) - print(runNext) - Proposition.processReports(runNext) - - while(lowQ.count != 0): - print("In LowQ") - runNext = lowQ.pop(0) - print(runNext) - runNext = Channel("Node.getSource","Node.getDest","Node.getType","Node.getCont") - if highQ: - Runner.run() - - while(actQ.count != 0): - print("In ActQ") - runNext = actQ.pop() - print(runNext) - if highQ and lowQ: - Runner.run() - - def addToHighQ(node): - highQ.append(node) - def addToLowQ(node): - lowQ.append(node) - def addToActQ(node): - actQ.append(node) \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py deleted file mode 100644 index 09af52d..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/Substitutions.py +++ /dev/null @@ -1,5 +0,0 @@ -class Substitutions(): - def __init__(self) -> None: - pass - def getSubs(): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py b/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py deleted file mode 100644 index 1209bdf..0000000 --- a/code/core/modules/ReasoningController/code/core/modules/ReasoningController/supportSet.py +++ /dev/null @@ -1,5 +0,0 @@ -class supportSet(): - def __init__(self,support): - support = [] - def getId(node): - pass \ No newline at end of file diff --git a/code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py b/code/core/modules/ReasoningController/code/core/modules/network/mind_controller.py deleted file mode 100644 index e69de29..0000000 From 302e96f6cbda3e848f097c104252d46b6b486d5e Mon Sep 17 00:00:00 2001 From: AmrLamei Date: Thu, 26 May 2022 04:02:55 +0200 Subject: [PATCH 20/25] commit-v3 --- Bindings.py | 4 ++++ Channel.py | 37 +++++++++++++++++++------------------ ChannelSet.py | 8 ++++---- Filter.py | 19 +++++++++++++------ Instance.py | 3 +++ KnownInstances.py | 14 +++++++------- Proposition.py | 12 +++++++++--- PropositionSet.py | 2 +- ReasoningController.py | 23 ++++++++++++----------- Report.py | 23 +++++++++++++---------- ReportSet.py | 4 ++-- Runner.py | 6 +++--- Switch.py | 5 +++-- 13 files changed, 93 insertions(+), 67 deletions(-) create mode 100644 Bindings.py diff --git a/Bindings.py b/Bindings.py new file mode 100644 index 0000000..a5ac331 --- /dev/null +++ b/Bindings.py @@ -0,0 +1,4 @@ +class Bindings() + +def __init__(self): + pass \ No newline at end of file diff --git a/Channel.py b/Channel.py index d3c0816..90ace4a 100644 --- a/Channel.py +++ b/Channel.py @@ -6,18 +6,19 @@ from ReportSet import ReportSet from Switch import Switch import ChannelType +from Substitutions import Substitutions class Channel: global count count = 0 global filter - filter = Filter() + filter: Filter global switch - switch = Switch() + switch: Switch global reportBuffer - reportBuffer = ReportSet() + reportBuffer: ReportSet - def __init__ (channel,id,source,destination,status,type,context): + def __init__ (channel,id,source: Node,destination: Node,status: bool ,type: String ,context: Context): channel.id = count channel.source = source channel.destination = destination @@ -26,7 +27,7 @@ def __init__ (channel,id,source,destination,status,type,context): channel.context = context count +1 - def reportToSend(self,report): + def reportToSend(self,report: Report): canPass = filter.canPass(report) if canPass: # and isAsserted(report) Switch.switchReport(report) @@ -34,44 +35,44 @@ def reportToSend(self,report): Proposition.recieveReport(self) self.getReportsBuffer().addReport(report) - def getId(channel): + def getId(channel: Channel): return channel.id - def setSubstitution(channel,substitution): + def setSubstitution(channel: Channel,substitution: Substitutions): channel.substitution = substitution - def getSupport(channel): + def getSupport(channel: Channel): return channel.support - def getFilter(channel): + def getFilter(channel: Channel): return channel.filter - def getType(channel): + def getType(channel: Channel): return channel.type - def setFilter(channel,filter): + def setFilter(channel: Channel,filter: Filter): channel.filter = filter - def getDestination(channel): + def getDestination(channel: Channel): return channel.destination - def setDestination(channel,destination): + def setDestination(channel: Channel,destination: Node): channel.destination = destination - def getSource(channel): + def getSource(channel: Channel): return channel.source - def setSource(channel,source): + def setSource(channel: Channel,source: Node): channel.source = source - def setReportsBuffer(self,reportsBuffer): + def setReportsBuffer(self,reportsBuffer: ReportSet): self.reportsBuffer = reportBuffer def getReportsBuffer(): return reportBuffer - def clearReportsBuffer(self,reportsBuffer): + def clearReportsBuffer(self,reportsBuffer: ReportSet): self.getReportsBuffer().clearReports() - def getContext(channel): + def getContext(channel: Channel): return channel.context \ No newline at end of file diff --git a/ChannelSet.py b/ChannelSet.py index 94160f1..e146d73 100644 --- a/ChannelSet.py +++ b/ChannelSet.py @@ -2,7 +2,7 @@ import ChannelType class ChannelSet(Channel): - def __init__(channel,id,filter,switch,source,destination,status,type): + def __init__(channel: Channel,id,filter: Filter ,switch: Switch,source: Node ,destination: Node,status: bool,type): global channels super().__init__(id,filter,switch,source,destination,status,type) MatchedChannels = { @@ -15,21 +15,21 @@ def __init__(channel,id,filter,switch,source,destination,status,type): 'RuleToCons' : channel } - def addChannel(channel): + def addChannel(channel: Channel): channelSourceId = channel.source.id channelDestinationId= channel.destination.id filtersubs = channel.filter.substitutions switchsubs = channel.channel.substitutions channelType = channel.getChannelType(channel) - def removeChannel(channel): + def removeChannel(channel: Channel): channelSourceId = channel.source.id channelDestinationId= channel.destination.id filtersubs = channel.filter.substitutions switchsubs = channel.channel.substitutions channelType = channel.getChannelType(channel) - def getChannelType(channel): + def getChannelType(channel: Channel): channeltype ='' if (ChannelType.RULEANT): channeltype = 'AntecedentToRule Channel' diff --git a/Filter.py b/Filter.py index c2c1f35..9599eef 100644 --- a/Filter.py +++ b/Filter.py @@ -1,13 +1,20 @@ +from Report import report class Filter: - def __init__(filter,report): + def __init__(filter: Filter,report: Report): filter.report = report - def canPass(report): - if True: - return True - else: - return False + def canPass(report: Report,attitude: Node): + for i in self.substitution.cardinality(): + currentFilterBinding: Bindings + currentFilterBinding = substitution.getBinding(i) + currentReportBinding: Bindings + currentReportBinding = report.getSubstitutions().getBindingByVariable(currentFilterBinding.getVariable()) + System.out.println("Bindings " + currentFilterBinding + " " + report.getSubstitutions()) + if currentReportBinding is not None and currentFilterBinding.getNode() is not currentReportBinding.getNode() and report.attitude is not attitude : + return false + + return true #x = Filter(1) #print(x.canPass()) diff --git a/Instance.py b/Instance.py index e69de29..fe60e97 100644 --- a/Instance.py +++ b/Instance.py @@ -0,0 +1,3 @@ +class Instance(): + def __init__(): + pass \ No newline at end of file diff --git a/KnownInstances.py b/KnownInstances.py index 62cb465..1af6f3e 100644 --- a/KnownInstances.py +++ b/KnownInstances.py @@ -1,19 +1,19 @@ -from Report import report +from Report import Report from ReportSet import reportSet from Substitutions import Substitutions from Substitutions import Substitutions -class KnownInstances(report): +class KnownInstances(Report): global knowninstances knowninstances = { 'Substitutions' : reportSet } - def __init__(knowninstances,substitution, support,source,destination): + def __init__(knowninstances: KnownInstances ,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node): super.__init__(substitution, support,source,destination) - def addReport(report): - reportSubs = Substitutions + def addReport(report: Report): + reportSubs: Substitutions reportSubs = report report.getSubstitution() reportSet = knowninstances.pop(reportSubs) @@ -23,8 +23,8 @@ def addReport(report): knowninstances.update(reportSubs,reportSet) - def getReportBySubs(Subs): + def getReportBySubs(Subs: Substitutions): return knowninstances.get('Substitutions') - def getSubstitution(report): + def getSubstitution(report: Report): pass diff --git a/Proposition.py b/Proposition.py index bf68222..e40b561 100644 --- a/Proposition.py +++ b/Proposition.py @@ -9,9 +9,9 @@ import supportSet class Proposition(): global outgoingChannels - outgoingChannels = ChannelSet + outgoingChannels: ChannelSet global incomingChannels - incomingChannels = ChannelSet + incomingChannels: ChannelSet global supports supports = supportSet @@ -23,8 +23,14 @@ def processReports(): for x in incomingChannels: ReasoningController.ProcessReportChannel(x) - def recieveReport(channel): + def recieveReport(channel: Channel): Runner.addToHighQ(channel) + + def addToOutgoingChannels(channel: Channel): + outgoingChannels.addChannel(channel) + + def addToIncomingChannels(channel: Channel): + incomingChannels.addChannel(channel) #Attributes class (supportSet, channelSet) \ No newline at end of file diff --git a/PropositionSet.py b/PropositionSet.py index 59fd62a..c17a532 100644 --- a/PropositionSet.py +++ b/PropositionSet.py @@ -5,5 +5,5 @@ class PropositionSet(): def __init__(self) -> None: pass - def addProp(node): + def addProp(node: Node): PropositionSet.propositions.add(node) \ No newline at end of file diff --git a/ReasoningController.py b/ReasoningController.py index 8ac5e97..2502825 100644 --- a/ReasoningController.py +++ b/ReasoningController.py @@ -31,9 +31,9 @@ def CheckCompatiableSubstitution (): type: inference type BackwardChain or ForwardChain """ - def Request (source,destination,status,type,context): + def Request (source: Node,destination: Node,status: bool,type,context: Context): request = Channel(source,destination,status,type,context) - def SendReport(report,channel): + def SendReport(report: Report,channel: Channel): channel = Channel if channel.reportToSend(report): print("Report:", report , "was sent from" , channel.getSource(), "to", channel.getDestination ) @@ -41,19 +41,20 @@ def SendReport(report,channel): print("Report:", report , "could not be sent from" , channel.getSource(), "to", channel.getDestination ) channel.clearReportsBuffer() - def AddToKnownInstances(report): + def AddToKnownInstances(report: Report): instances = KnownInstances instances.addReport(report) - def ForwardChain(report): + def ForwardChain(node: Node, context: Context, attitude: Node): Runner.run() report = Report contextName = MindGRAFController.get ReasoningController.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "FORWARD" ,report.getSource,report.getDestination) ReasoningController.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "FORWARD" ,report.getSource,report.getDestination) - def BackwardChain(report): - pass - def ProcessReportChannel(channel): + return "nodeSet" + def BackwardChain(node: Node, context: Context, attitude: Node): + return "nodeSet" + def ProcessReportChannel(channel: Channel): channel = Channel reports = Report reports = [channel.getReportsBuffer] @@ -71,7 +72,7 @@ def ProcessReportChannel(channel): channel.clearReportsBuffer - def getNodesToSendReport(self,type, context, substitutions, inferenceType,source,destination): + def getNodesToSendReport(self,type, context: Context, substitutions: Substitutions, inferenceType,source: Node,destination: Node): suppSet = supportSet() suppSet.add(suppSet.getId()) report = Report(substitutions,suppSet,inferenceType,source,destination) @@ -86,7 +87,7 @@ def getNodesToSendReport(self,type, context, substitutions, inferenceType,source ReasoningController.sendReportToNodeSet(antNodes,report,context,type) - def sendReportToMatches(matched,report,context): + def sendReportToMatches(matched: Matcher,report: Report,context: Context): for currentMatch in matched: reportSubs= Substitutions reportSubs.getSubs() @@ -95,12 +96,12 @@ def sendReportToMatches(matched,report,context): newChannel = Channel(currentMatch,"destinaion","status",ChannelType.MATCHED,context) ReasoningController.sendReport(report,newChannel) - def sendReportToNodeSet(nodeSet, report, context, type,source, destination): + def sendReportToNodeSet(nodeSet: NodeSet, report: Report, context: Context, type,source: Node, destination: Node): for sent in nodeSet: report = Report reportSubs = report.getSubstitution() newChannel = Channel(source,destination,type,"status",type,context) ReasoningController.SendReport(report,newChannel) - def isAsserted(context): + def isAsserted(context: Context): pass diff --git a/Report.py b/Report.py index 2de0d4c..8f3589f 100644 --- a/Report.py +++ b/Report.py @@ -1,36 +1,39 @@ +from Substitutions import Substitutions class Report: - def __init__(report,substitution,support,inference,source,destination): + def __init__(report: Report,substitution: Substitutions,support: supportSet,inference: str,source: Node, + destination: Node,attitude: Node): report.substitution = substitution report.support = support report.inference = inference report.destination = destination report.source = source + report.attitude = attitude - def getSubstitution(report): + def getSubstitution(report: Report): return report.substitution - def setSubstitution(report,substitution): + def setSubstitution(report: Report,substitution: Substitutions): report.substitution = substitution - def getSupport(report): + def getSupport(report: Report): return report.support - def getInference(report): + def getInference(report): Report: return report.inference - def setInference(report,inference): + def setInference(report: Report,inference: str): report.inference = inference - def getDestination(report): + def getDestination(report: Report): return report.destination - def setDestination(report,destination): + def setDestination(report: Report,destination: Node): report.destination = destination - def getSource(report): + def getSource(report: Report): return report.source - def setSource(report,source): + def setSource(report: Report,source: Node): report.source = source #report = Report(15,5,5,5,5) diff --git a/ReportSet.py b/ReportSet.py index 8a67880..4c2d359 100644 --- a/ReportSet.py +++ b/ReportSet.py @@ -7,13 +7,13 @@ class ReportSet(Report): def __innit__(self): pass - def addReport(reports,report): + def addReport(reports,report: Report): reports.append(report) def clearReports(reports): reports.clear() - def removeReport(reports,report): + def removeReport(reports,report: Report): reports.remove(report) def iterator(reports): diff --git a/Runner.py b/Runner.py index a64c19e..95b69b3 100644 --- a/Runner.py +++ b/Runner.py @@ -37,9 +37,9 @@ def run(): if highQ and lowQ: Runner.run() - def addToHighQ(node): + def addToHighQ(node: Node): highQ.append(node) - def addToLowQ(node): + def addToLowQ(node: Node): lowQ.append(node) - def addToActQ(node): + def addToActQ(node: Node): actQ.append(node) \ No newline at end of file diff --git a/Switch.py b/Switch.py index a7ae599..f08f8ae 100644 --- a/Switch.py +++ b/Switch.py @@ -1,8 +1,9 @@ +from Report import Report class Switch(): - def __init__(switch,report): + def __init__(switch: Switch,report: Report): switch.report = report - def switchReport(report): + def switchReport(report: Report): pass #x=Switch(1) #print(x.switchReport()) \ No newline at end of file From 08f0546a0cbf5060341a3e32072500b7e3f7c1b1 Mon Sep 17 00:00:00 2001 From: AmrLamei Date: Thu, 2 Jun 2022 04:03:35 +0200 Subject: [PATCH 21/25] commit-v3 --- Channel.py | 8 +++- Filter.py | 6 +-- KnownInstances.py | 16 ++++---- Proposition.py | 17 +++++---- ReasoningController.py | 82 +++++++++++++++++++++++++++++------------ Report.py | 84 ++++++++++++++++++++++++------------------ ReportSet.py | 4 +- Runner.py | 2 +- 8 files changed, 137 insertions(+), 82 deletions(-) diff --git a/Channel.py b/Channel.py index 90ace4a..e4fa4d5 100644 --- a/Channel.py +++ b/Channel.py @@ -18,7 +18,7 @@ class Channel: global reportBuffer reportBuffer: ReportSet - def __init__ (channel,id,source: Node,destination: Node,status: bool ,type: String ,context: Context): + def __init__ (channel,id,source: Node,destination: Node,status: bool ,type: str ,context: Context): channel.id = count channel.source = source channel.destination = destination @@ -29,11 +29,15 @@ def __init__ (channel,id,source: Node,destination: Node,status: bool ,type: Stri def reportToSend(self,report: Report): canPass = filter.canPass(report) - if canPass: # and isAsserted(report) + if canPass: # and isSupported(report) Switch.switchReport(report) requester = self.getSource() Proposition.recieveReport(self) self.getReportsBuffer().addReport(report) + return true + + return false + def getId(channel: Channel): return channel.id diff --git a/Filter.py b/Filter.py index 9599eef..f3c0dac 100644 --- a/Filter.py +++ b/Filter.py @@ -4,10 +4,10 @@ class Filter: def __init__(filter: Filter,report: Report): filter.report = report - def canPass(report: Report,attitude: Node): - for i in self.substitution.cardinality(): + def canPass(report: Report,attitude: str): + for x in self.substitution.cardinality(): currentFilterBinding: Bindings - currentFilterBinding = substitution.getBinding(i) + currentFilterBinding = substitution.getBinding(x) currentReportBinding: Bindings currentReportBinding = report.getSubstitutions().getBindingByVariable(currentFilterBinding.getVariable()) System.out.println("Bindings " + currentFilterBinding + " " + report.getSubstitutions()) diff --git a/KnownInstances.py b/KnownInstances.py index 1af6f3e..8ea8b8f 100644 --- a/KnownInstances.py +++ b/KnownInstances.py @@ -8,23 +8,23 @@ class KnownInstances(Report): 'Substitutions' : reportSet } - def __init__(knowninstances: KnownInstances ,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node): - super.__init__(substitution, support,source,destination) + def __init__(self,knowninstances: KnownInstances ,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node,attitude: str): + super.__init__(substitution, support,source,destination,attitude) - def addReport(report: Report): + def addReport(self,report: Report): reportSubs: Substitutions reportSubs = report report.getSubstitution() - reportSet = knowninstances.pop(reportSubs) + reportSet = self.pop(reportSubs) if reportSet == None: reportSet = [] reportSet.append(report) - knowninstances.update(reportSubs,reportSet) + self.update(reportSubs,reportSet) - def getReportBySubs(Subs: Substitutions): - return knowninstances.get('Substitutions') + def getReportBySubs(self): + return self.getSubstitution() - def getSubstitution(report: Report): + def getSubstitution(self,report: Report): pass diff --git a/Proposition.py b/Proposition.py index e40b561..8be4eb8 100644 --- a/Proposition.py +++ b/Proposition.py @@ -7,29 +7,32 @@ import ChannelSet import supportSet -class Proposition(): +class Proposition(Entity): global outgoingChannels outgoingChannels: ChannelSet global incomingChannels incomingChannels: ChannelSet global supports - supports = supportSet + supports: supportSet - def __init__(self): - pass + def __init__(self,outgoingChannels: ChannelSet,incomingChannels: ChannelSet,supports: supportSet): + self.outgoingChannels = outgoingChannels + self.incomingChannels = incomingChannels + self.supports = supports + def processReports(): for x in incomingChannels: ReasoningController.ProcessReportChannel(x) - def recieveReport(channel: Channel): + def recieveReport(self,channel: Channel): Runner.addToHighQ(channel) - def addToOutgoingChannels(channel: Channel): + def addToOutgoingChannels(self, channel: Channel): outgoingChannels.addChannel(channel) - def addToIncomingChannels(channel: Channel): + def addToIncomingChannels(self, channel: Channel): incomingChannels.addChannel(channel) diff --git a/ReasoningController.py b/ReasoningController.py index 2502825..7339508 100644 --- a/ReasoningController.py +++ b/ReasoningController.py @@ -14,8 +14,10 @@ from RuleNode import RuleNode from NodeSet import NodeSet from Runner import Runner +from Context import Context from MindGRAFController import MindGRAFController class ReasoningController: + global knownInstances= KnownInstances() def ApplySubstitution (): pass def CheckCompatiableSubstitution (): @@ -31,34 +33,36 @@ def CheckCompatiableSubstitution (): type: inference type BackwardChain or ForwardChain """ - def Request (source: Node,destination: Node,status: bool,type,context: Context): + def Request (self,source: Node,destination: Node,status: bool,type,context: Context): request = Channel(source,destination,status,type,context) - def SendReport(report: Report,channel: Channel): - channel = Channel + Runner.addToLowQ(request) + def SendReport(self,report: Report,channel: Channel): if channel.reportToSend(report): print("Report:", report , "was sent from" , channel.getSource(), "to", channel.getDestination ) else: print("Report:", report , "could not be sent from" , channel.getSource(), "to", channel.getDestination ) channel.clearReportsBuffer() - def AddToKnownInstances(report: Report): - instances = KnownInstances - instances.addReport(report) + def AddToKnownInstances(self,channel: Channel,report: Report): + knownInstances.addReport(report) - def ForwardChain(node: Node, context: Context, attitude: Node): + def ForwardChain(self,node: Node, context: Context, attitude: str): Runner.run() - report = Report - contextName = MindGRAFController.get - ReasoningController.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "FORWARD" ,report.getSource,report.getDestination) - ReasoningController.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "FORWARD" ,report.getSource,report.getDestination) + contextName = MindGRAFController.getContext() + self.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "FORWARD" ,None,None) + self.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "FORWARD" ,None,None) + #CheckContradiction("Built node: Node") after building return "nodeSet" - def BackwardChain(node: Node, context: Context, attitude: Node): + def BackwardChain(self, node: Node, context: Context, attitude: str): + Runner.run() + contextName = MindGRAFController.getContext() + self.getNodesToSendReport(ChannelType.RULEANT, contextName, None, "BACKWARD" ,None,None) + self.getNodesToSendReport(ChannelType.MATCHED, contextName, None, "BACKWARD" ,None,None) return "nodeSet" - def ProcessReportChannel(channel: Channel): - channel = Channel - reports = Report + def ProcessReportsChannel(self, channel: Channel): + reports: Report reports = [channel.getReportsBuffer] - currReport = Report + currReport: Report for currReport in reports: report = Report(currReport.getSubstitution,currReport.getSupport,currReport.getInference,currReport.getSource,currReport.getDestination) knownInstances = KnownInstances @@ -70,9 +74,39 @@ def ProcessReportChannel(channel: Channel): outChannel.addReport(report) channel.clearReportsBuffer channel.clearReportsBuffer + def processRequestsChannel(self, channel: Channel): + str currentContextName = channel.getContext() + desiredContext: Context + desiredContext = currentContextName + attitude = desiredContext.getAttitude() + if(isSupported(desiredContext)): + int propNodeId = getId() + supportPropSet = PropositionSet() + supportPropSet = supportPropSet.add(propNodeId) + reply = Report("subs".supportPropSet,"BACKWARD",None,None,attitude) + self.sendReport(reply,channel) + else + bool sentAtLeastOne = false + currentReport: Report + for(currentReport : knownInstances): + sentAtLeastOne |= sendReport(currentReport, channel) + filterSubs = channel.getFilter().getSubstitutions() + if(not sentAtLeastOne): + dominatingRules: NodeSet + dominatingRules=getUpConsNodeSet() + toBeSentToDom: NodeSet + toBeSentToDom = self.removeAlreadyWorkingOn(dominatingRules,channel,filterSubs,false) + self.sendRequestsToNodeSet(toBeSentToDom,filterSubs,currentContextName,ChannelTypes.RULEANT) + if(not(isinstance(currentChannel,MatchChannel)): + matchingNodes: Matcher + matchingNodes.match(this,filterSubs) + toBeSentToMatch: Matcher + toBeSentToMatch = self.removeAlreadyWorkingOn(matchingNodes,channel) + self.sendRequestsToMatches(toBeSentToMatch,currentContextName) + - def getNodesToSendReport(self,type, context: Context, substitutions: Substitutions, inferenceType,source: Node,destination: Node): + def getNodesToSendReport(self,type, context: Context, substitutions: Substitutions, inferenceType: str ,source: Node,destination: Node): suppSet = supportSet() suppSet.add(suppSet.getId()) report = Report(substitutions,suppSet,inferenceType,source,destination) @@ -80,28 +114,28 @@ def getNodesToSendReport(self,type, context: Context, substitutions: Substitutio case 'MATCHED': matches = [Matcher.Match] if matches: - ReasoningController.sendReportToMatches(matches,report,context) + self.sendReportToMatches(matches,report,context) case 'RULEANT': if isinstance(self,RuleNode): antNodes = NodeSet.getDownAnt() - ReasoningController.sendReportToNodeSet(antNodes,report,context,type) + self.sendReportToNodeSet(antNodes,report,context,type) - def sendReportToMatches(matched: Matcher,report: Report,context: Context): + def sendReportToMatches(self,matched: Matcher,report: Report,context: Context): for currentMatch in matched: reportSubs= Substitutions reportSubs.getSubs() currentMatch = Matcher #matchType = currentMatch.getMatchType() newChannel = Channel(currentMatch,"destinaion","status",ChannelType.MATCHED,context) - ReasoningController.sendReport(report,newChannel) + self.sendReport(report,newChannel) - def sendReportToNodeSet(nodeSet: NodeSet, report: Report, context: Context, type,source: Node, destination: Node): + def sendReportToNodeSet(nself,nodeSet: NodeSet, report: Report, context: Context, type: str,source: Node, destination: Node): for sent in nodeSet: report = Report reportSubs = report.getSubstitution() newChannel = Channel(source,destination,type,"status",type,context) - ReasoningController.SendReport(report,newChannel) + self.SendReport(report,newChannel) - def isAsserted(context: Context): + def isSupported(self,context: Context): pass diff --git a/Report.py b/Report.py index 8f3589f..3979d1d 100644 --- a/Report.py +++ b/Report.py @@ -1,40 +1,54 @@ from Substitutions import Substitutions class Report: - def __init__(report: Report,substitution: Substitutions,support: supportSet,inference: str,source: Node, - destination: Node,attitude: Node): - report.substitution = substitution - report.support = support - report.inference = inference - report.destination = destination - report.source = source - report.attitude = attitude - - def getSubstitution(report: Report): - return report.substitution - - def setSubstitution(report: Report,substitution: Substitutions): - report.substitution = substitution - - def getSupport(report: Report): - return report.support - - def getInference(report): Report: - return report.inference - - def setInference(report: Report,inference: str): - report.inference = inference - - def getDestination(report: Report): - return report.destination - - def setDestination(report: Report,destination: Node): - report.destination = destination - - def getSource(report: Report): - return report.source - - def setSource(report: Report,source: Node): - report.source = source + def __init__(self,substitution: Substitutions,support: supportSet,inference: str,source: Node, + destination: Node,attitude: str): + self.substitution = substitution + self.support = support + self.inference = inference + self.destination = destination + self.source = source + self.attitude = attitude + + def getSubstitution(self): + return self.substitution + + def setSubstitution(self,substitution: Substitutions): + self.substitution = substitution + + def getSupport(self): + return self.support + + def getInference(self): + return self.inference + + def setInference(self,inference: str): + self.inference = inference + + def getDestination(self): + return self.destination + + def setDestination(self,destination: Node): + self.destination = destination + + def getSource(self): + return self.source + + def setSource(self,source: Node): + self.source = source + + def computeReportFromDifferencesToSend(self,report: Report): + instanceInfType = self.getInferenceType() + reportInfType = report.getInferenceType() + instanceSupport = self.getSupport() + reportSupport = report.getSupport() + bool supportCheck = instanceSupport is reportSupport + if(instanceInfType == "BACKWARD" and reportInfType == "FORWARD"): + return report + else if(not supportCheck): + if(instanceInfType == "FORWARD" and reportInfType == "BACKWARD") + report.setInferenceType("FORWARD") + return report + return None #report = Report(15,5,5,5,5) #print(report.getSubstitution()) \ No newline at end of file diff --git a/ReportSet.py b/ReportSet.py index 4c2d359..7a73d9e 100644 --- a/ReportSet.py +++ b/ReportSet.py @@ -4,8 +4,8 @@ import Report class ReportSet(Report): reports = [] - def __innit__(self): - pass + def __innit__(self,reports: Report): + self.reports = [] def addReport(reports,report: Report): reports.append(report) diff --git a/Runner.py b/Runner.py index 95b69b3..b859055 100644 --- a/Runner.py +++ b/Runner.py @@ -34,7 +34,7 @@ def run(): print("In ActQ") runNext = actQ.pop() print(runNext) - if highQ and lowQ: + if highQ or lowQ: Runner.run() def addToHighQ(node: Node): From ac59f279d4fd96602a3a5d0b504745b10a728b6b Mon Sep 17 00:00:00 2001 From: AmrLam3y Date: Thu, 2 Jun 2022 04:59:03 +0200 Subject: [PATCH 22/25] commit-v3 --- Bindings.py | 8 ++++-- Channel.py | 65 ++++++++++++++++++++++-------------------- ChannelSet.py | 3 ++ Filter.py | 21 +++++++------- KnownInstances.py | 6 +++- ReasoningController.py | 2 -- Report.py | 9 ++++-- ReportSet.py | 2 -- Switch.py | 18 +++++++++--- 9 files changed, 78 insertions(+), 56 deletions(-) diff --git a/Bindings.py b/Bindings.py index a5ac331..c3421f4 100644 --- a/Bindings.py +++ b/Bindings.py @@ -1,4 +1,6 @@ -class Bindings() +class Bindings(): -def __init__(self): - pass \ No newline at end of file + def __init__(self): + pass + def getBinding(): + pass \ No newline at end of file diff --git a/Channel.py b/Channel.py index e4fa4d5..4ecc8b2 100644 --- a/Channel.py +++ b/Channel.py @@ -7,6 +7,9 @@ from Switch import Switch import ChannelType from Substitutions import Substitutions +from Node import Node +from Context import Context +from Report import Report class Channel: global count @@ -18,13 +21,13 @@ class Channel: global reportBuffer reportBuffer: ReportSet - def __init__ (channel,id,source: Node,destination: Node,status: bool ,type: str ,context: Context): - channel.id = count - channel.source = source - channel.destination = destination - channel.status = status - channel.type = type - channel.context = context + def __init__ (self,id,source: Node,destination: Node,status: bool ,type: str ,context: Context): + self.id = count + self.source = source + self.destination = destination + self.status = status + self.type = type + self.context = context count +1 def reportToSend(self,report: Report): @@ -34,40 +37,40 @@ def reportToSend(self,report: Report): requester = self.getSource() Proposition.recieveReport(self) self.getReportsBuffer().addReport(report) - return true + return True - return false + return False - def getId(channel: Channel): - return channel.id + def getId(self): + return self.id - def setSubstitution(channel: Channel,substitution: Substitutions): - channel.substitution = substitution + def setSubstitution(self,substitution: Substitutions): + self.substitution = substitution - def getSupport(channel: Channel): - return channel.support + def getSupport(self): + return self.support - def getFilter(channel: Channel): - return channel.filter + def getFilter(self): + return self.filter - def getType(channel: Channel): - return channel.type + def getType(self): + return self.type - def setFilter(channel: Channel,filter: Filter): - channel.filter = filter + def setFilter(self,filter: Filter): + self.filter = filter - def getDestination(channel: Channel): - return channel.destination + def getDestination(self): + return self.destination - def setDestination(channel: Channel,destination: Node): - channel.destination = destination + def setDestination(self,destination: Node): + self.destination = destination - def getSource(channel: Channel): - return channel.source + def getSource(self): + return self.source - def setSource(channel: Channel,source: Node): - channel.source = source + def setSource(self,source: Node): + self.source = source def setReportsBuffer(self,reportsBuffer: ReportSet): self.reportsBuffer = reportBuffer @@ -78,5 +81,5 @@ def getReportsBuffer(): def clearReportsBuffer(self,reportsBuffer: ReportSet): self.getReportsBuffer().clearReports() - def getContext(channel: Channel): - return channel.context \ No newline at end of file + def getContext(self): + return self.context \ No newline at end of file diff --git a/ChannelSet.py b/ChannelSet.py index e146d73..d84ce5e 100644 --- a/ChannelSet.py +++ b/ChannelSet.py @@ -1,4 +1,7 @@ from Channel import Channel +from Filter import Filter +from Switch import Switch +from Node import Node import ChannelType class ChannelSet(Channel): diff --git a/Filter.py b/Filter.py index f3c0dac..22f93d1 100644 --- a/Filter.py +++ b/Filter.py @@ -1,20 +1,21 @@ -from Report import report +from Report import Report +from Bindings import Bindings +from Substitutions import Substitutions class Filter: - def __init__(filter: Filter,report: Report): - filter.report = report + def __init__(self,report: Report): + self.report = report - def canPass(report: Report,attitude: str): + def canPass(self,report: Report,attitude: str): for x in self.substitution.cardinality(): currentFilterBinding: Bindings - currentFilterBinding = substitution.getBinding(x) + currentFilterBinding = Substitutions.getBinding(x) currentReportBinding: Bindings currentReportBinding = report.getSubstitutions().getBindingByVariable(currentFilterBinding.getVariable()) - System.out.println("Bindings " + currentFilterBinding + " " + report.getSubstitutions()) - if currentReportBinding is not None and currentFilterBinding.getNode() is not currentReportBinding.getNode() and report.attitude is not attitude : - return false - - return true + print("Bindings " + currentFilterBinding + " " + report.getSubstitutions()) + if (currentReportBinding is not None and currentFilterBinding.getNode() is not currentReportBinding.getNode() and report.attitude is not attitude) : + return False + return True #x = Filter(1) #print(x.canPass()) diff --git a/KnownInstances.py b/KnownInstances.py index 8ea8b8f..bf07d08 100644 --- a/KnownInstances.py +++ b/KnownInstances.py @@ -2,13 +2,17 @@ from ReportSet import reportSet from Substitutions import Substitutions from Substitutions import Substitutions +from supportSet import supportSet +from Node import Node + + class KnownInstances(Report): global knowninstances knowninstances = { 'Substitutions' : reportSet } - def __init__(self,knowninstances: KnownInstances ,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node,attitude: str): + def __init__(self,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node,attitude: str): super.__init__(substitution, support,source,destination,attitude) diff --git a/ReasoningController.py b/ReasoningController.py index 7339508..0bf3d52 100644 --- a/ReasoningController.py +++ b/ReasoningController.py @@ -104,8 +104,6 @@ def processRequestsChannel(self, channel: Channel): toBeSentToMatch = self.removeAlreadyWorkingOn(matchingNodes,channel) self.sendRequestsToMatches(toBeSentToMatch,currentContextName) - - def getNodesToSendReport(self,type, context: Context, substitutions: Substitutions, inferenceType: str ,source: Node,destination: Node): suppSet = supportSet() suppSet.add(suppSet.getId()) diff --git a/Report.py b/Report.py index 3979d1d..d4eb3e8 100644 --- a/Report.py +++ b/Report.py @@ -1,4 +1,7 @@ from Substitutions import Substitutions +from supportSet import supportSet +from Node import Node +from Report import Report class Report: def __init__(self,substitution: Substitutions,support: supportSet,inference: str,source: Node, destination: Node,attitude: str): @@ -41,11 +44,11 @@ def computeReportFromDifferencesToSend(self,report: Report): reportInfType = report.getInferenceType() instanceSupport = self.getSupport() reportSupport = report.getSupport() - bool supportCheck = instanceSupport is reportSupport + supportCheck = instanceSupport is reportSupport if(instanceInfType == "BACKWARD" and reportInfType == "FORWARD"): return report - else if(not supportCheck): - if(instanceInfType == "FORWARD" and reportInfType == "BACKWARD") + elif(not supportCheck): + if(instanceInfType == "FORWARD" and reportInfType == "BACKWARD"): report.setInferenceType("FORWARD") return report return None diff --git a/ReportSet.py b/ReportSet.py index 7a73d9e..782a439 100644 --- a/ReportSet.py +++ b/ReportSet.py @@ -1,7 +1,5 @@ from Report import Report - -import Report class ReportSet(Report): reports = [] def __innit__(self,reports: Report): diff --git a/Switch.py b/Switch.py index f08f8ae..9f2b028 100644 --- a/Switch.py +++ b/Switch.py @@ -1,9 +1,19 @@ +from Bindings import Bindings from Report import Report +from Substitutions import Substitutions class Switch(): - def __init__(switch: Switch,report: Report): - switch.report = report + def __init__(self,substitutions: Substitutions): + self.substitutions = substitutions - def switchReport(report: Report): - pass + def switchReport(self,report: Report): + subs = self.substitutions.cardinality() + for x in range(subs): + bindings: Bindings + bindings = report.getSubstitution().getBinding() + if(bindings is not None): + bindings.setVariable() + else: + report.getSubstitution() + #x=Switch(1) #print(x.switchReport()) \ No newline at end of file From 69e47b15de1830fa63907ffad1482adf2aef782e Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:05:48 +0200 Subject: [PATCH 23/25] Update Channel.py --- Channel.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Channel.py b/Channel.py index 4ecc8b2..8ca2f0b 100644 --- a/Channel.py +++ b/Channel.py @@ -1,6 +1,3 @@ -from multiprocessing import context -import re -from urllib import request from Filter import Filter from Proposition import Proposition from ReportSet import ReportSet @@ -82,4 +79,4 @@ def clearReportsBuffer(self,reportsBuffer: ReportSet): self.getReportsBuffer().clearReports() def getContext(self): - return self.context \ No newline at end of file + return self.context From 9ab3de4ab30221886fd1964dc231af1fc6a518b0 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:09:57 +0200 Subject: [PATCH 24/25] Update ReasoningController.py --- ReasoningController.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReasoningController.py b/ReasoningController.py index 0bf3d52..a353999 100644 --- a/ReasoningController.py +++ b/ReasoningController.py @@ -137,3 +137,7 @@ def sendReportToNodeSet(nself,nodeSet: NodeSet, report: Report, context: Context def isSupported(self,context: Context): pass + + #def removeworkingon + #def sendrequesttomatches / tonodeset + From f2d53289406ba82b8bcc39f78181aac83efa8e84 Mon Sep 17 00:00:00 2001 From: AmrLamei <65570174+AmrLamei@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:18:09 +0200 Subject: [PATCH 25/25] Update ReasoningController.py --- ReasoningController.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ReasoningController.py b/ReasoningController.py index a353999..6cad0a0 100644 --- a/ReasoningController.py +++ b/ReasoningController.py @@ -140,4 +140,5 @@ def isSupported(self,context: Context): #def removeworkingon #def sendrequesttomatches / tonodeset + #def getnodestosendreq