Exemple #1
0
def query(s):
    results = prefix.q( """  
SELECT ?a ?p ?o ?t  WHERE {
    <%s> ?p ?o.
    optional {
       ?o rdf:type ?t.
    }
}
    """ % s)
    d={}
    dt={}
    for x in results['results']['bindings']:
        v = prefix.clean(x['o']['value'])
        t = None
        if 't' in x:
            t = prefix.clean(x['t']['value'])
        else:
            #pprint.pprint(x)
            pass # have no node type

        k = x['p']['value']
        k = prefix.clean(k)
        if k not in d:
            if k not in skip:
                d[k]=v  # the value of the field
                dt[k]=t # the domain type of the field object
        else:
            #d[k]=[d[k],v]
            raise Exception("duplicate")
    
    return d, dt
Exemple #2
0
def query(s):
    results = prefix.q(
        """  
SELECT ?a ?p ?o ?t  WHERE {
    <%s> ?p ?o.
    optional {
       ?o rdf:type ?t.
    }
}
    """
        % s
    )
    d = {"node_id": prefix.clean(s)}
    dt = {"node_id": None}  # literal has no type...
    # pprint.pprint(results)
    for x in results["results"]["bindings"]:
        v = prefix.clean(x["o"]["value"])
        t = None
        if "t" in x:
            t = prefix.clean(x["t"]["value"])
        else:
            # pprint.pprint(x)
            pass  # have no node type

        k = x["p"]["value"]
        k = prefix.clean(k)
        if k not in d:
            if k not in skip:
                d[k] = v  # the value of the field
                dt[k] = t  # the domain type of the field object
        else:
            # d[k]=[d[k],v]
            raise Exception("duplicate")
    pprint.pprint({"query_results": d}, depth=2)
    return d, dt
def start():
    t = {}
    results = prefix.q("""  
SELECT ?a  WHERE {
  ?a fld:srcp 'eval.c:216'.
  ?a fld:name  [ fld:string 'parse_command'].
  ?a rdf:type nt:function_decl.
}
""")
    for x in results["results"]["bindings"]:
        print((x["a"]["value"]))
        r = recurse(x["a"]["value"])
        pprint.pprint(rec(r))
Exemple #4
0
def start():
    t = {}
    results = prefix.q( """  
SELECT ?a  WHERE {
  ?a fld:srcp 'eval.c:216'.
  ?a fld:name  [ fld:string 'parse_command'].
  ?a rdf:type nt:function_decl.
}
""")               
    for x in results['results']['bindings']:
        print x['a']['value']
        r= recurse(x['a']['value'])
        pprint.pprint(rec(r))
def start():
    t = {}
    results = prefix.q( """  
SELECT ?a  WHERE {
  ?a fld:srcp 'eval.c:216'.
  ?a fld:name  [ fld:string 'parse_command'].
  ?a rdf:type nt:function_decl.
}
""")               
    for x in results['results']['bindings']:
        print(x['a']['value'])
        r= recurse_ref(x['a']['value'],tree)
        o = open("data/body2.py","w")
        o.write("deep={v2}".format(v2=pprint.pformat(r)))
        o.close()
Exemple #6
0
def start():
    t = {}
    results = prefix.q(
        """  
SELECT ?a  WHERE {
  ?a fld:srcp 'eval.c:216'.
  ?a fld:name  [ fld:string 'parse_command'].
  ?a rdf:type nt:function_decl.
}
"""
    )
    for x in results["results"]["bindings"]:
        print((x["a"]["value"]))
        r = recurse_ref(x["a"]["value"], tree)
        o = open("data/body2.py", "w")
        o.write("deep={v2}".format(v2=pprint.pformat(r)))
        o.close()
def ftypes():
    t = {}
    results = prefix.q("""  

    SELECT ?st ?p ?ot (count(?o) as ?count) (min(?o) as ?firsto) (min(?s) as ?firsts)
WHERE {
    ?s rdf:type ?st.
    ?s ?p ?o.
    ?o rdf:type ?ot.                                                                                                                                            } group by  ?st ?p ?ot

""")
    print(("\t".join(["count", "firsto", "firsts", "st", "p", "ot"])))
    d1 = {}
    d2 = {}
    for x in results["results"]["bindings"]:
        s = prefix.clean(x["st"]["value"])
        o = prefix.clean(x["ot"]["value"])
        p = prefix.clean(x["p"]["value"])
        print(("\t".join([
            x["count"]["value"],
            prefix.clean(x["firsto"]["value"]),
            prefix.clean(x["firsts"]["value"]),
            prefix.clean(x["st"]["value"]),
            prefix.clean(x["p"]["value"]),
            prefix.clean(x["ot"]["value"]),
        ])))

        atype = False
        if o.endswith("type"):
            atype = True
        if s.endswith("type"):
            atype = True
        if p in (
                "type",
                "domn",
                "elts",
                "size",
                "unql",
                "chain",
                "scpe",
                "min",
                "max",
                "csts",
                "bpos",
                "retn",
                "argt",
                "ptd",
                "flds",
                "refd",
        ):
            atype = True

        if not atype:
            d = d1
            if s not in d:
                d[s] = {}
            if p not in d[s]:
                d[s][p] = {}

            if o not in d[s][p]:
                d[s][p][o] = x["count"]["value"]
            else:
                d[s][p][o] = d[s][p][o] + x["count"]["value"]
        else:
            d = d2
            if s not in d:
                d[s] = {}
            if p not in d[s]:
                d[s][p] = {}

            if o not in d[s][p]:
                d[s][p][o] = x["count"]["value"]
            else:
                d[s][p][o] = d[s][p][o] + x["count"]["value"]

    pprint.pprint({"exprs": d1, "types": d2})
Exemple #8
0
def ftypes():
    t = {}
    results = prefix.q( """  

    SELECT ?st ?p ?ot (count(?o) as ?count) (min(?o) as ?firsto) (min(?s) as ?firsts)
WHERE {
    ?s rdf:type ?st.
    ?s ?p ?o.
    ?o rdf:type ?ot.                                                                                                                                            } group by  ?st ?p ?ot

""")
    print "\t".join(
        [
            'count',
            'firsto',
            'firsts',
            'st',
            'p',
            'ot'])
    d1 = {}
    d2 = {}
    for x in results['results']['bindings']:
        s=prefix.clean(x['st']['value'])
        o=prefix.clean(x['ot']['value'])
        p=prefix.clean(x['p']['value'])
        print "\t".join(
            [
                x['count']['value'],
                prefix.clean(x['firsto']['value']),
                prefix.clean(x['firsts']['value']),
                prefix.clean(x['st']['value']),
                prefix.clean(x['p']['value']),
                prefix.clean(x['ot']['value'])
            ])
            

        atype =False
        if o.endswith('type'):
            atype=True
        if s.endswith('type'):
            atype=True
        if p in ('type','domn','elts',
                     'size','unql',
                     'chain',
                     'scpe',
                     'min',
                     'max',
                     'csts',
                     'bpos',
                     'retn',
                     'argt',
                     'ptd',
                     'flds',
                     'refd'
             ):
            atype=True


        if not atype:
            d = d1
            if s not in d:
                d[s] = {}
            if p not in d[s]:
                d[s][p] = {}

            if o not in d[s][p]:
                d[s][p][o]  =x['count']['value']
            else:
                d[s][p][o]= d[s][p][o] + x['count']['value']            
        else:
            d = d2
            if s not in d:
                d[s] = {}
            if p not in d[s]:
                d[s][p] = {}

            if o not in d[s][p]:
                d[s][p][o]  =x['count']['value']
            else:
                d[s][p][o]= d[s][p][o] + x['count']['value']            


    pprint.pprint( { 'exprs' :d1 ,
                     'types' :d2
                 })