Commit b93842e7 by Yolanda Nainggolan

add view dataframe function

parent 8f40867f
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -13,8 +13,30 @@ from itertools import count ...@@ -13,8 +13,30 @@ from itertools import count
import collections import collections
import math import math
from xml.etree.ElementTree import ElementTree from xml.etree.ElementTree import ElementTree
import pandas as pd
from django.shortcuts import render
import xml.etree.ElementTree as et
def data_view(data):
df_cols = ["DOCNO", "SONG", "ARTIST", "LYRICS"]
rows = []
for node in data:
s_docno = node.find("DOCNO").text if node is not None else None
s_song = node.find("SONG").text if node is not None else None
s_artist = node.find("ARTIST").text if node is not None else None
s_lyrics = node.find("LYRICS").text if node is not None else None
rows.append({"DOCNO": s_docno, "SONG": s_song,
"ARTIST": s_artist, "LYRICS": s_lyrics})
DataFrame = pd.DataFrame(rows, columns = df_cols)
return render(data, 'apps/dataframe.html', {'DataFrame': DataFrame})
##############Remove Punctuation, URL and Tokenize################### ##############Remove Punctuation, URL and Tokenize###################
def remove_punc_tokenize(sentence): def remove_punc_tokenize(sentence):
tokens = [] tokens = []
...@@ -80,7 +102,7 @@ def main(query): ...@@ -80,7 +102,7 @@ def main(query):
for i in range(N_DOC): for i in range(N_DOC):
tokens_doc[i] = to_lower(tokens_doc[i]) tokens_doc[i] = to_lower(tokens_doc[i])
stop_words = set(stopwords.words('indonesian')) stop_words = set(stopwords.words('english'))
stopping = [] stopping = []
for i in range(N_DOC): for i in range(N_DOC):
......
...@@ -95,6 +95,7 @@ main { ...@@ -95,6 +95,7 @@ main {
#content { #content {
width: 100%; width: 100%;
height: 100%;
} }
* { * {
...@@ -150,3 +151,26 @@ table, th, td { ...@@ -150,3 +151,26 @@ table, th, td {
border-collapse: collapse; border-collapse: collapse;
text-align: center; text-align: center;
} }
form button {
display: inline-block;
border-radius: 4px;
background-color: #7c1ca6;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 10px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
width: 80px;
}
input {
color: #000000;
border-radius: 4px;
text-align: center;
font-size: 30px;
width: 50%;
}
\ No newline at end of file
...@@ -17,19 +17,17 @@ ...@@ -17,19 +17,17 @@
<center><h1>Dataset</h1><br> <center><h1>Dataset</h1><br>
<table style="width:100%"> <table style="width:100%">
<tr> <tr>
<th>Judul</th> {% for data in DataFrame %}
<th>Penyanyi</th> <th>{{ data }}</th>
<th>tahun</th> {% endfor %}
</tr>
<tr> {% for i, row in DataFrame.iterrows %}
<td>Aku dan dirimu</td> <tr>
<td>Ari Lasso</td> {% for value in data %}
<td>2007</td> <td>{{ value }}</td>
</tr> {% endfor %}
<tr> </tr>
<td>Pupus</td> {% endfor %}
<td>Dewa19</td>
<td>2008</td>
</tr> </tr>
</table> </table>
</center> </center>
...@@ -46,7 +44,7 @@ ...@@ -46,7 +44,7 @@
<script> <script>
function pageRedirect() { function pageRedirect() {
window.location.href = "../../templates/apps/preprocessing.html"; window.location.href = "/preprocessing";
} }
</script> </script>
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<script> <script>
function pageRedirect() { function pageRedirect() {
window.location.href = "../../templates/apps/dataframe.html"; window.location.href = "/dataframe";
} }
</script> </script>
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head>
<head> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Song Lyric Search Engine</title>
<meta charset="utf-8"> <link href="../../static/assets/css/dataframe.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> </head>
<meta name="description" content="">
<meta name="author" content=""> <body>
<main>
<title>Inverted Index</title> <div id="content">
<article class="card">
<!-- Bootstrap core CSS --> <div class="row">
<link href="../../static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <center><h1 style="font-size:45px">Searching!<br></h1>
<p style="font-size:20px"><strong>Silahkan masukkan lirik dari lagu yang ingin Anda temukan</strong></p>
<!-- Custom fonts for this template -->
<link href="../../static/assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet"> <form method="POST" action="/result/">
<link href="../../static/assets/vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet" type="text/css"> {% csrf_token %}
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css"> <div class="form-row">
<input type="text" name="querysearch" placeholder="Masukkan Query Anda..."> <br>
<!-- Custom styles for this template --> <button type="submit">Cari!</button>
<link href="../../static/assets/css/landing-page.min.css" rel="stylesheet"> </div>
</form>
</head> </div>
</center>
<body> </article>
</div>
<!-- Navigation --> </main>
<nav class="navbar navbar-light bg-light static-top">
<div class="container"> <footer>
<a class="navbar-brand" href="/">CariLagu</a> <p>&copy; STBI-2020-03</p>
</div> </footer>
</nav>
</body>
<!-- Masthead -->
<header class="masthead text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-xl-9 mx-auto">
<h1 class="mb-5">Silahkan masukkan lirik dari lagu yang ingin Anda temukan</h1>
</div>
<div class="col-md-10 col-lg-8 col-xl-7 mx-auto">
<form method="POST" action="../../templates/apps/result.html">
{% csrf_token %}
<div class="form-row">
<div class="col-12 col-md-9 mb-2 mb-md-0">
<input type="text" class="form-control form-control-lg" name="querysearch" placeholder="Masukkan Query Anda...">
</div>
<div class="col-12 col-md-3">
<button type="submit" class="btn btn-block btn-lg btn-primary">Cari!</button>
</div>
</div>
</form>
</div>
</div>
</div>
</header>
<!-- Bootstrap core JavaScript -->
<script src="../../static/assets/vendor/jquery/jquery.min.js"></script>
<script src="../../static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Song Lyric Search Engine</title>
<link href="../../static/assets/css/dataframe.min.css" rel="stylesheet">
</head>
<body>
<main>
<div id="content">
<article class="card">
<div align="right">
<button onclick="pageRedirect()" class="button" style="vertical-align:middle"><span>Next</span></button>
</div>
<center><h1>Indexing</h1><br></center>
</article>
</div>
</main>
<footer>
<p>&copy; STBI-2020-03</p>
</footer>
</body>
<script>
function pageRedirect() {
window.location.href = "/index";
}
</script>
</html>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<script> <script>
function pageRedirect() { function pageRedirect() {
window.location.href = "../../templates/apps/index.html"; window.location.href = "/indexing";
} }
</script> </script>
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<div class="col-lg-4"> <div class="col-lg-4">
<div class="testimonial-item mx-auto mb-5 mb-lg-0"> <div class="testimonial-item mx-auto mb-5 mb-lg-0">
<img class="img-fluid rounded-circle mb-3" src="../../static/img/hkbp.jpg" alt=""> <img class="img-fluid rounded-circle mb-3" src="../../static/img/hkbp.jpg" alt="">
<h5><a href="/lyric/{{j.docno}}">Lagu No:{{ j.docno }}</a></h5> <h5><a href="/lyric">Lagu No:{{ j.docno }}</a></h5>
<h5>"{{ j.judul }}"</h5> <h5>"{{ j.judul }}"</h5>
<p class="font-weight-light mb-0">score :{{ j.score }}</p> <p class="font-weight-light mb-0">score :{{ j.score }}</p>
</div> </div>
......
...@@ -8,10 +8,10 @@ app_name = 'InvertedIndexSimulator' ...@@ -8,10 +8,10 @@ app_name = 'InvertedIndexSimulator'
urlpatterns = [ urlpatterns = [
path('', views.home), path('', views.home),
path('dataframe/', views.dataframe),
path('preprocessing/', views.preprocessing),
path('indexing/', views.indexing),
path('index/', views.index), path('index/', views.index),
path('result/', views.result), path('result/', views.result),
path('lyric/<int:id>', views.lyric, name='lyric'), path('lyric/<int:id>', views.lyric, name='lyric'),
] ]
\ No newline at end of file
...@@ -8,6 +8,22 @@ from InvertedIndexSimulator.inverted import main ...@@ -8,6 +8,22 @@ from InvertedIndexSimulator.inverted import main
def home(request): def home(request):
return render(request, 'apps/home.html') return render(request, 'apps/home.html')
def dataframe(request):
import pandas as pd
import xml.etree.ElementTree as et
parse_data = et.parse("InvertedIndexSimulator/data/dataset_STBI.xml")
data = parse_data.getroot()
content = main.data_view(data)
return render(request, 'apps/dataframe.html', content)
def preprocessing(request):
return render(request, 'apps/preprocessing.html')
def indexing(request):
return render(request, 'apps/indexing.html')
def index(request): def index(request):
return render(request, 'apps/index.html') return render(request, 'apps/index.html')
...@@ -27,6 +43,7 @@ def result(request): ...@@ -27,6 +43,7 @@ def result(request):
# proximity_index = collections.OrderedDict(sorted(proximity_index.items())) # proximity_index = collections.OrderedDict(sorted(proximity_index.items()))
# for key, value in proximity_index.items(): # for key, value in proximity_index.items():
# # print (key, value) # # print (key, value)
if request.method == 'POST': if request.method == 'POST':
query = request.POST['querysearch'] query = request.POST['querysearch']
hasil= main.main(query) hasil= main.main(query)
...@@ -35,4 +52,4 @@ def result(request): ...@@ -35,4 +52,4 @@ def result(request):
'hasil':hasil, 'hasil':hasil,
'query':query 'query':query
} }
return render(request, 'apps/result.html',content) return render(request, 'apps/result.html', content)
...@@ -68,6 +68,8 @@ TEMPLATES = [ ...@@ -68,6 +68,8 @@ TEMPLATES = [
}, },
] ]
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
WSGI_APPLICATION = 'SearchEngine.wsgi.application' WSGI_APPLICATION = 'SearchEngine.wsgi.application'
......
...@@ -20,10 +20,11 @@ from InvertedIndexSimulator import views ...@@ -20,10 +20,11 @@ from InvertedIndexSimulator import views
urlpatterns = [ urlpatterns = [
path('', views.home), path('', views.home),
path('dataframe/', views.dataframe),
path('preprocessing/', views.preprocessing),
path('indexing/', views.indexing),
path('index/', views.index), path('index/', views.index),
path('result/', views.result), path('result/', views.result),
path('lyric/<int:id>', views.lyric, name='lyric'), path('lyric/<int:id>', views.lyric, name='lyric'),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment