From 9344938970075991c989d6f7ce4b438337fa3778 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Wed, 8 Sep 2021 16:08:42 +0200
Subject: [PATCH] Added script to copy a column

---
 scripts/conlluCopyColumn.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100755 scripts/conlluCopyColumn.py

diff --git a/scripts/conlluCopyColumn.py b/scripts/conlluCopyColumn.py
new file mode 100755
index 0000000..8cf162c
--- /dev/null
+++ b/scripts/conlluCopyColumn.py
@@ -0,0 +1,29 @@
+#! /usr/bin/env python3
+
+import sys
+from readMCD import readMCD
+
+if len(sys.argv) < 4 :
+  print("USAGE : %s fromColumn toColumn file1.conllu file2.conllu..."%sys.argv[0], file=sys.stderr)
+  exit(1)
+
+fromCol = sys.argv[1]
+toCol = sys.argv[2]
+
+for filename in sys.argv[3:] :
+  lines = []
+  for line in open(filename, "r") :
+    line = line.strip()
+    if "# global.columns =" in line :
+      line = line + " " + toCol
+      conllMCD, conllMCDr = readMCD(line.split('=')[-1].strip())
+    if len(line) == 0 or line[0] == '#' :
+      lines.append(line)
+      continue
+    splited = line.split('\t')
+    fromValue = splited[conllMCD[fromCol]]
+    splited.append(fromValue)
+    lines.append("\t".join(splited))
+  with open(filename, "w") as out :
+    print("\n".join(lines), file=out)
+
-- 
GitLab