DataExtractor.py
Go to the documentation of this file.
00001 from LogReader import LogReader
00002 import pickle
00003 import math
00004 
00005 
00006 class DataExtractor:
00007     def __init__(self):
00008         self.rdrLog = LogReader()
00009         
00010     def extractData(self, strPath):
00011         log = self.rdrLog.loadLog(strPath)
00012         self.tti = log.getOwlData()["task-tree-individuals"]
00013         annot = None
00014         meta = None
00015         
00016         for key in self.tti:
00017             owlIndiv = self.tti[key]
00018             
00019             if owlIndiv.type() == "AnnotationInformation":
00020                 annot = owlIndiv
00021                 if annot and meta: break
00022             elif owlIndiv.type() == "ExperimentMetaData":
00023                 meta = owlIndiv
00024                 if annot and meta: break
00025         
00026         if annot and meta:
00027             params = annot.tagNodeValues("knowrob:annotatedParameterType")
00028             
00029             param_set = {}
00030             for param in params:
00031                 param_set[param] = "?"
00032             
00033             strHeadline = "TASK-CONTEXT, RESULT"
00034             for param in params:
00035                 strHeadline += ", " + param
00036             
00037             print strHeadline
00038             
00039             toplevelnodes = meta.tagAttributeValues("knowrob:subAction", "rdf:resource")
00040             
00041             for toplevelnode in toplevelnodes:
00042                 node_key = toplevelnode.split("#")[1]
00043                 self.printNode(node_key, param_set)
00044     
00045     def printNode(self, node_key, param_set):
00046         owlIndiv = self.tti[node_key]
00047         subactions = owlIndiv.tagAttributeValues("knowrob:subAction", "rdf:resource")
00048         
00049         for param in param_set:
00050             tnv = owlIndiv.tagNodeValues("knowrob:" + param)
00051             
00052             if len(tnv) > 0:
00053                 param_set[param] = tnv[0]
00054         
00055         strLine = ""
00056         strLine += owlIndiv.tagNodeValues("knowrob:taskContext")[0]
00057         
00058         failures = owlIndiv.tagAttributeValues("knowrob:eventFailure", "rdf:resource")
00059         
00060         if len(failures) > 0:
00061             failure = failures[0].split("#")[1]
00062             owlFailure = self.tti[failure]
00063             
00064             strLine += ", " + owlFailure.type()
00065         else:
00066             strLine += ", Success"
00067         
00068         for param in param_set:
00069             strLine += ", " + param_set[param]
00070         
00071         for subaction in subactions:
00072             self.printNode(subaction.split("#")[1], param_set)
00073         
00074         print strLine


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