Blame view

bin/replace-features.py 698 Bytes
e63ab06fc   Mathias Quillot   New organisation ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  
  import argparse
  
  from data import read_file, index_by_id, write_line
  
  # -- ARGPARSE
  parser = argparse.ArgumentParser(
      description="Replace features with file from to file to")
  parser.add_argument("fromfile", type=str, help="From list or features file")
  parser.add_argument("tofile", type=str, help="Features of 'from' saved into this file.")
  
  args = parser.parse_args()
  FROM = args.fromfile
  TO = args.tofile
  
  
  # -- READ AND INDEX FILES
  from_data = read_file(FROM)
  from_by_id = index_by_id(from_data)
  
  to_data = read_file(TO)
  
  with open(TO, "w") as f:
      for line in to_data:
          metas = line[0]
          features = from_by_id[metas[0]][metas[3]][1]
          write_line(metas, features, f)