#heur = ForgetFromList('datasets/university-example.owl', ["http://example.com/myOntology/Professor"])
#explainer = Explainer('datasets/university-example.owl', heur)

#explainer.print_all_subclasses()
#explainer.save_all_subclasses()
#explainer.print_all_explanations('datasets/subClasses.nt')
#explainer.save_all_explanations('datasets/subClasses.nt')
#explanations = explainer.load_all_explanations()
#explanations = explainer.get_all_explanations('datasets/subClasses.nt')
#print(explanations)
# testing heuristic
heur = StandardHeuristics('datasets/pizza.owl',
                     ("http://www.co-ode.org/ontologies/pizza/pizza.owl#Siciliana", "http://www.co-ode.org/ontologies/pizza/pizza.owl#Food"))

explainer = Explainer('datasets/pizza.owl', heur)

proof = explainer.get_proove("datasets/subClasses.nt", justification_step=True)
#print the proove
for line in proof:
    print('forgetting ' + str(line[0]))
    print(str(line[1]))
#
save_proof(proof)
print_proof(proof)

# test comparison
# gets the number of changes that would be needed to transform the left ontology into the right one.
diffs = xmldiff.diff_files('datasets/pizza_super_simple2.owl', 'datasets/pizza_super_simple.owl')
# Ignore the order of the nodes. They do not change what is entailed by the Ontology
diffs = [diff for diff in diffs if str(diff)[:8] != 'MoveNode']
print(len(diffs))
differences = []
processed_proofs = 0
num_samples = 50

# loop over all subclasses entailed by the ontology
with open(all_subclasses_file) as f:
    for subclass in f.readlines():
        # Load the current subsumption for heuristics and explainer
        subsumbtion_signatures = get_sub_from_nt(subclass)
        heuristic.set_subsumption(subsumbtion_signatures)
        with open('datasets/subClasses.nt', 'w+') as curr_sub_f:
            curr_sub_f.write(subclass)

        # get the proofs
        try:
            proof_just = explainer.get_proove('datasets/subClasses.nt', justification_step=True)
            proof_no_just = explainer.get_proove('datasets/subClasses.nt', justification_step=False)
        except Exception:  # this is really bad... but for the timeframe necessary
            # reset working ontology
            explainer.working_ontology = ontology
            heuristic.set_ontology(ontology)
            differences.append(-1)
            print("\n\n############################ ERROR ####################################\n\n")
            continue

        # compare proofs
        if len(proof_just) != len(proof_no_just):  # different number of lines in the proof
            differences.append(100)
        else:
            printing = False
            for i in range(len(proof_just)):
Пример #3
0
from explainer import Explainer
from forgetHeuristics import StandardHeuristics
import sys

ontology_file = sys.argv[2]
subsumption_file = sys.argv[4]
justification_step = sys.argv[6]
if justification_step == 'False':
    justification_step = False
else:
    justification_step = True

# load subsumption
with open(subsumption_file) as f:
    nt_string = f.readline()

comp = nt_string.split()
subsumption = (comp[0][1:-1], comp[2][1:-1])

heuristic = StandardHeuristics(ontology_file, subsumption)
explainer = Explainer(ontology_file, heuristic)

proof = explainer.get_proove(subsumption_file, justification_step)

for line in proof:
    print("justification after forgetting " + str(line[0]))
    print(str(line[1]))