Exemple #1
0
def tokenizeSPASS(partialStatement, sorts, transformDict, quantMap):
    #If there are no constraints
    if (partialStatement == ""):
        return [], []
#Strip all the unneccesary information
    statements = partialStatement.strip(" ").strip("->").strip(" ").split(" ")
    for statement in enumerate(statements):
        if (statement[1] == "->"):
            statements[statement[0]] = "TEMP"
            continue
        temp = statement[1]
        while True:
            nextTemp = temp.strip(".").strip(" ").strip("*").strip("+")
            if (temp == nextTemp):
                statements[statement[0]] = nextTemp
                break
            else:
                temp = nextTemp
#Conclusions are weird, stupid SPASS
    if statements[-1] == "":
        statements = statements[:-2]
#Initialize the return lists
    quants = []
    funcs = []
    #Find all the neccesary information
    for statement in statements:
        #Implies is weird
        if (statement == "TEMP"):
            funcs.append(["TEMP"])
            continue
#Find the functions derived in the proof
        temp = cleaning.tuckFunctions(statement)
        tokens = findSubTokens(temp, transformDict, sorts, quants, quantMap)
        #Funcs have isValid in front
        if tokens[0] == "isValid":
            if isinstance(tokens[1], str):
                if not tokens[1] in transformDict.keys(
                ) and not tokens[1] in quantMap.keys():
                    storeQuant(quants, tokens[1], "Boolean", transformDict,
                               quantMap)
            funcs.append(
                makeFuncs(quants, tokens[1], sorts, transformDict, quantMap))

#Implies is weird, collapse all the implies
    returner = []
    index = len(funcs) - 1
    while index >= 0:
        if funcs[index - 1][0] == "TEMP":
            returner.append(["implies", funcs[index - 2], funcs[index]])
            index -= 3
        else:
            returner.append(funcs[index])
            index -= 1
    funcs = returner
    return quants, funcs
Exemple #2
0
def tokenizeSPASS(partialStatement,sorts,transformDict,quantMap):
	#If there are no constraints	
    if(partialStatement == ""):
        return [],[]
	#Strip all the unneccesary information
    statements = partialStatement.strip(" ").strip("->").strip(" ").split(" ")
    for statement in enumerate(statements):
        if(statement[1] == "->"):
            statements[statement[0]] = "TEMP"
            continue
        temp = statement[1]
        while True:
            nextTemp = temp.strip(".").strip(" ").strip("*").strip("+")
            if(temp ==nextTemp):
                statements[statement[0]] = nextTemp
                break
            else:
                temp = nextTemp
	#Conclusions are weird, stupid SPASS
    if statements[-1] == "":
        statements = statements[:-2]
	#Initialize the return lists
    quants = []
    funcs = []
	#Find all the neccesary information
    for statement in statements:
		#Implies is weird
        if(statement == "TEMP"):
            funcs.append(["TEMP"])
            continue
		#Find the functions derived in the proof
        temp = cleaning.tuckFunctions(statement)
        tokens = findSubTokens(temp,transformDict,sorts,quants,quantMap)
		#Funcs have isValid in front
        if tokens[0] == "isValid":
            if isinstance(tokens[1],str):
                if not tokens[1] in transformDict.keys() and not tokens[1] in quantMap.keys():
                    storeQuant(quants,tokens[1],"Boolean",transformDict,quantMap)
            funcs.append(makeFuncs(quants,tokens[1],sorts,transformDict,quantMap))
	#Implies is weird, collapse all the implies
    returner = []
    index = len(funcs)-1
    while index >= 0:
        if funcs[index-1][0] == "TEMP":
            returner.append(["implies",funcs[index-2],funcs[index]])
            index -= 3
        else:
            returner.append(funcs[index])
            index -= 1
    funcs = returner
    return quants,funcs
Exemple #3
0
def tokenizeRandomDCEC(expression, namespace=""):
    '''
    This function creates a token representation of a random DCEC statement.
    It returns the token as well as sorts of new atomics and functions.
    '''
    #Default DCEC Functions
    if namespace == "":
        namespace = prototypes.NAMESPACE()
        namespace.addBasicDCEC()
    else:
        namespace = namespace
    #Remove Comments
    temp = removeComments(expression)
    #Check for an empty string
    if temp == "()":
        return ("", {}, {}, {})
    #Check for a parentheses mismatch error
    if not cleaning.checkParens(expression):
        print "ERROR: parentheses mismatch error."
        return (False, False, False, False)
    #Make symbols into functions
    temp = functorizeSymbols(temp)
    #Strip comments
    temp = cleaning.stripComments(temp)
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    #Strip whitespace again
    temp = cleaning.stripWhiteSpace(temp)
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    quantifiers = []
    #These are the tokens that should be added to the namespace
    addAtomics = {}
    addFunctions = {}
    addQuants = {}
    returnToken = TokenTree(temp, namespace, quantifiers, addQuants,
                            addAtomics, addFunctions)
    #check for errors that occur in the lower level
    if isinstance(returnToken, bool) and returnToken == False:
        return (False, False, False, False)
    #Add quantifiers to the TokenTree
    returnToken = tokenizeQuantifiers(returnToken, quantifiers)
    return (returnToken, addQuants, addAtomics, addFunctions)
def tokenizeRandomDCEC(expression,namespace = ""):
    '''
    This function creates a token representation of a random DCEC statement.
    It returns the token as well as sorts of new atomics and functions.
    '''
    #Default DCEC Functions
    if namespace == "":
        namespace = prototypes.NAMESPACE()
        namespace.addBasicDCEC()
    else:
        namespace = namespace
    #Remove Comments
    temp = removeComments(expression)
    #Check for an empty string
    if temp == "()":
        return ("",{},{},{})
    #Check for a parentheses mismatch error
    if not cleaning.checkParens(expression):
        print "ERROR: parentheses mismatch error."
        return (False,False,False,False)
    #Make symbols into functions
    temp = functorizeSymbols(temp)
    #Strip comments
    temp = cleaning.stripComments(temp)
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    #Strip whitespace again
    temp = cleaning.stripWhiteSpace(temp)
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    quantifiers = []
    #These are the tokens that should be added to the namespace
    addAtomics = {}
    addFunctions = {}
    addQuants = {}
    returnToken = TokenTree(temp,namespace,quantifiers,addQuants,addAtomics,addFunctions)
    #check for errors that occur in the lower level
    if isinstance(returnToken,bool) and returnToken == False:
        return (False,False,False,False)
    #Add quantifiers to the TokenTree
    returnToken = tokenizeQuantifiers(returnToken,quantifiers)
    return (returnToken,addQuants,addAtomics,addFunctions)
Exemple #5
0
 Testing suite.
 '''
 inputin = raw_input("Enter an expression: ")
 #Make symbols into functions
 temp = removeComments(inputin)
 print temp
 temp = functorizeSymbols(temp)
 print temp
 #Strip comments
 temp = cleaning.stripComments(temp)
 print temp
 #Strip whitespace so you can do the rest of the parsing
 temp = cleaning.stripWhiteSpace(temp)
 print temp
 #Tuck the functions inside thier parentheses
 temp = cleaning.tuckFunctions(temp)
 print temp
 #Consolidate Parentheses
 temp = cleaning.consolidateParens(temp)
 print temp
 testNAMESPACE = prototypes.NAMESPACE()
 testNAMESPACE.addBasicDCEC()
 testNAMESPACE.addBasicNumerics()
 testNAMESPACE.addBasicLogic()
 testNAMESPACE.addTextFunction("ActionType heal Agent")
 #testNAMESPACE.addTextFunction("Boolean B Agent Moment Boolean Certainty")
 addQuants = {}
 addAtomics = {}
 addFunctions = {}
 tree, addQuants, addAtomics, addFunctions = tokenizeRandomDCEC(
     temp, testNAMESPACE)
 Testing suite.
 '''
 inputin = raw_input("Enter an expression: ")
 #Make symbols into functions
 temp = removeComments(inputin)
 print temp
 temp = functorizeSymbols(temp)
 print temp
 #Strip comments
 temp = cleaning.stripComments(temp)
 print temp
 #Strip whitespace so you can do the rest of the parsing
 temp = cleaning.stripWhiteSpace(temp)
 print temp
 #Tuck the functions inside thier parentheses
 temp = cleaning.tuckFunctions(temp)
 print temp
 #Consolidate Parentheses
 temp = cleaning.consolidateParens(temp)
 print temp
 testNAMESPACE = prototypes.NAMESPACE()
 testNAMESPACE.addBasicDCEC()
 testNAMESPACE.addBasicNumerics()
 testNAMESPACE.addBasicLogic()
 testNAMESPACE.addTextFunction("ActionType heal Agent")
 #testNAMESPACE.addTextFunction("Boolean B Agent Moment Boolean Certainty")
 addQuants = {}
 addAtomics = {}
 addFunctions = {}     
 tree,addQuants,addAtomics,addFunctions = tokenizeRandomDCEC(temp,testNAMESPACE)
 if tree == False: