consistency-check.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 import sys
00004 import json
00005 from xml.dom.minidom import parse, parseString
00006 
00007 params_ok = True
00008 
00009 if len(sys.argv) < 3 or sys.argv[1] == "" or sys.argv[2] == "":
00010     print "Usage: " + sys.argv[0] + " <designators.json> <experiment.owl>"
00011     params_ok = False
00012 
00013 if params_ok:
00014     file_logged_designators = sys.argv[1]
00015     file_owl = sys.argv[2]
00016     # Load the logged designator indices
00017     logged_designators = []
00018     logged_details = []
00019     with open(file_logged_designators) as f:
00020         for line in iter(lambda: f.readline(), ''):
00021             data = json.loads(line)
00022             logged_designators.append(data['designator']['_id'])
00023             logged_details.append(data['designator'])
00024             
00025     # Load the OWL designators
00026     dom_owl = parse(file_owl)
00027     individuals = dom_owl.getElementsByTagName("owl:namedIndividual")
00028     owl_designators = []
00029     for individual in individuals:
00030         individual_type = individual.getElementsByTagName("rdf:type")
00031         if individual_type.length == 1:
00032             individual_type = individual_type[0]
00033             indiv_type_resource = individual_type.getAttribute("rdf:resource")
00034             if indiv_type_resource.split("#")[1] == "CRAMDesignator":
00035                 indiv_name = individual.getAttribute("rdf:about")
00036                 owl_designators.append(indiv_name.split("#")[1])
00037     
00038     # Evaluate
00039     logged_but_not_owl = []
00040     owl_but_not_logged = []
00041     logged_duplicates = []
00042     owl_duplicates = []
00043     
00044     logged_inspected = []
00045     owl_inspected = []
00046     
00047     for desig in logged_designators:
00048         seen = 0
00049         for desig2 in owl_designators:
00050             if desig2 == desig:
00051                 seen = 1
00052                 break
00053     
00054         if seen == 0:
00055             logged_but_not_owl.append(desig)
00056     
00057         seen = 0
00058         for desig2 in logged_inspected:
00059             if desig2 == desig:
00060                 seen = 1
00061                 break
00062     
00063         if seen == 1:
00064             logged_duplicates.append(desig)
00065         else:
00066             logged_inspected.append(desig)
00067 
00068     for desig in owl_designators:
00069         seen = 0
00070         for desig2 in logged_designators:
00071             if desig2 == desig:
00072                 seen = 1
00073                 break
00074     
00075         if seen == 0:
00076             owl_but_not_logged.append(desig)
00077     
00078         seen = 0
00079         for desig2 in owl_inspected:
00080             if desig2 == desig:
00081                 seen = 1
00082                 break
00083     
00084         if seen == 1:
00085             owl_duplicates.append(desig)
00086         else:
00087             owl_inspected.append(desig)
00088 
00089     # Print results
00090     if len(logged_but_not_owl) > 0:
00091         print "Designators logged but not present in OWL:"
00092         for desig in logged_but_not_owl:
00093             print " - " + desig
00094 
00095     if len(owl_but_not_logged) > 0:
00096         print "Designators present in OWL but not logged:"
00097         for desig in owl_but_not_logged:
00098             print " - " + desig
00099 
00100     # Print statistics
00101     print "\nStatistics:"
00102     print " - Total logged: " + str(len(logged_designators))
00103     print " - Total in OWL: " + str(len(owl_designators))
00104     print " - Logged, but not in OWL: " + str(len(logged_but_not_owl))
00105     print " - In OWL, but not logged: " + str(len(owl_but_not_logged))
00106     print " - Duplicates in logged: " + str(len(logged_duplicates))
00107     print " - Duplicates in OWL: " + str(len(owl_duplicates))
00108     
00109     if len(logged_but_not_owl) == 0 and len(owl_but_not_logged) == 0:
00110         print
00111         print "Results consistent."


beliefstate
Author(s): Jan Winkler
autogenerated on Sun Oct 5 2014 22:30:15