diff --git a/Bindings.py b/Bindings.py new file mode 100644 index 0000000..c3421f4 --- /dev/null +++ b/Bindings.py @@ -0,0 +1,6 @@ +class Bindings(): + + def __init__(self): + pass + def getBinding(): + pass \ No newline at end of file diff --git a/Channel.py b/Channel.py new file mode 100644 index 0000000..8ca2f0b --- /dev/null +++ b/Channel.py @@ -0,0 +1,82 @@ +from Filter import Filter +from Proposition import Proposition +from ReportSet import ReportSet +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 + count = 0 + global filter + filter: Filter + global switch + switch: Switch + global reportBuffer + reportBuffer: ReportSet + + 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): + canPass = filter.canPass(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(self): + return self.id + + def setSubstitution(self,substitution: Substitutions): + self.substitution = substitution + + def getSupport(self): + return self.support + + def getFilter(self): + return self.filter + + def getType(self): + return self.type + + def setFilter(self,filter: Filter): + self.filter = filter + + 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 setReportsBuffer(self,reportsBuffer: ReportSet): + self.reportsBuffer = reportBuffer + + def getReportsBuffer(): + return reportBuffer + + def clearReportsBuffer(self,reportsBuffer: ReportSet): + self.getReportsBuffer().clearReports() + + def getContext(self): + return self.context diff --git a/Channel.pyc b/Channel.pyc new file mode 100644 index 0000000..4985023 Binary files /dev/null and b/Channel.pyc differ diff --git a/ChannelSet.py b/ChannelSet.py new file mode 100644 index 0000000..d84ce5e --- /dev/null +++ b/ChannelSet.py @@ -0,0 +1,45 @@ +from Channel import Channel +from Filter import Filter +from Switch import Switch +from Node import Node +import ChannelType +class ChannelSet(Channel): + + 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 = { + 'Matched' : channel + } + AntToRuleChannels = { + 'AntToRule' : channel + } + RuletoConsChannels = { + 'RuleToCons' : 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: Channel): + channelSourceId = channel.source.id + channelDestinationId= channel.destination.id + filtersubs = channel.filter.substitutions + switchsubs = channel.channel.substitutions + channelType = channel.getChannelType(channel) + + def getChannelType(channel: 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 0000000..9a8247a Binary files /dev/null and b/ChannelType.pyc differ diff --git a/Filter.py b/Filter.py new file mode 100644 index 0000000..22f93d1 --- /dev/null +++ b/Filter.py @@ -0,0 +1,21 @@ +from Report import Report +from Bindings import Bindings +from Substitutions import Substitutions +class Filter: + + def __init__(self,report: Report): + self.report = report + + def canPass(self,report: Report,attitude: str): + for x in self.substitution.cardinality(): + currentFilterBinding: Bindings + currentFilterBinding = Substitutions.getBinding(x) + currentReportBinding: Bindings + currentReportBinding = report.getSubstitutions().getBindingByVariable(currentFilterBinding.getVariable()) + 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/Filter.pyc b/Filter.pyc new file mode 100644 index 0000000..a745c42 Binary files /dev/null and b/Filter.pyc differ diff --git a/Instance.py b/Instance.py new file mode 100644 index 0000000..fe60e97 --- /dev/null +++ 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 new file mode 100644 index 0000000..bf07d08 --- /dev/null +++ b/KnownInstances.py @@ -0,0 +1,34 @@ +from Report import Report +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,substitution: Substitutions, support: supportSet ,source: Node ,destination: Node,attitude: str): + super.__init__(substitution, support,source,destination,attitude) + + + def addReport(self,report: Report): + reportSubs: Substitutions + reportSubs = report + report.getSubstitution() + reportSet = self.pop(reportSubs) + if reportSet == None: + reportSet = [] + reportSet.append(report) + self.update(reportSubs,reportSet) + + + def getReportBySubs(self): + return self.getSubstitution() + + def getSubstitution(self,report: 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..8be4eb8 --- /dev/null +++ b/Proposition.py @@ -0,0 +1,39 @@ +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(Entity): + global outgoingChannels + outgoingChannels: ChannelSet + global incomingChannels + incomingChannels: ChannelSet + global supports + supports: supportSet + + + 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(self,channel: Channel): + Runner.addToHighQ(channel) + + def addToOutgoingChannels(self, channel: Channel): + outgoingChannels.addChannel(channel) + + def addToIncomingChannels(self, channel: Channel): + incomingChannels.addChannel(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..c17a532 --- /dev/null +++ b/PropositionSet.py @@ -0,0 +1,9 @@ +class PropositionSet(): + + propositions = {} + + def __init__(self) -> None: + pass + + def addProp(node: 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..6cad0a0 --- /dev/null +++ b/ReasoningController.py @@ -0,0 +1,144 @@ +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 Context import Context +from MindGRAFController import MindGRAFController +class ReasoningController: + global knownInstances= KnownInstances() + 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 (self,source: Node,destination: Node,status: bool,type,context: Context): + request = Channel(source,destination,status,type,context) + 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(self,channel: Channel,report: Report): + knownInstances.addReport(report) + + def ForwardChain(self,node: Node, context: Context, attitude: str): + Runner.run() + 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(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 ProcessReportsChannel(self, 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 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: str ,source: Node,destination: Node): + suppSet = supportSet() + suppSet.add(suppSet.getId()) + report = Report(substitutions,suppSet,inferenceType,source,destination) + match type: + case 'MATCHED': + matches = [Matcher.Match] + if matches: + self.sendReportToMatches(matches,report,context) + case 'RULEANT': + if isinstance(self,RuleNode): + antNodes = NodeSet.getDownAnt() + self.sendReportToNodeSet(antNodes,report,context,type) + + + 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) + self.sendReport(report,newChannel) + + 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) + self.SendReport(report,newChannel) + + def isSupported(self,context: Context): + pass + + #def removeworkingon + #def sendrequesttomatches / tonodeset + #def getnodestosendreq + diff --git a/Report.py b/Report.py new file mode 100644 index 0000000..d4eb3e8 --- /dev/null +++ b/Report.py @@ -0,0 +1,57 @@ +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): + 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() + supportCheck = instanceSupport is reportSupport + if(instanceInfType == "BACKWARD" and reportInfType == "FORWARD"): + return report + elif(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/Report.pyc b/Report.pyc new file mode 100644 index 0000000..a77175f Binary files /dev/null and b/Report.pyc differ diff --git a/ReportSet.py b/ReportSet.py new file mode 100644 index 0000000..782a439 --- /dev/null +++ b/ReportSet.py @@ -0,0 +1,19 @@ +from Report import Report + +class ReportSet(Report): + reports = [] + def __innit__(self,reports: Report): + self.reports = [] + + def addReport(reports,report: Report): + reports.append(report) + + def clearReports(reports): + reports.clear() + + def removeReport(reports,report: Report): + reports.remove(report) + + def iterator(reports): + for x in reports: + print(x) \ No newline at end of file diff --git a/RuleNode.py b/RuleNode.py new file mode 100644 index 0000000..7c836a4 --- /dev/null +++ b/RuleNode.py @@ -0,0 +1,3 @@ +class RuleNode(): + def __init__(self) -> None: + pass \ No newline at end of file diff --git a/Runner.py b/Runner.py new file mode 100644 index 0000000..b859055 --- /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 or lowQ: + Runner.run() + + def addToHighQ(node: Node): + highQ.append(node) + def addToLowQ(node: Node): + lowQ.append(node) + def addToActQ(node: 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..9f2b028 --- /dev/null +++ b/Switch.py @@ -0,0 +1,19 @@ +from Bindings import Bindings +from Report import Report +from Substitutions import Substitutions +class Switch(): + def __init__(self,substitutions: Substitutions): + self.substitutions = substitutions + + 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 diff --git a/Switch.pyc b/Switch.pyc new file mode 100644 index 0000000..19d3f0a Binary files /dev/null and b/Switch.pyc differ diff --git a/__pycache__/Channel.cpython-39.pyc b/__pycache__/Channel.cpython-39.pyc new file mode 100644 index 0000000..2226516 Binary files /dev/null and b/__pycache__/Channel.cpython-39.pyc differ diff --git a/__pycache__/ChannelType.cpython-39.pyc b/__pycache__/ChannelType.cpython-39.pyc new file mode 100644 index 0000000..eaf5e81 Binary files /dev/null and b/__pycache__/ChannelType.cpython-39.pyc differ diff --git a/__pycache__/Filter.cpython-39.pyc b/__pycache__/Filter.cpython-39.pyc new file mode 100644 index 0000000..d2360e0 Binary files /dev/null and b/__pycache__/Filter.cpython-39.pyc differ diff --git a/__pycache__/Switch.cpython-39.pyc b/__pycache__/Switch.cpython-39.pyc new file mode 100644 index 0000000..fda51f1 Binary files /dev/null and b/__pycache__/Switch.cpython-39.pyc differ diff --git a/code/core/modules/ReasoningController/.DS_Store b/code/core/modules/ReasoningController/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/code/core/modules/ReasoningController/.DS_Store differ diff --git a/code/core/modules/ReasoningController/Channel.py b/code/core/modules/ReasoningController/Channel.py new file mode 100644 index 0000000..d3c0816 --- /dev/null +++ b/code/core/modules/ReasoningController/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/code/core/modules/ReasoningController/Channel.pyc b/code/core/modules/ReasoningController/Channel.pyc new file mode 100644 index 0000000..4985023 Binary files /dev/null and b/code/core/modules/ReasoningController/Channel.pyc differ 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 0000000..9a8247a Binary files /dev/null and b/code/core/modules/ReasoningController/ChannelType.pyc differ 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 0000000..a745c42 Binary files /dev/null and b/code/core/modules/ReasoningController/Filter.pyc differ 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 0000000..a77175f Binary files /dev/null and b/code/core/modules/ReasoningController/Report.pyc differ diff --git a/code/core/modules/ReasoningController/ReportSet.py b/code/core/modules/ReasoningController/ReportSet.py new file mode 100644 index 0000000..8a67880 --- /dev/null +++ b/code/core/modules/ReasoningController/ReportSet.py @@ -0,0 +1,21 @@ +from Report import Report + + +import Report +class ReportSet(Report): + reports = [] + def __innit__(self): + pass + + def addReport(reports,report): + reports.append(report) + + def clearReports(reports): + reports.clear() + + def removeReport(reports,report): + reports.remove(report) + + def iterator(reports): + for x in reports: + print(x) \ 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/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 0000000..19d3f0a Binary files /dev/null and b/code/core/modules/ReasoningController/Switch.pyc differ 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 0000000..2226516 Binary files /dev/null and b/code/core/modules/ReasoningController/__pycache__/Channel.cpython-39.pyc differ 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 0000000..eaf5e81 Binary files /dev/null and b/code/core/modules/ReasoningController/__pycache__/ChannelType.cpython-39.pyc differ 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 0000000..d2360e0 Binary files /dev/null and b/code/core/modules/ReasoningController/__pycache__/Filter.cpython-39.pyc differ 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 0000000..fda51f1 Binary files /dev/null and b/code/core/modules/ReasoningController/__pycache__/Switch.cpython-39.pyc differ 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/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 0000000..d605665 Binary files /dev/null and b/code/core/modules/ReasoningController/tests/__pycache__/test_unittest.cpython-37-pytest-7.0.1.pyc differ diff --git a/code/core/modules/ReasoningController/tests/test_unittest.py b/code/core/modules/ReasoningController/tests/test_unittest.py new file mode 100644 index 0000000..680741e --- /dev/null +++ b/code/core/modules/ReasoningController/tests/test_unittest.py @@ -0,0 +1,5 @@ +def test_success(): + assert True + +def test_failure(): + assert False \ No newline at end of file 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