예제 #1
0
def count_existential(quantifiers):
    '''
    Returns the number of universally quantified variables

    '''

    quantified_variables = []
    for quantifier in quantifiers:
        Translation.get_existentially_quantified(quantifier, quantified_variables)
예제 #2
0
def existential_predicate(predicate, quantifiers):

    if predicate == [] or quantifiers == []:
        return False

    existentials = []
    for quant in quantifiers:
        Translation.get_existentially_quantified(quant, existentials)

    if all([x in existentials for x in predicate[1:]]):
        return predicate
    else:
        return False
예제 #3
0
def universal_predicate(predicate, quantifiers):

    if predicate == [] or quantifiers == []:
        return False

    universals = []
    
    for quant in quantifiers:
        Translation.get_universally_quantified(quant, universals)

    if all([x in universals for x in predicate[1:]]):
        return predicate
    else:
        return False
예제 #4
0
def generate_all_axiom(sentences):
    '''
    Utility function which accepts a raw set of axioms and returns a set of
    quantified CNF axioms
    '''

    new_sentences = []
    for sentence in sentences:

        # Skip the import lines
        if sentence[0] == 'cl-imports':
            continue

        cnf = []

        print("[+] Sentence:")
        pprint.pprint(sentence)

        quantifiers, axiom = Translation.translate_sentence(sentence)
        axioms = extract_conjuncts(axiom[:])

        print("[+] Translated Sentence:")
        pprint.pprint(axiom)

        print("------------------")
        for axiom in axioms:
            cnf.append(generate_quantifier(axiom, copy.deepcopy(quantifiers)))
            print("[-]  ", cnf[-1])

        new_sentences.append((sentence, cnf))
        print("")

    return new_sentences
예제 #5
0
def extract_conjuncts(sentence):
    '''
    Accepts a conjunction and returns a list of individual conjuncts to be
    examined later
    '''

    axioms = []

    if Translation.is_conjunction(sentence):
        axioms += Translation.is_conjunction(sentence)
    elif Translation.is_disjunction(sentence):
        axioms = [sentence]
    else:
        print("We're going down captain!")

    return axioms
예제 #6
0
def count_variables(axiom):
    '''
    Returns the number of variables actually used in the clause, as opposed to
    over the entire conjunction it may be part of.
    '''

    variables = set()

    for clause in axiom:

        if Translation.is_negated(clause):

            clause = Translation.is_negated(clause)

        if Translation.is_unary(clause):

            variables.add(clause[1])

        elif Translation.is_binary(clause):

            variables.add(clause[1])
            variables.add(clause[2])

    return len(variables)
예제 #7
0
def generate_quantifier(sentence, quantifiers):
    '''
    Take a sentence and set of quantifiers and trim the quantifiers so only
    variables in the sentence exist in the quantifier. Return the new
    quantifier and sentence together in a list.

    return list axiom, [[quantifiers], [sentence]]
    '''

    new_quantifiers = quantifiers[:]

    predicates = []
    Translation.find_binary_predicates(sentence, predicates)
    Translation.find_unary_predicates(sentence, predicates)
    predicates = list(set([get_predicate_name(p) for p in predicates]))

    #print("[+] Found Predicates:", predicates)

    quantified_variables = []
    for quantifier in new_quantifiers:
        Translation.get_universally_quantified(quantifier, quantified_variables)
        Translation.get_existentially_quantified(quantifier, quantified_variables)

    quantified_variables = list(set(quantified_variables))

    #print("[+] Found Quantified Variables:", quantified_variables)

    flattened_axiom = list(set(list(Util.flatten(sentence))))

    variables = list(filter(Translation.is_nonlogical, flattened_axiom))
    variables = [v for v in variables if v not in predicates]

    #print("[+] Found Variables:", variables)

    variables_to_trim = [v for v in quantified_variables if v not in variables]

    #print("[+] Removing Variables:", variables_to_trim)

    #print("[+] Starting Quantifier:", new_quantifiers)

    new_quantifiers = trim_quantifier(new_quantifiers, variables_to_trim)

    #print("[+] Generated Quantifier:", new_quantifiers)

    return [copy.deepcopy(new_quantifiers), copy.deepcopy(sentence)]
예제 #8
0
def same_variables(pred_one, pred_two):
    '''
    Returns true if both predicates are over the same variable
    '''

    if Translation.is_negated(pred_one):
        pred_one = Translation.negate_negation(pred_one)

    if Translation.is_negated(pred_two):
        pred_two = Translation.negate_negation(pred_two)

    if Translation.is_unary(pred_one) and Translation.is_unary(pred_two):

        if pred_one[1] == pred_two[1]:
            return True

    if Translation.is_binary(pred_one) and Translation.is_binary(pred_two):

        if pred_one[1] == pred_two[1] and pred_one[2] == pred_two[2]:
            return True

    return False
예제 #9
0
                        help='Input Clif',
                        required=True)
    args = parser.parse_args()

    axioms, extractions = Extractions.get_all_extractions(args.file)

    unary = set()
    binary = set()

    for a in axioms:

        print(a)
        unary_predicates = []
        binary_predicates = []

        Translation.find_unary_predicates(a[0], unary_predicates)
        Translation.find_binary_predicates(a[0], binary_predicates)

        print('-----------')
        #pp.pprint(s)
        print('')
        #print(is_all_unary(translated[1]))
        #pp.pprint(translated)

        print(unary_predicates)
        print(binary_predicates)

        for u in unary_predicates:
            unary.add(u[0])

        for b in binary_predicates:
예제 #10
0
def negative_predicates(lst):

    return [Translation.is_negated(i) for i in lst if Translation.is_negated(i)]
예제 #11
0
def positive_predicates(lst):

    return [i for i in lst if not Translation.is_negated(i)]