def main():
    args = (sys.argv)
    inputFile= str(args[1])
    outputFile= str(args[2])
    depth = int(args[3])
    try:
        root = fun.getFileContent(inputFile)
        child_branch= fun.MiniMax(root,depth,True)
        children = fun.GenerateMovesOpening(root)
        fun.writeToFile(outputFile,children[child_branch])
    except Exception as e:
        print("An Error occured :",e)
def main():

    thread_in = fns.inverted_thread_class()
    thread_seq = fns.sequential_thread_class()

    thread_in.start()
    thread_seq.start()

    thread_in.join()
    thread_seq.join()

    fns.addToUids()
    fns.writeToFile()

    thread_find_in = fns.find_name_in_thread_class()
    thread_find_seq = fns.find_name_seq_thread_class()
    thread_find_in.start()
    thread_find_seq.start()
    thread_find_in.join()
    thread_find_seq.join()

    fns.writeNames()

    fns.makeMarkdown()
示例#3
0
    for row in innerbody:
        if row[0][0] == "":
            continue
        doc2list[row[0][0]] = row[0]
        doc2list[row[2][0]] = row[2]
        doc2list[row[4][0]] = row[4]
        count += 1

notpresent = list()
present = list()
for record in doc2list.values():
    if doc1list.get(record[0]):
        for row in doc1list:
            del row[3]
            del row[4]
            del row[5]
            present.append(record)
    else:
        notpresent.append(record)

document1 = Document(docx="D:\\PycharmProjects\\docfilefinder\\MASTERRYANLABELFILE.docx")
tables = document1.tables
for tab in tables:
    print("Columns: ", len(tab.columns), "Rows: ", len(tab.rows))
tab = tables[0]

writeToFile(notpresent, document1, tab)



def triplify_dataset(change_file, parcel_file,  output_folder):
    startEpoch = time.time()    
    files = []
    print('Compute and triplify change detection result')
    village = parcel_file[-20:-15]
    triples = []
    iFiles = 0
    iTriples = 0
    lsNameSpaces, lsTriplesTemplate = readTemplate(templateFile)
    changeFile = rasterio.open(change_file)   
    print("Change data read, CRS (expected 32630):", changeFile.crs)
    img1 = changeFile.tags()['T1_Product_ID']
    img2 = changeFile.tags()['T2_Product_ID']
    start_date = changeFile.tags()['T1_Start_Date']
    end_date = changeFile.tags()['T2_Start_Date']
    parcelFile = gpd.read_file(parcel_file)  
    if '.shp' in parcel_file:
        project = partial(
                pyproj.transform,
                pyproj.Proj(init='epsg:4326'),
                pyproj.Proj(init=changeFile.crs))

    for index, row in parcelFile.iterrows():
        clear_output()
        print(str(index) + '/' + str(len(parcelFile)))
        feat = {}
        feat['id'] = row['id']
        feat['parcel'] = row['id']
        try:           
            geom = transform(project, row['geometry'])
            parcelChange, changeTransform = mask(changeFile, [geom], crop=True, indexes=1, nodata=-1)
        except ValueError as err:
            print(err)
            continue

        total = parcelChange[parcelChange>=0].size
        if total <= 0:
            try:
                geom = transform(project, row['geometry'])
                parcelChange, changeTransform = mask(changeFile, [geom], crop=True, all_touched=True, indexes=1, nodata=-1)
            except ValueError as err:
                print(err)
                continue

        if total > 0:
            feat['nop'] = round(parcelChange[(parcelChange < 0.1) & (parcelChange >= 0)].size*100/total,2)
            feat['lowp'] = round(parcelChange[(parcelChange >= 0.1) & (parcelChange < 0.4)].size*100/total,2)
            feat['midp'] = round(parcelChange[(parcelChange >= 0.4) & (parcelChange < 0.7)].size*100/total,2)
            feat['highp'] = round(parcelChange[(parcelChange >= 0.7)].size*100/total,2)
            feat['id'] = "PC" + str(feat['id']) + "_" + start_date + "_" + end_date
            feat['id'] = str(feat['id']).replace('-','_')
            feat['image1'] = img1
            feat['image2'] = img2
            uriDummy = URIBase + 'Change/' + str(feat['id'])+">"
            triplesRow = triplify(feat, lsTriplesTemplate,
                                  uriDummy, str(feat['id']), str(feat['parcel']))

            triples = triples + triplesRow

        else:
            print("no data on this parcel")

    file = output_folder + 'change.ttl'

    files.append(file)
    writeToFile(lsNameSpaces, triples, output_folder)
    clear_output()
    print('Number of triples', iTriples)
    print('Number of parcel', len(parcelFile))
    
    endEpoch = time.time()
    elapsedTime = endEpoch - startEpoch
    if elapsedTime < 60:
        print('Elapsed time : ', elapsedTime, ' seconds')
    else:
        print('Elapsed time : ', math.floor(elapsedTime / 60),
              ' minutes and ', elapsedTime % 60, ' seconds')

    return files
示例#5
0
def triplify_dataset(file, parcel_file, product_id, output_folder='./rdf'):

    startEpoch = time.time()

    files = []
    triples = []
    iFiles = 0
    iTriples = 0
    village = parcel_file[-20:-15]
    lsNameSpaces, lsTriplesTemplate = readTemplate(templateFile)

    ndvi_file = rasterio.open(file)

    print("ndvi_file data read, CRS (expected 32630):", ndvi_file.crs)
    parcelFile = gpd.read_file(parcel_file)
    if '/' in file:
        image_date = file[file.rfind('/') + 1:-7]
    else:
        image_date = file[0:-7]

    project = partial(pyproj.transform, pyproj.Proj(init='epsg:4326'),
                      pyproj.Proj(init=ndvi_file.crs))

    for index, row in parcelFile.iterrows():
        clear_output()
        print(str(index) + '/' + str(len(parcelFile)))
        feat = {}
        feat['id'] = str(row['id'])
        feat['parcel'] = str(row['id'])
        feat['area_type'] = str(row['area_type'])
        feat['geojson'] = shape(row['geometry']).wkt
        try:
            geom = transform(project, row['geometry'])
            ndviParcel, ndviTransform = mask(ndvi_file, [geom],
                                             crop=True,
                                             all_touched=True,
                                             indexes=1)
        except ValueError as err:
            print(err)
            continue
        ndvi = np.float16(ndviParcel)
        total = ndvi[ndvi >= 0.2].size
        if total <= 0:
            try:
                geom = transform(project, row['geometry'])
                ndviParcel, ndviTransform = mask(ndvi_file, [geom],
                                                 crop=True,
                                                 indexes=1)
            except ValueError as err:
                print(err)
                continue
        ndvi = np.float16(ndviParcel)
        total = ndvi[ndvi >= 0.2].size
        if total > 0:
            feat['lowp'] = round(
                ndvi[(ndvi >= 0.2) & (ndvi < 0.5)].size * 100 / total, 2)
            feat['midp'] = round(
                ndvi[(ndvi >= 0.5) & (ndvi < 0.7)].size * 100 / total, 2)
            feat['highp'] = round(ndvi[(ndvi >= 0.7)].size * 100 / total, 2)

            feat['id'] = "PN" + feat['id'] + "_" + image_date
            feat['id'] = feat['id'].replace('-', '_')

            feat['image'] = product_id
            uriDummy = URIBase + 'NDVI/' + feat['id'] + ">"
            triplesRow = triplify(feat, lsTriplesTemplate, uriDummy,
                                  feat['id'], feat['parcel'])

            triples = triples + triplesRow
            if len(triples) > maxRecordsPerFile:
                file = output_folder
                files.append(file)
                writeToFile(lsNameSpaces, triples, file)
                iFiles = iFiles + 1
                iTriples = iTriples + len(triples)
                triples = []
        else:
            print("Too small!")

    file = output_folder + 'ndvi.ttl'
    writeToFile(lsNameSpaces, triples, file)

    files.append(file)
    clear_output()
    print('Number of parcel', len(parcelFile))
    print('Number of triples', iTriples)
    endEpoch = time.time()
    elapsedTime = endEpoch - startEpoch
    if elapsedTime < 60:
        print('Elapsed time : ', elapsedTime, ' seconds')
    else:
        print('Elapsed time : ', math.floor(elapsedTime / 60), ' minutes and ',
              elapsedTime % 60, ' seconds')
    return files
示例#6
0
def triplify_dataset(cesbio_file, parcel_file, output_folder):
    startEpoch = time.time()
    print('triplify Cadastral parcel and its land-cover')
    village = parcel_file[-20:-15]
    triples = []
    files = []
    iFiles = 0
    iTriples = 0
    lsNameSpaces, lsTriplesTemplate = readTemplate(templateFile)
    CesbioFile = rasterio.open(cesbio_file)
    print("Land cover (expected 4326):", CesbioFile.crs)
    parcelFile = gpd.read_file(parcel_file)

    print(CesbioFile.crs)
    if '.shp' in parcel_file:
        project = partial(pyproj.transform, pyproj.Proj(init='epsg:4326'),
                          pyproj.Proj(init='epsg:4326'))

    for index, row in parcelFile.iterrows():
        clear_output()
        print(str(index) + '/' + str(len(parcelFile)))
        feat = {}
        feat['id'] = row['id']
        feat['geojson'] = shape(row['geometry']).wkt
        try:
            geom = transform(project, row['geometry'])
            LCParcel, LCTransform = mask(CesbioFile, [geom],
                                         crop=True,
                                         indexes=1,
                                         nodata=0)
        except ValueError as err:
            print(err)
            continue

        if np.count_nonzero(LCParcel) <= 0:
            try:
                geom = transform(project, row['geometry'])
                LCParcel, LCTransform = mask(CesbioFile, [geom],
                                             crop=True,
                                             all_touched=True,
                                             indexes=1,
                                             nodata=0)
            except ValueError as err:
                print(err)
                continue

        if np.count_nonzero(LCParcel) > 0:
            counter = Counter(LCParcel.ravel())
            dominantLCCode, DominantLCFreq = counter.most_common(2)[0]
            if dominantLCCode == 0:
                dominantLCCode, DominantLCFreq = counter.most_common(2)[1]

            percentage = round(
                DominantLCFreq * 100 / np.count_nonzero(LCParcel), 0)
            feat['lc'] = correspond_land_cover(dominantLCCode)
            URI = URIBase + 'Parcel/' + str(row['id']) + ">"
            triplesRow = triplify(feat, lsTriplesTemplate, URI,
                                  "p" + str(row['id']))
            triples = triples + triplesRow
        else:
            print("Too small!")

    file = output_folder + 'land_cover.ttl'
    files.append(file)
    writeToFile(lsNameSpaces, triples, file)
    clear_output()
    print('Number of triples', iTriples)
    print('Number of parcel', len(parcelFile))
    endEpoch = time.time()
    elapsedTime = endEpoch - startEpoch

    if elapsedTime < 60:
        print('Elapsed time : ', elapsedTime, ' seconds')
    else:
        print('Elapsed time : ', math.floor(elapsedTime / 60), ' minutes and ',
              elapsedTime % 60, ' seconds')
    return files
示例#7
0
def sort_trans(dset, new_file_name, file):
    f = open(file, 'r')
    fw = open(new_file_name, 'w')
    fw_tst = open(new_file_name + 'test', 'w')
    wp = ""
    wp_tst = ""
    total_trans = DSET1_TRANS_CNT
    bucket_list = [0, 0]
    line = f.readline()
    if dset == 2:
        line = f.readline()
        total_trans = DSET2_TRANS_CNT
    prod_sup = {}
    trans_small = RPERC[1] * total_trans
    trans_big = RPERC[0] * total_trans
    while line != "":
        line = line.strip()
        trans = line.split(';')
        trans.sort()

        if bucket_list[1] < trans_small:
            if bucket_list[0] >= trans_big:
                bucket = 1
            else:
                bucket = random.randint(0, 1)
        else:
            bucket = 0

        if bucket == 0:
            for item in trans:
                if not prod_sup.has_key(item):
                    prod_sup[item] = 1
                else:
                    prod_sup[item] += 1

            sp = ';'.join(trans)
            wp += sp + '\n'
            if len(wp) > 5000:
                fw.write(wp)
                wp = ""
        else:
            for item in trans:
                if not prod_sup.has_key(item):
                    prod_sup[item] = 0
            sp_tst = ';'.join(trans)
            wp_tst += sp_tst + '\n'
            if len(wp_tst) > 5000:
                fw_tst.write(wp_tst)
                wp_tst = ""

        bucket_list[bucket] += 1

        line = f.readline()

    if len(wp) > 0:
        fw.write(wp)
    if len(wp_tst) > 0:
        fw_tst.write(wp_tst)

    fw.close()
    fw_tst.close()

    prod_list = prod_sup.keys()
    prod_list.sort()
    if dset == 1:
        writeToFile('DSET1/prod_list.txt', prod_list, [])
        writeToFile('DSET1/prod_sup.txt', prod_sup, [])
    else:
        if new_file_name == 'DSET2/trans_prod_sort.txt':
            writeToFile('DSET2/prod_list.txt', prod_list, [])
            writeToFile('DSET2/prod_sup.txt', prod_sup, [])
        else:
            writeToFile('DSET2/prod_sup_tst.txt', prod_sup, [])