Exemplo n.º 1
0
 def download(self, path):
     if self.isJson():
         dumpJson(path, self.response.json())
     elif self.isJsonp():
         data = self.jsonpToJson()
         dumpJson(path, data)
     else:
         print "can't download successfully"
Exemplo n.º 2
0
def localGroup(fName):
    lines = tools.loadJson(fName)
    if lines == -1:
        return -1
    i = 0
    while i < len(lines):
        j = i
        i = group(lines, i, "PER")
        i = group(lines, i, "LOC")
        i = group(lines, i, "ORG")
        if i == j:
            i += 1
    tools.dumpJson(lines, fName)
Exemplo n.º 3
0
    result = []
    for line in text.splitlines():
        taggedWords = {}
        words = line.split(delim)
        if len(words) < 2:
            for index in header.keys():
                taggedWords[header[index]] = ""
        else:
            for index in header.keys():
                taggedWords[header[index]] = words[index]
        taggedWords["virtual"] = False
        result.append(taggedWords)
    return result


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "usage : 2json.py fileName"
    f = os.path.abspath(sys.argv[1])
    exts = f.split(".")
    newFile = exts[0] + ".json"
    if not os.path.isfile(f):
        print "Error " + f + " file does not exists"
        sys.exit()
    if exts[-1] == "NER":
        if exts[-2] == "post":
            result = convert(postNERHeader, f, "\t")
    else:
        sys.exit()
    tools.dumpJson(newFile)
Exemplo n.º 4
0
def add2Results(partial, store):
    for k in partial.keys():
        for v in partial[k].keys():
            if not store.has_key(k):
                store[k] = {}
            if not store[k].has_key(v):
                store[k][v] = 0
            store[k][v] += partial[k][v]
    return store

if __name__=="__main__":
    amira_dir = settings.amira_dir
    results = {}
    if len(sys.argv) < 3:
        print "usage: getStats.py folder format[json|...]\nFolder should contain files in .t extension"
    folder = os.path.abspath(sys.argv[1])
    fmt  = sys.argv[2]
    i = 0
    for fName in tools.files(folder, ".*"):
        fName = os.path.abspath(fName)
        if fmt == 'json':
            if i%100 == 0:
                print  i, " files finished"
            partial = parseJson(fName, isNNPVirt, "NER")
            i+=1
        else:
            partial = parsePostNER(fName)
        add2Results(partial, results)
    statFile = os.path.join(folder, 'stats')
    tools.dumpJson(results, statFile)
Exemplo n.º 5
0
def tagFile(f, dictionary):
    jText = tools.loadJson(f)
    if jText == -1:
        return -1
    jNewText = tag(jText, dictionary)
    tools.dumpJson(jNewText, f+".t")
Exemplo n.º 6
0
def csv2dict(fName):
    result = buildDictionary(csv2dicts(fName), "Arabic")
    newFile = fName.split(os.path.extsep)[0]+".json"
    tools.dumpJson(result, newFile)
Exemplo n.º 7
0
def csv2json(fName):
    result = csv2dicts(fName)
    newFile = fName.split(os.path.extsep)[0]+".json"
    tools.dumpJson(result, newFile)