def emit_arg2(arg): uri = bn() kbdbg(uri + " rdf:type kbdbg:" + arg.__class__.__name__) #if type(arg) in (rdflib.Variable, rdflib.URIRef, rdflib.): arg = rdflib.Literal(arg.n3()) kbdbg(uri + " kbdbg:has_value " + arg.n3()) return uri
def find_ep(s, args): nolog or log("ep check: %s vs..", args) for head in s.ep_heads: if ep_match(args, head.items): nolog or kbdbg(bn() + ' rdf:type kbdbg:ep_match') return True nolog or log("..no ep match")
def success(msg, orig, uri=None): if not nolog: if uri == None: uri = bn() log(uri) emit_binding(uri, orig) kbdbg(uri + " kbdbg:message " + rdflib.Literal(msg).n3()) #step() yield msg if not nolog: kbdbg(uri + " kbdbg:was_unbound true")
def fail(msg, orig, uri=None): if not nolog: if uri == None: uri = bn() emit_binding(uri, orig) kbdbg(uri + " kbdbg:failed true") kbdbg(uri + " kbdbg:message " + rdflib.Literal(msg).n3()) while False: yield msg if not nolog: #step() kbdbg(uri + " kbdbg:was_unbound true")
def bind_to(x, y, orig): assert x.bound_to == None x.bound_to = y if not nolog: msg = "bound " + str(x) + " to " + str(y) nolog or log(msg) uri = bn() emit_binding(uri, orig) #step() yield nolog or msg x.bound_to = None if not nolog: kbdbg(uri + " kbdbg:was_unbound true")
def emit_list(l, uri=None): if uri == None: uri = bn().strip(':') uri = '_:' + uri r = uri if len(l) == 0: kbdbg(r + " rdf:value rdf:nil") return r uri += 'v' kbdbg(r + " rdf:value " + uri) kbdbg(uri + " a " + rdflib.RDF.List.n3()) for idx, i in enumerate(l): if type(i) in (unicode, str): v = i elif isinstance(i, rdflib.Variable): v = rdflib.Literal('?' + str(i)).n3() elif not isinstance(i, rdflib.Graph): v = i.n3() if i == rdflib.RDF.nil: v = (i + "_").n3() # json.ld workaround else: v = rdflib.URIRef(i.identifier).n3() kbdbg(uri + " rdf:first " + v) if isinstance(i, rdflib.BNode): kbdbg( i.n3() + ' kbdbg:comment "thats a bnode from the kb input graph, a subj or an obj of an implication. fixme."' ) if idx != len(l) - 1: #uri2 = uri + "X" uri2 = '_:' + bn().strip(':') else: uri2 = 'rdf:nil' kbdbg(uri + " rdf:rest " + uri2) uri = uri2 return r
def inference_resnet(images): with tf.variable_scope('1'): conv1 = common.conv(images, 64, ksize=7, stride=2) conv1 = common.bn(conv1) pool1 = common.max_pool(conv1) with tf.variable_scope('2'): stack2 = common.res_stack(pool1, [256, 256, 256], pool=False) with tf.variable_scope('3'): stack3 = common.res_stack(stack2, [512, 512, 512, 512]) with tf.variable_scope('4'): stack4 = common.res_stack(stack3, [1024, 1024, 1024, 1024, 1024, 1024]) with tf.variable_scope('5'): stack5 = common.res_stack(stack4, [2048, 2048, 2048]) pool5 = common.global_ave_pool(stack5) with tf.variable_scope('fc'): fc = common.fc(pool5, 1) return fc
def inference_small(images): with tf.variable_scope('1'): conv1 = common.conv(images, 64, ksize=7, stride=2) conv1 = common.bn(conv1) pool1 = common.max_pool(conv1) with tf.variable_scope('2'): stack2 = common.stack(pool1, common.res_block, [64, 64]) pool2 = common.max_pool(stack2) with tf.variable_scope('3'): stack3 = common.stack(pool2, common.res_block, [128, 128]) pool3 = common.max_pool(stack3) with tf.variable_scope('4'): stack4 = common.stack(pool3, common.res_block, [256, 256, 256]) pool4 = common.max_pool(stack4) with tf.variable_scope('5'): stack5 = common.stack(pool4, common.res_block, [512, 512]) pool5 = common.global_ave_pool(stack5) with tf.variable_scope('fc'): fc = common.fc(pool5, 1) return fc
def emit_arg(x): r = bn() kbdbg(r + " rdf:type kbdbg:arg") kbdbg(r + " kbdbg:has_frame " + x.frame.n3()) if isinstance(x.is_in_head, bool): if x.is_in_head: kbdbg(r + " kbdbg:is_in_head true") else: if x.is_in_head == 'bnode': kbdbg(r + ' kbdbg:is_bnode true') if x.term_idx != None: if isinstance(x.term_idx, int): t = str(x.term_idx) elif isinstance(x.term_idx, rdflib.Variable): t = rdflib.Literal('?' + str(x.term_idx)).n3() else: t = rdflib.Literal(x.term_idx).n3() kbdbg(r + ' kbdbg:term_idx ' + t) if x.arg_idx != None: kbdbg(r + ' kbdbg:arg_idx ' + str(x.arg_idx)) return r
def emit(s): kbdbg( rdflib.URIRef(s.kbdbg_name).n3() + " rdf:type kbdbg:" + s.bnode_or_locals) kbdbg( rdflib.URIRef(s.kbdbg_name).n3() + " kbdbg:has_parent " + rdflib.URIRef(s.kbdbg_frame).n3()) items = [] for k, v in s.items(): if not is_var(k): continue uri = bn() items.append(uri) if type(k) is rdflib.Variable: sss = k.n3() else: sss = k kbdbg(uri + ' kbdbg:has_name ' + rdflib.Literal(sss).n3()) kbdbg(uri + " kbdbg:has_value_description " + rdflib.Literal(v.kbdbg_name).n3()) kbdbg(uri + " kbdbg:has_value " + rdflib.Literal(v.__short__str__()).n3()) kbdbg( rdflib.URIRef(s.kbdbg_name).n3() + " kbdbg:has_items " + emit_list(items))
def emit_terms(terms): c = [] for i in terms: c.append(emit_term(i, bn())) return c