Ejemplo n.º 1
0
def main(inputPtnPath, outputPath, pspath):

    model, table = projizz.readPrefixTreeModelWithTable(
        "./yagoPatternTree.model", "./yagoPatternTree.table")
    properties = projizz.buildYagoProperties({
        "tp": [],
        "tn": [],
        "fp": [],
        "fn": []
    })
    sp = projizz.getSortedStatistic(projizz.jsonRead(pspath))
    validate = []

    # Get Top 200 Relation
    for relation in sp:
        count = 0
        for ptnId, ptnS in sp[relation]:
            ptnData = table[ptnId]
            if len(ptnData["relations"]) == 1:
                count += 1
                validate.append(ptnId)
            if count >= 200:
                break

    start_time = datetime.now()

    pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
    t = 0
    result = []
    for filename in os.listdir(inputPtnPath):
        if ".json" in filename:
            partAns = copy.deepcopy(properties)
            result.append(
                pool.apply_async(filterFunction,
                                 (t, filename, inputPtnPath, model, table,
                                  partAns, validate)))
            t += 1
    pool.close()
    pool.join()

    for res in result:
        r = res.get()
        for m in r:
            properties[m]["tp"] += r[m]["tp"]
            properties[m]["tn"] += r[m]["tn"]
            properties[m]["fp"] += r[m]["fp"]
            properties[m]["fn"] += r[m]["fn"]

    print "start write out to %s" % (outputPath)
    json.dump(properties, open(outputPath, "w"))

    diff = datetime.now() - start_time
    print "Spend %d.%d seconds" % (diff.seconds, diff.microseconds)
def main(inputPtnPath,outputPath,pspath):
    
    model, table = projizz.readPrefixTreeModelWithTable("./yagoPatternTree.model","./yagoPatternTree.table")
    properties = projizz.buildYagoProperties({"tp":[],"tn":[],"fp":[],"fn":[]})
    sp = projizz.getSortedStatistic(projizz.jsonRead(pspath))
    validate = []
   
    # Get Top 100 Relation
    for relation in sp:
        count = 0
        for ptnId,ptnS in sp[relation]:
            ptnData = table[ptnId]
            if len(ptnData["relations"]) == 1:
                count += 1
                validate.append(ptnId)
            if count >= 100:
                break

    start_time = datetime.now()

    pool = multiprocessing.Pool(processes=multiprocessing.cpu_count()) 
    t = 0
    result = []
    for filename in os.listdir(inputPtnPath):
        if ".json" in filename:
            partAns = copy.deepcopy(properties)
            result.append(pool.apply_async(filterFunction, (t,filename,inputPtnPath,model,table,partAns,validate )))
            t += 1
    pool.close()
    pool.join()

    for res in result:
        r = res.get()
        for m in r:
            properties[m]["tp"] += r[m]["tp"]
            properties[m]["tn"] += r[m]["tn"]
            properties[m]["fp"] += r[m]["fp"]
            properties[m]["fn"] += r[m]["fn"]

    print "start write out to %s" % (outputPath)
    json.dump(properties,open(outputPath,"w"))

    diff = datetime.now() - start_time
    print "Spend %d.%d seconds" % (diff.seconds, diff.microseconds)
Ejemplo n.º 3
0
# -*- coding: utf-8 -*-
# qcl
#

import sys
import projizz

if len(sys.argv) <= 1:
    print "$ python ./simpleSortedViewer.py [ps json]"
else:
    filename = sys.argv[1]
    ps = projizz.jsonRead(filename)
    sortedp = projizz.getSortedStatistic(ps)
    model, table = projizz.readPrefixTreeModelWithTable(
        "./yagoPatternTree.model", "./yagoPatternTree.table")
    for relation in sortedp:
        print relation
        for ptnId, ptnS in sortedp[relation]:
            print "%s\t%s %s %s" % (relation, table[ptnId]["pattern"], ptnId,
                                    ptnS)
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
# qcl
#

import sys
import projizz

if len(sys.argv) <= 1:
    print "$ python ./simpleSortedViewer.py [ps json]"
else:
    filename = sys.argv[1]
    ps = projizz.jsonRead(filename)
    sortedp = projizz.getSortedStatistic(ps)
    model,table = projizz.readPrefixTreeModelWithTable("./yagoPatternTree.model","./yagoPatternTree.table")
    for relation in sortedp:
        print relation
        for ptnId,ptnS in sortedp[relation]:
            print "%s\t%s %s %s" % (relation,table[ptnId]["pattern"],ptnId,ptnS)