Commit 188c3fbd by andreas

website

parent f24c8ae6
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import string
import re
from sklearn.feature_extraction.text import CountVectorizer
import xml.dom.minidom as minidom
dcmnt_xml = minidom.parse("Dataset_Article.xml")
# In[2]:
all_doc_no = dcmnt_xml.getElementsByTagName('Id')
all_profile = dcmnt_xml.getElementsByTagName('title')
all_date = dcmnt_xml.getElementsByTagName('year')
all_text = dcmnt_xml.getElementsByTagName('content')
all_pub = dcmnt_xml.getElementsByTagName('author')
N_DOC_sample = len(all_doc_no)
# In[3]:
# print(N_DOC_sample)
# In[4]:
all_sentence_doc_sample = []
for i in range(N_DOC_sample):
sentence_doc_sample = ' '+ all_text[i].firstChild.data
all_sentence_doc_sample.append(sentence_doc_sample)
# In[5]:
all_sentence_doc_sample
# print(all_sentence_doc_sample)
# ## Preprocessing
# In[6]:
tokens_doc = []
# In[7]:
def remove_punc_tokenize(sentence):
tokens = []
for punctuation in string.punctuation:
sentence = sentence.replace(punctuation," ")
sentence = re.sub(r'^https?:\/\/.*[\r\n]*', '', sentence, flags=re.MULTILINE)
for w in CountVectorizer().build_tokenizer()(sentence):
tokens.append(w)
return tokens
# In[8]:
for i in range(N_DOC_sample):
tokens_doc.append(remove_punc_tokenize(all_sentence_doc_sample[i]))
# In[9]:
tokens_doc
# print(tokens_doc)
# In[10]:
import nltk
# nltk.download('stopwords')
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
def stop_word_token(tokens):
tokens = [w for w in tokens if not w in stop_words]
return tokens
for i in range(N_DOC_sample):
tokens_doc[i] = stop_word_token(tokens_doc[i])
# In[11]:
for i in range(N_DOC_sample):
tokens_doc[i] = ([w for w in tokens_doc[i] if not any(j.isdigit() for j in w)])
# In[12]:
tokens_doc
# print(tokens_doc)
# In[13]:
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
def stemming(tokens):
for i in range(0, len(tokens)):
if (tokens[i] != stemmer.stem(tokens[i])):
tokens[i] = stemmer.stem(tokens[i])
return tokens
for i in range(N_DOC_sample):
tokens_doc[i] = stemming(tokens_doc[i])
# print("aa")
# In[14]:
all_tokens = []
for i in range(N_DOC_sample):
for w in tokens_doc[i]:
all_tokens.append(w)
new_sentence = ' '.join([w for w in all_tokens])
for w in CountVectorizer().build_tokenizer()(new_sentence):
all_tokens.append(w)
# In[15]:
all_tokens
# print(all_tokens)
# In[16]:
# print("aaa")
from itertools import count
try:
from itertools import izip as zip
except ImportError:
pass
proximity_index = {}
for token in all_tokens:
dict_doc_position = {}
for n in range(N_DOC_sample):
if(token in tokens_doc[n]):
dict_doc_position[all_doc_no[n].firstChild.data] = [i+1 for i, j in zip(count(), tokens_doc[n]) if j == token]
proximity_index[token] = dict_doc_position
# print("aaa")
# In[17]:
import sys
text = sys.argv[1]
import collections
proximity_index = collections.OrderedDict(sorted(proximity_index.items()))
for key, value in proximity_index.items():
if(key == text):
print (key, value)
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 2.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=wjy&krc(c696%*n6)dcrj=htk@01hkp+q7-nr+6%iuc^)r!ls'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#mysil
'polls',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'
"""mysite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
from django.contrib import admin
from polls.views import home_view, contact_view, result_view, data_view, button, output, external
urlpatterns = [
path('', home_view, name='home'),
path('silv/', contact_view, name='home'),
path('data/', data_view, name='home'),
path('result/', result_view, name='home'),
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
# url(r'^admin/', admin.site.urls),
url('test/', button),
url('output/', output,name="script"),
url('external/', external),
]
"""
WSGI config for mysite project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
from django.contrib import admin
# Register your models here.
from .models import Product
admin.site.register(Product)
\ No newline at end of file
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
# Generated by Django 2.0.5 on 2020-05-26 05:10
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tittle', models.TextField()),
('describtion', models.TextField()),
('price', models.TextField()),
],
),
]
from django.db import models
# Create your models here.
class Product(models.Model):
tittle = models.TextField()
describtion = models.TextField()
price = models.TextField()
\ No newline at end of file
print ("Hello, Python!")
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
# path('', views.index, name='index'),
]
from django.shortcuts import render
from django.http import HttpResponse
import requests
# def index(request):
# return "Hello, world. You're at the polls index."
def home_view(request, *args, **kwargs):
# return HttpResponse("<h1> hello world </h1>")
return render(request, "index.html", {})
def contact_view(request, *args, **kwargs):
return render(request, "contact.html", {})
def data_view(request, *args, **kwargs):
my_data= {
"judul": "data yang ada",
"data" : 12324324,
"penguji": ["tenov", "mario", "mona"]
}
return render(request, "data.html", my_data)
def result_view(request, *args, **kwargs):
return render(request, "result.html", {})
# def button(request):
# return render(request,'home.html')
# def output(request):
# data=requests.get("https://www.google.com/")
# print(data.text)
# data=data.text
# return render(request,'home.html',{'data':data})
from subprocess import run,PIPE
import sys
def button(request):
return render(request,'home.html')
def output(request):
data=requests.get("https://www.google.com/")
print(data.text)
data=data.text
return render(request,'home.html',{'data':data})
def external(request):
inp= request.POST.get('param')
out= run([sys.executable,'//home//andreas//mysite//Project_STBI.py',inp],shell=False,stdout=PIPE)
print(out)
return render(request,'home.html',{'data1':out.stdout})
<!doctype html>
<html>
<head>
<title> Project STBI</title>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>hy sill how are you</h1>
<p>this is the template</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>hy sill how are you</h1>
<p>this is the template</p>
<p>
{{ judul }}
{{ data }}
{{ penguji }}
</p>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>
Python button script
</title>
</head>
<body>
<!-- <button onclick="location.href='{% url 'script' %}'">Execute Script</button> -->
<h1>Position of term in Collection</h1>
<hr>
{% if data %}
{{data | safe}}
{% endif %}
<form action="/external/" method="post">
{% csrf_token %}
Input Text:
<input type="text" name="param" required><br><br>
{{data_external}}<br><br>
{{data1}}
<br><br>
<input type="submit" value="Execute External Python Script">
</form>
</body>
</html>
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>hy sill how are you</h1>
<p>this is the template</p>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block content %}
<h1>hy sill how are you</h1>
<p>this is the template</p>
{% endblock %}
\ No newline at end of file
import sys
import datetime
time=datetime.datetime.now()
output="%s current time is %s" % (sys.argv[1],time)
print(output)
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