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
import collections
import math
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###################
def remove_punc_tokenize(sentence):
tokens = []
......@@ -80,7 +102,7 @@ def main(query):
for i in range(N_DOC):
tokens_doc[i] = to_lower(tokens_doc[i])
stop_words = set(stopwords.words('indonesian'))
stop_words = set(stopwords.words('english'))
stopping = []
for i in range(N_DOC):
......
......@@ -95,6 +95,7 @@ main {
#content {
width: 100%;
height: 100%;
}
* {
......@@ -150,3 +151,26 @@ table, th, td {
border-collapse: collapse;
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 @@
<center><h1>Dataset</h1><br>
<table style="width:100%">
<tr>
<th>Judul</th>
<th>Penyanyi</th>
<th>tahun</th>
</tr>
<tr>
<td>Aku dan dirimu</td>
<td>Ari Lasso</td>
<td>2007</td>
</tr>
<tr>
<td>Pupus</td>
<td>Dewa19</td>
<td>2008</td>
{% for data in DataFrame %}
<th>{{ data }}</th>
{% endfor %}
{% for i, row in DataFrame.iterrows %}
<tr>
{% for value in data %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</tr>
</table>
</center>
......@@ -46,7 +44,7 @@
<script>
function pageRedirect() {
window.location.href = "../../templates/apps/preprocessing.html";
window.location.href = "/preprocessing";
}
</script>
......
......@@ -40,7 +40,7 @@
<script>
function pageRedirect() {
window.location.href = "../../templates/apps/dataframe.html";
window.location.href = "/dataframe";
}
</script>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Inverted Index</title>
<!-- Bootstrap core CSS -->
<link href="../../static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom fonts for this template -->
<link href="../../static/assets/vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
<link href="../../static/assets/vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="../../static/assets/css/landing-page.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-light bg-light static-top">
<div class="container">
<a class="navbar-brand" href="/">CariLagu</a>
</div>
</nav>
<!-- 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>
<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 class="row">
<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>
<form method="POST" action="/result/">
{% csrf_token %}
<div class="form-row">
<input type="text" name="querysearch" placeholder="Masukkan Query Anda..."> <br>
<button type="submit">Cari!</button>
</div>
</form>
</div>
</center>
</article>
</div>
</main>
<footer>
<p>&copy; STBI-2020-03</p>
</footer>
</body>
</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 @@
<script>
function pageRedirect() {
window.location.href = "../../templates/apps/index.html";
window.location.href = "/indexing";
}
</script>
......
......@@ -45,7 +45,7 @@
<div class="col-lg-4">
<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="">
<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>
<p class="font-weight-light mb-0">score :{{ j.score }}</p>
</div>
......
......@@ -8,10 +8,10 @@ app_name = 'InvertedIndexSimulator'
urlpatterns = [
path('', views.home),
path('dataframe/', views.dataframe),
path('preprocessing/', views.preprocessing),
path('indexing/', views.indexing),
path('index/', views.index),
path('result/', views.result),
path('lyric/<int:id>', views.lyric, name='lyric'),
]
\ No newline at end of file
......@@ -8,6 +8,22 @@ from InvertedIndexSimulator.inverted import main
def home(request):
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):
return render(request, 'apps/index.html')
......@@ -27,6 +43,7 @@ def result(request):
# proximity_index = collections.OrderedDict(sorted(proximity_index.items()))
# for key, value in proximity_index.items():
# # print (key, value)
if request.method == 'POST':
query = request.POST['querysearch']
hasil= main.main(query)
......@@ -35,4 +52,4 @@ def result(request):
'hasil':hasil,
'query':query
}
return render(request, 'apps/result.html',content)
return render(request, 'apps/result.html', content)
......@@ -68,6 +68,8 @@ TEMPLATES = [
},
]
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
WSGI_APPLICATION = 'SearchEngine.wsgi.application'
......
......@@ -20,10 +20,11 @@ from InvertedIndexSimulator import views
urlpatterns = [
path('', views.home),
path('dataframe/', views.dataframe),
path('preprocessing/', views.preprocessing),
path('indexing/', views.indexing),
path('index/', views.index),
path('result/', views.result),
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