Exemple #1
0
def genHypoList(stmt, acc=[]):
    if(stmt.operator == None):
        if(stmt.value == False):
            return acc
        stmtN = Statement(None,None,None,False)
        acc.append(Statement(stmt, stmtN,'>',
            "(" + str(stmt.value) + ")>(False)"))
        return acc
    acc.append(stmt.left)
    return genHypoList(stmt.right,acc)
Exemple #2
0
    def Parse(self):
        id = Id.Id()
        statement = Statement.Statement()
        index = 0
        file = open("test.lua")
        filetext = file.read()
        text = filetext.split(
        )  #Uses delimiter SPACE to separate the words into a list ; Stores in list split_text
        file.close()
        #Begins initial checks
        if (text.pop(0) != "function"):
            sys.exit("function not found, program terminated.")

        id.Include(text, 0)
        text.pop(0)

        if (text.pop(0) != '('):
            sys.exit("Left paran not found, program terminated.")

        if (text.pop(0) != ')'):
            sys.exit("Right paran not found, program terminated.")

#Ends initial checks
        while text[index] != "end":
            index = statement.determineStatement(text, index)
        return
Exemple #3
0
 def get_while(self):
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.WHILE_KW_TOK)
     bool = self.get_boolean_expression()
     block = self.get_block()
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.END_KW_TOK)
     return Statement.WhileStatement(bool, block)
Exemple #4
0
 def get_for(self):
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.FOR_KW_TOK)
     id_var = self.get_id()
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.ASSIGN_TOK)
     iterator = self.get_iter()
     block = self.get_block()
     tok = self.lex.get_next_token()
     self.match(tok, TokenType.END_KW_TOK)
     return Statement.ForStatement(id_var, iterator, block)
Exemple #5
0
def prepare_knowledgebase(FOL_SENTENCES):
    """
    Takes a set of FOL statements and performs 
    preprocessing for converting them to CNF form
    adds the converted CNF statements to KNOWLEDGE_BASE and 
    updates the KNOWLEDGE_BASE_HASH
    """
    global predicates_dict
    for statement in FOL_SENTENCES:
        predicates_dict.clear()
        statement, predicates_dict = replace_predicate_by_constant(statement)
        statement = convert_to_postfix(statement)
        root = convert_postfix_to_tree(statement)  # convert to expression tree
        remove_implication(root)  # remove implication
        propagate_negation(root)  # propagate negation
        distribute_and_over_or(root)  # distribute AND over OR
        inorder = inorder_traversal(root)
        statement = replace_constant_by_predicate(inorder, predicates_dict)
        statements = statement.split('&')
        statements = standardize_variables(statements)
        for cnf_stmt in statements:
            stmt_obj = Statement(cnf_stmt)
            stmt_obj.add_statement_to_KB(KNOWLEDGE_BASE, KNOWLEDGE_BASE_HASH)