diff --git a/tasks/get_index.py b/tasks/get_index.py new file mode 100644 index 0000000000000000000000000000000000000000..a511a3fa1b8cb1c4e0389a3df2e414de39a2afd0 --- /dev/null +++ b/tasks/get_index.py @@ -0,0 +1,45 @@ +import os +import re + +for root, dirs, files in os.walk("."): + break + +class Data: + title = "" + id = "" + index = 0 + def __init__(self, title, id, index): + self.title = title + self.id = id + self.index = index + + +for dir in dirs: + indices = [] + + for root, dirs, files in os.walk(dir): + for file in files: + if file.endswith(".md"): + f = open(dir + "/" + file, "r", encoding='utf-8') + + title = "" + id = "" + index = 0 + + for line in f: + if line.startswith("id:"): + print(line.split(":")[1]) + id = line.split(":")[1] + elif line.startswith("index:"): + index = int(line.split(":")[1]) + elif line.startswith("title:"): + title = line.split(":")[1] + indices.append(Data(title, id, index)) + + indices = sorted(indices, key=lambda x: x.index) + + with open(dir + "/index_list.txt","w+", encoding='utf-8') as output: + for index in indices: + output.write(index.title.rstrip("\n") + ", " + index.id.rstrip("\n")) + output.write("\n") + diff --git a/tasks/kapitel_1/index_list.txt b/tasks/kapitel_1/index_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..759b29b45d6f53b01906754c41cdc5031b1f085e --- /dev/null +++ b/tasks/kapitel_1/index_list.txt @@ -0,0 +1,6 @@ + 'Vad är naturligt språk-behandling?', '1f0394bd-e7ae-4349-9962-7fa647f8a252' + 'Sökning och inlärning', '1e78e6d7-6df3-446b-8ee8-c92ff5f4a5e0' + 'NLP i ett bredare perspektiv', 'f8dca544-8cd6-43b6-8425-d4ef0609127d' + 'Linjär regression', 'a9c513a9-418e-4e4d-9e3f-50a0e84a206e' + 'Gradientsökning', '04d9bb5e-9a05-44f0-961a-8741cc66845f' + 'Deluppgift 1, 'c2ca1421-5b03-404d-9f1e-f2aa9362e6a3' diff --git a/tasks/kapitel_2/index_list.txt b/tasks/kapitel_2/index_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..03a40dea68cdc9691b3ede776c5a76f5710e92bd --- /dev/null +++ b/tasks/kapitel_2/index_list.txt @@ -0,0 +1,8 @@ + 'Språkliga datamängder', '08064988-ab0b-49e7-877f-1a311ee4d315' + 'Annoterade data', '405f0994-a4ff-41af-acea-1b2c4a5b3fd0' + 'Deluppgift 1, '2e7634a5-ef13-4ffe-880f-7f86c51c6126' + 'Statistiska egenskaper hos språkdata', '26a431ab-351f-423c-a73d-d0b8cf7ef71a' + 'Deluppgift 2, '09ccf457-d9a9-4f76-bdd9-5b00806c7244' + 'Från råmaterial till segmenterad text', 'd8cad020-9d98-439a-b098-22561d272c51' + 'Deluppgift 3, '097df357-932e-4352-9bf6-39ebfe642fd3' + 'Slutuppgift, 'bb08a19c-0163-4741-91c9-90658352c1cf' diff --git a/tasks/kapitel_3/index_list.txt b/tasks/kapitel_3/index_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..e1a81e9b57db9384872dba1c5ed9aed5d8de3ff0 --- /dev/null +++ b/tasks/kapitel_3/index_list.txt @@ -0,0 +1,10 @@ + 'Introduktion till textklassificering', 'c34bfdfd-1056-4273-a434-495dc7e65666' + 'Textklassificering som maskininlärning', '8c91f044-030c-4549-9b7c-c997f78726de' + 'Deluppgift 1, '1c4ffffb-a99b-4da2-b5f1-097f83d1708e' + 'Utvärdering av textklassificerare', 'af837ecb-1ca7-4b8b-b1b4-30e7df4c8005' + 'Naive Bayes-klassificeraren', '61f20a90-1031-4f74-a3c3-1595f0ed3499' + 'Dokumentrepresentationer', '9bf8f580-a889-4e64-bc18-fb91223d39bc' + 'Deluppgift 2, '673e568d-7d75-4707-90dc-4bc3b2c1b034' + 'Deluppgift 3, '56967e0b-132b-497f-92f7-bc1cf68e82d6' + 'Logistisk regression', 'cc834b0b-3f0b-433b-967f-e0f48e232c89' + 'Slutuppgift, '27a2fe79-4122-4962-a8c8-a7c4d828959b' diff --git a/tasks/kapitel_4/index_list.txt b/tasks/kapitel_4/index_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b1066705cba86555e9fe0badf82735bff3e86bb --- /dev/null +++ b/tasks/kapitel_4/index_list.txt @@ -0,0 +1,7 @@ + 'Ordinbäddningar', '43b35978-739e-4eeb-a504-7a112c11c3b4' + 'Ordinbäddningar via matriskomprimering', '01e1e2c0-528b-4fbc-a1c1-62fce6888253' + 'Ordinbäddningar via neuronnät', '4804421d-5d8f-40ab-8bfc-679708d10496' + 'Deluppgift 1, '499a81cc-0810-4874-9ed5-2f61f807070c' + 'Deluppgift 2, 'd12aa24f-b3be-413e-ba1c-52e1c3bc74dd' + 'Begränsningar med ordinbäddningar', 'ea77fb95-505a-4980-b132-06f1236e475d' + 'Slutuppgift, '9bb3fecf-b75e-4e05-9a55-1b516db9d050' diff --git a/tasks/kapitel_5/index_list.txt b/tasks/kapitel_5/index_list.txt new file mode 100644 index 0000000000000000000000000000000000000000..24334b6d2b782c28fc9236014c0faba40f274146 --- /dev/null +++ b/tasks/kapitel_5/index_list.txt @@ -0,0 +1,8 @@ + 'Automatisk språkförståelse', '2a07780b-3704-441d-9150-a2e9372bdbf7' + 'Sekvenstaggning', '6c63232f-dbd4-4bf4-89d4-b8e06f8e4b86' + 'Sekvenstaggning med lokal sökning', '6481175e-7103-4b8c-9493-acbfd1ad6ccc' + 'Deluppgift 1, '86458015-3420-4c2e-8aeb-35f09dbf39ab' + 'Dependensparsning', '50560bf2-68fe-4b6e-932a-1278eb9cdce6' + 'Transitionsbaserad dependensparsning', '61fbedfe-33b2-48d1-9d07-f5848013c502' + 'Deluppgift 2, '886c9349-8934-4035-a434-984f74505451' + 'Slutuppgift, 'f06b66d3-588a-4fdd-8ebe-2bd67c14c2cc' diff --git a/tasks/update_index.py b/tasks/update_index.py new file mode 100644 index 0000000000000000000000000000000000000000..3ac3abb9316771545f967b40d5d0ce0017b89715 --- /dev/null +++ b/tasks/update_index.py @@ -0,0 +1,70 @@ +import os +import re + +for root, dirs, files in os.walk("."): + break + +class Data: + title = "" + id = "" + index = 0 + def __init__(self, title, id, index): + self.title = title + self.id = id + self.index = index + + +for dir in dirs: + f = open(dir + "/" + "index_list.txt", "r", encoding='utf-8') + + indices = [] + updated_indices = [] + for line in f: + updated_indices.append(line.split(",")[1].strip()) + + for root, dirs, files in os.walk(dir): + for file in files: + if file.endswith(".md"): + f = open(dir + "/" + file, "r", encoding='utf-8') + title = "" + id = "" + index = 0 + for line in f: + if line.startswith("id:"): + id = line.split(":")[1].strip() + elif line.startswith("index:"): + index = int(line.split(":")[1]) + + elif line.startswith("title:"): + title = line.split(":")[1] + indices.append(Data(title, id, index)) + + indices = sorted(indices, key=lambda x: x.index) + + for a, b in zip(indices, updated_indices): + if a.id != b: + print("Found modified chapter index") + + #Go through every file and update index. Can be optimized. Prev and next can be added. + + for file in files: + if file.endswith(".md"): + + f = open(dir + "/" + file, "r", encoding='utf-8') + + data = f.read() + m = re.search('^id: (.+)', data, re.MULTILINE) + id = m.group(1) + + m2 = re.search('index: (.+)', data) + index_pos = m2.span(1)[0] + + # we use 1 as starting index + new_index = updated_indices.index(id) + 1 + + replace_data = data[:index_pos] + str(new_index) + data[index_pos+1:] + f2 = open(dir + "/" + file, "w", encoding='utf-8') + print(replace_data == data) + print(index_pos) + f2.write(replace_data) + break