{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#
DETEKSI POLA AMBIGUITAS STRUKTURAL
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Import Library NLTK RegexpParser & Pandas" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import nltk\n", "from nltk import RegexpParser\n", "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Import Dokumen Anotasi Pernyataan Kebutuhan Perangkat Lunak" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def open_file(nameFile):\n", " with open(nameFile, encoding=\"utf-8\") as reqs:\n", " data_reqs = reqs.readlines()\n", " all_reqs = [x.rstrip('\\n') for x in data_reqs]\n", " return all_reqs" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pdpt dikti\n" ] } ], "source": [ "inputreadfile = input()\n", "readFile = \"Hasil Tag/Tag \"+inputreadfile+\".txt\"\n", "requirements = open_file(readFile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Sentence Splitting" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "sentences= []\n", "tags = []\n", "kalimat = []\n", "index = 0\n", "while index < len(requirements):\n", " sent = [] #untuk menampung katanya\n", " kata = []\n", " tag = [] #untuk menampung postag dari tiap kata\n", " while not requirements[index].startswith('}\n", "coordination:{}\n", "PPattachment:{*}\n", "\"\"\"\n", "chunk = RegexpParser(pola)\n", "for kalimats in sentences:\n", " result = chunk.parse(kalimats)\n", " polaAmbiguity.append(str(result).split(\"\\n\"))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 ['(S Mampu/NN menambahkan/VB (analytical data/NN user/NN baru/JJ))']\n", "11 ['(S', ' Aplikasi/NN', ' menampilkan/VB', ' rasio/NN', ' jumlah/NN', ' dosen/NN', ' dan/CC', ' mahasiswa/NN', ' berdasarkan/VB', ' (analytical jenis/NND perguruan/NN tinggi/JJ)', ' (/Z', ' PTN/PTS/NN', ' )/Z)']\n", "14 ['(S', ' Aplikasi/NN', ' menampilkan/VB', ' (analytical jumlah/NN guru/NN besar/JJ)', ' per/IN', ' tahun/NN)']\n", "15 ['(S', ' Aplikasi/NN', ' menampilkan/VB', ' (analytical jumlah/NN guru/NN besar/JJ)', ' berdasarkan/VB', ' jenis/NND', ' PT/NN', ' per/IN', ' tahun/NN)']\n", "16 ['(S', ' Aplikasi/NN', ' menampilkan/VB', ' (analytical jumlah/NN guru/NN besar/JJ)', ' berdasarkan/VB', ' PT/NN', ' per/IN', ' tahun/NN)']\n", "17 ['(S', ' Aplikasi/NN', ' menampilkan/VB', ' (analytical jumlah/NN guru/NN besar/JJ)', ' berdasarkan/VB', ' lokasi/NN', ' geografis/NN', ' per/IN', ' tahun/NN)']\n", "22 ['(S', ' Aplikasi/NN', ' (PPattachment', ' menampilkan/VB', ' jumlah/NN', ' dosen/JJ', ' per/IN', ' jabatan/NN', ' akademik/JJ)', ' per/IN', ' tahun/NN)']\n", "{40: 'vague', 1: 'analytical', 11: 'analytical', 14: 'analytical', 15: 'analytical', 16: 'analytical', 17: 'analytical', 22: 'PPattachment'}\n" ] } ], "source": [ "kataAnalytical = \"analytical\"\n", "kataPPattachment = \"PPattachment\"\n", "kataCoordination = \"coordination\"\n", "countAnalytical = 0\n", "countCoordination = 0\n", "countPPattachment = 0\n", "for i in range(len(polaAmbiguity)):\n", " for j in polaAmbiguity[i]:\n", " if (kataAnalytical in j):\n", " print(i,polaAmbiguity[i])\n", " if i in dictionaryAmbiguity:\n", " dictionaryAmbiguity[i] += ', analytical'\n", " else:\n", " dictionaryAmbiguity[i] = 'analytical'\n", " countAnalytical+=1\n", " if (kataCoordination in j):\n", " print(i,polaAmbiguity[i])\n", " if i in dictionaryAmbiguity:\n", " dictionaryAmbiguity[i] += ', coordination'\n", " else:\n", " dictionaryAmbiguity[i] = 'coordination'\n", " countCoordination+=1\n", " if (kataPPattachment in j):\n", " print(i,polaAmbiguity[i])\n", " if i in dictionaryAmbiguity:\n", " dictionaryAmbiguity[i] += ', PPattachment'\n", " else:\n", " dictionaryAmbiguity[i] = 'PPattachment'\n", " countPPattachment+=1\n", "print(dictionaryAmbiguity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 7. Data Hasil Analisis Jenis Ambiguitas" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "11\n", "14\n", "15\n", "16\n", "17\n", "22\n", "40\n" ] } ], "source": [ "listSentences = []\n", "for i in range(len(sentences)):\n", " if i in dictionaryAmbiguity.keys():\n", " print(i)\n", " listSentences.append((sentences[i],dictionaryAmbiguity[i]))\n", " else:\n", " listSentences.append((sentences[i],'-'))" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Jumlah Kata Vague: 1\n", "Jumlah Ambiguitas Analitis: 6\n", "Jumlah Ambiguitas Corrdination: 0\n", "Jumlah Ambiguitas PP Attachment: 1\n", "Total Ambiguitas Struktural dalam dokumen: 8\n" ] } ], "source": [ "print(\"Jumlah Kata Vague: \",countVague)\n", "# print(\"Jumlah Missing Unit of Measurement: \",countMUoM)\n", "print(\"Jumlah Ambiguitas Analitis: \",countAnalytical)\n", "print(\"Jumlah Ambiguitas Corrdination: \",countCoordination)\n", "print(\"Jumlah Ambiguitas PP Attachment: \",countPPattachment)\n", "totalAmbiguitasStruktural = countVague+countAnalytical+countCoordination+countPPattachment\n", "print(\"Total Ambiguitas Struktural dalam dokumen: \",totalAmbiguitasStruktural)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 8. Transformasi Data ke Dokumen" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Pernyataan Kebutuhan PLUrutan Tag Kebutuhan PLJenis Ambiguitas
0[Aplikasi, mampu, melakukan, pengelolaan, terh...[NN, JJ, VB, NN, IN, NN, NN, SC, VB, IN, NN, N...-
1[Mampu, menambahkan, data, user, baru][NN, VB, NN, NN, JJ]analytical
2[Mampu, mengubah, data, user][NN, VB, NN, NN]-
3[Mampu, menghapus, data, user][NN, VB, NN, NN]-
4[Aplikasi, menampilkan, jumlah, kumulatif, IPK...[NN, VB, NN, NN, NNP, IN, NN]-
5[Aplikasi, menampilkan, jumlah, APK, berdasark...[NN, VB, NN, NN, VB, NN, IN, NN]-
6[Aplikasi, menampilkan, jumlah, APK, berdasark...[NN, VB, NN, NN, VB, NN, IN, NN]-
7[Aplikasi, menampilkan, perbandingan, lama, st...[NN, VB, NN, NN, NN, IN, NN, NN, NN, IN, NN, Z...-
8[Aplikasi, menampilkan, lama, studi, dengan, w...[NN, VB, NN, NN, IN, NN, NN, NN, IN, NN, IN, NN]-
9[Aplikasi, menampilkan, lama, studi, dengan, w...[NN, VB, NN, NN, IN, NN, NN, NN, VB, NN, NN, I...-
10[Aplikasi, menampilkan, rasio, jumlah, dosen, ...[NN, VB, NN, NN, NN, CC, NN, IN, NN]-
11[Aplikasi, menampilkan, rasio, jumlah, dosen, ...[NN, VB, NN, NN, NN, CC, NN, VB, NND, NN, JJ, ...analytical
12[Aplikasi, menampilkan, rasio, jumlah, dosen, ...[NN, VB, NN, NN, NN, CC, NN, VB, NN, JJ]-
13[Aplikasi, menampilkan, rasio, jumlah, dosen, ...[NN, VB, NN, NN, NN, CC, NN, VB, NN, NN]-
14[Aplikasi, menampilkan, jumlah, guru, besar, p...[NN, VB, NN, NN, JJ, IN, NN]analytical
15[Aplikasi, menampilkan, jumlah, guru, besar, b...[NN, VB, NN, NN, JJ, VB, NND, NN, IN, NN]analytical
16[Aplikasi, menampilkan, jumlah, guru, besar, b...[NN, VB, NN, NN, JJ, VB, NN, IN, NN]analytical
17[Aplikasi, menampilkan, jumlah, guru, besar, b...[NN, VB, NN, NN, JJ, VB, NN, NN, IN, NN]analytical
18[Aplikasi, menampilkan, jumlah, dosen, pertahun][NN, VB, NN, NN, NN]-
19[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NND, NN, IN, NN]-
20[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, IN, NN]-
21[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, NN, IN, NN]-
22[Aplikasi, menampilkan, jumlah, dosen, per, ja...[NN, VB, NN, JJ, IN, NN, JJ, IN, NN]PPattachment
23[Aplikasi, menampilkan, jumlah, dosen, per, ja...[NN, VB, NN, NN, IN, NN, JJ, VB, NND, NN, IN, NN]-
24[Aplikasi, menampilkan, jumlah, dosen, per, ja...[NN, VB, NN, NN, IN, NN, JJ, VB, NN, IN, NN]-
25[Aplikasi, menampilkan, jumlah, dosen, per, ja...[NN, VB, NN, NN, IN, NN, JJ, VB, NN, NN, IN, NN]-
26[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, NN, IN, NN]-
27[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, JJ, IN, NN]-
28[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, NN, IN, NN]-
29[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, NN, NN, IN, NN]-
30[Aplikasi, menampilkan, jumlah, dosen, berdasa...[NN, VB, NN, NN, VB, NN, IN, NN]-
31[Aplikasi, menampilkan, jumlah, mahasiswa, per...[NN, VB, NN, NN, IN, NN, IN, NN]-
32[Aplikasi, menampilkan, jumlah, mahasiswa, per...[NN, VB, NN, NN, IN, NN, NN, IN, NN]-
33[Aplikasi, menampilkan, jumlah, mahasiswa, ber...[NN, VB, NN, NN, VB, NN, IN, NN]-
34[Aplikasi, menampilkan, jumlah, mahasiswa, ber...[NN, VB, NN, NN, VB, NN, IN, NN]-
35[Aplikasi, menampilkan, jumlah, mahasiswa, ber...[NN, VB, NN, NN, VB, NN, IN, NN]-
36[Aplikasi, menampilkan, jumlah, PT, per, semes...[NN, VB, NN, NN, IN, NN]-
37[Aplikasi, menampilkan, jumlah, PT, berdasarka...[NN, VB, NN, NN, VB, NN, IN, NN]-
38[Aplikasi, menampilkan, jumlah, PT, berdasarka...[NN, VB, NND, NN, VB, NND, NN, IN, NN]-
39[Ketersediaan, aplikasi, yang, dapat, di, upda...[NN, NN, SC, MD, IN, NN, NN, NN, CC, MD, JJ, V...-
40[Aplikasi, yang, dikembangkan, nantinya, harus...[NN, SC, VB, NN, MD, VB, NN, NN, SC, JJ, NN, V...vague
41[Aplikasi, yang, dikembangkan, nantinya, harus...[NN, SC, VB, NN, MD, VB, NN, NN, SC, JJ, NN, C...-
\n", "
" ], "text/plain": [ " Pernyataan Kebutuhan PL \\\n", "0 [Aplikasi, mampu, melakukan, pengelolaan, terh... \n", "1 [Mampu, menambahkan, data, user, baru] \n", "2 [Mampu, mengubah, data, user] \n", "3 [Mampu, menghapus, data, user] \n", "4 [Aplikasi, menampilkan, jumlah, kumulatif, IPK... \n", "5 [Aplikasi, menampilkan, jumlah, APK, berdasark... \n", "6 [Aplikasi, menampilkan, jumlah, APK, berdasark... \n", "7 [Aplikasi, menampilkan, perbandingan, lama, st... \n", "8 [Aplikasi, menampilkan, lama, studi, dengan, w... \n", "9 [Aplikasi, menampilkan, lama, studi, dengan, w... \n", "10 [Aplikasi, menampilkan, rasio, jumlah, dosen, ... \n", "11 [Aplikasi, menampilkan, rasio, jumlah, dosen, ... \n", "12 [Aplikasi, menampilkan, rasio, jumlah, dosen, ... \n", "13 [Aplikasi, menampilkan, rasio, jumlah, dosen, ... \n", "14 [Aplikasi, menampilkan, jumlah, guru, besar, p... \n", "15 [Aplikasi, menampilkan, jumlah, guru, besar, b... \n", "16 [Aplikasi, menampilkan, jumlah, guru, besar, b... \n", "17 [Aplikasi, menampilkan, jumlah, guru, besar, b... \n", "18 [Aplikasi, menampilkan, jumlah, dosen, pertahun] \n", "19 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "20 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "21 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "22 [Aplikasi, menampilkan, jumlah, dosen, per, ja... \n", "23 [Aplikasi, menampilkan, jumlah, dosen, per, ja... \n", "24 [Aplikasi, menampilkan, jumlah, dosen, per, ja... \n", "25 [Aplikasi, menampilkan, jumlah, dosen, per, ja... \n", "26 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "27 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "28 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "29 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "30 [Aplikasi, menampilkan, jumlah, dosen, berdasa... \n", "31 [Aplikasi, menampilkan, jumlah, mahasiswa, per... \n", "32 [Aplikasi, menampilkan, jumlah, mahasiswa, per... \n", "33 [Aplikasi, menampilkan, jumlah, mahasiswa, ber... \n", "34 [Aplikasi, menampilkan, jumlah, mahasiswa, ber... \n", "35 [Aplikasi, menampilkan, jumlah, mahasiswa, ber... \n", "36 [Aplikasi, menampilkan, jumlah, PT, per, semes... \n", "37 [Aplikasi, menampilkan, jumlah, PT, berdasarka... \n", "38 [Aplikasi, menampilkan, jumlah, PT, berdasarka... \n", "39 [Ketersediaan, aplikasi, yang, dapat, di, upda... \n", "40 [Aplikasi, yang, dikembangkan, nantinya, harus... \n", "41 [Aplikasi, yang, dikembangkan, nantinya, harus... \n", "\n", " Urutan Tag Kebutuhan PL Jenis Ambiguitas \n", "0 [NN, JJ, VB, NN, IN, NN, NN, SC, VB, IN, NN, N... - \n", "1 [NN, VB, NN, NN, JJ] analytical \n", "2 [NN, VB, NN, NN] - \n", "3 [NN, VB, NN, NN] - \n", "4 [NN, VB, NN, NN, NNP, IN, NN] - \n", "5 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "6 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "7 [NN, VB, NN, NN, NN, IN, NN, NN, NN, IN, NN, Z... - \n", "8 [NN, VB, NN, NN, IN, NN, NN, NN, IN, NN, IN, NN] - \n", "9 [NN, VB, NN, NN, IN, NN, NN, NN, VB, NN, NN, I... - \n", "10 [NN, VB, NN, NN, NN, CC, NN, IN, NN] - \n", "11 [NN, VB, NN, NN, NN, CC, NN, VB, NND, NN, JJ, ... analytical \n", "12 [NN, VB, NN, NN, NN, CC, NN, VB, NN, JJ] - \n", "13 [NN, VB, NN, NN, NN, CC, NN, VB, NN, NN] - \n", "14 [NN, VB, NN, NN, JJ, IN, NN] analytical \n", "15 [NN, VB, NN, NN, JJ, VB, NND, NN, IN, NN] analytical \n", "16 [NN, VB, NN, NN, JJ, VB, NN, IN, NN] analytical \n", "17 [NN, VB, NN, NN, JJ, VB, NN, NN, IN, NN] analytical \n", "18 [NN, VB, NN, NN, NN] - \n", "19 [NN, VB, NN, NN, VB, NND, NN, IN, NN] - \n", "20 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "21 [NN, VB, NN, NN, VB, NN, NN, IN, NN] - \n", "22 [NN, VB, NN, JJ, IN, NN, JJ, IN, NN] PPattachment \n", "23 [NN, VB, NN, NN, IN, NN, JJ, VB, NND, NN, IN, NN] - \n", "24 [NN, VB, NN, NN, IN, NN, JJ, VB, NN, IN, NN] - \n", "25 [NN, VB, NN, NN, IN, NN, JJ, VB, NN, NN, IN, NN] - \n", "26 [NN, VB, NN, NN, VB, NN, NN, IN, NN] - \n", "27 [NN, VB, NN, NN, VB, JJ, IN, NN] - \n", "28 [NN, VB, NN, NN, VB, NN, NN, IN, NN] - \n", "29 [NN, VB, NN, NN, VB, NN, NN, NN, IN, NN] - \n", "30 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "31 [NN, VB, NN, NN, IN, NN, IN, NN] - \n", "32 [NN, VB, NN, NN, IN, NN, NN, IN, NN] - \n", "33 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "34 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "35 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "36 [NN, VB, NN, NN, IN, NN] - \n", "37 [NN, VB, NN, NN, VB, NN, IN, NN] - \n", "38 [NN, VB, NND, NN, VB, NND, NN, IN, NN] - \n", "39 [NN, NN, SC, MD, IN, NN, NN, NN, CC, MD, JJ, V... - \n", "40 [NN, SC, VB, NN, MD, VB, NN, NN, SC, JJ, NN, V... vague \n", "41 [NN, SC, VB, NN, MD, VB, NN, NN, SC, JJ, NN, C... - " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw_data = {\n", " 'Pernyataan Kebutuhan PL': [kalimat[i] for i in range(len(kalimat))],\n", " 'Urutan Tag Kebutuhan PL': [tags[i] for i in range(len(tags))],\n", " 'Jenis Ambiguitas': [listSentences[i][1] for i in range(len(listSentences))]\n", " }\n", "df = pd.DataFrame(raw_data,columns=['Pernyataan Kebutuhan PL','Urutan Tag Kebutuhan PL','Jenis Ambiguitas'])\n", "fileHasilAnalisis=\"Hasil Analisis/Analisis \"+inputreadfile+\".csv\"\n", "df.to_csv(fileHasilAnalisis,encoding='utf-8')\n", "df" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" } }, "nbformat": 4, "nbformat_minor": 2 }